Annotation of loncom/interface/loncreateuser.pm, revision 1.406.2.20.2.3
1.20 harris41 1: # The LearningOnline Network with CAPA
1.1 www 2: # Create a user
3: #
1.406.2.20.2. (raeburn 4:): # $Id: loncreateuser.pm,v 1.406.2.20.2.2 2022/11/16 14:47:57 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.406.2.20 raeburn 74: use HTML::Entities;
1.1 www 75:
1.20 harris41 76: my $loginscript; # piece of javascript used in two separate instances
77: my $authformnop;
78: my $authformkrb;
79: my $authformint;
80: my $authformfsys;
81: my $authformloc;
82:
1.94 matthew 83: sub initialize_authen_forms {
1.227 raeburn 84: my ($dom,$formname,$curr_authtype,$mode) = @_;
85: my ($krbdef,$krbdefdom) = &Apache::loncommon::get_kerberos_defaults($dom);
86: my %param = ( formname => $formname,
1.187 raeburn 87: kerb_def_dom => $krbdefdom,
1.227 raeburn 88: kerb_def_auth => $krbdef,
1.187 raeburn 89: domain => $dom,
90: );
1.188 raeburn 91: my %abv_auth = &auth_abbrev();
1.227 raeburn 92: if ($curr_authtype =~ /^(krb4|krb5|internal|localauth|unix):(.*)$/) {
1.188 raeburn 93: my $long_auth = $1;
1.227 raeburn 94: my $curr_autharg = $2;
1.188 raeburn 95: my %abv_auth = &auth_abbrev();
96: $param{'curr_authtype'} = $abv_auth{$long_auth};
97: if ($long_auth =~ /^krb(4|5)$/) {
98: $param{'curr_kerb_ver'} = $1;
1.227 raeburn 99: $param{'curr_autharg'} = $curr_autharg;
1.188 raeburn 100: }
1.205 raeburn 101: if ($mode eq 'modifyuser') {
102: $param{'mode'} = $mode;
103: }
1.187 raeburn 104: }
1.227 raeburn 105: $loginscript = &Apache::loncommon::authform_header(%param);
106: $authformkrb = &Apache::loncommon::authform_kerberos(%param);
1.31 matthew 107: $authformnop = &Apache::loncommon::authform_nochange(%param);
108: $authformint = &Apache::loncommon::authform_internal(%param);
109: $authformfsys = &Apache::loncommon::authform_filesystem(%param);
110: $authformloc = &Apache::loncommon::authform_local(%param);
1.20 harris41 111: }
112:
1.188 raeburn 113: sub auth_abbrev {
114: my %abv_auth = (
1.368 raeburn 115: krb5 => 'krb',
116: krb4 => 'krb',
117: internal => 'int',
118: localauth => 'loc',
119: unix => 'fsys',
1.188 raeburn 120: );
121: return %abv_auth;
122: }
1.43 www 123:
1.134 raeburn 124: # ====================================================
125:
1.378 raeburn 126: sub user_quotas {
1.134 raeburn 127: my ($ccuname,$ccdomain) = @_;
128: my %lt = &Apache::lonlocal::texthash(
1.267 raeburn 129: 'usrt' => "User Tools",
130: 'cust' => "Custom quota",
131: 'chqu' => "Change quota",
1.134 raeburn 132: );
1.378 raeburn 133:
1.149 raeburn 134: my $quota_javascript = <<"END_SCRIPT";
135: <script type="text/javascript">
1.301 bisitz 136: // <![CDATA[
1.378 raeburn 137: function quota_changes(caller,context) {
138: var customoff = document.getElementById('custom_'+context+'quota_off');
139: var customon = document.getElementById('custom_'+context+'quota_on');
140: var number = document.getElementById(context+'quota');
1.149 raeburn 141: if (caller == "custom") {
1.378 raeburn 142: if (customoff) {
143: if (customoff.checked) {
144: number.value = "";
145: }
1.149 raeburn 146: }
147: }
148: if (caller == "quota") {
1.378 raeburn 149: if (customon) {
150: customon.checked = true;
151: }
1.149 raeburn 152: }
1.378 raeburn 153: return;
1.149 raeburn 154: }
1.301 bisitz 155: // ]]>
1.149 raeburn 156: </script>
157: END_SCRIPT
1.378 raeburn 158: my $longinsttype;
159: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($ccdomain);
1.267 raeburn 160: my $output = $quota_javascript."\n".
161: '<h3>'.$lt{'usrt'}.'</h3>'."\n".
162: &Apache::loncommon::start_data_table();
163:
1.406.2.6 raeburn 164: if ((&Apache::lonnet::allowed('mut',$ccdomain)) ||
165: (&Apache::lonnet::allowed('udp',$ccdomain))) {
1.275 raeburn 166: $output .= &build_tools_display($ccuname,$ccdomain,'tools');
1.267 raeburn 167: }
1.378 raeburn 168:
169: my %titles = &Apache::lonlocal::texthash (
170: portfolio => "Disk space allocated to user's portfolio files",
1.385 bisitz 171: author => "Disk space allocated to user's Authoring Space (if role assigned)",
1.378 raeburn 172: );
173: foreach my $name ('portfolio','author') {
174: my ($currquota,$quotatype,$inststatus,$defquota) =
175: &Apache::loncommon::get_user_quota($ccuname,$ccdomain,$name);
176: if ($longinsttype eq '') {
177: if ($inststatus ne '') {
178: if ($usertypes->{$inststatus} ne '') {
179: $longinsttype = $usertypes->{$inststatus};
180: }
181: }
182: }
183: my ($showquota,$custom_on,$custom_off,$defaultinfo);
184: $custom_on = ' ';
185: $custom_off = ' checked="checked" ';
186: if ($quotatype eq 'custom') {
187: $custom_on = $custom_off;
188: $custom_off = ' ';
189: $showquota = $currquota;
190: if ($longinsttype eq '') {
191: $defaultinfo = &mt('For this user, the default quota would be [_1]'
1.383 raeburn 192: .' MB.',$defquota);
1.378 raeburn 193: } else {
194: $defaultinfo = &mt("For this user, the default quota would be [_1]".
1.383 raeburn 195: " MB, as determined by the user's institutional".
1.378 raeburn 196: " affiliation ([_2]).",$defquota,$longinsttype);
197: }
198: } else {
199: if ($longinsttype eq '') {
200: $defaultinfo = &mt('For this user, the default quota is [_1]'
1.383 raeburn 201: .' MB.',$defquota);
1.378 raeburn 202: } else {
203: $defaultinfo = &mt("For this user, the default quota of [_1]".
1.383 raeburn 204: " MB, is determined by the user's institutional".
1.378 raeburn 205: " affiliation ([_2]).",$defquota,$longinsttype);
206: }
207: }
208:
209: if (&Apache::lonnet::allowed('mpq',$ccdomain)) {
210: $output .= '<tr class="LC_info_row">'."\n".
211: ' <td>'.$titles{$name}.'</td>'."\n".
212: ' </tr>'."\n".
213: &Apache::loncommon::start_data_table_row()."\n".
1.390 bisitz 214: ' <td><span class="LC_nobreak">'.
215: &mt('Current quota: [_1] MB',$currquota).'</span> '.
1.378 raeburn 216: $defaultinfo.'</td>'."\n".
217: &Apache::loncommon::end_data_table_row()."\n".
218: &Apache::loncommon::start_data_table_row()."\n".
219: ' <td><span class="LC_nobreak">'.$lt{'chqu'}.
220: ': <label>'.
221: '<input type="radio" name="custom_'.$name.'quota" id="custom_'.$name.'quota_off" '.
1.379 raeburn 222: 'value="0" '.$custom_off.' onchange="javascript:quota_changes('."'custom','$name'".');"'.
1.390 bisitz 223: ' /><span class="LC_nobreak">'.
224: &mt('Default ([_1] MB)',$defquota).'</span></label> '.
1.378 raeburn 225: ' <label><input type="radio" name="custom_'.$name.'quota" id="custom_'.$name.'quota_on" '.
1.379 raeburn 226: 'value="1" '.$custom_on.' onchange="javascript:quota_changes('."'custom','$name'".');"'.
1.378 raeburn 227: ' />'.$lt{'cust'}.':</label> '.
1.379 raeburn 228: '<input type="text" name="'.$name.'quota" id="'.$name.'quota" size ="5" '.
229: 'value="'.$showquota.'" onfocus="javascript:quota_changes('."'quota','$name'".');"'.
1.390 bisitz 230: ' /> '.&mt('MB').'</span></td>'."\n".
1.378 raeburn 231: &Apache::loncommon::end_data_table_row()."\n";
232: }
233: }
1.267 raeburn 234: $output .= &Apache::loncommon::end_data_table();
1.134 raeburn 235: return $output;
236: }
237:
1.275 raeburn 238: sub build_tools_display {
239: my ($ccuname,$ccdomain,$context) = @_;
1.306 raeburn 240: my (@usertools,%userenv,$output,@options,%validations,%reqtitles,%reqdisplay,
1.332 raeburn 241: $colspan,$isadv,%domconfig);
1.275 raeburn 242: my %lt = &Apache::lonlocal::texthash (
243: 'blog' => "Personal User Blog",
244: 'aboutme' => "Personal Information Page",
1.385 bisitz 245: 'webdav' => "WebDAV access to Authoring Spaces (if SSL and author/co-author)",
1.275 raeburn 246: 'portfolio' => "Personal User Portfolio",
1.406.2.20.2. (raeburn 247:): 'timezone' => "Can set Time Zone",
1.275 raeburn 248: 'avai' => "Available",
249: 'cusa' => "availability",
250: 'chse' => "Change setting",
251: 'usde' => "Use default",
252: 'uscu' => "Use custom",
253: 'official' => 'Can request creation of official courses',
1.299 raeburn 254: 'unofficial' => 'Can request creation of unofficial courses',
255: 'community' => 'Can request creation of communities',
1.384 raeburn 256: 'textbook' => 'Can request creation of textbook courses',
1.362 raeburn 257: 'requestauthor' => 'Can request author space',
1.275 raeburn 258: );
1.406.2.20.2. (raeburn 259:): $isadv = &Apache::lonnet::is_advanced_user($ccdomain,$ccuname);
1.279 raeburn 260: if ($context eq 'requestcourses') {
1.275 raeburn 261: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
1.299 raeburn 262: 'requestcourses.official','requestcourses.unofficial',
1.384 raeburn 263: 'requestcourses.community','requestcourses.textbook');
264: @usertools = ('official','unofficial','community','textbook');
1.309 raeburn 265: @options =('norequest','approval','autolimit','validate');
1.306 raeburn 266: %validations = &Apache::lonnet::auto_courserequest_checks($ccdomain);
267: %reqtitles = &courserequest_titles();
268: %reqdisplay = &courserequest_display();
269: $colspan = ' colspan="2"';
1.332 raeburn 270: %domconfig =
271: &Apache::lonnet::get_dom('configuration',['requestcourses'],$ccdomain);
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',
1.406.2.20.2. (raeburn 285:): 'tools.webdav','tools.timezone');
286:): @usertools = ('aboutme','blog','webdav','portfolio','timezone');
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" ';
1.406.2.20.2. (raeburn 293:): $curr_access =
1.275 raeburn 294: &Apache::lonnet::usertools_access($ccuname,$ccdomain,$item,undef,
1.406.2.20.2. (raeburn 295:): $context,\%userenv,'',
296:): {'is_adv' => $isadv});
1.362 raeburn 297: if ($context eq 'requestauthor') {
298: if ($userenv{$context} ne '') {
299: $cust_on = ' checked="checked" ';
300: $cust_off = '';
301: }
302: } elsif ($userenv{$context.'.'.$item} ne '') {
1.306 raeburn 303: $cust_on = ' checked="checked" ';
304: $cust_off = '';
305: }
306: if ($context eq 'requestcourses') {
307: if ($userenv{$context.'.'.$item} eq '') {
1.314 raeburn 308: $custom_access = &mt('Currently from default setting.');
1.306 raeburn 309: } else {
310: $custom_access = &mt('Currently from custom setting.');
1.275 raeburn 311: }
1.362 raeburn 312: } elsif ($context eq 'requestauthor') {
313: if ($userenv{$context} eq '') {
314: $custom_access = &mt('Currently from default setting.');
315: } else {
316: $custom_access = &mt('Currently from custom setting.');
317: }
1.275 raeburn 318: } else {
1.306 raeburn 319: if ($userenv{$context.'.'.$item} eq '') {
1.314 raeburn 320: $custom_access =
1.306 raeburn 321: &mt('Availability determined currently from default setting.');
322: if (!$curr_access) {
323: $tool_off = 'checked="checked" ';
324: $tool_on = '';
325: }
326: } else {
1.314 raeburn 327: $custom_access =
1.306 raeburn 328: &mt('Availability determined currently from custom setting.');
329: if ($userenv{$context.'.'.$item} == 0) {
330: $tool_off = 'checked="checked" ';
331: $tool_on = '';
332: }
1.275 raeburn 333: }
334: }
335: $output .= ' <tr class="LC_info_row">'."\n".
1.306 raeburn 336: ' <td'.$colspan.'>'.$lt{$item}.'</td>'."\n".
1.275 raeburn 337: ' </tr>'."\n".
1.306 raeburn 338: &Apache::loncommon::start_data_table_row()."\n";
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).
432: $lt{'avai'}.': '.$currdisp.'</td>'."\n".
1.406.2.6 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.406.2.6 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.300 raeburn 457: );
458:
459: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
460: 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
1.384 raeburn 461: 'reqcrsotherdom.community','reqcrsotherdom.textbook');
462: @usertools = ('official','unofficial','community','textbook');
1.309 raeburn 463: @options = ('approval','validate','autolimit');
1.306 raeburn 464: %validations = &Apache::lonnet::auto_courserequest_checks($cdom);
465: my $optregex = join('|',@options);
466: my %reqtitles = &courserequest_titles();
1.300 raeburn 467: foreach my $item (@usertools) {
1.306 raeburn 468: my ($curroption,$currlimit,$tooloff);
1.300 raeburn 469: if ($userenv{'reqcrsotherdom.'.$item} ne '') {
470: my @curr = split(',',$userenv{'reqcrsotherdom.'.$item});
1.314 raeburn 471: foreach my $req (@curr) {
472: if ($req =~ /^\Q$cdom\E\:($optregex)=?(\d*)$/) {
473: $curroption = $1;
474: $currlimit = $2;
475: last;
1.306 raeburn 476: }
477: }
1.314 raeburn 478: if (!$curroption) {
479: $curroption = 'norequest';
480: $tooloff = ' checked="checked"';
481: }
1.306 raeburn 482: } else {
483: $curroption = 'norequest';
484: $tooloff = ' checked="checked"';
485: }
486: $output.= &Apache::loncommon::start_data_table_row()."\n".
1.314 raeburn 487: ' <td><span class="LC_nobreak">'.$lt{$item}.': </span></td><td>'.
488: '<table><tr><td valign="top">'."\n".
1.306 raeburn 489: '<label><input type="radio" name="reqcrsotherdom_'.$item.
1.314 raeburn 490: '" value=""'.$tooloff.' />'.$reqtitles{'norequest'}.
491: '</label></td>';
1.306 raeburn 492: foreach my $option (@options) {
493: if ($option eq 'validate') {
494: my $canvalidate = 0;
495: if (ref($validations{$item}) eq 'HASH') {
496: if ($validations{$item}{'_external_'}) {
497: $canvalidate = 1;
498: }
499: }
500: next if (!$canvalidate);
501: }
502: my $checked = '';
503: if ($option eq $curroption) {
504: $checked = ' checked="checked"';
505: }
1.314 raeburn 506: $output .= '<td valign="top"><span class="LC_nobreak"><label>'.
1.306 raeburn 507: '<input type="radio" name="reqcrsotherdom_'.$item.
508: '" value="'.$option.'"'.$checked.' />'.
1.314 raeburn 509: $reqtitles{$option}.'</label>';
1.306 raeburn 510: if ($option eq 'autolimit') {
1.314 raeburn 511: $output .= ' <input type="text" name="reqcrsotherdom_'.
1.306 raeburn 512: $item.'_limit" size="1" '.
1.314 raeburn 513: 'value="'.$currlimit.'" /></span>'.
514: '<br />'.$reqtitles{'unlimited'};
515: } else {
516: $output .= '</span>';
1.300 raeburn 517: }
1.314 raeburn 518: $output .= '</td>';
1.300 raeburn 519: }
1.314 raeburn 520: $output .= '</td></tr></table></td>'."\n".
1.300 raeburn 521: &Apache::loncommon::end_data_table_row()."\n";
522: }
523: return $output;
524: }
525:
1.362 raeburn 526: sub domainrole_req {
527: my ($ccuname,$ccdomain) = @_;
528: return '<br /><h3>'.
529: &mt('User Can Request Assignment of Domain Roles?').
530: '</h3>'."\n".
531: &Apache::loncommon::start_data_table().
532: &build_tools_display($ccuname,$ccdomain,
533: 'requestauthor').
534: &Apache::loncommon::end_data_table();
535: }
536:
1.306 raeburn 537: sub courserequest_titles {
538: my %titles = &Apache::lonlocal::texthash (
539: official => 'Official',
540: unofficial => 'Unofficial',
541: community => 'Communities',
1.384 raeburn 542: textbook => 'Textbook',
1.306 raeburn 543: norequest => 'Not allowed',
1.309 raeburn 544: approval => 'Approval by Dom. Coord.',
1.306 raeburn 545: validate => 'With validation',
546: autolimit => 'Numerical limit',
1.314 raeburn 547: unlimited => '(blank for unlimited)',
1.306 raeburn 548: );
549: return %titles;
550: }
551:
552: sub courserequest_display {
553: my %titles = &Apache::lonlocal::texthash (
1.309 raeburn 554: approval => 'Yes, need approval',
1.306 raeburn 555: validate => 'Yes, with validation',
556: norequest => 'No',
557: );
558: return %titles;
559: }
560:
1.362 raeburn 561: sub requestauthor_titles {
562: my %titles = &Apache::lonlocal::texthash (
563: norequest => 'Not allowed',
564: approval => 'Approval by Dom. Coord.',
565: automatic => 'Automatic approval',
566: );
567: return %titles;
568:
569: }
570:
571: sub requestauthor_display {
572: my %titles = &Apache::lonlocal::texthash (
573: approval => 'Yes, need approval',
574: automatic => 'Yes, automatic approval',
575: norequest => 'No',
576: );
577: return %titles;
578: }
579:
1.383 raeburn 580: sub requestchange_display {
581: my %titles = &Apache::lonlocal::texthash (
582: approval => "availability set to 'on' (approval required)",
583: automatic => "availability set to 'on' (automatic approval)",
584: norequest => "availability set to 'off'",
585: );
586: return %titles;
587: }
588:
1.362 raeburn 589: sub curr_requestauthor {
590: my ($uname,$udom,$isadv,$inststatuses,$domconfig) = @_;
591: return unless ((ref($inststatuses) eq 'ARRAY') && (ref($domconfig) eq 'HASH'));
592: if ($uname eq '' || $udom eq '') {
593: $uname = $env{'user.name'};
594: $udom = $env{'user.domain'};
595: $isadv = $env{'user.adv'};
596: }
597: my (%userenv,%settings,$val);
598: my @options = ('automatic','approval');
599: %userenv =
600: &Apache::lonnet::userenvironment($udom,$uname,'requestauthor','inststatus');
601: if ($userenv{'requestauthor'}) {
602: $val = $userenv{'requestauthor'};
603: @{$inststatuses} = ('_custom_');
604: } else {
605: my %alltasks;
606: if (ref($domconfig->{'requestauthor'}) eq 'HASH') {
607: %settings = %{$domconfig->{'requestauthor'}};
608: if (($isadv) && ($settings{'_LC_adv'} ne '')) {
609: $val = $settings{'_LC_adv'};
610: @{$inststatuses} = ('_LC_adv_');
611: } else {
612: if ($userenv{'inststatus'} ne '') {
613: @{$inststatuses} = split(',',$userenv{'inststatus'});
614: } else {
615: @{$inststatuses} = ('default');
616: }
617: foreach my $status (@{$inststatuses}) {
618: if (exists($settings{$status})) {
619: my $value = $settings{$status};
620: next unless ($value);
621: unless (exists($alltasks{$value})) {
622: if (ref($alltasks{$value}) eq 'ARRAY') {
623: unless(grep(/^\Q$status\E$/,@{$alltasks{$value}})) {
624: push(@{$alltasks{$value}},$status);
625: }
626: } else {
627: @{$alltasks{$value}} = ($status);
628: }
629: }
630: }
631: }
632: foreach my $option (@options) {
633: if ($alltasks{$option}) {
634: $val = $option;
635: last;
636: }
637: }
638: }
639: }
640: }
641: return $val;
642: }
643:
1.2 www 644: # =================================================================== Phase one
1.1 www 645:
1.42 matthew 646: sub print_username_entry_form {
1.406.2.14 raeburn 647: my ($r,$context,$response,$srch,$forcenewuser,$crstype,$brcrum,
648: $permission) = @_;
1.101 albertel 649: my $defdom=$env{'request.role.domain'};
1.160 raeburn 650: my $formtoset = 'crtuser';
651: if (exists($env{'form.startrolename'})) {
652: $formtoset = 'docustom';
653: $env{'form.rolename'} = $env{'form.startrolename'};
1.207 raeburn 654: } elsif ($env{'form.origform'} eq 'crtusername') {
655: $formtoset = $env{'form.origform'};
1.160 raeburn 656: }
657:
658: my ($jsback,$elements) = &crumb_utilities();
659:
660: my $jscript = &Apache::loncommon::studentbrowser_javascript()."\n".
1.165 albertel 661: '<script type="text/javascript">'."\n".
1.301 bisitz 662: '// <![CDATA['."\n".
663: &Apache::lonhtmlcommon::set_form_elements($elements->{$formtoset})."\n".
664: '// ]]>'."\n".
1.162 raeburn 665: '</script>'."\n";
1.160 raeburn 666:
1.324 raeburn 667: my %existingroles=&Apache::lonuserutils::my_custom_roles($crstype);
668: if (($env{'form.action'} eq 'custom') && (keys(%existingroles) > 0)
669: && (&Apache::lonnet::allowed('mcr','/'))) {
670: $jscript .= &customrole_javascript();
671: }
1.224 raeburn 672: my $helpitem = 'Course_Change_Privileges';
673: if ($env{'form.action'} eq 'custom') {
1.406.2.14 raeburn 674: if ($context eq 'course') {
675: $helpitem = 'Course_Editing_Custom_Roles';
676: } elsif ($context eq 'domain') {
677: $helpitem = 'Domain_Editing_Custom_Roles';
678: }
1.224 raeburn 679: } elsif ($env{'form.action'} eq 'singlestudent') {
680: $helpitem = 'Course_Add_Student';
1.406.2.5 raeburn 681: } elsif ($env{'form.action'} eq 'accesslogs') {
682: $helpitem = 'Domain_User_Access_Logs';
1.406.2.14 raeburn 683: } elsif ($context eq 'author') {
684: $helpitem = 'Author_Change_Privileges';
685: } elsif ($context eq 'domain') {
686: if ($permission->{'cusr'}) {
687: $helpitem = 'Domain_Change_Privileges';
688: } elsif ($permission->{'view'}) {
689: $helpitem = 'Domain_View_Privileges';
690: } else {
691: undef($helpitem);
692: }
1.224 raeburn 693: }
1.406.2.7 raeburn 694: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$defdom);
1.351 raeburn 695: if ($env{'form.action'} eq 'custom') {
696: push(@{$brcrum},
697: {href=>"javascript:backPage(document.crtuser)",
698: text=>"Pick custom role",
699: help => $helpitem,}
700: );
701: } else {
702: push (@{$brcrum},
703: {href => "javascript:backPage(document.crtuser)",
704: text => $breadcrumb_text{'search'},
705: help => $helpitem,
706: faq => 282,
707: bug => 'Instructor Interface',}
708: );
709: }
710: my %loaditems = (
711: 'onload' => "javascript:setFormElements(document.$formtoset)",
712: );
713: my $args = {bread_crumbs => $brcrum,
714: bread_crumbs_component => 'User Management',
715: add_entries => \%loaditems,};
716: $r->print(&Apache::loncommon::start_page('User Management',$jscript,$args));
717:
1.71 sakharuk 718: my %lt=&Apache::lonlocal::texthash(
1.229 raeburn 719: 'srst' => 'Search for a user and enroll as a student',
1.318 raeburn 720: 'srme' => 'Search for a user and enroll as a member',
1.229 raeburn 721: 'srad' => 'Search for a user and modify/add user information or roles',
1.406.2.7 raeburn 722: 'srvu' => 'Search for a user and view user information and roles',
1.406.2.5 raeburn 723: 'srva' => 'Search for a user and view access log information',
1.71 sakharuk 724: 'usr' => "Username",
725: 'dom' => "Domain",
1.324 raeburn 726: 'ecrp' => "Define or Edit Custom Role",
727: 'nr' => "role name",
1.282 schafran 728: 'cre' => "Next",
1.71 sakharuk 729: );
1.351 raeburn 730:
1.214 raeburn 731: if ($env{'form.action'} eq 'custom') {
1.190 raeburn 732: if (&Apache::lonnet::allowed('mcr','/')) {
1.324 raeburn 733: my $newroletext = &mt('Define new custom role:');
734: $r->print('<form action="/adm/createuser" method="post" name="docustom">'.
735: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
736: '<input type="hidden" name="phase" value="selected_custom_edit" />'.
737: '<h3>'.$lt{'ecrp'}.'</h3>'.
738: &Apache::loncommon::start_data_table().
739: &Apache::loncommon::start_data_table_row().
740: '<td>');
741: if (keys(%existingroles) > 0) {
742: $r->print('<br /><label><input type="radio" name="customroleaction" value="new" checked="checked" onclick="setCustomFields();" /><b>'.$newroletext.'</b></label>');
743: } else {
744: $r->print('<br /><input type="hidden" name="customroleaction" value="new" /><b>'.$newroletext.'</b>');
745: }
746: $r->print('</td><td align="center">'.$lt{'nr'}.'<br /><input type="text" size="15" name="newrolename" onfocus="setCustomAction('."'new'".');" /></td>'.
747: &Apache::loncommon::end_data_table_row());
748: if (keys(%existingroles) > 0) {
749: $r->print(&Apache::loncommon::start_data_table_row().'<td><br />'.
750: '<label><input type="radio" name="customroleaction" value="edit" onclick="setCustomFields();"/><b>'.
751: &mt('View/Modify existing role:').'</b></label></td>'.
752: '<td align="center"><br />'.
753: '<select name="rolename" onchange="setCustomAction('."'edit'".');">'.
1.326 raeburn 754: '<option value="" selected="selected">'.
1.324 raeburn 755: &mt('Select'));
756: foreach my $role (sort(keys(%existingroles))) {
1.326 raeburn 757: $r->print('<option value="'.$role.'">'.$role.'</option>');
1.324 raeburn 758: }
759: $r->print('</select>'.
760: '</td>'.
761: &Apache::loncommon::end_data_table_row());
762: }
763: $r->print(&Apache::loncommon::end_data_table().'<p>'.
764: '<input name="customeditor" type="submit" value="'.
765: $lt{'cre'}.'" /></p>'.
766: '</form>');
1.190 raeburn 767: }
1.213 raeburn 768: } else {
1.229 raeburn 769: my $actiontext = $lt{'srad'};
1.406.2.13 raeburn 770: my $fixeddom;
1.213 raeburn 771: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 772: if ($crstype eq 'Community') {
773: $actiontext = $lt{'srme'};
774: } else {
775: $actiontext = $lt{'srst'};
776: }
1.406.2.5 raeburn 777: } elsif ($env{'form.action'} eq 'accesslogs') {
778: $actiontext = $lt{'srva'};
1.406.2.13 raeburn 779: $fixeddom = 1;
1.406.2.7 raeburn 780: } elsif (($env{'form.action'} eq 'singleuser') &&
781: ($context eq 'domain') && (!&Apache::lonnet::allowed('mau',$defdom))) {
782: $actiontext = $lt{'srvu'};
1.406.2.14 raeburn 783: $fixeddom = 1;
1.213 raeburn 784: }
1.324 raeburn 785: $r->print("<h3>$actiontext</h3>");
1.213 raeburn 786: if ($env{'form.origform'} ne 'crtusername') {
1.406.2.5 raeburn 787: if ($response) {
788: $r->print("\n<div>$response</div>".
789: '<br clear="all" />');
790: }
1.213 raeburn 791: }
1.406.2.13 raeburn 792: $r->print(&entry_form($defdom,$srch,$forcenewuser,$context,$response,$crstype,$fixeddom));
1.107 www 793: }
1.110 albertel 794: }
795:
1.324 raeburn 796: sub customrole_javascript {
797: my $js = <<"END";
798: <script type="text/javascript">
799: // <![CDATA[
800:
801: function setCustomFields() {
802: if (document.docustom.customroleaction.length > 0) {
803: for (var i=0; i<document.docustom.customroleaction.length; i++) {
804: if (document.docustom.customroleaction[i].checked) {
805: if (document.docustom.customroleaction[i].value == 'new') {
806: document.docustom.rolename.selectedIndex = 0;
807: } else {
808: document.docustom.newrolename.value = '';
809: }
810: }
811: }
812: }
813: return;
814: }
815:
816: function setCustomAction(caller) {
817: if (document.docustom.customroleaction.length > 0) {
818: for (var i=0; i<document.docustom.customroleaction.length; i++) {
819: if (document.docustom.customroleaction[i].value == caller) {
820: document.docustom.customroleaction[i].checked = true;
821: }
822: }
823: }
824: setCustomFields();
825: return;
826: }
827:
828: // ]]>
829: </script>
830: END
831: return $js;
832: }
833:
1.160 raeburn 834: sub entry_form {
1.406.2.5 raeburn 835: my ($dom,$srch,$forcenewuser,$context,$responsemsg,$crstype,$fixeddom) = @_;
1.229 raeburn 836: my ($usertype,$inexact);
1.214 raeburn 837: if (ref($srch) eq 'HASH') {
838: if (($srch->{'srchin'} eq 'dom') &&
839: ($srch->{'srchby'} eq 'uname') &&
840: ($srch->{'srchtype'} eq 'exact') &&
841: ($srch->{'srchdomain'} ne '') &&
842: ($srch->{'srchterm'} ne '')) {
1.353 raeburn 843: my (%curr_rules,%got_rules);
1.214 raeburn 844: my ($rules,$ruleorder) =
845: &Apache::lonnet::inst_userrules($srch->{'srchdomain'},'username');
1.353 raeburn 846: $usertype = &Apache::lonuserutils::check_usertype($srch->{'srchdomain'},$srch->{'srchterm'},$rules,\%curr_rules,\%got_rules);
1.229 raeburn 847: } else {
848: $inexact = 1;
1.214 raeburn 849: }
1.207 raeburn 850: }
1.406.2.14 raeburn 851: my ($cancreate,$noinstd);
852: if ($env{'form.action'} eq 'accesslogs') {
853: $noinstd = 1;
854: } else {
855: $cancreate =
856: &Apache::lonuserutils::can_create_user($dom,$context,$usertype);
857: }
1.406.2.3 raeburn 858: my ($userpicker,$cansearch) =
1.179 raeburn 859: &Apache::loncommon::user_picker($dom,$srch,$forcenewuser,
1.406.2.14 raeburn 860: 'document.crtuser',$cancreate,$usertype,$context,$fixeddom,$noinstd);
1.160 raeburn 861: my $srchbutton = &mt('Search');
1.229 raeburn 862: if ($env{'form.action'} eq 'singlestudent') {
863: $srchbutton = &mt('Search and Enroll');
1.406.2.5 raeburn 864: } elsif ($env{'form.action'} eq 'accesslogs') {
865: $srchbutton = &mt('Search');
1.229 raeburn 866: } elsif ($cancreate && $responsemsg ne '' && $inexact) {
867: $srchbutton = &mt('Search or Add New User');
868: }
1.406.2.3 raeburn 869: my $output;
870: if ($cansearch) {
871: $output = <<"ENDBLOCK";
1.160 raeburn 872: <form action="/adm/createuser" method="post" name="crtuser">
1.190 raeburn 873: <input type="hidden" name="action" value="$env{'form.action'}" />
1.160 raeburn 874: <input type="hidden" name="phase" value="get_user_info" />
875: $userpicker
1.179 raeburn 876: <input name="userrole" type="button" value="$srchbutton" onclick="javascript:validateEntry(document.crtuser)" />
1.160 raeburn 877: </form>
1.207 raeburn 878: ENDBLOCK
1.406.2.3 raeburn 879: } else {
880: $output = '<p>'.$userpicker.'</p>';
881: }
1.406.2.7 raeburn 882: if (($env{'form.phase'} eq '') && ($env{'form.action'} ne 'accesslogs') &&
883: (!(($env{'form.action'} eq 'singleuser') && ($context eq 'domain') &&
884: (!&Apache::lonnet::allowed('mau',$env{'request.role.domain'}))))) {
1.207 raeburn 885: my $defdom=$env{'request.role.domain'};
886: my $domform = &Apache::loncommon::select_dom_form($defdom,'srchdomain');
887: my %lt=&Apache::lonlocal::texthash(
1.229 raeburn 888: 'enro' => 'Enroll one student',
1.318 raeburn 889: 'enrm' => 'Enroll one member',
1.229 raeburn 890: 'admo' => 'Add/modify a single user',
891: 'crea' => 'create new user if required',
892: 'uskn' => "username is known",
1.207 raeburn 893: 'crnu' => 'Create a new user',
894: 'usr' => 'Username',
895: 'dom' => 'in domain',
1.229 raeburn 896: 'enrl' => 'Enroll',
897: 'cram' => 'Create/Modify user',
1.207 raeburn 898: );
1.229 raeburn 899: my $sellink=&Apache::loncommon::selectstudent_link('crtusername','srchterm','srchdomain');
900: my ($title,$buttontext,$showresponse);
1.318 raeburn 901: if ($env{'form.action'} eq 'singlestudent') {
902: if ($crstype eq 'Community') {
903: $title = $lt{'enrm'};
904: } else {
905: $title = $lt{'enro'};
906: }
1.229 raeburn 907: $buttontext = $lt{'enrl'};
908: } else {
909: $title = $lt{'admo'};
910: $buttontext = $lt{'cram'};
911: }
912: if ($cancreate) {
913: $title .= ' <span class="LC_cusr_subheading">('.$lt{'crea'}.')</span>';
914: } else {
915: $title .= ' <span class="LC_cusr_subheading">('.$lt{'uskn'}.')</span>';
916: }
917: if ($env{'form.origform'} eq 'crtusername') {
918: $showresponse = $responsemsg;
919: }
1.207 raeburn 920: $output .= <<"ENDDOCUMENT";
1.229 raeburn 921: <br />
1.207 raeburn 922: <form action="/adm/createuser" method="post" name="crtusername">
923: <input type="hidden" name="action" value="$env{'form.action'}" />
924: <input type="hidden" name="phase" value="createnewuser" />
925: <input type="hidden" name="srchtype" value="exact" />
1.233 raeburn 926: <input type="hidden" name="srchby" value="uname" />
1.207 raeburn 927: <input type="hidden" name="srchin" value="dom" />
928: <input type="hidden" name="forcenewuser" value="1" />
929: <input type="hidden" name="origform" value="crtusername" />
1.229 raeburn 930: <h3>$title</h3>
931: $showresponse
1.207 raeburn 932: <table>
933: <tr>
934: <td>$lt{'usr'}:</td>
935: <td><input type="text" size="15" name="srchterm" /></td>
936: <td> $lt{'dom'}:</td><td>$domform</td>
1.229 raeburn 937: <td> $sellink </td>
938: <td> <input name="userrole" type="submit" value="$buttontext" /></td>
1.207 raeburn 939: </tr>
940: </table>
941: </form>
1.160 raeburn 942: ENDDOCUMENT
1.207 raeburn 943: }
1.160 raeburn 944: return $output;
945: }
1.110 albertel 946:
947: sub user_modification_js {
1.113 raeburn 948: my ($pjump_def,$dc_setcourse_code,$nondc_setsection_code,$groupslist)=@_;
949:
1.110 albertel 950: return <<END;
951: <script type="text/javascript" language="Javascript">
1.301 bisitz 952: // <![CDATA[
1.314 raeburn 953:
1.110 albertel 954: $pjump_def
955: $dc_setcourse_code
956:
957: function dateset() {
958: eval("document.cu."+document.cu.pres_marker.value+
959: ".value=document.cu.pres_value.value");
1.359 www 960: modalWindow.close();
1.110 albertel 961: }
962:
1.113 raeburn 963: $nondc_setsection_code
1.301 bisitz 964: // ]]>
1.110 albertel 965: </script>
966: END
1.2 www 967: }
968:
969: # =================================================================== Phase two
1.160 raeburn 970: sub print_user_selection_page {
1.351 raeburn 971: my ($r,$response,$srch,$srch_results,$srcharray,$context,$opener_elements,$crstype,$brcrum) = @_;
1.160 raeburn 972: my @fields = ('username','domain','lastname','firstname','permanentemail');
973: my $sortby = $env{'form.sortby'};
974:
975: if (!grep(/^\Q$sortby\E$/,@fields)) {
976: $sortby = 'lastname';
977: }
978:
979: my ($jsback,$elements) = &crumb_utilities();
980:
981: my $jscript = (<<ENDSCRIPT);
982: <script type="text/javascript">
1.301 bisitz 983: // <![CDATA[
1.160 raeburn 984: function pickuser(uname,udom) {
985: document.usersrchform.seluname.value=uname;
986: document.usersrchform.seludom.value=udom;
987: document.usersrchform.phase.value="userpicked";
988: document.usersrchform.submit();
989: }
990:
991: $jsback
1.301 bisitz 992: // ]]>
1.160 raeburn 993: </script>
994: ENDSCRIPT
995:
996: my %lt=&Apache::lonlocal::texthash(
1.179 raeburn 997: 'usrch' => "User Search to add/modify roles",
998: 'stusrch' => "User Search to enroll student",
1.318 raeburn 999: 'memsrch' => "User Search to enroll member",
1.406.2.5 raeburn 1000: 'srcva' => "Search for a user and view access log information",
1.406.2.7 raeburn 1001: 'usrvu' => "User Search to view user roles",
1.179 raeburn 1002: 'usel' => "Select a user to add/modify roles",
1.406.2.7 raeburn 1003: 'suvr' => "Select a user to view roles",
1.318 raeburn 1004: 'stusel' => "Select a user to enroll as a student",
1005: 'memsel' => "Select a user to enroll as a member",
1.406.2.5 raeburn 1006: 'vacsel' => "Select a user to view access log",
1.160 raeburn 1007: 'username' => "username",
1008: 'domain' => "domain",
1009: 'lastname' => "last name",
1010: 'firstname' => "first name",
1011: 'permanentemail' => "permanent e-mail",
1012: );
1.302 raeburn 1013: if ($context eq 'requestcrs') {
1014: $r->print('<div>');
1015: } else {
1.406.2.7 raeburn 1016: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$srch->{'srchdomain'});
1.351 raeburn 1017: my $helpitem;
1018: if ($env{'form.action'} eq 'singleuser') {
1019: $helpitem = 'Course_Change_Privileges';
1020: } elsif ($env{'form.action'} eq 'singlestudent') {
1021: $helpitem = 'Course_Add_Student';
1.406.2.14 raeburn 1022: } elsif ($context eq 'author') {
1023: $helpitem = 'Author_Change_Privileges';
1024: } elsif ($context eq 'domain') {
1025: $helpitem = 'Domain_Change_Privileges';
1.351 raeburn 1026: }
1027: push (@{$brcrum},
1028: {href => "javascript:backPage(document.usersrchform,'','')",
1029: text => $breadcrumb_text{'search'},
1030: faq => 282,
1031: bug => 'Instructor Interface',},
1032: {href => "javascript:backPage(document.usersrchform,'get_user_info','select')",
1033: text => $breadcrumb_text{'userpicked'},
1034: faq => 282,
1035: bug => 'Instructor Interface',
1036: help => $helpitem}
1037: );
1038: $r->print(&Apache::loncommon::start_page('User Management',$jscript,{bread_crumbs => $brcrum}));
1.302 raeburn 1039: if ($env{'form.action'} eq 'singleuser') {
1.406.2.7 raeburn 1040: my $readonly;
1041: if (($context eq 'domain') && (!&Apache::lonnet::allowed('mau',$srch->{'srchdomain'}))) {
1042: $readonly = 1;
1043: $r->print("<b>$lt{'usrvu'}</b><br />");
1044: } else {
1045: $r->print("<b>$lt{'usrch'}</b><br />");
1046: }
1.318 raeburn 1047: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,$crstype));
1.406.2.7 raeburn 1048: if ($readonly) {
1049: $r->print('<h3>'.$lt{'suvr'}.'</h3>');
1050: } else {
1051: $r->print('<h3>'.$lt{'usel'}.'</h3>');
1052: }
1.302 raeburn 1053: } elsif ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1054: $r->print($jscript."<b>");
1055: if ($crstype eq 'Community') {
1056: $r->print($lt{'memsrch'});
1057: } else {
1058: $r->print($lt{'stusrch'});
1059: }
1060: $r->print("</b><br />");
1061: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,$crstype));
1062: $r->print('</form><h3>');
1063: if ($crstype eq 'Community') {
1064: $r->print($lt{'memsel'});
1065: } else {
1066: $r->print($lt{'stusel'});
1067: }
1068: $r->print('</h3>');
1.406.2.5 raeburn 1069: } elsif ($env{'form.action'} eq 'accesslogs') {
1070: $r->print("<b>$lt{'srcva'}</b><br />");
1.406.2.14 raeburn 1071: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,undef,1));
1.406.2.5 raeburn 1072: $r->print('<h3>'.$lt{'vacsel'}.'</h3>');
1.302 raeburn 1073: }
1.179 raeburn 1074: }
1.380 bisitz 1075: $r->print('<form name="usersrchform" method="post" action="">'.
1.160 raeburn 1076: &Apache::loncommon::start_data_table()."\n".
1077: &Apache::loncommon::start_data_table_header_row()."\n".
1078: ' <th> </th>'."\n");
1079: foreach my $field (@fields) {
1080: $r->print(' <th><a href="javascript:document.usersrchform.sortby.value='.
1081: "'".$field."'".';document.usersrchform.submit();">'.
1082: $lt{$field}.'</a></th>'."\n");
1083: }
1084: $r->print(&Apache::loncommon::end_data_table_header_row());
1085:
1086: my @sorted_users = sort {
1.167 albertel 1087: lc($srch_results->{$a}->{$sortby}) cmp lc($srch_results->{$b}->{$sortby})
1.160 raeburn 1088: ||
1.167 albertel 1089: lc($srch_results->{$a}->{lastname}) cmp lc($srch_results->{$b}->{lastname})
1.160 raeburn 1090: ||
1091: lc($srch_results->{$a}->{firstname}) cmp lc($srch_results->{$b}->{firstname})
1.167 albertel 1092: ||
1093: lc($a) cmp lc($b)
1.160 raeburn 1094: } (keys(%$srch_results));
1095:
1096: foreach my $user (@sorted_users) {
1097: my ($uname,$udom) = split(/:/,$user);
1.302 raeburn 1098: my $onclick;
1099: if ($context eq 'requestcrs') {
1.314 raeburn 1100: $onclick =
1.302 raeburn 1101: 'onclick="javascript:gochoose('."'$uname','$udom',".
1102: "'$srch_results->{$user}->{firstname}',".
1103: "'$srch_results->{$user}->{lastname}',".
1104: "'$srch_results->{$user}->{permanentemail}'".');"';
1105: } else {
1.314 raeburn 1106: $onclick =
1.302 raeburn 1107: ' onclick="javascript:pickuser('."'".$uname."'".','."'".$udom."'".');"';
1108: }
1.160 raeburn 1109: $r->print(&Apache::loncommon::start_data_table_row().
1.302 raeburn 1110: '<td><input type="button" name="seluser" value="'.&mt('Select').'" '.
1111: $onclick.' /></td>'.
1.160 raeburn 1112: '<td><tt>'.$uname.'</tt></td>'.
1113: '<td><tt>'.$udom.'</tt></td>');
1114: foreach my $field ('lastname','firstname','permanentemail') {
1115: $r->print('<td>'.$srch_results->{$user}->{$field}.'</td>');
1116: }
1117: $r->print(&Apache::loncommon::end_data_table_row());
1118: }
1119: $r->print(&Apache::loncommon::end_data_table().'<br /><br />');
1.179 raeburn 1120: if (ref($srcharray) eq 'ARRAY') {
1121: foreach my $item (@{$srcharray}) {
1122: $r->print('<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n");
1123: }
1124: }
1.160 raeburn 1125: $r->print(' <input type="hidden" name="sortby" value="'.$sortby.'" />'."\n".
1126: ' <input type="hidden" name="seluname" value="" />'."\n".
1127: ' <input type="hidden" name="seludom" value="" />'."\n".
1.179 raeburn 1128: ' <input type="hidden" name="currstate" value="select" />'."\n".
1.190 raeburn 1129: ' <input type="hidden" name="phase" value="get_user_info" />'."\n".
1.214 raeburn 1130: ' <input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n");
1.302 raeburn 1131: if ($context eq 'requestcrs') {
1132: $r->print($opener_elements.'</form></div>');
1133: } else {
1.351 raeburn 1134: $r->print($response.'</form>');
1.302 raeburn 1135: }
1.160 raeburn 1136: }
1137:
1138: sub print_user_query_page {
1.351 raeburn 1139: my ($r,$caller,$brcrum) = @_;
1.160 raeburn 1140: # FIXME - this is for a network-wide name search (similar to catalog search)
1141: # To use frames with similar behavior to catalog/portfolio search.
1142: # To be implemented.
1143: return;
1144: }
1145:
1.42 matthew 1146: sub print_user_modification_page {
1.375 raeburn 1147: my ($r,$ccuname,$ccdomain,$srch,$response,$context,$permission,$crstype,
1148: $brcrum,$showcredits) = @_;
1.185 raeburn 1149: if (($ccuname eq '') || ($ccdomain eq '')) {
1.215 raeburn 1150: my $usermsg = &mt('No username and/or domain provided.');
1151: $env{'form.phase'} = '';
1.406.2.14 raeburn 1152: &print_username_entry_form($r,$context,$usermsg,'','',$crstype,$brcrum,
1153: $permission);
1.58 www 1154: return;
1155: }
1.213 raeburn 1156: my ($form,$formname);
1157: if ($env{'form.action'} eq 'singlestudent') {
1158: $form = 'document.enrollstudent';
1159: $formname = 'enrollstudent';
1160: } else {
1161: $form = 'document.cu';
1162: $formname = 'cu';
1163: }
1.188 raeburn 1164: my %abv_auth = &auth_abbrev();
1.227 raeburn 1165: my (%rulematch,%inst_results,$newuser,%alerts,%curr_rules,%got_rules);
1.185 raeburn 1166: my $uhome=&Apache::lonnet::homeserver($ccuname,$ccdomain);
1167: if ($uhome eq 'no_host') {
1.215 raeburn 1168: my $usertype;
1169: my ($rules,$ruleorder) =
1170: &Apache::lonnet::inst_userrules($ccdomain,'username');
1171: $usertype =
1.353 raeburn 1172: &Apache::lonuserutils::check_usertype($ccdomain,$ccuname,$rules,
1.362 raeburn 1173: \%curr_rules,\%got_rules);
1.215 raeburn 1174: my $cancreate =
1175: &Apache::lonuserutils::can_create_user($ccdomain,$context,
1176: $usertype);
1177: if (!$cancreate) {
1.292 bisitz 1178: my $helplink = 'javascript:helpMenu('."'display'".')';
1.215 raeburn 1179: my %usertypetext = (
1180: official => 'institutional',
1181: unofficial => 'non-institutional',
1182: );
1183: my $response;
1184: if ($env{'form.origform'} eq 'crtusername') {
1.362 raeburn 1185: $response = '<span class="LC_warning">'.
1186: &mt('No match found for the username [_1] in LON-CAPA domain: [_2]',
1187: '<b>'.$ccuname.'</b>',$ccdomain).
1.215 raeburn 1188: '</span><br />';
1189: }
1.292 bisitz 1190: $response .= '<p class="LC_warning">'
1191: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
1.406.2.6 raeburn 1192: .' ';
1193: if ($context eq 'domain') {
1194: $response .= &mt('Please contact a [_1] for assistance.',
1195: &Apache::lonnet::plaintext('dc'));
1196: } else {
1197: $response .= &mt('Please contact the [_1]helpdesk[_2] for assistance.'
1198: ,'<a href="'.$helplink.'">','</a>');
1199: }
1200: $response .= '</p><br />';
1.215 raeburn 1201: $env{'form.phase'} = '';
1.406.2.14 raeburn 1202: &print_username_entry_form($r,$context,$response,undef,undef,$crstype,$brcrum,
1203: $permission);
1.215 raeburn 1204: return;
1205: }
1.188 raeburn 1206: $newuser = 1;
1.193 raeburn 1207: my $checkhash;
1208: my $checks = { 'username' => 1 };
1.196 raeburn 1209: $checkhash->{$ccuname.':'.$ccdomain} = { 'newuser' => $newuser };
1.193 raeburn 1210: &Apache::loncommon::user_rule_check($checkhash,$checks,
1.196 raeburn 1211: \%alerts,\%rulematch,\%inst_results,\%curr_rules,\%got_rules);
1212: if (ref($alerts{'username'}) eq 'HASH') {
1213: if (ref($alerts{'username'}{$ccdomain}) eq 'HASH') {
1214: my $domdesc =
1.193 raeburn 1215: &Apache::lonnet::domain($ccdomain,'description');
1.196 raeburn 1216: if ($alerts{'username'}{$ccdomain}{$ccuname}) {
1217: my $userchkmsg;
1218: if (ref($curr_rules{$ccdomain}) eq 'HASH') {
1219: $userchkmsg =
1220: &Apache::loncommon::instrule_disallow_msg('username',
1.193 raeburn 1221: $domdesc,1).
1222: &Apache::loncommon::user_rule_formats($ccdomain,
1223: $domdesc,$curr_rules{$ccdomain}{'username'},
1224: 'username');
1.196 raeburn 1225: }
1.215 raeburn 1226: $env{'form.phase'} = '';
1.406.2.14 raeburn 1227: &print_username_entry_form($r,$context,$userchkmsg,undef,undef,$crstype,$brcrum,
1228: $permission);
1.196 raeburn 1229: return;
1.215 raeburn 1230: }
1.193 raeburn 1231: }
1.185 raeburn 1232: }
1.187 raeburn 1233: } else {
1.188 raeburn 1234: $newuser = 0;
1.185 raeburn 1235: }
1.160 raeburn 1236: if ($response) {
1.215 raeburn 1237: $response = '<br />'.$response;
1.160 raeburn 1238: }
1.149 raeburn 1239:
1.52 matthew 1240: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
1.88 raeburn 1241: my $dc_setcourse_code = '';
1.119 raeburn 1242: my $nondc_setsection_code = '';
1.112 albertel 1243: my %loaditem;
1.114 albertel 1244:
1.216 raeburn 1245: my $groupslist = &Apache::lonuserutils::get_groupslist();
1.88 raeburn 1246:
1.375 raeburn 1247: my $js = &validation_javascript($context,$ccdomain,$pjump_def,$crstype,
1.216 raeburn 1248: $groupslist,$newuser,$formname,\%loaditem);
1.406.2.7 raeburn 1249: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$ccdomain);
1.224 raeburn 1250: my $helpitem = 'Course_Change_Privileges';
1251: if ($env{'form.action'} eq 'singlestudent') {
1252: $helpitem = 'Course_Add_Student';
1.406.2.14 raeburn 1253: } elsif ($context eq 'author') {
1254: $helpitem = 'Author_Change_Privileges';
1255: } elsif ($context eq 'domain') {
1256: $helpitem = 'Domain_Change_Privileges';
1.224 raeburn 1257: }
1.351 raeburn 1258: push (@{$brcrum},
1259: {href => "javascript:backPage($form)",
1260: text => $breadcrumb_text{'search'},
1261: faq => 282,
1262: bug => 'Instructor Interface',});
1263: if ($env{'form.phase'} eq 'userpicked') {
1264: push(@{$brcrum},
1265: {href => "javascript:backPage($form,'get_user_info','select')",
1266: text => $breadcrumb_text{'userpicked'},
1267: faq => 282,
1268: bug => 'Instructor Interface',});
1269: }
1270: push(@{$brcrum},
1271: {href => "javascript:backPage($form,'$env{'form.phase'}','modify')",
1272: text => $breadcrumb_text{'modify'},
1273: faq => 282,
1274: bug => 'Instructor Interface',
1275: help => $helpitem});
1276: my $args = {'add_entries' => \%loaditem,
1277: 'bread_crumbs' => $brcrum,
1278: 'bread_crumbs_component' => 'User Management'};
1279: if ($env{'form.popup'}) {
1280: $args->{'no_nav_bar'} = 1;
1281: }
1282: my $start_page =
1283: &Apache::loncommon::start_page('User Management',$js,$args);
1.3 www 1284:
1.25 matthew 1285: my $forminfo =<<"ENDFORMINFO";
1.216 raeburn 1286: <form action="/adm/createuser" method="post" name="$formname">
1.190 raeburn 1287: <input type="hidden" name="phase" value="update_user_data" />
1.188 raeburn 1288: <input type="hidden" name="ccuname" value="$ccuname" />
1289: <input type="hidden" name="ccdomain" value="$ccdomain" />
1.157 albertel 1290: <input type="hidden" name="pres_value" value="" />
1291: <input type="hidden" name="pres_type" value="" />
1292: <input type="hidden" name="pres_marker" value="" />
1.25 matthew 1293: ENDFORMINFO
1.375 raeburn 1294: my (%inccourses,$roledom,$defaultcredits);
1.329 raeburn 1295: if ($context eq 'course') {
1296: $inccourses{$env{'request.course.id'}}=1;
1297: $roledom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1.375 raeburn 1298: if ($showcredits) {
1299: $defaultcredits = &Apache::lonuserutils::get_defaultcredits();
1300: }
1.329 raeburn 1301: } elsif ($context eq 'author') {
1302: $roledom = $env{'request.role.domain'};
1303: } elsif ($context eq 'domain') {
1304: foreach my $key (keys(%env)) {
1305: $roledom = $env{'request.role.domain'};
1306: if ($key=~/^user\.priv\.cm\.\/($roledom)\/($match_username)/) {
1307: $inccourses{$1.'_'.$2}=1;
1308: }
1309: }
1310: } else {
1311: foreach my $key (keys(%env)) {
1312: if ($key=~/^user\.priv\.cm\.\/($match_domain)\/($match_username)/) {
1313: $inccourses{$1.'_'.$2}=1;
1314: }
1.2 www 1315: }
1.24 matthew 1316: }
1.389 bisitz 1317: my $title = '';
1.216 raeburn 1318: if ($newuser) {
1.406.2.9 raeburn 1319: my ($portfolioform,$domroleform);
1.267 raeburn 1320: if ((&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) ||
1321: (&Apache::lonnet::allowed('mut',$env{'request.role.domain'}))) {
1322: # Current user has quota or user tools modification privileges
1.378 raeburn 1323: $portfolioform = '<br />'.&user_quotas($ccuname,$ccdomain);
1.134 raeburn 1324: }
1.383 raeburn 1325: if ((&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) &&
1326: ($ccdomain eq $env{'request.role.domain'})) {
1.362 raeburn 1327: $domroleform = '<br />'.&domainrole_req($ccuname,$ccdomain);
1328: }
1.227 raeburn 1329: &initialize_authen_forms($ccdomain,$formname);
1.188 raeburn 1330: my %lt=&Apache::lonlocal::texthash(
1331: 'lg' => 'Login Data',
1.190 raeburn 1332: 'hs' => "Home Server",
1.188 raeburn 1333: );
1.185 raeburn 1334: $r->print(<<ENDTITLE);
1.110 albertel 1335: $start_page
1.160 raeburn 1336: $response
1.25 matthew 1337: $forminfo
1.31 matthew 1338: <script type="text/javascript" language="Javascript">
1.301 bisitz 1339: // <![CDATA[
1.20 harris41 1340: $loginscript
1.301 bisitz 1341: // ]]>
1.31 matthew 1342: </script>
1.20 harris41 1343: <input type='hidden' name='makeuser' value='1' />
1.185 raeburn 1344: ENDTITLE
1.213 raeburn 1345: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1346: if ($crstype eq 'Community') {
1.389 bisitz 1347: $title = &mt('Create New User [_1] in domain [_2] as a member',
1348: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1349: } else {
1.389 bisitz 1350: $title = &mt('Create New User [_1] in domain [_2] as a student',
1351: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1352: }
1.389 bisitz 1353: } else {
1354: $title = &mt('Create New User [_1] in domain [_2]',
1355: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.213 raeburn 1356: }
1.389 bisitz 1357: $r->print('<h2>'.$title.'</h2>'."\n");
1358: $r->print('<div class="LC_left_float">');
1.393 raeburn 1359: $r->print(&personal_data_display($ccuname,$ccdomain,$newuser,$context,
1360: $inst_results{$ccuname.':'.$ccdomain}));
1361: # Option to disable student/employee ID conflict checking not offerred for new users.
1.187 raeburn 1362: my ($home_server_pick,$numlib) =
1363: &Apache::loncommon::home_server_form_item($ccdomain,'hserver',
1364: 'default','hide');
1365: if ($numlib > 1) {
1366: $r->print("
1.185 raeburn 1367: <br />
1.187 raeburn 1368: $lt{'hs'}: $home_server_pick
1369: <br />");
1370: } else {
1371: $r->print($home_server_pick);
1372: }
1.304 raeburn 1373: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.362 raeburn 1374: $r->print('<br /><h3>'.
1375: &mt('User Can Request Creation of Courses/Communities in this Domain?').'</h3>'.
1.304 raeburn 1376: &Apache::loncommon::start_data_table().
1377: &build_tools_display($ccuname,$ccdomain,
1378: 'requestcourses').
1379: &Apache::loncommon::end_data_table());
1380: }
1.188 raeburn 1381: $r->print('</div>'."\n".'<div class="LC_left_float"><h3>'.
1382: $lt{'lg'}.'</h3>');
1.185 raeburn 1383: my ($fixedauth,$varauth,$authmsg);
1.193 raeburn 1384: if (ref($rulematch{$ccuname.':'.$ccdomain}) eq 'HASH') {
1385: my $matchedrule = $rulematch{$ccuname.':'.$ccdomain}{'username'};
1386: my ($rules,$ruleorder) =
1387: &Apache::lonnet::inst_userrules($ccdomain,'username');
1.185 raeburn 1388: if (ref($rules) eq 'HASH') {
1.193 raeburn 1389: if (ref($rules->{$matchedrule}) eq 'HASH') {
1390: my $authtype = $rules->{$matchedrule}{'authtype'};
1.185 raeburn 1391: if ($authtype !~ /^(krb4|krb5|int|fsys|loc)$/) {
1.190 raeburn 1392: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.275 raeburn 1393: } else {
1.193 raeburn 1394: my $authparm = $rules->{$matchedrule}{'authparm'};
1.273 raeburn 1395: $authmsg = $rules->{$matchedrule}{'authmsg'};
1.185 raeburn 1396: if ($authtype =~ /^krb(4|5)$/) {
1397: my $ver = $1;
1398: if ($authparm ne '') {
1399: $fixedauth = <<"KERB";
1400: <input type="hidden" name="login" value="krb" />
1401: <input type="hidden" name="krbver" value="$ver" />
1402: <input type="hidden" name="krbarg" value="$authparm" />
1403: KERB
1404: }
1405: } else {
1406: $fixedauth =
1407: '<input type="hidden" name="login" value="'.$authtype.'" />'."\n";
1.193 raeburn 1408: if ($rules->{$matchedrule}{'authparmfixed'}) {
1.185 raeburn 1409: $fixedauth .=
1410: '<input type="hidden" name="'.$authtype.'arg" value="'.$authparm.'" />'."\n";
1411: } else {
1.273 raeburn 1412: if ($authtype eq 'int') {
1413: $varauth = '<br />'.
1.301 bisitz 1414: &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 1415: } elsif ($authtype eq 'loc') {
1416: $varauth = '<br />'.
1417: &mt('[_1] Local Authentication with argument [_2]','','<input type="text" name="'.$authtype.'arg" value="" />')."\n";
1418: } else {
1419: $varauth =
1.185 raeburn 1420: '<input type="text" name="'.$authtype.'arg" value="" />'."\n";
1.273 raeburn 1421: }
1.185 raeburn 1422: }
1423: }
1424: }
1425: } else {
1.190 raeburn 1426: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.185 raeburn 1427: }
1428: }
1429: if ($authmsg) {
1430: $r->print(<<ENDAUTH);
1431: $fixedauth
1432: $authmsg
1433: $varauth
1434: ENDAUTH
1435: }
1436: } else {
1.190 raeburn 1437: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.187 raeburn 1438: }
1.406.2.9 raeburn 1439: $r->print($portfolioform.$domroleform);
1.215 raeburn 1440: if ($env{'form.action'} eq 'singlestudent') {
1441: $r->print(&date_sections_select($context,$newuser,$formname,
1.375 raeburn 1442: $permission,$crstype,$ccuname,
1443: $ccdomain,$showcredits));
1.215 raeburn 1444: }
1445: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.216 raeburn 1446: } else { # user already exists
1.389 bisitz 1447: $r->print($start_page.$forminfo);
1.213 raeburn 1448: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1449: if ($crstype eq 'Community') {
1.389 bisitz 1450: $title = &mt('Enroll one member: [_1] in domain [_2]',
1451: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1452: } else {
1.389 bisitz 1453: $title = &mt('Enroll one student: [_1] in domain [_2]',
1454: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1455: }
1.213 raeburn 1456: } else {
1.406.2.6 raeburn 1457: if ($permission->{'cusr'}) {
1458: $title = &mt('Modify existing user: [_1] in domain [_2]',
1459: '"'.$ccuname.'"','"'.$ccdomain.'"');
1460: } else {
1461: $title = &mt('Existing user: [_1] in domain [_2]',
1.389 bisitz 1462: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.406.2.6 raeburn 1463: }
1.213 raeburn 1464: }
1.389 bisitz 1465: $r->print('<h2>'.$title.'</h2>'."\n");
1466: $r->print('<div class="LC_left_float">');
1.393 raeburn 1467: $r->print(&personal_data_display($ccuname,$ccdomain,$newuser,$context,
1468: $inst_results{$ccuname.':'.$ccdomain}));
1.406.2.6 raeburn 1469: if ((&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) ||
1470: (&Apache::lonnet::allowed('udp',$env{'request.role.domain'}))) {
1.362 raeburn 1471: $r->print('<br /><h3>'.&mt('User Can Request Creation of Courses/Communities in this Domain?').'</h3>'.
1.300 raeburn 1472: &Apache::loncommon::start_data_table());
1.314 raeburn 1473: if ($env{'request.role.domain'} eq $ccdomain) {
1.300 raeburn 1474: $r->print(&build_tools_display($ccuname,$ccdomain,'requestcourses'));
1475: } else {
1476: $r->print(&coursereq_externaluser($ccuname,$ccdomain,
1477: $env{'request.role.domain'}));
1478: }
1479: $r->print(&Apache::loncommon::end_data_table());
1.275 raeburn 1480: }
1.199 raeburn 1481: $r->print('</div>');
1.406.2.9 raeburn 1482: my @order = ('auth','quota','tools','requestauthor');
1.362 raeburn 1483: my %user_text;
1484: my ($isadv,$isauthor) =
1.406.2.6 raeburn 1485: &Apache::lonnet::is_advanced_user($ccdomain,$ccuname);
1.362 raeburn 1486: if ((!$isauthor) &&
1.406.2.6 raeburn 1487: ((&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) ||
1488: (&Apache::lonnet::allowed('udp',$env{'request.role.domain'}))) &&
1489: ($env{'request.role.domain'} eq $ccdomain)) {
1.362 raeburn 1490: $user_text{'requestauthor'} = &domainrole_req($ccuname,$ccdomain);
1491: }
1.406.2.17 raeburn 1492: $user_text{'auth'} = &user_authentication($ccuname,$ccdomain,$formname,$crstype,$permission);
1.267 raeburn 1493: if ((&Apache::lonnet::allowed('mpq',$ccdomain)) ||
1.406.2.6 raeburn 1494: (&Apache::lonnet::allowed('mut',$ccdomain)) ||
1495: (&Apache::lonnet::allowed('udp',$ccdomain))) {
1.188 raeburn 1496: # Current user has quota modification privileges
1.378 raeburn 1497: $user_text{'quota'} = &user_quotas($ccuname,$ccdomain);
1.267 raeburn 1498: }
1499: if (!&Apache::lonnet::allowed('mpq',$ccdomain)) {
1500: if (&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) {
1501: my %lt=&Apache::lonlocal::texthash(
1.385 bisitz 1502: 'dska' => "Disk quotas for user's portfolio and Authoring Space",
1503: 'youd' => "You do not have privileges to modify the portfolio and/or Authoring Space quotas for this user.",
1.267 raeburn 1504: 'ichr' => "If a change is required, contact a domain coordinator for the domain",
1505: );
1.362 raeburn 1506: $user_text{'quota'} = <<ENDNOPORTPRIV;
1.188 raeburn 1507: <h3>$lt{'dska'}</h3>
1508: $lt{'youd'} $lt{'ichr'}: $ccdomain
1509: ENDNOPORTPRIV
1.267 raeburn 1510: }
1511: }
1512: if (!&Apache::lonnet::allowed('mut',$ccdomain)) {
1513: if (&Apache::lonnet::allowed('mut',$env{'request.role.domain'})) {
1514: my %lt=&Apache::lonlocal::texthash(
1515: 'utav' => "User Tools Availability",
1.361 raeburn 1516: 'yodo' => "You do not have privileges to modify Portfolio, Blog, WebDAV, or Personal Information Page settings for this user.",
1.267 raeburn 1517: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
1518: );
1.362 raeburn 1519: $user_text{'tools'} = <<ENDNOTOOLSPRIV;
1.267 raeburn 1520: <h3>$lt{'utav'}</h3>
1521: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1522: ENDNOTOOLSPRIV
1523: }
1.188 raeburn 1524: }
1.362 raeburn 1525: my $gotdiv = 0;
1526: foreach my $item (@order) {
1527: if ($user_text{$item} ne '') {
1528: unless ($gotdiv) {
1529: $r->print('<div class="LC_left_float">');
1530: $gotdiv = 1;
1531: }
1532: $r->print('<br />'.$user_text{$item});
1533: }
1534: }
1535: if ($env{'form.action'} eq 'singlestudent') {
1536: unless ($gotdiv) {
1537: $r->print('<div class="LC_left_float">');
1.213 raeburn 1538: }
1.375 raeburn 1539: my $credits;
1540: if ($showcredits) {
1541: $credits = &get_user_credits($ccuname,$ccdomain,$defaultcredits);
1542: if ($credits eq '') {
1543: $credits = $defaultcredits;
1544: }
1545: }
1.374 raeburn 1546: $r->print(&date_sections_select($context,$newuser,$formname,
1.375 raeburn 1547: $permission,$crstype,$ccuname,
1548: $ccdomain,$showcredits));
1.374 raeburn 1549: }
1.362 raeburn 1550: if ($gotdiv) {
1551: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.188 raeburn 1552: }
1.406.2.6 raeburn 1553: my $statuses;
1554: if (($context eq 'domain') && (&Apache::lonnet::allowed('udp',$ccdomain)) &&
1555: (!&Apache::lonnet::allowed('mau',$ccdomain))) {
1556: $statuses = ['active'];
1557: } elsif (($context eq 'course') && ((&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) ||
1558: ($env{'request.course.sec'} &&
1559: &Apache::lonnet::allowed('vcl',$env{'request.course.id'}.'/'.$env{'request.course.sec'})))) {
1560: $statuses = ['active'];
1561: }
1.217 raeburn 1562: if ($env{'form.action'} ne 'singlestudent') {
1.329 raeburn 1563: &display_existing_roles($r,$ccuname,$ccdomain,\%inccourses,$context,
1.406.2.6 raeburn 1564: $roledom,$crstype,$showcredits,$statuses);
1.217 raeburn 1565: }
1.25 matthew 1566: } ## End of new user/old user logic
1.218 raeburn 1567: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1568: my $btntxt;
1569: if ($crstype eq 'Community') {
1570: $btntxt = &mt('Enroll Member');
1571: } else {
1572: $btntxt = &mt('Enroll Student');
1573: }
1574: $r->print('<br /><input type="button" value="'.$btntxt.'" onclick="setSections(this.form)" />'."\n");
1.406.2.6 raeburn 1575: } elsif ($permission->{'cusr'}) {
1.393 raeburn 1576: $r->print('<div class="LC_left_float">'.
1577: '<fieldset><legend>'.&mt('Add Roles').'</legend>');
1.218 raeburn 1578: my $addrolesdisplay = 0;
1579: if ($context eq 'domain' || $context eq 'author') {
1580: $addrolesdisplay = &new_coauthor_roles($r,$ccuname,$ccdomain);
1581: }
1582: if ($context eq 'domain') {
1.357 raeburn 1583: my $add_domainroles = &new_domain_roles($r,$ccdomain);
1.218 raeburn 1584: if (!$addrolesdisplay) {
1585: $addrolesdisplay = $add_domainroles;
1.2 www 1586: }
1.375 raeburn 1587: $r->print(&course_level_dc($env{'request.role.domain'},$showcredits));
1.393 raeburn 1588: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1589: '<br /><input type="button" value="'.&mt('Save').'" onclick="setCourse()" />'."\n");
1.218 raeburn 1590: } elsif ($context eq 'author') {
1591: if ($addrolesdisplay) {
1.393 raeburn 1592: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1593: '<br /><input type="button" value="'.&mt('Save').'"');
1.218 raeburn 1594: if ($newuser) {
1.301 bisitz 1595: $r->print(' onclick="auth_check()" \>'."\n");
1.218 raeburn 1596: } else {
1.406.2.20.2. (raeburn 1597:): $r->print(' onclick="this.form.submit()" \>'."\n");
1.218 raeburn 1598: }
1.188 raeburn 1599: } else {
1.393 raeburn 1600: $r->print('</fieldset></div>'.
1601: '<div class="LC_clear_float_footer"></div>'.
1602: '<br /><a href="javascript:backPage(document.cu)">'.
1.218 raeburn 1603: &mt('Back to previous page').'</a>');
1.188 raeburn 1604: }
1605: } else {
1.375 raeburn 1606: $r->print(&course_level_table(\%inccourses,$showcredits,$defaultcredits));
1.393 raeburn 1607: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1608: '<br /><input type="button" value="'.&mt('Save').'" onclick="setSections(this.form)" />'."\n");
1.188 raeburn 1609: }
1.88 raeburn 1610: }
1.188 raeburn 1611: $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','userrole','ccdomain','prevphase','currstate','ccuname','ccdomain']));
1.179 raeburn 1612: $r->print('<input type="hidden" name="currstate" value="" />');
1.393 raeburn 1613: $r->print('<input type="hidden" name="prevphase" value="'.$env{'form.phase'}.'" /></form><br /><br />');
1.218 raeburn 1614: return;
1.2 www 1615: }
1.1 www 1616:
1.213 raeburn 1617: sub singleuser_breadcrumb {
1.406.2.7 raeburn 1618: my ($crstype,$context,$domain) = @_;
1.213 raeburn 1619: my %breadcrumb_text;
1620: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1621: if ($crstype eq 'Community') {
1622: $breadcrumb_text{'search'} = 'Enroll a member';
1623: } else {
1624: $breadcrumb_text{'search'} = 'Enroll a student';
1625: }
1.406.2.7 raeburn 1626: $breadcrumb_text{'userpicked'} = 'Select a user';
1627: $breadcrumb_text{'modify'} = 'Set section/dates';
1.406.2.5 raeburn 1628: } elsif ($env{'form.action'} eq 'accesslogs') {
1629: $breadcrumb_text{'search'} = 'View access logs for a user';
1.406.2.7 raeburn 1630: $breadcrumb_text{'userpicked'} = 'Select a user';
1631: $breadcrumb_text{'activity'} = 'Activity';
1632: } elsif (($env{'form.action'} eq 'singleuser') && ($context eq 'domain') &&
1633: (!&Apache::lonnet::allowed('mau',$domain))) {
1634: $breadcrumb_text{'search'} = "View user's roles";
1635: $breadcrumb_text{'userpicked'} = 'Select a user';
1636: $breadcrumb_text{'modify'} = 'User roles';
1.213 raeburn 1637: } else {
1.229 raeburn 1638: $breadcrumb_text{'search'} = 'Create/modify a user';
1.406.2.7 raeburn 1639: $breadcrumb_text{'userpicked'} = 'Select a user';
1640: $breadcrumb_text{'modify'} = 'Set user role';
1.213 raeburn 1641: }
1642: return %breadcrumb_text;
1643: }
1644:
1645: sub date_sections_select {
1.375 raeburn 1646: my ($context,$newuser,$formname,$permission,$crstype,$ccuname,$ccdomain,
1647: $showcredits) = @_;
1648: my $credits;
1649: if ($showcredits) {
1650: my $defaultcredits = &Apache::lonuserutils::get_defaultcredits();
1651: $credits = &get_user_credits($ccuname,$ccdomain,$defaultcredits);
1652: if ($credits eq '') {
1653: $credits = $defaultcredits;
1654: }
1655: }
1.213 raeburn 1656: my $cid = $env{'request.course.id'};
1657: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity($cid);
1658: my $date_table = '<h3>'.&mt('Starting and Ending Dates').'</h3>'."\n".
1659: &Apache::lonuserutils::date_setting_table(undef,undef,$context,
1660: undef,$formname,$permission);
1661: my $rowtitle = 'Section';
1.375 raeburn 1662: my $secbox = '<h3>'.&mt('Section and Credits').'</h3>'."\n".
1.213 raeburn 1663: &Apache::lonuserutils::section_picker($cdom,$cnum,'st',$rowtitle,
1.375 raeburn 1664: $permission,$context,'',$crstype,
1665: $showcredits,$credits);
1.213 raeburn 1666: my $output = $date_table.$secbox;
1667: return $output;
1668: }
1669:
1.216 raeburn 1670: sub validation_javascript {
1.375 raeburn 1671: my ($context,$ccdomain,$pjump_def,$crstype,$groupslist,$newuser,$formname,
1.216 raeburn 1672: $loaditem) = @_;
1673: my $dc_setcourse_code = '';
1674: my $nondc_setsection_code = '';
1675: if ($context eq 'domain') {
1676: my $dcdom = $env{'request.role.domain'};
1677: $loaditem->{'onload'} = "document.cu.coursedesc.value='';";
1.227 raeburn 1678: $dc_setcourse_code =
1679: &Apache::lonuserutils::dc_setcourse_js('cu','singleuser',$context);
1.216 raeburn 1680: } else {
1.227 raeburn 1681: my $checkauth;
1682: if (($newuser) || (&Apache::lonnet::allowed('mau',$ccdomain))) {
1683: $checkauth = 1;
1684: }
1685: if ($context eq 'course') {
1686: $nondc_setsection_code =
1687: &Apache::lonuserutils::setsections_javascript($formname,$groupslist,
1.375 raeburn 1688: undef,$checkauth,
1689: $crstype);
1.227 raeburn 1690: }
1691: if ($checkauth) {
1692: $nondc_setsection_code .=
1693: &Apache::lonuserutils::verify_authen($formname,$context);
1694: }
1.216 raeburn 1695: }
1696: my $js = &user_modification_js($pjump_def,$dc_setcourse_code,
1697: $nondc_setsection_code,$groupslist);
1698: my ($jsback,$elements) = &crumb_utilities();
1699: $js .= "\n".
1.301 bisitz 1700: '<script type="text/javascript">'."\n".
1701: '// <![CDATA['."\n".
1702: $jsback."\n".
1703: '// ]]>'."\n".
1704: '</script>'."\n";
1.216 raeburn 1705: return $js;
1706: }
1707:
1.217 raeburn 1708: sub display_existing_roles {
1.375 raeburn 1709: my ($r,$ccuname,$ccdomain,$inccourses,$context,$roledom,$crstype,
1.406.2.6 raeburn 1710: $showcredits,$statuses) = @_;
1.329 raeburn 1711: my $now=time;
1.406.2.6 raeburn 1712: my $showall = 1;
1713: my ($showexpired,$showactive);
1714: if ((ref($statuses) eq 'ARRAY') && (@{$statuses} > 0)) {
1715: $showall = 0;
1716: if (grep(/^expired$/,@{$statuses})) {
1717: $showexpired = 1;
1718: }
1719: if (grep(/^active$/,@{$statuses})) {
1720: $showactive = 1;
1721: }
1722: if ($showexpired && $showactive) {
1723: $showall = 1;
1724: }
1725: }
1.329 raeburn 1726: my %lt=&Apache::lonlocal::texthash(
1.217 raeburn 1727: 'rer' => "Existing Roles",
1728: 'rev' => "Revoke",
1729: 'del' => "Delete",
1730: 'ren' => "Re-Enable",
1731: 'rol' => "Role",
1732: 'ext' => "Extent",
1.375 raeburn 1733: 'crd' => "Credits",
1.217 raeburn 1734: 'sta' => "Start",
1735: 'end' => "End",
1736: );
1.329 raeburn 1737: my (%rolesdump,%roletext,%sortrole,%roleclass,%rolepriv);
1738: if ($context eq 'course' || $context eq 'author') {
1739: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
1740: my %roleshash =
1741: &Apache::lonnet::get_my_roles($ccuname,$ccdomain,'userroles',
1742: ['active','previous','future'],\@roles,$roledom,1);
1743: foreach my $key (keys(%roleshash)) {
1744: my ($start,$end) = split(':',$roleshash{$key});
1745: next if ($start eq '-1' || $end eq '-1');
1746: my ($rnum,$rdom,$role,$sec) = split(':',$key);
1747: if ($context eq 'course') {
1748: next unless (($rnum eq $env{'course.'.$env{'request.course.id'}.'.num'})
1749: && ($rdom eq $env{'course.'.$env{'request.course.id'}.'.domain'}));
1750: } elsif ($context eq 'author') {
1751: next unless (($rnum eq $env{'user.name'}) && ($rdom eq $env{'request.role.domain'}));
1752: }
1753: my ($newkey,$newvalue,$newrole);
1754: $newkey = '/'.$rdom.'/'.$rnum;
1755: if ($sec ne '') {
1756: $newkey .= '/'.$sec;
1757: }
1758: $newvalue = $role;
1759: if ($role =~ /^cr/) {
1760: $newrole = 'cr';
1761: } else {
1762: $newrole = $role;
1763: }
1764: $newkey .= '_'.$newrole;
1765: if ($start ne '' && $end ne '') {
1766: $newvalue .= '_'.$end.'_'.$start;
1.335 raeburn 1767: } elsif ($end ne '') {
1768: $newvalue .= '_'.$end;
1.329 raeburn 1769: }
1770: $rolesdump{$newkey} = $newvalue;
1771: }
1772: } else {
1.360 raeburn 1773: %rolesdump=&Apache::lonnet::dump('roles',$ccdomain,$ccuname);
1.329 raeburn 1774: }
1775: # Build up table of user roles to allow revocation and re-enabling of roles.
1776: my ($tmp) = keys(%rolesdump);
1777: return if ($tmp =~ /^(con_lost|error)/i);
1778: foreach my $area (sort { my $a1=join('_',(split('_',$a))[1,0]);
1779: my $b1=join('_',(split('_',$b))[1,0]);
1780: return $a1 cmp $b1;
1781: } keys(%rolesdump)) {
1782: next if ($area =~ /^rolesdef/);
1783: my $envkey=$area;
1784: my $role = $rolesdump{$area};
1785: my $thisrole=$area;
1786: $area =~ s/\_\w\w$//;
1787: my ($role_code,$role_end_time,$role_start_time) =
1788: split(/_/,$role);
1.406.2.6 raeburn 1789: my $active=1;
1790: $active=0 if (($role_end_time) && ($now>$role_end_time));
1791: if ($active) {
1792: next unless($showall || $showactive);
1793: } else {
1794: next unless($showall || $showexpired);
1795: }
1.217 raeburn 1796: # Is this a custom role? Get role owner and title.
1.329 raeburn 1797: my ($croleudom,$croleuname,$croletitle)=
1798: ($role_code=~m{^cr/($match_domain)/($match_username)/(\w+)$});
1799: my $allowed=0;
1800: my $delallowed=0;
1801: my $sortkey=$role_code;
1802: my $class='Unknown';
1.375 raeburn 1803: my $credits='';
1.406.2.6 raeburn 1804: my $csec;
1.406.2.7 raeburn 1805: if ($area =~ m{^/($match_domain)/($match_courseid)}) {
1.329 raeburn 1806: $class='Course';
1807: my ($coursedom,$coursedir) = ($1,$2);
1808: my $cid = $1.'_'.$2;
1809: # $1.'_'.$2 is the course id (eg. 103_12345abcef103l3).
1.406.2.7 raeburn 1810: next if ($envkey =~ m{^/$match_domain/$match_courseid/[A-Za-z0-9]+_gr$});
1.329 raeburn 1811: my %coursedata=
1812: &Apache::lonnet::coursedescription($cid);
1813: if ($coursedir =~ /^$match_community$/) {
1814: $class='Community';
1815: }
1816: $sortkey.="\0$coursedom";
1817: my $carea;
1818: if (defined($coursedata{'description'})) {
1819: $carea=$coursedata{'description'}.
1820: '<br />'.&mt('Domain').': '.$coursedom.(' 'x8).
1821: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$coursedir,$coursedom);
1822: $sortkey.="\0".$coursedata{'description'};
1823: } else {
1824: if ($class eq 'Community') {
1825: $carea=&mt('Unavailable community').': '.$area;
1826: $sortkey.="\0".&mt('Unavailable community').': '.$area;
1.217 raeburn 1827: } else {
1828: $carea=&mt('Unavailable course').': '.$area;
1829: $sortkey.="\0".&mt('Unavailable course').': '.$area;
1830: }
1.329 raeburn 1831: }
1832: $sortkey.="\0$coursedir";
1833: $inccourses->{$cid}=1;
1.375 raeburn 1834: if (($showcredits) && ($class eq 'Course') && ($role_code eq 'st')) {
1835: my $defaultcredits = $coursedata{'internal.defaultcredits'};
1836: $credits =
1837: &get_user_credits($ccuname,$ccdomain,$defaultcredits,
1838: $coursedom,$coursedir);
1839: if ($credits eq '') {
1840: $credits = $defaultcredits;
1841: }
1842: }
1.329 raeburn 1843: if ((&Apache::lonnet::allowed('c'.$role_code,$coursedom.'/'.$coursedir)) ||
1844: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
1845: $allowed=1;
1846: }
1847: unless ($allowed) {
1.365 raeburn 1848: my $isowner = &Apache::lonuserutils::is_courseowner($cid,$coursedata{'internal.courseowner'});
1.329 raeburn 1849: if ($isowner) {
1850: if (($role_code eq 'co') && ($class eq 'Community')) {
1851: $allowed = 1;
1852: } elsif (($role_code eq 'cc') && ($class eq 'Course')) {
1853: $allowed = 1;
1854: }
1.217 raeburn 1855: }
1.329 raeburn 1856: }
1857: if ((&Apache::lonnet::allowed('dro',$coursedom)) ||
1858: (&Apache::lonnet::allowed('dro',$ccdomain))) {
1859: $delallowed=1;
1860: }
1.217 raeburn 1861: # - custom role. Needs more info, too
1.329 raeburn 1862: if ($croletitle) {
1863: if (&Apache::lonnet::allowed('ccr',$coursedom.'/'.$coursedir)) {
1864: $allowed=1;
1865: $thisrole.='.'.$role_code;
1.217 raeburn 1866: }
1.329 raeburn 1867: }
1.406.2.6 raeburn 1868: if ($area=~m{^/($match_domain/$match_courseid/(\w+))}) {
1869: $csec = $2;
1870: $carea.='<br />'.&mt('Section: [_1]',$csec);
1871: $sortkey.="\0$csec";
1.329 raeburn 1872: if (!$allowed) {
1.406.2.6 raeburn 1873: if ($env{'request.course.sec'} eq $csec) {
1874: if (&Apache::lonnet::allowed('c'.$role_code,$1)) {
1.329 raeburn 1875: $allowed = 1;
1.217 raeburn 1876: }
1877: }
1878: }
1.329 raeburn 1879: }
1880: $area=$carea;
1881: } else {
1882: $sortkey.="\0".$area;
1883: # Determine if current user is able to revoke privileges
1884: if ($area=~m{^/($match_domain)/}) {
1885: if ((&Apache::lonnet::allowed('c'.$role_code,$1)) ||
1886: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
1887: $allowed=1;
1.217 raeburn 1888: }
1.329 raeburn 1889: if (((&Apache::lonnet::allowed('dro',$1)) ||
1890: (&Apache::lonnet::allowed('dro',$ccdomain))) &&
1891: ($role_code ne 'dc')) {
1892: $delallowed=1;
1.217 raeburn 1893: }
1.329 raeburn 1894: } else {
1895: if (&Apache::lonnet::allowed('c'.$role_code,'/')) {
1.217 raeburn 1896: $allowed=1;
1897: }
1898: }
1.363 raeburn 1899: if ($role_code eq 'ca' || $role_code eq 'au' || $role_code eq 'aa') {
1.377 raeburn 1900: $class='Authoring Space';
1.329 raeburn 1901: } elsif ($role_code eq 'su') {
1902: $class='System';
1.217 raeburn 1903: } else {
1.329 raeburn 1904: $class='Domain';
1.217 raeburn 1905: }
1.329 raeburn 1906: }
1907: if (($role_code eq 'ca') || ($role_code eq 'aa')) {
1908: $area=~m{/($match_domain)/($match_username)};
1909: if (&Apache::lonuserutils::authorpriv($2,$1)) {
1910: $allowed=1;
1.217 raeburn 1911: } else {
1.329 raeburn 1912: $allowed=0;
1.217 raeburn 1913: }
1.329 raeburn 1914: }
1915: my $row = '';
1.406.2.6 raeburn 1916: if ($showall) {
1917: $row.= '<td>';
1918: if (($active) && ($allowed)) {
1919: $row.= '<input type="checkbox" name="rev:'.$thisrole.'" />';
1.217 raeburn 1920: } else {
1.406.2.6 raeburn 1921: if ($active) {
1922: $row.=' ';
1923: } else {
1924: $row.=&mt('expired or revoked');
1925: }
1.217 raeburn 1926: }
1.406.2.6 raeburn 1927: $row.='</td><td>';
1928: if ($allowed && !$active) {
1929: $row.= '<input type="checkbox" name="ren:'.$thisrole.'" />';
1930: } else {
1931: $row.=' ';
1932: }
1933: $row.='</td><td>';
1934: if ($delallowed) {
1935: $row.= '<input type="checkbox" name="del:'.$thisrole.'" />';
1936: } else {
1937: $row.=' ';
1938: }
1939: $row.= '</td>';
1.329 raeburn 1940: }
1941: my $plaintext='';
1942: if (!$croletitle) {
1.375 raeburn 1943: $plaintext=&Apache::lonnet::plaintext($role_code,$class);
1944: if (($showcredits) && ($credits ne '')) {
1945: $plaintext .= '<br/ ><span class="LC_nobreak">'.
1946: '<span class="LC_fontsize_small">'.
1947: &mt('Credits: [_1]',$credits).
1948: '</span></span>';
1949: }
1.329 raeburn 1950: } else {
1951: $plaintext=
1.395 bisitz 1952: &mt('Custom role [_1][_2]defined by [_3]',
1.346 bisitz 1953: '"'.$croletitle.'"',
1954: '<br />',
1955: $croleuname.':'.$croleudom);
1.329 raeburn 1956: }
1.406.2.6 raeburn 1957: $row.= '<td>'.$plaintext.'</td>'.
1958: '<td>'.$area.'</td>'.
1959: '<td>'.($role_start_time?&Apache::lonlocal::locallocaltime($role_start_time)
1960: : ' ' ).'</td>'.
1961: '<td>'.($role_end_time ?&Apache::lonlocal::locallocaltime($role_end_time)
1962: : ' ' ).'</td>';
1.329 raeburn 1963: $sortrole{$sortkey}=$envkey;
1964: $roletext{$envkey}=$row;
1965: $roleclass{$envkey}=$class;
1.406.2.6 raeburn 1966: if ($allowed) {
1967: $rolepriv{$envkey}='edit';
1968: } else {
1969: if ($context eq 'domain') {
1.406.2.7 raeburn 1970: if ((&Apache::lonnet::allowed('vur',$ccdomain)) &&
1971: ($envkey=~m{^/$ccdomain/})) {
1.406.2.6 raeburn 1972: $rolepriv{$envkey}='view';
1973: }
1974: } elsif ($context eq 'course') {
1975: if ((&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) ||
1976: ($env{'request.course.sec'} && ($env{'request.course.sec'} eq $csec) &&
1977: &Apache::lonnet::allowed('vcl',$env{'request.course.id'}.'/'.$env{'request.course.sec'}))) {
1978: $rolepriv{$envkey}='view';
1979: }
1980: }
1981: }
1.329 raeburn 1982: } # end of foreach (table building loop)
1983:
1984: my $rolesdisplay = 0;
1985: my %output = ();
1.377 raeburn 1986: foreach my $type ('Authoring Space','Course','Community','Domain','System','Unknown') {
1.329 raeburn 1987: $output{$type} = '';
1988: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
1989: if ( ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/ ) && ($rolepriv{$sortrole{$which}}) ) {
1990: $output{$type}.=
1991: &Apache::loncommon::start_data_table_row().
1992: $roletext{$sortrole{$which}}.
1993: &Apache::loncommon::end_data_table_row();
1.217 raeburn 1994: }
1.329 raeburn 1995: }
1996: unless($output{$type} eq '') {
1997: $output{$type} = '<tr class="LC_info_row">'.
1998: "<td align='center' colspan='7'>".&mt($type)."</td></tr>".
1999: $output{$type};
2000: $rolesdisplay = 1;
2001: }
2002: }
2003: if ($rolesdisplay == 1) {
2004: my $contextrole='';
2005: if ($env{'request.course.id'}) {
2006: if (&Apache::loncommon::course_type() eq 'Community') {
2007: $contextrole = &mt('Existing Roles in this Community');
1.290 bisitz 2008: } else {
1.329 raeburn 2009: $contextrole = &mt('Existing Roles in this Course');
1.290 bisitz 2010: }
1.329 raeburn 2011: } elsif ($env{'request.role'} =~ /^au\./) {
1.377 raeburn 2012: $contextrole = &mt('Existing Co-Author Roles in your Authoring Space');
1.329 raeburn 2013: } else {
1.406.2.6 raeburn 2014: if ($showall) {
2015: $contextrole = &mt('Existing Roles in this Domain');
2016: } elsif ($showactive) {
2017: $contextrole = &mt('Unexpired Roles in this Domain');
2018: } elsif ($showexpired) {
2019: $contextrole = &mt('Expired or Revoked Roles in this Domain');
2020: }
1.329 raeburn 2021: }
1.393 raeburn 2022: $r->print('<div class="LC_left_float">'.
1.375 raeburn 2023: '<fieldset><legend>'.$contextrole.'</legend>'.
1.217 raeburn 2024: &Apache::loncommon::start_data_table("LC_createuser").
1.406.2.6 raeburn 2025: &Apache::loncommon::start_data_table_header_row());
2026: if ($showall) {
2027: $r->print(
2028: '<th>'.$lt{'rev'}.'</th><th>'.$lt{'ren'}.'</th><th>'.$lt{'del'}.'</th>'
2029: );
2030: } elsif ($showexpired) {
2031: $r->print('<th>'.$lt{'rev'}.'</th>');
2032: }
2033: $r->print(
2034: '<th>'.$lt{'rol'}.'</th><th>'.$lt{'ext'}.'</th>'.
2035: '<th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
1.217 raeburn 2036: &Apache::loncommon::end_data_table_header_row());
1.377 raeburn 2037: foreach my $type ('Authoring Space','Course','Community','Domain','System','Unknown') {
1.329 raeburn 2038: if ($output{$type}) {
2039: $r->print($output{$type}."\n");
1.217 raeburn 2040: }
2041: }
1.375 raeburn 2042: $r->print(&Apache::loncommon::end_data_table().
2043: '</fieldset></div>');
1.329 raeburn 2044: }
1.217 raeburn 2045: return;
2046: }
2047:
1.218 raeburn 2048: sub new_coauthor_roles {
2049: my ($r,$ccuname,$ccdomain) = @_;
2050: my $addrolesdisplay = 0;
2051: #
2052: # Co-Author
2053: #
2054: if (&Apache::lonuserutils::authorpriv($env{'user.name'},
2055: $env{'request.role.domain'}) &&
2056: ($env{'user.name'} ne $ccuname || $env{'user.domain'} ne $ccdomain)) {
2057: # No sense in assigning co-author role to yourself
2058: $addrolesdisplay = 1;
2059: my $cuname=$env{'user.name'};
2060: my $cudom=$env{'request.role.domain'};
2061: my %lt=&Apache::lonlocal::texthash(
1.377 raeburn 2062: 'cs' => "Authoring Space",
1.218 raeburn 2063: 'act' => "Activate",
2064: 'rol' => "Role",
2065: 'ext' => "Extent",
2066: 'sta' => "Start",
2067: 'end' => "End",
2068: 'cau' => "Co-Author",
2069: 'caa' => "Assistant Co-Author",
2070: 'ssd' => "Set Start Date",
2071: 'sed' => "Set End Date"
2072: );
2073: $r->print('<h4>'.$lt{'cs'}.'</h4>'."\n".
2074: &Apache::loncommon::start_data_table()."\n".
2075: &Apache::loncommon::start_data_table_header_row()."\n".
2076: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'.
2077: '<th>'.$lt{'ext'}.'</th><th>'.$lt{'sta'}.'</th>'.
2078: '<th>'.$lt{'end'}.'</th>'."\n".
2079: &Apache::loncommon::end_data_table_header_row()."\n".
2080: &Apache::loncommon::start_data_table_row().'
2081: <td>
1.291 bisitz 2082: <input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_ca" />
1.218 raeburn 2083: </td>
2084: <td>'.$lt{'cau'}.'</td>
2085: <td>'.$cudom.'_'.$cuname.'</td>
2086: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_ca" value="" />
2087: <a href=
2088: "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>
2089: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_ca" value="" />
2090: <a href=
2091: "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".
2092: &Apache::loncommon::end_data_table_row()."\n".
2093: &Apache::loncommon::start_data_table_row()."\n".
1.291 bisitz 2094: '<td><input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_aa" /></td>
1.218 raeburn 2095: <td>'.$lt{'caa'}.'</td>
2096: <td>'.$cudom.'_'.$cuname.'</td>
2097: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_aa" value="" />
2098: <a href=
2099: "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>
2100: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_aa" value="" />
2101: <a href=
2102: "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".
2103: &Apache::loncommon::end_data_table_row()."\n".
2104: &Apache::loncommon::end_data_table());
2105: } elsif ($env{'request.role'} =~ /^au\./) {
2106: if (!(&Apache::lonuserutils::authorpriv($env{'user.name'},
2107: $env{'request.role.domain'}))) {
2108: $r->print('<span class="LC_error">'.
2109: &mt('You do not have privileges to assign co-author roles.').
2110: '</span>');
2111: } elsif (($env{'user.name'} eq $ccuname) &&
2112: ($env{'user.domain'} eq $ccdomain)) {
1.377 raeburn 2113: $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 2114: }
2115: }
2116: return $addrolesdisplay;;
2117: }
2118:
2119: sub new_domain_roles {
1.357 raeburn 2120: my ($r,$ccdomain) = @_;
1.218 raeburn 2121: my $addrolesdisplay = 0;
2122: #
2123: # Domain level
2124: #
2125: my $num_domain_level = 0;
2126: my $domaintext =
2127: '<h4>'.&mt('Domain Level').'</h4>'.
2128: &Apache::loncommon::start_data_table().
2129: &Apache::loncommon::start_data_table_header_row().
2130: '<th>'.&mt('Activate').'</th><th>'.&mt('Role').'</th><th>'.
2131: &mt('Extent').'</th>'.
2132: '<th>'.&mt('Start').'</th><th>'.&mt('End').'</th>'.
2133: &Apache::loncommon::end_data_table_header_row();
1.312 raeburn 2134: my @allroles = &Apache::lonuserutils::roles_by_context('domain');
1.218 raeburn 2135: foreach my $thisdomain (sort(&Apache::lonnet::all_domains())) {
1.312 raeburn 2136: foreach my $role (@allroles) {
2137: next if ($role eq 'ad');
1.357 raeburn 2138: next if (($role eq 'au') && ($ccdomain ne $thisdomain));
1.218 raeburn 2139: if (&Apache::lonnet::allowed('c'.$role,$thisdomain)) {
2140: my $plrole=&Apache::lonnet::plaintext($role);
2141: my %lt=&Apache::lonlocal::texthash(
2142: 'ssd' => "Set Start Date",
2143: 'sed' => "Set End Date"
2144: );
2145: $num_domain_level ++;
2146: $domaintext .=
2147: &Apache::loncommon::start_data_table_row().
1.291 bisitz 2148: '<td><input type="checkbox" name="act_'.$thisdomain.'_'.$role.'" /></td>
1.218 raeburn 2149: <td>'.$plrole.'</td>
2150: <td>'.$thisdomain.'</td>
2151: <td><input type="hidden" name="start_'.$thisdomain.'_'.$role.'" value="" />
2152: <a href=
2153: "javascript:pjump('."'date_start','Start Date $plrole',document.cu.start_$thisdomain\_$role.value,'start_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'ssd'}.'</a></td>
2154: <td><input type="hidden" name="end_'.$thisdomain.'_'.$role.'" value="" />
2155: <a href=
2156: "javascript:pjump('."'date_end','End Date $plrole',document.cu.end_$thisdomain\_$role.value,'end_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'sed'}.'</a></td>'.
2157: &Apache::loncommon::end_data_table_row();
2158: }
2159: }
2160: }
2161: $domaintext.= &Apache::loncommon::end_data_table();
2162: if ($num_domain_level > 0) {
2163: $r->print($domaintext);
2164: $addrolesdisplay = 1;
2165: }
2166: return $addrolesdisplay;
2167: }
2168:
1.188 raeburn 2169: sub user_authentication {
1.406.2.17 raeburn 2170: my ($ccuname,$ccdomain,$formname,$crstype,$permission) = @_;
1.188 raeburn 2171: my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
1.227 raeburn 2172: my $outcome;
1.406.2.6 raeburn 2173: my %lt=&Apache::lonlocal::texthash(
2174: 'err' => "ERROR",
2175: 'uuas' => "This user has an unrecognized authentication scheme",
2176: 'adcs' => "Please alert a domain coordinator of this situation",
2177: 'sldb' => "Please specify login data below",
2178: 'ld' => "Login Data"
2179: );
1.188 raeburn 2180: # Check for a bad authentication type
2181: if ($currentauth !~ /^(krb4|krb5|unix|internal|localauth):/) {
2182: # bad authentication scheme
2183: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
1.227 raeburn 2184: &initialize_authen_forms($ccdomain,$formname);
2185:
1.190 raeburn 2186: my $choices = &Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc);
1.188 raeburn 2187: $outcome = <<ENDBADAUTH;
2188: <script type="text/javascript" language="Javascript">
1.301 bisitz 2189: // <![CDATA[
1.188 raeburn 2190: $loginscript
1.301 bisitz 2191: // ]]>
1.188 raeburn 2192: </script>
2193: <span class="LC_error">$lt{'err'}:
2194: $lt{'uuas'} ($currentauth). $lt{'sldb'}.</span>
2195: <h3>$lt{'ld'}</h3>
2196: $choices
2197: ENDBADAUTH
2198: } else {
2199: # This user is not allowed to modify the user's
2200: # authentication scheme, so just notify them of the problem
2201: $outcome = <<ENDBADAUTH;
2202: <span class="LC_error"> $lt{'err'}:
2203: $lt{'uuas'} ($currentauth). $lt{'adcs'}.
2204: </span>
2205: ENDBADAUTH
2206: }
2207: } else { # Authentication type is valid
1.227 raeburn 2208: &initialize_authen_forms($ccdomain,$formname,$currentauth,'modifyuser');
1.205 raeburn 2209: my ($authformcurrent,$can_modify,@authform_others) =
1.188 raeburn 2210: &modify_login_block($ccdomain,$currentauth);
2211: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
2212: # Current user has login modification privileges
2213: $outcome =
2214: '<script type="text/javascript" language="Javascript">'."\n".
1.301 bisitz 2215: '// <![CDATA['."\n".
1.188 raeburn 2216: $loginscript."\n".
1.301 bisitz 2217: '// ]]>'."\n".
1.188 raeburn 2218: '</script>'."\n".
2219: '<h3>'.$lt{'ld'}.'</h3>'.
2220: &Apache::loncommon::start_data_table().
1.205 raeburn 2221: &Apache::loncommon::start_data_table_row().
1.188 raeburn 2222: '<td>'.$authformnop;
1.406.2.6 raeburn 2223: if (($can_modify) && (&Apache::lonnet::allowed('mau',$ccdomain))) {
1.188 raeburn 2224: $outcome .= '</td>'."\n".
2225: &Apache::loncommon::end_data_table_row().
2226: &Apache::loncommon::start_data_table_row().
2227: '<td>'.$authformcurrent.'</td>'.
2228: &Apache::loncommon::end_data_table_row()."\n";
2229: } else {
1.200 raeburn 2230: $outcome .= ' ('.$authformcurrent.')</td>'.
2231: &Apache::loncommon::end_data_table_row()."\n";
1.188 raeburn 2232: }
1.406.2.6 raeburn 2233: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
2234: foreach my $item (@authform_others) {
2235: $outcome .= &Apache::loncommon::start_data_table_row().
2236: '<td>'.$item.'</td>'.
2237: &Apache::loncommon::end_data_table_row()."\n";
2238: }
1.188 raeburn 2239: }
1.205 raeburn 2240: $outcome .= &Apache::loncommon::end_data_table();
1.188 raeburn 2241: } else {
1.406.2.17 raeburn 2242: if (($currentauth =~ /^internal:/) &&
2243: (&Apache::lonuserutils::can_change_internalpass($ccuname,$ccdomain,$crstype,$permission))) {
2244: $outcome = <<"ENDJS";
2245: <script type="text/javascript">
2246: // <![CDATA[
2247: function togglePwd(form) {
2248: if (form.newintpwd.length) {
2249: if (document.getElementById('LC_ownersetpwd')) {
2250: for (var i=0; i<form.newintpwd.length; i++) {
2251: if (form.newintpwd[i].checked) {
2252: if (form.newintpwd[i].value == 1) {
2253: document.getElementById('LC_ownersetpwd').style.display = 'inline-block';
2254: } else {
2255: document.getElementById('LC_ownersetpwd').style.display = 'none';
2256: }
2257: }
2258: }
2259: }
2260: }
2261: }
2262: // ]]>
2263: </script>
2264: ENDJS
2265:
2266: $outcome .= '<h3>'.$lt{'ld'}.'</h3>'.
2267: &Apache::loncommon::start_data_table().
2268: &Apache::loncommon::start_data_table_row().
2269: '<td>'.&mt('Internally authenticated').'<br />'.&mt("Change user's password?").
2270: '<label><input type="radio" name="newintpwd" value="0" checked="checked" onclick="togglePwd(this.form);" />'.
2271: &mt('No').'</label>'.(' 'x2).
2272: '<label><input type="radio" name="newintpwd" value="1" onclick="togglePwd(this.form);" />'.&mt('Yes').'</label>'.
2273: '<div id="LC_ownersetpwd" style="display:none">'.
2274: ' '.&mt('Password').' <input type="password" size="15" name="intarg" value="" />'.
2275: '<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></div></td>'.
2276: &Apache::loncommon::end_data_table_row().
2277: &Apache::loncommon::end_data_table();
2278: }
1.406.2.6 raeburn 2279: if (&Apache::lonnet::allowed('udp',$ccdomain)) {
2280: # Current user has rights to view domain preferences for user's domain
2281: my $result;
2282: if ($currentauth =~ /^krb(4|5):([^:]*)$/) {
2283: my ($krbver,$krbrealm) = ($1,$2);
2284: if ($krbrealm eq '') {
2285: $result = &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2286: } else {
2287: $result = &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
1.406.2.9 raeburn 2288: $krbrealm,$krbver);
1.406.2.6 raeburn 2289: }
2290: } elsif ($currentauth =~ /^internal:/) {
2291: $result = &mt('Currently internally authenticated.');
2292: } elsif ($currentauth =~ /^localauth:/) {
2293: $result = &mt('Currently using local (institutional) authentication.');
2294: } elsif ($currentauth =~ /^unix:/) {
2295: $result = &mt('Currently Filesystem Authenticated.');
2296: }
2297: $outcome = '<h3>'.$lt{'ld'}.'</h3>'.
2298: &Apache::loncommon::start_data_table().
2299: &Apache::loncommon::start_data_table_row().
2300: '<td>'.$result.'</td>'.
2301: &Apache::loncommon::end_data_table_row()."\n".
2302: &Apache::loncommon::end_data_table();
2303: } elsif (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
1.188 raeburn 2304: my %lt=&Apache::lonlocal::texthash(
2305: 'ccld' => "Change Current Login Data",
2306: 'yodo' => "You do not have privileges to modify the authentication configuration for this user.",
2307: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
2308: );
2309: $outcome .= <<ENDNOPRIV;
2310: <h3>$lt{'ccld'}</h3>
2311: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1.235 raeburn 2312: <input type="hidden" name="login" value="nochange" />
1.188 raeburn 2313: ENDNOPRIV
2314: }
2315: }
2316: } ## End of "check for bad authentication type" logic
2317: return $outcome;
2318: }
2319:
1.187 raeburn 2320: sub modify_login_block {
2321: my ($dom,$currentauth) = @_;
2322: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2323: my ($authnum,%can_assign) =
2324: &Apache::loncommon::get_assignable_auth($dom);
1.205 raeburn 2325: my ($authformcurrent,@authform_others,$show_override_msg);
1.187 raeburn 2326: if ($currentauth=~/^krb(4|5):/) {
2327: $authformcurrent=$authformkrb;
2328: if ($can_assign{'int'}) {
1.205 raeburn 2329: push(@authform_others,$authformint);
1.187 raeburn 2330: }
2331: if ($can_assign{'loc'}) {
1.205 raeburn 2332: push(@authform_others,$authformloc);
1.187 raeburn 2333: }
2334: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
2335: $show_override_msg = 1;
2336: }
2337: } elsif ($currentauth=~/^internal:/) {
2338: $authformcurrent=$authformint;
2339: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2340: push(@authform_others,$authformkrb);
1.187 raeburn 2341: }
2342: if ($can_assign{'loc'}) {
1.205 raeburn 2343: push(@authform_others,$authformloc);
1.187 raeburn 2344: }
2345: if ($can_assign{'int'}) {
2346: $show_override_msg = 1;
2347: }
2348: } elsif ($currentauth=~/^unix:/) {
2349: $authformcurrent=$authformfsys;
2350: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2351: push(@authform_others,$authformkrb);
1.187 raeburn 2352: }
2353: if ($can_assign{'int'}) {
1.205 raeburn 2354: push(@authform_others,$authformint);
1.187 raeburn 2355: }
2356: if ($can_assign{'loc'}) {
1.205 raeburn 2357: push(@authform_others,$authformloc);
1.187 raeburn 2358: }
2359: if ($can_assign{'fsys'}) {
2360: $show_override_msg = 1;
2361: }
2362: } elsif ($currentauth=~/^localauth:/) {
2363: $authformcurrent=$authformloc;
2364: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2365: push(@authform_others,$authformkrb);
1.187 raeburn 2366: }
2367: if ($can_assign{'int'}) {
1.205 raeburn 2368: push(@authform_others,$authformint);
1.187 raeburn 2369: }
2370: if ($can_assign{'loc'}) {
2371: $show_override_msg = 1;
2372: }
2373: }
2374: if ($show_override_msg) {
1.205 raeburn 2375: $authformcurrent = '<table><tr><td colspan="3">'.$authformcurrent.
2376: '</td></tr>'."\n".
2377: '<tr><td> </td>'.
2378: '<td><b>'.&mt('Currently in use').'</b></td>'.
2379: '<td align="right"><span class="LC_cusr_emph">'.
1.187 raeburn 2380: &mt('will override current values').
1.205 raeburn 2381: '</span></td></tr></table>';
1.187 raeburn 2382: }
1.205 raeburn 2383: return ($authformcurrent,$show_override_msg,@authform_others);
1.187 raeburn 2384: }
2385:
1.188 raeburn 2386: sub personal_data_display {
1.406.2.20 raeburn 2387: my ($ccuname,$ccdomain,$newuser,$context,$inst_results,$rolesarray,$now,
2388: $captchaform,$emailusername,$usertype,$usernameset,$condition,$excluded,$showsubmit) = @_;
1.388 bisitz 2389: my ($output,%userenv,%canmodify,%canmodify_status);
1.219 raeburn 2390: my @userinfo = ('firstname','middlename','lastname','generation',
2391: 'permanentemail','id');
1.252 raeburn 2392: my $rowcount = 0;
2393: my $editable = 0;
1.391 raeburn 2394: my %textboxsize = (
2395: firstname => '15',
2396: middlename => '15',
2397: lastname => '15',
2398: generation => '5',
2399: permanentemail => '25',
2400: id => '15',
2401: );
2402:
2403: my %lt=&Apache::lonlocal::texthash(
2404: 'pd' => "Personal Data",
2405: 'firstname' => "First Name",
2406: 'middlename' => "Middle Name",
2407: 'lastname' => "Last Name",
2408: 'generation' => "Generation",
2409: 'permanentemail' => "Permanent e-mail address",
2410: 'id' => "Student/Employee ID",
2411: 'lg' => "Login Data",
2412: 'inststatus' => "Affiliation",
2413: 'email' => 'E-mail address',
2414: 'valid' => 'Validation',
1.406.2.16 raeburn 2415: 'username' => 'Username',
1.391 raeburn 2416: );
2417:
2418: %canmodify_status =
1.286 raeburn 2419: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
2420: ['inststatus'],$rolesarray);
1.253 raeburn 2421: if (!$newuser) {
1.188 raeburn 2422: # Get the users information
2423: %userenv = &Apache::lonnet::get('environment',
2424: ['firstname','middlename','lastname','generation',
1.286 raeburn 2425: 'permanentemail','id','inststatus'],$ccdomain,$ccuname);
1.219 raeburn 2426: %canmodify =
2427: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
1.252 raeburn 2428: \@userinfo,$rolesarray);
1.257 raeburn 2429: } elsif ($context eq 'selfcreate') {
1.391 raeburn 2430: if ($newuser eq 'email') {
1.396 raeburn 2431: if (ref($emailusername) eq 'HASH') {
2432: if (ref($emailusername->{$usertype}) eq 'HASH') {
2433: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.406.2.16 raeburn 2434: @userinfo = ();
1.396 raeburn 2435: if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
2436: foreach my $field (@{$infofields}) {
2437: if ($emailusername->{$usertype}->{$field}) {
2438: push(@userinfo,$field);
2439: $canmodify{$field} = 1;
2440: unless ($textboxsize{$field}) {
2441: $textboxsize{$field} = 25;
2442: }
2443: unless ($lt{$field}) {
2444: $lt{$field} = $infotitles->{$field};
2445: }
2446: if ($emailusername->{$usertype}->{$field} eq 'required') {
2447: $lt{$field} .= '<b>*</b>';
2448: }
1.391 raeburn 2449: }
2450: }
2451: }
2452: }
2453: }
2454: } else {
2455: %canmodify = &selfcreate_canmodify($context,$ccdomain,\@userinfo,
2456: $inst_results,$rolesarray);
2457: }
1.188 raeburn 2458: }
1.391 raeburn 2459:
1.188 raeburn 2460: my $genhelp=&Apache::loncommon::help_open_topic('Generation');
2461: $output = '<h3>'.$lt{'pd'}.'</h3>'.
2462: &Apache::lonhtmlcommon::start_pick_box();
1.391 raeburn 2463: if (($context eq 'selfcreate') && ($newuser eq 'email')) {
1.406.2.16 raeburn 2464: my $size = 25;
2465: if ($condition) {
2466: if ($condition =~ /^\@[^\@]+$/) {
2467: $size = 10;
2468: } else {
2469: undef($condition);
2470: }
2471: }
2472: if ($excluded) {
2473: unless ($excluded =~ /^\@[^\@]+$/) {
2474: undef($condition);
2475: }
2476: }
1.396 raeburn 2477: $output .= &Apache::lonhtmlcommon::row_title($lt{'email'}.'<b>*</b>',undef,
1.391 raeburn 2478: 'LC_oddrow_value')."\n".
1.406.2.16 raeburn 2479: '<input type="text" name="uname" size="'.$size.'" value="" autocomplete="off" />';
2480: if ($condition) {
2481: $output .= $condition;
2482: } elsif ($excluded) {
2483: $output .= '<br /><span style="font-size: smaller">'.&mt('You must use an e-mail address that does not end with [_1]',
2484: $excluded).'</span>';
2485: }
2486: if ($usernameset eq 'first') {
2487: $output .= '<br /><span style="font-size: smaller">';
2488: if ($condition) {
2489: $output .= &mt('Your username in LON-CAPA will be the part of your e-mail address before [_1]',
2490: $condition);
2491: } else {
2492: $output .= &mt('Your username in LON-CAPA will be the part of your e-mail address before the @');
2493: }
2494: $output .= '</span>';
2495: }
1.391 raeburn 2496: $rowcount ++;
2497: $output .= &Apache::lonhtmlcommon::row_closure(1);
1.406.2.20.2. (raeburn 2498:): my $upassone = '<input type="password" name="upass'.$now.'" size="20" autocomplete="new-password" />';
2499:): my $upasstwo = '<input type="password" name="upasscheck'.$now.'" size="20" autocomplete="new-password" />';
1.396 raeburn 2500: $output .= &Apache::lonhtmlcommon::row_title(&mt('Password').'<b>*</b>',
1.391 raeburn 2501: 'LC_pick_box_title',
2502: 'LC_oddrow_value')."\n".
2503: $upassone."\n".
2504: &Apache::lonhtmlcommon::row_closure(1)."\n".
1.396 raeburn 2505: &Apache::lonhtmlcommon::row_title(&mt('Confirm password').'<b>*</b>',
1.391 raeburn 2506: 'LC_pick_box_title',
2507: 'LC_oddrow_value')."\n".
2508: $upasstwo.
2509: &Apache::lonhtmlcommon::row_closure()."\n";
1.406.2.16 raeburn 2510: if ($usernameset eq 'free') {
2511: my $onclick = "toggleUsernameDisp(this,'selfcreateusername');";
2512: $output .= &Apache::lonhtmlcommon::row_title($lt{'username'},undef,'LC_oddrow_value')."\n".
1.406.2.20 raeburn 2513: '<span class="LC_nobreak">'.&mt('Use e-mail address: ').
2514: '<label><input type="radio" name="emailused" value="1" checked="checked" onclick="'.$onclick.'" />'.
2515: &mt('Yes').'</label>'.(' 'x2).
2516: '<label><input type="radio" name="emailused" value="0" onclick="'.$onclick.'" />'.
2517: &mt('No').'</label></span>'."\n".
1.406.2.16 raeburn 2518: '<div id="selfcreateusername" style="display: none; font-size: smaller">'.
2519: '<br /><span class="LC_nobreak">'.&mt('Preferred username').
2520: ' <input type="text" name="username" value="" size="20" autocomplete="off"/>'.
2521: '</span></div>'."\n".&Apache::lonhtmlcommon::row_closure(1);
2522: $rowcount ++;
2523: }
1.391 raeburn 2524: }
1.188 raeburn 2525: foreach my $item (@userinfo) {
2526: my $rowtitle = $lt{$item};
1.252 raeburn 2527: my $hiderow = 0;
1.188 raeburn 2528: if ($item eq 'generation') {
2529: $rowtitle = $genhelp.$rowtitle;
2530: }
1.252 raeburn 2531: my $row = &Apache::lonhtmlcommon::row_title($rowtitle,undef,'LC_oddrow_value')."\n";
1.188 raeburn 2532: if ($newuser) {
1.210 raeburn 2533: if (ref($inst_results) eq 'HASH') {
2534: if ($inst_results->{$item} ne '') {
1.252 raeburn 2535: $row .= '<input type="hidden" name="c'.$item.'" value="'.$inst_results->{$item}.'" />'.$inst_results->{$item};
1.210 raeburn 2536: } else {
1.252 raeburn 2537: if ($context eq 'selfcreate') {
1.391 raeburn 2538: if ($canmodify{$item}) {
1.394 raeburn 2539: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.252 raeburn 2540: $editable ++;
2541: } else {
2542: $hiderow = 1;
2543: }
1.253 raeburn 2544: } else {
2545: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1.252 raeburn 2546: }
1.210 raeburn 2547: }
1.188 raeburn 2548: } else {
1.252 raeburn 2549: if ($context eq 'selfcreate') {
1.401 raeburn 2550: if ($canmodify{$item}) {
2551: if ($newuser eq 'email') {
2552: $row .= '<input type="text" name="'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.287 raeburn 2553: } else {
1.401 raeburn 2554: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.287 raeburn 2555: }
1.401 raeburn 2556: $editable ++;
2557: } else {
2558: $hiderow = 1;
1.252 raeburn 2559: }
1.253 raeburn 2560: } else {
2561: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1.252 raeburn 2562: }
1.188 raeburn 2563: }
2564: } else {
1.219 raeburn 2565: if ($canmodify{$item}) {
1.252 raeburn 2566: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="'.$userenv{$item}.'" />';
1.393 raeburn 2567: if (($item eq 'id') && (!$newuser)) {
2568: $row .= '<br />'.&Apache::lonuserutils::forceid_change($context);
2569: }
1.188 raeburn 2570: } else {
1.252 raeburn 2571: $row .= $userenv{$item};
1.188 raeburn 2572: }
2573: }
1.252 raeburn 2574: $row .= &Apache::lonhtmlcommon::row_closure(1);
2575: if (!$hiderow) {
2576: $output .= $row;
2577: $rowcount ++;
2578: }
1.188 raeburn 2579: }
1.286 raeburn 2580: if (($canmodify_status{'inststatus'}) || ($context ne 'selfcreate')) {
2581: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($ccdomain);
2582: if (ref($types) eq 'ARRAY') {
2583: if (@{$types} > 0) {
2584: my ($hiderow,$shown);
2585: if ($canmodify_status{'inststatus'}) {
2586: $shown = &pick_inst_statuses($userenv{'inststatus'},$usertypes,$types);
2587: } else {
2588: if ($userenv{'inststatus'} eq '') {
2589: $hiderow = 1;
1.334 raeburn 2590: } else {
2591: my @showitems;
2592: foreach my $item ( map { &unescape($_); } split(':',$userenv{'inststatus'})) {
2593: if (exists($usertypes->{$item})) {
2594: push(@showitems,$usertypes->{$item});
2595: } else {
2596: push(@showitems,$item);
2597: }
2598: }
2599: if (@showitems) {
2600: $shown = join(', ',@showitems);
2601: } else {
2602: $hiderow = 1;
2603: }
1.286 raeburn 2604: }
2605: }
2606: if (!$hiderow) {
1.389 bisitz 2607: my $row = &Apache::lonhtmlcommon::row_title(&mt('Affiliations'),undef,'LC_oddrow_value')."\n".
1.286 raeburn 2608: $shown.&Apache::lonhtmlcommon::row_closure(1);
2609: if ($context eq 'selfcreate') {
2610: $rowcount ++;
2611: }
2612: $output .= $row;
2613: }
2614: }
2615: }
2616: }
1.391 raeburn 2617: if (($context eq 'selfcreate') && ($newuser eq 'email')) {
2618: if ($captchaform) {
1.406.2.2 raeburn 2619: $output .= &Apache::lonhtmlcommon::row_title($lt{'valid'}.'*',
1.391 raeburn 2620: 'LC_pick_box_title')."\n".
2621: $captchaform."\n".'<br /><br />'.
2622: &Apache::lonhtmlcommon::row_closure(1);
2623: $rowcount ++;
2624: }
1.406.2.20 raeburn 2625: if ($showsubmit) {
2626: my $submit_text = &mt('Create account');
2627: $output .= &Apache::lonhtmlcommon::row_title()."\n".
2628: '<br /><input type="submit" name="createaccount" value="'.
2629: $submit_text.'" />';
2630: if ($usertype ne '') {
2631: $output .= '<input type="hidden" name="type" value="'.$usertype.'" />'.
2632: &Apache::lonhtmlcommon::row_closure(1);
2633: }
2634: }
1.391 raeburn 2635: }
1.188 raeburn 2636: $output .= &Apache::lonhtmlcommon::end_pick_box();
1.206 raeburn 2637: if (wantarray) {
1.252 raeburn 2638: if ($context eq 'selfcreate') {
2639: return($output,$rowcount,$editable);
2640: } else {
1.388 bisitz 2641: return $output;
1.252 raeburn 2642: }
1.206 raeburn 2643: } else {
2644: return $output;
2645: }
1.188 raeburn 2646: }
2647:
1.286 raeburn 2648: sub pick_inst_statuses {
2649: my ($curr,$usertypes,$types) = @_;
2650: my ($output,$rem,@currtypes);
2651: if ($curr ne '') {
2652: @currtypes = map { &unescape($_); } split(/:/,$curr);
2653: }
2654: my $numinrow = 2;
2655: if (ref($types) eq 'ARRAY') {
2656: $output = '<table>';
2657: my $lastcolspan;
2658: for (my $i=0; $i<@{$types}; $i++) {
2659: if (defined($usertypes->{$types->[$i]})) {
2660: my $rem = $i%($numinrow);
2661: if ($rem == 0) {
2662: if ($i<@{$types}-1) {
2663: if ($i > 0) {
2664: $output .= '</tr>';
2665: }
2666: $output .= '<tr>';
2667: }
2668: } elsif ($i==@{$types}-1) {
2669: my $colsleft = $numinrow - $rem;
2670: if ($colsleft > 1) {
2671: $lastcolspan = ' colspan="'.$colsleft.'"';
2672: }
2673: }
2674: my $check = ' ';
2675: if (grep(/^\Q$types->[$i]\E$/,@currtypes)) {
2676: $check = ' checked="checked" ';
2677: }
2678: $output .= '<td class="LC_left_item"'.$lastcolspan.'>'.
2679: '<span class="LC_nobreak"><label>'.
2680: '<input type="checkbox" name="inststatus" '.
2681: 'value="'.$types->[$i].'"'.$check.'/>'.
2682: $usertypes->{$types->[$i]}.'</label></span></td>';
2683: }
2684: }
2685: $output .= '</tr></table>';
2686: }
2687: return $output;
2688: }
2689:
1.257 raeburn 2690: sub selfcreate_canmodify {
2691: my ($context,$dom,$userinfo,$inst_results,$rolesarray) = @_;
2692: if (ref($inst_results) eq 'HASH') {
2693: my @inststatuses = &get_inststatuses($inst_results);
2694: if (@inststatuses == 0) {
2695: @inststatuses = ('default');
2696: }
2697: $rolesarray = \@inststatuses;
2698: }
2699: my %canmodify =
2700: &Apache::lonuserutils::can_modify_userinfo($context,$dom,$userinfo,
2701: $rolesarray);
2702: return %canmodify;
2703: }
2704:
1.252 raeburn 2705: sub get_inststatuses {
2706: my ($insthashref) = @_;
2707: my @inststatuses = ();
2708: if (ref($insthashref) eq 'HASH') {
2709: if (ref($insthashref->{'inststatus'}) eq 'ARRAY') {
2710: @inststatuses = @{$insthashref->{'inststatus'}};
2711: }
2712: }
2713: return @inststatuses;
2714: }
2715:
1.4 www 2716: # ================================================================= Phase Three
1.42 matthew 2717: sub update_user_data {
1.406.2.17 raeburn 2718: my ($r,$context,$crstype,$brcrum,$showcredits,$permission) = @_;
1.101 albertel 2719: my $uhome=&Apache::lonnet::homeserver($env{'form.ccuname'},
2720: $env{'form.ccdomain'});
1.27 matthew 2721: # Error messages
1.188 raeburn 2722: my $error = '<span class="LC_error">'.&mt('Error').': ';
1.193 raeburn 2723: my $end = '</span><br /><br />';
2724: my $rtnlink = '<a href="javascript:backPage(document.userupdate,'.
1.188 raeburn 2725: "'$env{'form.prevphase'}','modify')".'" />'.
1.219 raeburn 2726: &mt('Return to previous page').'</a>'.
2727: &Apache::loncommon::end_page();
2728: my $now = time;
1.40 www 2729: my $title;
1.101 albertel 2730: if (exists($env{'form.makeuser'})) {
1.40 www 2731: $title='Set Privileges for New User';
2732: } else {
2733: $title='Modify User Privileges';
2734: }
1.213 raeburn 2735: my $newuser = 0;
1.160 raeburn 2736: my ($jsback,$elements) = &crumb_utilities();
2737: my $jscript = '<script type="text/javascript">'."\n".
1.301 bisitz 2738: '// <![CDATA['."\n".
2739: $jsback."\n".
2740: '// ]]>'."\n".
2741: '</script>'."\n";
1.406.2.7 raeburn 2742: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$env{'form.ccdomain'});
1.351 raeburn 2743: push (@{$brcrum},
2744: {href => "javascript:backPage(document.userupdate)",
2745: text => $breadcrumb_text{'search'},
2746: faq => 282,
2747: bug => 'Instructor Interface',}
2748: );
2749: if ($env{'form.prevphase'} eq 'userpicked') {
2750: push(@{$brcrum},
2751: {href => "javascript:backPage(document.userupdate,'get_user_info','select')",
2752: text => $breadcrumb_text{'userpicked'},
2753: faq => 282,
2754: bug => 'Instructor Interface',});
1.233 raeburn 2755: }
1.224 raeburn 2756: my $helpitem = 'Course_Change_Privileges';
2757: if ($env{'form.action'} eq 'singlestudent') {
2758: $helpitem = 'Course_Add_Student';
1.406.2.14 raeburn 2759: } elsif ($context eq 'author') {
2760: $helpitem = 'Author_Change_Privileges';
2761: } elsif ($context eq 'domain') {
2762: $helpitem = 'Domain_Change_Privileges';
1.224 raeburn 2763: }
1.351 raeburn 2764: push(@{$brcrum},
2765: {href => "javascript:backPage(document.userupdate,'$env{'form.prevphase'}','modify')",
2766: text => $breadcrumb_text{'modify'},
2767: faq => 282,
2768: bug => 'Instructor Interface',},
2769: {href => "/adm/createuser",
2770: text => "Result",
2771: faq => 282,
2772: bug => 'Instructor Interface',
2773: help => $helpitem});
2774: my $args = {bread_crumbs => $brcrum,
2775: bread_crumbs_component => 'User Management'};
2776: if ($env{'form.popup'}) {
2777: $args->{'no_nav_bar'} = 1;
2778: }
2779: $r->print(&Apache::loncommon::start_page($title,$jscript,$args));
1.188 raeburn 2780: $r->print(&update_result_form($uhome));
1.27 matthew 2781: # Check Inputs
1.101 albertel 2782: if (! $env{'form.ccuname'} ) {
1.193 raeburn 2783: $r->print($error.&mt('No login name specified').'.'.$end.$rtnlink);
1.27 matthew 2784: return;
2785: }
1.138 albertel 2786: if ( $env{'form.ccuname'} ne
2787: &LONCAPA::clean_username($env{'form.ccuname'}) ) {
1.281 bisitz 2788: $r->print($error.&mt('Invalid login name.').' '.
2789: &mt('Only letters, numbers, periods, dashes, @, and underscores are valid.').
1.193 raeburn 2790: $end.$rtnlink);
1.27 matthew 2791: return;
2792: }
1.101 albertel 2793: if (! $env{'form.ccdomain'} ) {
1.193 raeburn 2794: $r->print($error.&mt('No domain specified').'.'.$end.$rtnlink);
1.27 matthew 2795: return;
2796: }
1.138 albertel 2797: if ( $env{'form.ccdomain'} ne
2798: &LONCAPA::clean_domain($env{'form.ccdomain'}) ) {
1.281 bisitz 2799: $r->print($error.&mt('Invalid domain name.').' '.
2800: &mt('Only letters, numbers, periods, dashes, and underscores are valid.').
1.193 raeburn 2801: $end.$rtnlink);
1.27 matthew 2802: return;
2803: }
1.219 raeburn 2804: if ($uhome eq 'no_host') {
2805: $newuser = 1;
2806: }
1.101 albertel 2807: if (! exists($env{'form.makeuser'})) {
1.29 matthew 2808: # Modifying an existing user, so check the validity of the name
2809: if ($uhome eq 'no_host') {
1.389 bisitz 2810: $r->print(
2811: $error
2812: .'<p class="LC_error">'
2813: .&mt('Unable to determine home server for [_1] in domain [_2].',
2814: '"'.$env{'form.ccuname'}.'"','"'.$env{'form.ccdomain'}.'"')
2815: .'</p>');
1.29 matthew 2816: return;
2817: }
2818: }
1.27 matthew 2819: # Determine authentication method and password for the user being modified
2820: my $amode='';
2821: my $genpwd='';
1.101 albertel 2822: if ($env{'form.login'} eq 'krb') {
1.41 albertel 2823: $amode='krb';
1.101 albertel 2824: $amode.=$env{'form.krbver'};
2825: $genpwd=$env{'form.krbarg'};
2826: } elsif ($env{'form.login'} eq 'int') {
1.27 matthew 2827: $amode='internal';
1.101 albertel 2828: $genpwd=$env{'form.intarg'};
2829: } elsif ($env{'form.login'} eq 'fsys') {
1.27 matthew 2830: $amode='unix';
1.101 albertel 2831: $genpwd=$env{'form.fsysarg'};
2832: } elsif ($env{'form.login'} eq 'loc') {
1.27 matthew 2833: $amode='localauth';
1.101 albertel 2834: $genpwd=$env{'form.locarg'};
1.27 matthew 2835: $genpwd=" " if (!$genpwd);
1.101 albertel 2836: } elsif (($env{'form.login'} eq 'nochange') ||
2837: ($env{'form.login'} eq '' )) {
1.34 matthew 2838: # There is no need to tell the user we did not change what they
2839: # did not ask us to change.
1.35 matthew 2840: # If they are creating a new user but have not specified login
2841: # information this will be caught below.
1.30 matthew 2842: } else {
1.367 golterma 2843: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
2844: return;
1.27 matthew 2845: }
1.164 albertel 2846:
1.188 raeburn 2847: $r->print('<h3>'.&mt('User [_1] in domain [_2]',
1.367 golterma 2848: $env{'form.ccuname'}.' ('.&Apache::loncommon::plainname($env{'form.ccuname'},
2849: $env{'form.ccdomain'}).')', $env{'form.ccdomain'}).'</h3>');
2850: my %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($r,2);
1.344 bisitz 2851:
1.193 raeburn 2852: my (%alerts,%rulematch,%inst_results,%curr_rules);
1.334 raeburn 2853: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
1.406.2.20.2. (raeburn 2854:): my @usertools = ('aboutme','blog','webdav','portfolio','timezone');
1.384 raeburn 2855: my @requestcourses = ('official','unofficial','community','textbook');
1.362 raeburn 2856: my @requestauthor = ('requestauthor');
1.286 raeburn 2857: my ($othertitle,$usertypes,$types) =
2858: &Apache::loncommon::sorted_inst_types($env{'form.ccdomain'});
1.334 raeburn 2859: my %canmodify_status =
2860: &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},
2861: ['inststatus']);
1.101 albertel 2862: if ($env{'form.makeuser'}) {
1.164 albertel 2863: $r->print('<h3>'.&mt('Creating new account.').'</h3>');
1.27 matthew 2864: # Check for the authentication mode and password
2865: if (! $amode || ! $genpwd) {
1.193 raeburn 2866: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
1.27 matthew 2867: return;
1.18 albertel 2868: }
1.29 matthew 2869: # Determine desired host
1.101 albertel 2870: my $desiredhost = $env{'form.hserver'};
1.29 matthew 2871: if (lc($desiredhost) eq 'default') {
2872: $desiredhost = undef;
2873: } else {
1.147 albertel 2874: my %home_servers =
2875: &Apache::lonnet::get_servers($env{'form.ccdomain'},'library');
1.29 matthew 2876: if (! exists($home_servers{$desiredhost})) {
1.193 raeburn 2877: $r->print($error.&mt('Invalid home server specified').$end.$rtnlink);
2878: return;
2879: }
2880: }
2881: # Check ID format
2882: my %checkhash;
2883: my %checks = ('id' => 1);
2884: %{$checkhash{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}}} = (
1.219 raeburn 2885: 'newuser' => $newuser,
1.196 raeburn 2886: 'id' => $env{'form.cid'},
1.193 raeburn 2887: );
1.196 raeburn 2888: if ($env{'form.cid'} ne '') {
2889: &Apache::loncommon::user_rule_check(\%checkhash,\%checks,\%alerts,
2890: \%rulematch,\%inst_results,\%curr_rules);
2891: if (ref($alerts{'id'}) eq 'HASH') {
2892: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
2893: my $domdesc =
2894: &Apache::lonnet::domain($env{'form.ccdomain'},'description');
2895: if ($alerts{'id'}{$env{'form.ccdomain'}}{$env{'form.cid'}}) {
2896: my $userchkmsg;
2897: if (ref($curr_rules{$env{'form.ccdomain'}}) eq 'HASH') {
2898: $userchkmsg =
2899: &Apache::loncommon::instrule_disallow_msg('id',
2900: $domdesc,1).
2901: &Apache::loncommon::user_rule_formats($env{'form.ccdomain'},
2902: $domdesc,$curr_rules{$env{'form.ccdomain'}}{'id'},'id');
2903: }
2904: $r->print($error.&mt('Invalid ID format').$end.
2905: $userchkmsg.$rtnlink);
2906: return;
2907: }
2908: }
1.29 matthew 2909: }
2910: }
1.367 golterma 2911: &Apache::lonhtmlcommon::Increment_PrgWin($r, \%prog_state);
1.27 matthew 2912: # Call modifyuser
2913: my $result = &Apache::lonnet::modifyuser
1.193 raeburn 2914: ($env{'form.ccdomain'},$env{'form.ccuname'},$env{'form.cid'},
1.188 raeburn 2915: $amode,$genpwd,$env{'form.cfirstname'},
2916: $env{'form.cmiddlename'},$env{'form.clastname'},
2917: $env{'form.cgeneration'},undef,$desiredhost,
2918: $env{'form.cpermanentemail'});
1.77 www 2919: $r->print(&mt('Generating user').': '.$result);
1.219 raeburn 2920: $uhome = &Apache::lonnet::homeserver($env{'form.ccuname'},
1.101 albertel 2921: $env{'form.ccdomain'});
1.334 raeburn 2922: my (%changeHash,%newcustom,%changed,%changedinfo);
1.267 raeburn 2923: if ($uhome ne 'no_host') {
1.334 raeburn 2924: if ($context eq 'domain') {
1.378 raeburn 2925: foreach my $name ('portfolio','author') {
2926: if ($env{'form.custom_'.$name.'quota'} == 1) {
2927: if ($env{'form.'.$name.'quota'} eq '') {
2928: $newcustom{$name.'quota'} = 0;
2929: } else {
2930: $newcustom{$name.'quota'} = $env{'form.'.$name.'quota'};
2931: $newcustom{$name.'quota'} =~ s/[^\d\.]//g;
2932: }
2933: if ("a_admin($newcustom{$name.'quota'},\%changeHash,$name)) {
2934: $changed{$name.'quota'} = 1;
2935: }
1.334 raeburn 2936: }
2937: }
2938: foreach my $item (@usertools) {
2939: if ($env{'form.custom'.$item} == 1) {
2940: $newcustom{$item} = $env{'form.tools_'.$item};
2941: $changed{$item} = &tool_admin($item,$newcustom{$item},
2942: \%changeHash,'tools');
2943: }
1.267 raeburn 2944: }
1.334 raeburn 2945: foreach my $item (@requestcourses) {
1.341 raeburn 2946: if ($env{'form.custom'.$item} == 1) {
2947: $newcustom{$item} = $env{'form.crsreq_'.$item};
2948: if ($env{'form.crsreq_'.$item} eq 'autolimit') {
2949: $newcustom{$item} .= '=';
1.383 raeburn 2950: $env{'form.crsreq_'.$item.'_limit'} =~ s/\D+//g;
2951: if ($env{'form.crsreq_'.$item.'_limit'}) {
1.341 raeburn 2952: $newcustom{$item} .= $env{'form.crsreq_'.$item.'_limit'};
2953: }
1.334 raeburn 2954: }
1.341 raeburn 2955: $changed{$item} = &tool_admin($item,$newcustom{$item},
2956: \%changeHash,'requestcourses');
1.334 raeburn 2957: }
1.275 raeburn 2958: }
1.362 raeburn 2959: if ($env{'form.customrequestauthor'} == 1) {
2960: $newcustom{'requestauthor'} = $env{'form.requestauthor'};
2961: $changed{'requestauthor'} = &tool_admin('requestauthor',
2962: $newcustom{'requestauthor'},
2963: \%changeHash,'requestauthor');
2964: }
1.275 raeburn 2965: }
1.334 raeburn 2966: if ($canmodify_status{'inststatus'}) {
2967: if (exists($env{'form.inststatus'})) {
2968: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
2969: if (@inststatuses > 0) {
2970: $changeHash{'inststatus'} = join(',',@inststatuses);
2971: $changed{'inststatus'} = $changeHash{'inststatus'};
1.306 raeburn 2972: }
2973: }
1.232 raeburn 2974: }
1.334 raeburn 2975: if (keys(%changed)) {
2976: foreach my $item (@userinfo) {
2977: $changeHash{$item} = $env{'form.c'.$item};
1.286 raeburn 2978: }
1.267 raeburn 2979: my $chgresult =
2980: &Apache::lonnet::put('environment',\%changeHash,
2981: $env{'form.ccdomain'},$env{'form.ccuname'});
2982: }
1.232 raeburn 2983: }
1.406.2.19 raeburn 2984: $r->print('<br />'.&mt('Home Server').': '.$uhome.' '.
1.219 raeburn 2985: &Apache::lonnet::hostname($uhome));
1.101 albertel 2986: } elsif (($env{'form.login'} ne 'nochange') &&
2987: ($env{'form.login'} ne '' )) {
1.27 matthew 2988: # Modify user privileges
2989: if (! $amode || ! $genpwd) {
1.193 raeburn 2990: $r->print($error.'Invalid login mode or password'.$end.$rtnlink);
1.27 matthew 2991: return;
1.20 harris41 2992: }
1.395 bisitz 2993: # Only allow authentication modification if the person has authority
1.101 albertel 2994: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.20 harris41 2995: $r->print('Modifying authentication: '.
1.31 matthew 2996: &Apache::lonnet::modifyuserauth(
1.101 albertel 2997: $env{'form.ccdomain'},$env{'form.ccuname'},
1.21 harris41 2998: $amode,$genpwd));
1.406.2.19 raeburn 2999: $r->print('<br />'.&mt('Home Server').': '.&Apache::lonnet::homeserver
1.101 albertel 3000: ($env{'form.ccuname'},$env{'form.ccdomain'}));
1.4 www 3001: } else {
1.27 matthew 3002: # Okay, this is a non-fatal error.
1.406.2.17 raeburn 3003: $r->print($error.&mt('You do not have privileges to modify the authentication configuration for this user.').$end);
1.27 matthew 3004: }
1.406.2.17 raeburn 3005: } elsif (($env{'form.intarg'} ne '') &&
3006: (&Apache::lonnet::queryauthenticate($env{'form.ccuname'},$env{'form.ccdomain'}) =~ /^internal:/) &&
3007: (&Apache::lonuserutils::can_change_internalpass($env{'form.ccuname'},$env{'form.ccdomain'},$crstype,$permission))) {
3008: $r->print('Modifying authentication: '.
3009: &Apache::lonnet::modifyuserauth(
3010: $env{'form.ccdomain'},$env{'form.ccuname'},
3011: 'internal',$env{'form.intarg'}));
1.28 matthew 3012: }
1.344 bisitz 3013: $r->rflush(); # Finish display of header before time consuming actions start
1.367 golterma 3014: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state);
1.28 matthew 3015: ##
1.375 raeburn 3016: my (@userroles,%userupdate,$cnum,$cdom,$defaultcredits,%namechanged);
1.213 raeburn 3017: if ($context eq 'course') {
1.375 raeburn 3018: ($cnum,$cdom) =
3019: &Apache::lonuserutils::get_course_identity();
1.318 raeburn 3020: $crstype = &Apache::loncommon::course_type($cdom.'_'.$cnum);
1.375 raeburn 3021: if ($showcredits) {
3022: $defaultcredits = &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
3023: }
1.213 raeburn 3024: }
1.101 albertel 3025: if (! $env{'form.makeuser'} ) {
1.28 matthew 3026: # Check for need to change
3027: my %userenv = &Apache::lonnet::get
1.134 raeburn 3028: ('environment',['firstname','middlename','lastname','generation',
1.378 raeburn 3029: 'id','permanentemail','portfolioquota','authorquota','inststatus',
1.406.2.20.2. (raeburn 3030:): 'tools.aboutme','tools.blog','tools.webdav',
3031:): 'tools.portfolio','tools.timezone',
1.361 raeburn 3032: 'requestcourses.official','requestcourses.unofficial',
1.384 raeburn 3033: 'requestcourses.community','requestcourses.textbook',
3034: 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
3035: 'reqcrsotherdom.community','reqcrsotherdom.textbook',
1.406.2.9 raeburn 3036: 'requestauthor'],
1.160 raeburn 3037: $env{'form.ccdomain'},$env{'form.ccuname'});
1.28 matthew 3038: my ($tmp) = keys(%userenv);
3039: if ($tmp =~ /^(con_lost|error)/i) {
3040: %userenv = ();
3041: }
1.206 raeburn 3042: my $no_forceid_alert;
3043: # Check to see if user information can be changed
3044: my %domconfig =
3045: &Apache::lonnet::get_dom('configuration',['usermodification'],
3046: $env{'form.ccdomain'});
1.213 raeburn 3047: my @statuses = ('active','future');
3048: my %roles = &Apache::lonnet::get_my_roles($env{'form.ccuname'},$env{'form.ccdomain'},'userroles',\@statuses,undef,$env{'request.role.domain'});
3049: my ($auname,$audom);
1.220 raeburn 3050: if ($context eq 'author') {
1.206 raeburn 3051: $auname = $env{'user.name'};
3052: $audom = $env{'user.domain'};
3053: }
3054: foreach my $item (keys(%roles)) {
1.220 raeburn 3055: my ($rolenum,$roledom,$role) = split(/:/,$item,-1);
1.206 raeburn 3056: if ($context eq 'course') {
3057: if ($cnum ne '' && $cdom ne '') {
3058: if ($rolenum eq $cnum && $roledom eq $cdom) {
3059: if (!grep(/^\Q$role\E$/,@userroles)) {
3060: push(@userroles,$role);
3061: }
3062: }
3063: }
3064: } elsif ($context eq 'author') {
3065: if ($rolenum eq $auname && $roledom eq $audom) {
3066: if (!grep(/^\Q$role\E$/,@userroles)) {
3067: push(@userroles,$role);
3068: }
3069: }
3070: }
3071: }
1.220 raeburn 3072: if ($env{'form.action'} eq 'singlestudent') {
3073: if (!grep(/^st$/,@userroles)) {
3074: push(@userroles,'st');
3075: }
3076: } else {
3077: # Check for course or co-author roles being activated or re-enabled
3078: if ($context eq 'author' || $context eq 'course') {
3079: foreach my $key (keys(%env)) {
3080: if ($context eq 'author') {
3081: if ($key=~/^form\.act_\Q$audom\E_\Q$auname\E_([^_]+)/) {
3082: if (!grep(/^\Q$1\E$/,@userroles)) {
3083: push(@userroles,$1);
3084: }
3085: } elsif ($key =~/^form\.ren\:\Q$audom\E\/\Q$auname\E_([^_]+)/) {
3086: if (!grep(/^\Q$1\E$/,@userroles)) {
3087: push(@userroles,$1);
3088: }
1.206 raeburn 3089: }
1.220 raeburn 3090: } elsif ($context eq 'course') {
3091: if ($key=~/^form\.act_\Q$cdom\E_\Q$cnum\E_([^_]+)/) {
3092: if (!grep(/^\Q$1\E$/,@userroles)) {
3093: push(@userroles,$1);
3094: }
3095: } elsif ($key =~/^form\.ren\:\Q$cdom\E\/\Q$cnum\E(\/?\w*)_([^_]+)/) {
3096: if (!grep(/^\Q$1\E$/,@userroles)) {
3097: push(@userroles,$1);
3098: }
1.206 raeburn 3099: }
3100: }
3101: }
3102: }
3103: }
3104: #Check to see if we can change personal data for the user
3105: my (@mod_disallowed,@longroles);
3106: foreach my $role (@userroles) {
3107: if ($role eq 'cr') {
3108: push(@longroles,'Custom');
3109: } else {
1.318 raeburn 3110: push(@longroles,&Apache::lonnet::plaintext($role,$crstype));
1.206 raeburn 3111: }
3112: }
1.219 raeburn 3113: my %canmodify = &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},\@userinfo,\@userroles);
3114: foreach my $item (@userinfo) {
1.28 matthew 3115: # Strip leading and trailing whitespace
1.203 raeburn 3116: $env{'form.c'.$item} =~ s/(\s+$|^\s+)//g;
1.219 raeburn 3117: if (!$canmodify{$item}) {
1.207 raeburn 3118: if (defined($env{'form.c'.$item})) {
3119: if ($env{'form.c'.$item} ne $userenv{$item}) {
3120: push(@mod_disallowed,$item);
3121: }
1.206 raeburn 3122: }
3123: $env{'form.c'.$item} = $userenv{$item};
3124: }
1.28 matthew 3125: }
1.259 bisitz 3126: # Check to see if we can change the Student/Employee ID
1.196 raeburn 3127: my $forceid = $env{'form.forceid'};
3128: my $recurseid = $env{'form.recurseid'};
3129: my (%alerts,%rulematch,%idinst_results,%curr_rules,%got_rules);
1.203 raeburn 3130: my %uidhash = &Apache::lonnet::idrget($env{'form.ccdomain'},
3131: $env{'form.ccuname'});
3132: if (($uidhash{$env{'form.ccuname'}}) &&
3133: ($uidhash{$env{'form.ccuname'}}!~/error\:/) &&
3134: (!$forceid)) {
3135: if ($env{'form.cid'} ne $uidhash{$env{'form.ccuname'}}) {
3136: $env{'form.cid'} = $userenv{'id'};
1.293 bisitz 3137: $no_forceid_alert = &mt('New student/employee ID does not match existing ID for this user.')
1.259 bisitz 3138: .'<br />'
3139: .&mt("Change is not permitted without checking the 'Force ID change' checkbox on the previous page.")
3140: .'<br />'."\n";
1.203 raeburn 3141: }
3142: }
3143: if ($env{'form.cid'} ne $userenv{'id'}) {
1.196 raeburn 3144: my $checkhash;
3145: my $checks = { 'id' => 1 };
3146: $checkhash->{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}} =
3147: { 'newuser' => $newuser,
3148: 'id' => $env{'form.cid'},
3149: };
3150: &Apache::loncommon::user_rule_check($checkhash,$checks,
3151: \%alerts,\%rulematch,\%idinst_results,\%curr_rules,\%got_rules);
3152: if (ref($alerts{'id'}) eq 'HASH') {
3153: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
1.203 raeburn 3154: $env{'form.cid'} = $userenv{'id'};
1.196 raeburn 3155: }
3156: }
3157: }
1.378 raeburn 3158: my (%quotachanged,%oldquota,%newquota,%olddefquota,%newdefquota,
3159: $oldinststatus,$newinststatus,%oldisdefault,%newisdefault,%oldsettings,
1.339 raeburn 3160: %oldsettingstext,%newsettings,%newsettingstext,@disporder,
1.378 raeburn 3161: %oldsettingstatus,%newsettingstatus);
1.334 raeburn 3162: @disporder = ('inststatus');
3163: if ($env{'request.role.domain'} eq $env{'form.ccdomain'}) {
1.362 raeburn 3164: push(@disporder,'requestcourses','requestauthor');
1.334 raeburn 3165: } else {
3166: push(@disporder,'reqcrsotherdom');
3167: }
3168: push(@disporder,('quota','tools'));
1.338 raeburn 3169: $oldinststatus = $userenv{'inststatus'};
1.378 raeburn 3170: foreach my $name ('portfolio','author') {
3171: ($olddefquota{$name},$oldsettingstatus{$name}) =
3172: &Apache::loncommon::default_quota($env{'form.ccdomain'},$oldinststatus,$name);
3173: ($newdefquota{$name},$newsettingstatus{$name}) = ($olddefquota{$name},$oldsettingstatus{$name});
3174: }
1.334 raeburn 3175: my %canshow;
1.220 raeburn 3176: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
1.334 raeburn 3177: $canshow{'quota'} = 1;
1.220 raeburn 3178: }
1.267 raeburn 3179: if (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
1.334 raeburn 3180: $canshow{'tools'} = 1;
1.267 raeburn 3181: }
1.275 raeburn 3182: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
1.334 raeburn 3183: $canshow{'requestcourses'} = 1;
1.300 raeburn 3184: } elsif (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.334 raeburn 3185: $canshow{'reqcrsotherdom'} = 1;
1.275 raeburn 3186: }
1.286 raeburn 3187: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.334 raeburn 3188: $canshow{'inststatus'} = 1;
1.286 raeburn 3189: }
1.362 raeburn 3190: if (&Apache::lonnet::allowed('cau',$env{'form.ccdomain'})) {
3191: $canshow{'requestauthor'} = 1;
3192: }
1.267 raeburn 3193: my (%changeHash,%changed);
1.286 raeburn 3194: if ($oldinststatus eq '') {
1.334 raeburn 3195: $oldsettings{'inststatus'} = $othertitle;
1.286 raeburn 3196: } else {
3197: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 3198: $oldsettings{'inststatus'} = join(', ',map{ $usertypes->{ &unescape($_) }; } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 3199: } else {
1.334 raeburn 3200: $oldsettings{'inststatus'} = join(', ',map{ &unescape($_); } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 3201: }
3202: }
3203: $changeHash{'inststatus'} = $userenv{'inststatus'};
1.334 raeburn 3204: if ($canmodify_status{'inststatus'}) {
3205: $canshow{'inststatus'} = 1;
1.286 raeburn 3206: if (exists($env{'form.inststatus'})) {
3207: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
3208: if (@inststatuses > 0) {
3209: $newinststatus = join(':',map { &escape($_); } @inststatuses);
3210: $changeHash{'inststatus'} = $newinststatus;
3211: if ($newinststatus ne $oldinststatus) {
3212: $changed{'inststatus'} = $newinststatus;
1.378 raeburn 3213: foreach my $name ('portfolio','author') {
3214: ($newdefquota{$name},$newsettingstatus{$name}) =
3215: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
3216: }
1.286 raeburn 3217: }
3218: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 3219: $newsettings{'inststatus'} = join(', ',map{ $usertypes->{$_}; } (@inststatuses));
1.286 raeburn 3220: } else {
1.337 raeburn 3221: $newsettings{'inststatus'} = join(', ',@inststatuses);
1.286 raeburn 3222: }
1.334 raeburn 3223: }
3224: } else {
3225: $newinststatus = '';
3226: $changeHash{'inststatus'} = $newinststatus;
3227: $newsettings{'inststatus'} = $othertitle;
3228: if ($newinststatus ne $oldinststatus) {
3229: $changed{'inststatus'} = $changeHash{'inststatus'};
1.378 raeburn 3230: foreach my $name ('portfolio','author') {
3231: ($newdefquota{$name},$newsettingstatus{$name}) =
3232: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
3233: }
1.286 raeburn 3234: }
3235: }
1.334 raeburn 3236: } elsif ($context ne 'selfcreate') {
3237: $canshow{'inststatus'} = 1;
1.337 raeburn 3238: $newsettings{'inststatus'} = $oldsettings{'inststatus'};
1.286 raeburn 3239: }
1.378 raeburn 3240: foreach my $name ('portfolio','author') {
3241: $changeHash{$name.'quota'} = $userenv{$name.'quota'};
3242: }
1.334 raeburn 3243: if ($context eq 'domain') {
1.378 raeburn 3244: foreach my $name ('portfolio','author') {
3245: if ($userenv{$name.'quota'} ne '') {
3246: $oldquota{$name} = $userenv{$name.'quota'};
3247: if ($env{'form.custom_'.$name.'quota'} == 1) {
3248: if ($env{'form.'.$name.'quota'} eq '') {
3249: $newquota{$name} = 0;
3250: } else {
3251: $newquota{$name} = $env{'form.'.$name.'quota'};
3252: $newquota{$name} =~ s/[^\d\.]//g;
3253: }
3254: if ($newquota{$name} != $oldquota{$name}) {
3255: if ("a_admin($newquota{$name},\%changeHash,$name)) {
3256: $changed{$name.'quota'} = 1;
3257: }
3258: }
1.334 raeburn 3259: } else {
1.378 raeburn 3260: if ("a_admin('',\%changeHash,$name)) {
3261: $changed{$name.'quota'} = 1;
3262: $newquota{$name} = $newdefquota{$name};
3263: $newisdefault{$name} = 1;
3264: }
1.334 raeburn 3265: }
1.149 raeburn 3266: } else {
1.378 raeburn 3267: $oldisdefault{$name} = 1;
3268: $oldquota{$name} = $olddefquota{$name};
3269: if ($env{'form.custom_'.$name.'quota'} == 1) {
3270: if ($env{'form.'.$name.'quota'} eq '') {
3271: $newquota{$name} = 0;
3272: } else {
3273: $newquota{$name} = $env{'form.'.$name.'quota'};
3274: $newquota{$name} =~ s/[^\d\.]//g;
3275: }
3276: if ("a_admin($newquota{$name},\%changeHash,$name)) {
3277: $changed{$name.'quota'} = 1;
3278: }
1.334 raeburn 3279: } else {
1.378 raeburn 3280: $newquota{$name} = $newdefquota{$name};
3281: $newisdefault{$name} = 1;
1.334 raeburn 3282: }
1.378 raeburn 3283: }
3284: if ($oldisdefault{$name}) {
3285: $oldsettingstext{'quota'}{$name} = &get_defaultquota_text($oldsettingstatus{$name});
1.383 raeburn 3286: } else {
3287: $oldsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$oldquota{$name});
1.378 raeburn 3288: }
3289: if ($newisdefault{$name}) {
3290: $newsettingstext{'quota'}{$name} = &get_defaultquota_text($newsettingstatus{$name});
1.383 raeburn 3291: } else {
3292: $newsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$newquota{$name});
1.134 raeburn 3293: }
3294: }
1.334 raeburn 3295: &tool_changes('tools',\@usertools,\%oldsettings,\%oldsettingstext,\%userenv,
3296: \%changeHash,\%changed,\%newsettings,\%newsettingstext);
3297: if ($env{'form.ccdomain'} eq $env{'request.role.domain'}) {
3298: &tool_changes('requestcourses',\@requestcourses,\%oldsettings,\%oldsettingstext,
3299: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.384 raeburn 3300: &tool_changes('requestauthor',\@requestauthor,\%oldsettings,\%oldsettingstext,
3301: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 3302: } else {
1.334 raeburn 3303: &tool_changes('reqcrsotherdom',\@requestcourses,\%oldsettings,\%oldsettingstext,
3304: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 3305: }
3306: }
1.334 raeburn 3307: foreach my $item (@userinfo) {
3308: if ($env{'form.c'.$item} ne $userenv{$item}) {
3309: $namechanged{$item} = 1;
3310: }
1.204 raeburn 3311: }
1.378 raeburn 3312: foreach my $name ('portfolio','author') {
1.390 bisitz 3313: $oldsettings{'quota'}{$name} = &mt('[_1] MB',$oldquota{$name});
3314: $newsettings{'quota'}{$name} = &mt('[_1] MB',$newquota{$name});
1.378 raeburn 3315: }
1.334 raeburn 3316: if ((keys(%namechanged) > 0) || (keys(%changed) > 0)) {
1.267 raeburn 3317: my ($chgresult,$namechgresult);
3318: if (keys(%changed) > 0) {
3319: $chgresult =
1.204 raeburn 3320: &Apache::lonnet::put('environment',\%changeHash,
3321: $env{'form.ccdomain'},$env{'form.ccuname'});
1.267 raeburn 3322: if ($chgresult eq 'ok') {
3323: if (($env{'user.name'} eq $env{'form.ccuname'}) &&
3324: ($env{'user.domain'} eq $env{'form.ccdomain'})) {
1.270 raeburn 3325: my %newenvhash;
3326: foreach my $key (keys(%changed)) {
1.299 raeburn 3327: if (($key eq 'official') || ($key eq 'unofficial')
1.403 raeburn 3328: || ($key eq 'community') || ($key eq 'textbook')) {
1.279 raeburn 3329: $newenvhash{'environment.requestcourses.'.$key} =
3330: $changeHash{'requestcourses.'.$key};
1.362 raeburn 3331: if ($changeHash{'requestcourses.'.$key}) {
1.332 raeburn 3332: $newenvhash{'environment.canrequest.'.$key} = 1;
1.279 raeburn 3333: } else {
3334: $newenvhash{'environment.canrequest.'.$key} =
3335: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3336: $key,'reload','requestcourses');
3337: }
1.362 raeburn 3338: } elsif ($key eq 'requestauthor') {
3339: $newenvhash{'environment.'.$key} = $changeHash{$key};
3340: if ($changeHash{$key}) {
3341: $newenvhash{'environment.canrequest.author'} = 1;
3342: } else {
3343: $newenvhash{'environment.canrequest.author'} =
3344: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3345: $key,'reload','requestauthor');
3346: }
1.275 raeburn 3347: } elsif ($key ne 'quota') {
1.270 raeburn 3348: $newenvhash{'environment.tools.'.$key} =
3349: $changeHash{'tools.'.$key};
1.279 raeburn 3350: if ($changeHash{'tools.'.$key} ne '') {
3351: $newenvhash{'environment.availabletools.'.$key} =
3352: $changeHash{'tools.'.$key};
3353: } else {
3354: $newenvhash{'environment.availabletools.'.$key} =
1.367 golterma 3355: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3356: $key,'reload','tools');
1.279 raeburn 3357: }
1.270 raeburn 3358: }
3359: }
1.271 raeburn 3360: if (keys(%newenvhash)) {
3361: &Apache::lonnet::appenv(\%newenvhash);
3362: }
1.267 raeburn 3363: }
1.406.2.20.2. (raeburn 3364:): if ($changed{'aboutme'}) {
3365:): &Apache::loncommon::devalidate_aboutme_cache($env{'form.ccuname'},
3366:): $env{'form.ccdomain'});
3367:): }
1.267 raeburn 3368: }
1.204 raeburn 3369: }
1.334 raeburn 3370: if (keys(%namechanged) > 0) {
1.337 raeburn 3371: foreach my $field (@userinfo) {
3372: $changeHash{$field} = $env{'form.c'.$field};
3373: }
3374: # Make the change
1.204 raeburn 3375: $namechgresult =
3376: &Apache::lonnet::modifyuser($env{'form.ccdomain'},
3377: $env{'form.ccuname'},$changeHash{'id'},undef,undef,
3378: $changeHash{'firstname'},$changeHash{'middlename'},
3379: $changeHash{'lastname'},$changeHash{'generation'},
1.337 raeburn 3380: $changeHash{'id'},undef,$changeHash{'permanentemail'},undef,\@userinfo);
1.220 raeburn 3381: %userupdate = (
3382: lastname => $env{'form.clastname'},
3383: middlename => $env{'form.cmiddlename'},
3384: firstname => $env{'form.cfirstname'},
3385: generation => $env{'form.cgeneration'},
3386: id => $env{'form.cid'},
3387: );
1.204 raeburn 3388: }
1.334 raeburn 3389: if (((keys(%namechanged) > 0) && $namechgresult eq 'ok') ||
1.267 raeburn 3390: ((keys(%changed) > 0) && $chgresult eq 'ok')) {
1.28 matthew 3391: # Tell the user we changed the name
1.334 raeburn 3392: &display_userinfo($r,1,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 3393: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,
1.334 raeburn 3394: \%oldsettings, \%oldsettingstext,\%newsettings,
3395: \%newsettingstext);
1.203 raeburn 3396: if ($env{'form.cid'} ne $userenv{'id'}) {
3397: &Apache::lonnet::idput($env{'form.ccdomain'},
1.406.2.5 raeburn 3398: {$env{'form.ccuname'} => $env{'form.cid'}});
1.203 raeburn 3399: if (($recurseid) &&
3400: (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}))) {
3401: my $idresult =
3402: &Apache::lonuserutils::propagate_id_change(
3403: $env{'form.ccuname'},$env{'form.ccdomain'},
3404: \%userupdate);
3405: $r->print('<br />'.$idresult.'<br />');
3406: }
1.196 raeburn 3407: }
1.149 raeburn 3408: if (($env{'form.ccdomain'} eq $env{'user.domain'}) &&
3409: ($env{'form.ccuname'} eq $env{'user.name'})) {
3410: my %newenvhash;
3411: foreach my $key (keys(%changeHash)) {
3412: $newenvhash{'environment.'.$key} = $changeHash{$key};
3413: }
1.238 raeburn 3414: &Apache::lonnet::appenv(\%newenvhash);
1.149 raeburn 3415: }
1.28 matthew 3416: } else { # error occurred
1.389 bisitz 3417: $r->print(
3418: '<p class="LC_error">'
3419: .&mt('Unable to successfully change environment for [_1] in domain [_2].',
3420: '"'.$env{'form.ccuname'}.'"',
3421: '"'.$env{'form.ccdomain'}.'"')
3422: .'</p>');
1.28 matthew 3423: }
1.334 raeburn 3424: } else { # End of if ($env ... ) logic
1.275 raeburn 3425: # They did not want to change the users name, quota, tool availability,
3426: # or ability to request creation of courses,
1.267 raeburn 3427: # but we can still tell them what the name and quota and availabilities are
1.334 raeburn 3428: &display_userinfo($r,undef,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 3429: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,\%oldsettings,
1.334 raeburn 3430: \%oldsettingstext,\%newsettings,\%newsettingstext);
1.28 matthew 3431: }
1.206 raeburn 3432: if (@mod_disallowed) {
3433: my ($rolestr,$contextname);
3434: if (@longroles > 0) {
3435: $rolestr = join(', ',@longroles);
3436: } else {
3437: $rolestr = &mt('No roles');
3438: }
3439: if ($context eq 'course') {
1.399 bisitz 3440: $contextname = 'course';
1.206 raeburn 3441: } elsif ($context eq 'author') {
1.399 bisitz 3442: $contextname = 'co-author';
1.206 raeburn 3443: }
3444: $r->print(&mt('The following fields were not updated: ').'<ul>');
3445: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
3446: foreach my $field (@mod_disallowed) {
3447: $r->print('<li>'.$fieldtitles{$field}.'</li>'."\n");
3448: }
1.207 raeburn 3449: $r->print('</ul>');
3450: if (@mod_disallowed == 1) {
1.399 bisitz 3451: $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 3452: } else {
1.399 bisitz 3453: $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 3454: }
1.292 bisitz 3455: my $helplink = 'javascript:helpMenu('."'display'".')';
3456: $r->print('<span class="LC_cusr_emph">'.$rolestr.'</span><br />'
3457: .&mt('Please contact your [_1]helpdesk[_2] for more information.'
3458: ,'<a href="'.$helplink.'">','</a>')
3459: .'<br />');
1.206 raeburn 3460: }
1.259 bisitz 3461: $r->print('<span class="LC_warning">'
3462: .$no_forceid_alert
3463: .&Apache::lonuserutils::print_namespacing_alerts($env{'form.ccdomain'},\%alerts,\%curr_rules)
3464: .'</span>');
1.4 www 3465: }
1.367 golterma 3466: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1.220 raeburn 3467: if ($env{'form.action'} eq 'singlestudent') {
1.375 raeburn 3468: &enroll_single_student($r,$uhome,$amode,$genpwd,$now,$newuser,$context,
3469: $crstype,$showcredits,$defaultcredits);
1.386 bisitz 3470: my $linktext = ($crstype eq 'Community' ?
3471: &mt('Enroll Another Member') : &mt('Enroll Another Student'));
3472: $r->print(
3473: &Apache::lonhtmlcommon::actionbox([
3474: '<a href="javascript:backPage(document.userupdate)">'
3475: .($crstype eq 'Community' ?
3476: &mt('Enroll Another Member') : &mt('Enroll Another Student'))
3477: .'</a>']));
1.220 raeburn 3478: } else {
1.375 raeburn 3479: my @rolechanges = &update_roles($r,$context,$showcredits);
1.334 raeburn 3480: if (keys(%namechanged) > 0) {
1.220 raeburn 3481: if ($context eq 'course') {
3482: if (@userroles > 0) {
1.225 raeburn 3483: if ((@rolechanges == 0) ||
3484: (!(grep(/^st$/,@rolechanges)))) {
3485: if (grep(/^st$/,@userroles)) {
3486: my $classlistupdated =
3487: &Apache::lonuserutils::update_classlist($cdom,
1.220 raeburn 3488: $cnum,$env{'form.ccdomain'},
3489: $env{'form.ccuname'},\%userupdate);
1.225 raeburn 3490: }
1.220 raeburn 3491: }
3492: }
3493: }
3494: }
1.226 raeburn 3495: my $userinfo = &Apache::loncommon::plainname($env{'form.ccuname'},
1.233 raeburn 3496: $env{'form.ccdomain'});
3497: if ($env{'form.popup'}) {
3498: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
3499: } else {
1.367 golterma 3500: $r->print('<br />'.&Apache::lonhtmlcommon::actionbox(['<a href="javascript:backPage(document.userupdate,'."'$env{'form.prevphase'}','modify'".')">'
3501: .&mt('Modify this user: [_1]','<span class="LC_cusr_emph">'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.' ('.$userinfo.')</span>').'</a>',
3502: '<a href="javascript:backPage(document.userupdate)">'.&mt('Create/Modify Another User').'</a>']));
1.233 raeburn 3503: }
1.220 raeburn 3504: }
3505: }
3506:
1.334 raeburn 3507: sub display_userinfo {
1.362 raeburn 3508: my ($r,$changed,$order,$canshow,$requestcourses,$usertools,$requestauthor,
3509: $userenv,$changedhash,$namechangedhash,$oldsetting,$oldsettingtext,
1.334 raeburn 3510: $newsetting,$newsettingtext) = @_;
3511: return unless (ref($order) eq 'ARRAY' &&
3512: ref($canshow) eq 'HASH' &&
3513: ref($requestcourses) eq 'ARRAY' &&
1.362 raeburn 3514: ref($requestauthor) eq 'ARRAY' &&
1.334 raeburn 3515: ref($usertools) eq 'ARRAY' &&
3516: ref($userenv) eq 'HASH' &&
3517: ref($changedhash) eq 'HASH' &&
3518: ref($oldsetting) eq 'HASH' &&
3519: ref($oldsettingtext) eq 'HASH' &&
3520: ref($newsetting) eq 'HASH' &&
3521: ref($newsettingtext) eq 'HASH');
3522: my %lt=&Apache::lonlocal::texthash(
1.372 raeburn 3523: 'ui' => 'User Information',
1.334 raeburn 3524: 'uic' => 'User Information Changed',
3525: 'firstname' => 'First Name',
3526: 'middlename' => 'Middle Name',
3527: 'lastname' => 'Last Name',
3528: 'generation' => 'Generation',
3529: 'id' => 'Student/Employee ID',
3530: 'permanentemail' => 'Permanent e-mail address',
1.378 raeburn 3531: 'portfolioquota' => 'Disk space allocated to portfolio files',
1.385 bisitz 3532: 'authorquota' => 'Disk space allocated to Authoring Space',
1.334 raeburn 3533: 'blog' => 'Blog Availability',
1.361 raeburn 3534: 'webdav' => 'WebDAV Availability',
1.334 raeburn 3535: 'aboutme' => 'Personal Information Page Availability',
3536: 'portfolio' => 'Portfolio Availability',
1.406.2.20.2. (raeburn 3537:): 'timezone' => 'Can set own Time Zone',
1.334 raeburn 3538: 'official' => 'Can Request Official Courses',
3539: 'unofficial' => 'Can Request Unofficial Courses',
3540: 'community' => 'Can Request Communities',
1.384 raeburn 3541: 'textbook' => 'Can Request Textbook Courses',
1.362 raeburn 3542: 'requestauthor' => 'Can Request Author Role',
1.334 raeburn 3543: 'inststatus' => "Affiliation",
3544: 'prvs' => 'Previous Value:',
3545: 'chto' => 'Changed To:'
3546: );
3547: if ($changed) {
1.372 raeburn 3548: $r->print('<h3>'.$lt{'uic'}.'</h3>'.
1.367 golterma 3549: &Apache::loncommon::start_data_table().
3550: &Apache::loncommon::start_data_table_header_row());
1.334 raeburn 3551: $r->print("<th> </th>\n");
1.367 golterma 3552: $r->print('<th><b>'.$lt{'prvs'}.'</b></th>');
3553: $r->print('<th><span class="LC_nobreak"><b>'.$lt{'chto'}.'</b></span></th>');
3554: $r->print(&Apache::loncommon::end_data_table_header_row());
3555: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
3556:
1.334 raeburn 3557: foreach my $item (@userinfo) {
3558: my $value = $env{'form.c'.$item};
1.367 golterma 3559: #show changes only:
1.383 raeburn 3560: unless ($value eq $userenv->{$item}){
1.367 golterma 3561: $r->print(&Apache::loncommon::start_data_table_row());
3562: $r->print("<td>$lt{$item}</td>\n");
1.383 raeburn 3563: $r->print("<td>".$userenv->{$item}."</td>\n");
1.367 golterma 3564: $r->print("<td>$value </td>\n");
3565: $r->print(&Apache::loncommon::end_data_table_row());
1.334 raeburn 3566: }
3567: }
3568: foreach my $entry (@{$order}) {
1.383 raeburn 3569: if ($canshow->{$entry}) {
3570: if (($entry eq 'requestcourses') || ($entry eq 'reqcrsotherdom') || ($entry eq 'requestauthor')) {
3571: my @items;
3572: if ($entry eq 'requestauthor') {
3573: @items = ($entry);
3574: } else {
3575: @items = @{$requestcourses};
1.384 raeburn 3576: }
1.383 raeburn 3577: foreach my $item (@items) {
3578: if (($newsetting->{$item} ne $oldsetting->{$item}) ||
3579: ($newsettingtext->{$item} ne $oldsettingtext->{$item})) {
3580: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3581: $r->print("<td>$lt{$item}</td>\n");
3582: $r->print("<td>".$oldsetting->{$item});
3583: if ($oldsettingtext->{$item}) {
3584: if ($oldsetting->{$item}) {
3585: $r->print(' -- ');
3586: }
3587: $r->print($oldsettingtext->{$item});
3588: }
3589: $r->print("</td>\n");
3590: $r->print("<td>".$newsetting->{$item});
3591: if ($newsettingtext->{$item}) {
3592: if ($newsetting->{$item}) {
3593: $r->print(' -- ');
3594: }
3595: $r->print($newsettingtext->{$item});
3596: }
3597: $r->print("</td>\n");
3598: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3599: }
3600: }
3601: } elsif ($entry eq 'tools') {
3602: foreach my $item (@{$usertools}) {
1.383 raeburn 3603: if ($newsetting->{$item} ne $oldsetting->{$item}) {
3604: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3605: $r->print("<td>$lt{$item}</td>\n");
3606: $r->print("<td>".$oldsetting->{$item}.' '.$oldsettingtext->{$item}."</td>\n");
3607: $r->print("<td>".$newsetting->{$item}.' '.$newsettingtext->{$item}."</td>\n");
3608: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3609: }
3610: }
1.378 raeburn 3611: } elsif ($entry eq 'quota') {
3612: if ((ref($oldsetting->{$entry}) eq 'HASH') && (ref($oldsettingtext->{$entry}) eq 'HASH') &&
3613: (ref($newsetting->{$entry}) eq 'HASH') && (ref($newsettingtext->{$entry}) eq 'HASH')) {
3614: foreach my $name ('portfolio','author') {
1.383 raeburn 3615: if ($newsetting->{$entry}->{$name} ne $oldsetting->{$entry}->{$name}) {
3616: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3617: $r->print("<td>$lt{$name.$entry}</td>\n");
3618: $r->print("<td>".$oldsettingtext->{$entry}->{$name}."</td>\n");
3619: $r->print("<td>".$newsettingtext->{$entry}->{$name}."</td>\n");
3620: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.378 raeburn 3621: }
3622: }
3623: }
1.334 raeburn 3624: } else {
1.383 raeburn 3625: if ($newsetting->{$entry} ne $oldsetting->{$entry}) {
3626: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3627: $r->print("<td>$lt{$entry}</td>\n");
3628: $r->print("<td>".$oldsetting->{$entry}.' '.$oldsettingtext->{$entry}."</td>\n");
3629: $r->print("<td>".$newsetting->{$entry}.' '.$newsettingtext->{$entry}."</td>\n");
3630: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3631: }
3632: }
3633: }
3634: }
1.367 golterma 3635: $r->print(&Apache::loncommon::end_data_table().'<br />');
1.372 raeburn 3636: } else {
3637: $r->print('<h3>'.$lt{'ui'}.'</h3>'.
3638: '<p>'.&mt('No changes made to user information').'</p>');
1.334 raeburn 3639: }
3640: return;
3641: }
3642:
1.275 raeburn 3643: sub tool_changes {
3644: my ($context,$usertools,$oldaccess,$oldaccesstext,$userenv,$changeHash,
3645: $changed,$newaccess,$newaccesstext) = @_;
3646: if (!((ref($usertools) eq 'ARRAY') && (ref($oldaccess) eq 'HASH') &&
3647: (ref($oldaccesstext) eq 'HASH') && (ref($userenv) eq 'HASH') &&
3648: (ref($changeHash) eq 'HASH') && (ref($changed) eq 'HASH') &&
3649: (ref($newaccess) eq 'HASH') && (ref($newaccesstext) eq 'HASH'))) {
3650: return;
3651: }
1.383 raeburn 3652: my %reqdisplay = &requestchange_display();
1.300 raeburn 3653: if ($context eq 'reqcrsotherdom') {
1.309 raeburn 3654: my @options = ('approval','validate','autolimit');
1.306 raeburn 3655: my $optregex = join('|',@options);
1.300 raeburn 3656: my $cdom = $env{'request.role.domain'};
3657: foreach my $tool (@{$usertools}) {
1.383 raeburn 3658: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
1.314 raeburn 3659: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
1.300 raeburn 3660: $changeHash->{$context.'.'.$tool} = $userenv->{$context.'.'.$tool};
1.383 raeburn 3661: my ($newop,$limit);
1.314 raeburn 3662: if ($env{'form.'.$context.'_'.$tool}) {
3663: $newop = $env{'form.'.$context.'_'.$tool};
3664: if ($newop eq 'autolimit') {
1.383 raeburn 3665: $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
1.314 raeburn 3666: $limit =~ s/\D+//g;
3667: $newop .= '='.$limit;
3668: }
3669: }
1.300 raeburn 3670: if ($userenv->{$context.'.'.$tool} eq '') {
1.314 raeburn 3671: if ($newop) {
3672: $changed->{$tool}=&tool_admin($tool,$cdom.':'.$newop,
1.300 raeburn 3673: $changeHash,$context);
3674: if ($changed->{$tool}) {
1.383 raeburn 3675: if ($newop =~ /^autolimit/) {
3676: if ($limit) {
3677: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3678: } else {
3679: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3680: }
3681: } else {
3682: $newaccesstext->{$tool} = $reqdisplay{$newop};
3683: }
1.300 raeburn 3684: } else {
3685: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3686: }
3687: }
3688: } else {
3689: my @curr = split(',',$userenv->{$context.'.'.$tool});
3690: my @new;
3691: my $changedoms;
1.314 raeburn 3692: foreach my $req (@curr) {
3693: if ($req =~ /^\Q$cdom\E\:($optregex\=?\d*)$/) {
3694: my $oldop = $1;
1.383 raeburn 3695: if ($oldop =~ /^autolimit=(\d*)/) {
3696: my $limit = $1;
3697: if ($limit) {
3698: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3699: } else {
3700: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3701: }
3702: } else {
3703: $oldaccesstext->{$tool} = $reqdisplay{$oldop};
3704: }
1.314 raeburn 3705: if ($oldop ne $newop) {
3706: $changedoms = 1;
3707: foreach my $item (@curr) {
3708: my ($reqdom,$option) = split(':',$item);
3709: unless ($reqdom eq $cdom) {
3710: push(@new,$item);
3711: }
3712: }
3713: if ($newop) {
3714: push(@new,$cdom.':'.$newop);
1.300 raeburn 3715: }
1.314 raeburn 3716: @new = sort(@new);
1.300 raeburn 3717: }
1.314 raeburn 3718: last;
1.300 raeburn 3719: }
1.314 raeburn 3720: }
3721: if ((!$changedoms) && ($newop)) {
1.300 raeburn 3722: $changedoms = 1;
1.306 raeburn 3723: @new = sort(@curr,$cdom.':'.$newop);
1.300 raeburn 3724: }
3725: if ($changedoms) {
1.314 raeburn 3726: my $newdomstr;
1.300 raeburn 3727: if (@new) {
3728: $newdomstr = join(',',@new);
3729: }
3730: $changed->{$tool}=&tool_admin($tool,$newdomstr,$changeHash,
3731: $context);
3732: if ($changed->{$tool}) {
3733: if ($env{'form.'.$context.'_'.$tool}) {
1.306 raeburn 3734: if ($env{'form.'.$context.'_'.$tool} eq 'autolimit') {
1.314 raeburn 3735: my $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
3736: $limit =~ s/\D+//g;
3737: if ($limit) {
1.383 raeburn 3738: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
1.314 raeburn 3739: } else {
1.383 raeburn 3740: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
1.306 raeburn 3741: }
1.314 raeburn 3742: } else {
1.306 raeburn 3743: $newaccesstext->{$tool} = $reqdisplay{$env{'form.'.$context.'_'.$tool}};
3744: }
1.300 raeburn 3745: } else {
1.383 raeburn 3746: $newaccesstext->{$tool} = &mt("availability set to 'off'");
1.300 raeburn 3747: }
3748: }
3749: }
3750: }
3751: }
3752: return;
3753: }
1.275 raeburn 3754: foreach my $tool (@{$usertools}) {
1.383 raeburn 3755: my ($newval,$limit,$envkey);
1.362 raeburn 3756: $envkey = $context.'.'.$tool;
1.306 raeburn 3757: if ($context eq 'requestcourses') {
3758: $newval = $env{'form.crsreq_'.$tool};
3759: if ($newval eq 'autolimit') {
1.383 raeburn 3760: $limit = $env{'form.crsreq_'.$tool.'_limit'};
3761: $limit =~ s/\D+//g;
3762: $newval .= '='.$limit;
1.306 raeburn 3763: }
1.362 raeburn 3764: } elsif ($context eq 'requestauthor') {
3765: $newval = $env{'form.'.$context};
3766: $envkey = $context;
1.314 raeburn 3767: } else {
1.306 raeburn 3768: $newval = $env{'form.'.$context.'_'.$tool};
3769: }
1.362 raeburn 3770: if ($userenv->{$envkey} ne '') {
1.275 raeburn 3771: $oldaccess->{$tool} = &mt('custom');
1.383 raeburn 3772: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3773: if ($userenv->{$envkey} =~ /^autolimit=(\d*)$/) {
3774: my $currlimit = $1;
3775: if ($currlimit eq '') {
3776: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3777: } else {
3778: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$currlimit);
3779: }
3780: } elsif ($userenv->{$envkey}) {
3781: $oldaccesstext->{$tool} = $reqdisplay{$userenv->{$envkey}};
3782: } else {
3783: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
3784: }
1.275 raeburn 3785: } else {
1.383 raeburn 3786: if ($userenv->{$envkey}) {
3787: $oldaccesstext->{$tool} = &mt("availability set to 'on'");
3788: } else {
3789: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
3790: }
1.275 raeburn 3791: }
1.362 raeburn 3792: $changeHash->{$envkey} = $userenv->{$envkey};
1.275 raeburn 3793: if ($env{'form.custom'.$tool} == 1) {
1.362 raeburn 3794: if ($newval ne $userenv->{$envkey}) {
1.306 raeburn 3795: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
3796: $context);
1.275 raeburn 3797: if ($changed->{$tool}) {
3798: $newaccess->{$tool} = &mt('custom');
1.383 raeburn 3799: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3800: if ($newval =~ /^autolimit/) {
3801: if ($limit) {
3802: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3803: } else {
3804: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3805: }
3806: } elsif ($newval) {
3807: $newaccesstext->{$tool} = $reqdisplay{$newval};
3808: } else {
3809: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3810: }
1.275 raeburn 3811: } else {
1.383 raeburn 3812: if ($newval) {
3813: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3814: } else {
3815: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3816: }
1.275 raeburn 3817: }
3818: } else {
3819: $newaccess->{$tool} = $oldaccess->{$tool};
1.383 raeburn 3820: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3821: if ($newval =~ /^autolimit/) {
3822: if ($limit) {
3823: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3824: } else {
3825: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3826: }
3827: } elsif ($newval) {
3828: $newaccesstext->{$tool} = $reqdisplay{$newval};
3829: } else {
3830: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3831: }
1.275 raeburn 3832: } else {
1.383 raeburn 3833: if ($userenv->{$context.'.'.$tool}) {
3834: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3835: } else {
3836: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3837: }
1.275 raeburn 3838: }
3839: }
3840: } else {
3841: $newaccess->{$tool} = $oldaccess->{$tool};
3842: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3843: }
3844: } else {
3845: $changed->{$tool} = &tool_admin($tool,'',$changeHash,$context);
3846: if ($changed->{$tool}) {
3847: $newaccess->{$tool} = &mt('default');
3848: } else {
3849: $newaccess->{$tool} = $oldaccess->{$tool};
1.383 raeburn 3850: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3851: if ($newval =~ /^autolimit/) {
3852: if ($limit) {
3853: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3854: } else {
3855: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3856: }
3857: } elsif ($newval) {
3858: $newaccesstext->{$tool} = $reqdisplay{$newval};
3859: } else {
3860: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3861: }
1.275 raeburn 3862: } else {
1.383 raeburn 3863: if ($userenv->{$context.'.'.$tool}) {
3864: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3865: } else {
3866: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3867: }
1.275 raeburn 3868: }
3869: }
3870: }
3871: } else {
3872: $oldaccess->{$tool} = &mt('default');
3873: if ($env{'form.custom'.$tool} == 1) {
1.306 raeburn 3874: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
3875: $context);
1.275 raeburn 3876: if ($changed->{$tool}) {
3877: $newaccess->{$tool} = &mt('custom');
1.383 raeburn 3878: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3879: if ($newval =~ /^autolimit/) {
3880: if ($limit) {
3881: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3882: } else {
3883: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3884: }
3885: } elsif ($newval) {
3886: $newaccesstext->{$tool} = $reqdisplay{$newval};
3887: } else {
3888: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3889: }
1.275 raeburn 3890: } else {
1.383 raeburn 3891: if ($newval) {
3892: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3893: } else {
3894: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3895: }
1.275 raeburn 3896: }
3897: } else {
3898: $newaccess->{$tool} = $oldaccess->{$tool};
3899: }
3900: } else {
3901: $newaccess->{$tool} = $oldaccess->{$tool};
3902: }
3903: }
3904: }
3905: return;
3906: }
3907:
1.220 raeburn 3908: sub update_roles {
1.375 raeburn 3909: my ($r,$context,$showcredits) = @_;
1.4 www 3910: my $now=time;
1.225 raeburn 3911: my @rolechanges;
1.220 raeburn 3912: my %disallowed;
1.73 sakharuk 3913: $r->print('<h3>'.&mt('Modifying Roles').'</h3>');
1.404 raeburn 3914: foreach my $key (keys(%env)) {
1.135 raeburn 3915: next if (! $env{$key});
1.190 raeburn 3916: next if ($key eq 'form.action');
1.27 matthew 3917: # Revoke roles
1.135 raeburn 3918: if ($key=~/^form\.rev/) {
3919: if ($key=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) {
1.64 www 3920: # Revoke standard role
1.170 albertel 3921: my ($scope,$role) = ($1,$2);
3922: my $result =
3923: &Apache::lonnet::revokerole($env{'form.ccdomain'},
3924: $env{'form.ccuname'},
1.239 raeburn 3925: $scope,$role,'','',$context);
1.367 golterma 3926: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 3927: &mt('Revoking [_1] in [_2]',
3928: &Apache::lonnet::plaintext($role),
1.372 raeburn 3929: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 3930: $result ne "ok").'<br />');
3931: if ($result ne "ok") {
3932: $r->print(&mt('Error: [_1]',$result).'<br />');
3933: }
1.170 albertel 3934: if ($role eq 'st') {
1.202 raeburn 3935: my $result =
1.198 raeburn 3936: &Apache::lonuserutils::classlist_drop($scope,
3937: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 3938: $now);
1.367 golterma 3939: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.53 www 3940: }
1.225 raeburn 3941: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3942: push(@rolechanges,$role);
3943: }
1.196 raeburn 3944: }
1.195 raeburn 3945: if ($key=~m{^form\.rev\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}s) {
1.64 www 3946: # Revoke custom role
1.369 bisitz 3947: my $result = &Apache::lonnet::revokecustomrole(
3948: $env{'form.ccdomain'},$env{'form.ccuname'},$1,$2,$3,$4,'','',$context);
1.367 golterma 3949: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 3950: &mt('Revoking custom role [_1] by [_2] in [_3]',
1.372 raeburn 3951: $4,$3.':'.$2,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 3952: $result ne 'ok').'<br />');
3953: if ($result ne "ok") {
3954: $r->print(&mt('Error: [_1]',$result).'<br />');
3955: }
1.225 raeburn 3956: if (!grep(/^cr$/,@rolechanges)) {
3957: push(@rolechanges,'cr');
3958: }
1.64 www 3959: }
1.135 raeburn 3960: } elsif ($key=~/^form\.del/) {
3961: if ($key=~/^form\.del\:([^\_]+)\_([^\_\.]+)$/) {
1.116 raeburn 3962: # Delete standard role
1.170 albertel 3963: my ($scope,$role) = ($1,$2);
3964: my $result =
3965: &Apache::lonnet::assignrole($env{'form.ccdomain'},
3966: $env{'form.ccuname'},
1.239 raeburn 3967: $scope,$role,$now,0,1,'',
3968: $context);
1.367 golterma 3969: $r->print(&Apache::lonhtmlcommon::confirm_success(
3970: &mt('Deleting [_1] in [_2]',
1.369 bisitz 3971: &Apache::lonnet::plaintext($role),
1.372 raeburn 3972: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 3973: $result ne 'ok').'<br />');
3974: if ($result ne "ok") {
3975: $r->print(&mt('Error: [_1]',$result).'<br />');
3976: }
1.367 golterma 3977:
1.170 albertel 3978: if ($role eq 'st') {
1.202 raeburn 3979: my $result =
1.198 raeburn 3980: &Apache::lonuserutils::classlist_drop($scope,
3981: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 3982: $now);
1.369 bisitz 3983: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.81 albertel 3984: }
1.225 raeburn 3985: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3986: push(@rolechanges,$role);
3987: }
1.116 raeburn 3988: }
1.139 albertel 3989: if ($key=~m{^form\.del\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 3990: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
3991: # Delete custom role
1.369 bisitz 3992: my $result =
3993: &Apache::lonnet::assigncustomrole($env{'form.ccdomain'},
3994: $env{'form.ccuname'},$url,$rdom,$rnam,$rolename,$now,
3995: 0,1,$context);
3996: $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('Deleting custom role [_1] by [_2] in [_3]',
1.372 raeburn 3997: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 3998: $result ne "ok").'<br />');
3999: if ($result ne "ok") {
4000: $r->print(&mt('Error: [_1]',$result).'<br />');
4001: }
1.367 golterma 4002:
1.225 raeburn 4003: if (!grep(/^cr$/,@rolechanges)) {
4004: push(@rolechanges,'cr');
4005: }
1.116 raeburn 4006: }
1.135 raeburn 4007: } elsif ($key=~/^form\.ren/) {
1.101 albertel 4008: my $udom = $env{'form.ccdomain'};
4009: my $uname = $env{'form.ccuname'};
1.116 raeburn 4010: # Re-enable standard role
1.135 raeburn 4011: if ($key=~/^form\.ren\:([^\_]+)\_([^\_\.]+)$/) {
1.89 raeburn 4012: my $url = $1;
4013: my $role = $2;
4014: my $logmsg;
4015: my $output;
4016: if ($role eq 'st') {
1.141 albertel 4017: if ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
1.374 raeburn 4018: my ($cdom,$cnum,$csec) = ($1,$2,$3);
1.375 raeburn 4019: my $credits;
4020: if ($showcredits) {
4021: my $defaultcredits =
4022: &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
4023: $credits = &get_user_credits($defaultcredits,$cdom,$cnum);
4024: }
4025: my $result = &Apache::loncommon::commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$cdom,$cnum,$csec,$context,$credits);
1.220 raeburn 4026: if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course') || ($result eq 'refused')) {
1.223 raeburn 4027: if ($result eq 'refused' && $logmsg) {
4028: $output = $logmsg;
4029: } else {
1.369 bisitz 4030: $output = &mt('Error: [_1]',$result)."\n";
1.223 raeburn 4031: }
1.89 raeburn 4032: } else {
1.372 raeburn 4033: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Assigning [_1] in [_2] starting [_3]',
4034: &Apache::lonnet::plaintext($role),
4035: &Apache::loncommon::show_role_extent($url,$context,'st'),
4036: &Apache::lonlocal::locallocaltime($now))).'<br />'.$logmsg.'<br />';
1.89 raeburn 4037: }
4038: }
4039: } else {
1.101 albertel 4040: my $result=&Apache::lonnet::assignrole($env{'form.ccdomain'},
1.239 raeburn 4041: $env{'form.ccuname'},$url,$role,0,$now,'','',
4042: $context);
1.367 golterma 4043: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Re-enabling [_1] in [_2]',
1.372 raeburn 4044: &Apache::lonnet::plaintext($role),
4045: &Apache::loncommon::show_role_extent($url,$context,$role)),$result ne "ok").'<br />';
1.369 bisitz 4046: if ($result ne "ok") {
4047: $output .= &mt('Error: [_1]',$result).'<br />';
4048: }
4049: }
1.89 raeburn 4050: $r->print($output);
1.225 raeburn 4051: if (!grep(/^\Q$role\E$/,@rolechanges)) {
4052: push(@rolechanges,$role);
4053: }
1.113 raeburn 4054: }
1.116 raeburn 4055: # Re-enable custom role
1.139 albertel 4056: if ($key=~m{^form\.ren\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 4057: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
4058: my $result = &Apache::lonnet::assigncustomrole(
4059: $env{'form.ccdomain'}, $env{'form.ccuname'},
1.240 raeburn 4060: $url,$rdom,$rnam,$rolename,0,$now,undef,$context);
1.369 bisitz 4061: $r->print(&Apache::lonhtmlcommon::confirm_success(
4062: &mt('Re-enabling custom role [_1] by [_2] in [_3]',
1.372 raeburn 4063: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 4064: $result ne "ok").'<br />');
4065: if ($result ne "ok") {
4066: $r->print(&mt('Error: [_1]',$result).'<br />');
4067: }
1.225 raeburn 4068: if (!grep(/^cr$/,@rolechanges)) {
4069: push(@rolechanges,'cr');
4070: }
1.116 raeburn 4071: }
1.135 raeburn 4072: } elsif ($key=~/^form\.act/) {
1.101 albertel 4073: my $udom = $env{'form.ccdomain'};
4074: my $uname = $env{'form.ccuname'};
1.141 albertel 4075: if ($key=~/^form\.act\_($match_domain)\_($match_courseid)\_cr_cr_($match_domain)_($match_username)_([^\_]+)$/) {
1.65 www 4076: # Activate a custom role
1.83 albertel 4077: my ($one,$two,$three,$four,$five)=($1,$2,$3,$4,$5);
4078: my $url='/'.$one.'/'.$two;
4079: my $full=$one.'_'.$two.'_cr_cr_'.$three.'_'.$four.'_'.$five;
1.65 www 4080:
1.101 albertel 4081: my $start = ( $env{'form.start_'.$full} ?
4082: $env{'form.start_'.$full} :
1.88 raeburn 4083: $now );
1.101 albertel 4084: my $end = ( $env{'form.end_'.$full} ?
4085: $env{'form.end_'.$full} :
1.88 raeburn 4086: 0 );
4087:
4088: # split multiple sections
4089: my %sections = ();
1.101 albertel 4090: my $num_sections = &build_roles($env{'form.sec_'.$full},\%sections,$5);
1.88 raeburn 4091: if ($num_sections == 0) {
1.240 raeburn 4092: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end,$context));
1.88 raeburn 4093: } else {
1.114 albertel 4094: my %curr_groups =
1.117 raeburn 4095: &Apache::longroup::coursegroups($one,$two);
1.404 raeburn 4096: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.113 raeburn 4097: if (($sec eq 'none') || ($sec eq 'all') ||
4098: exists($curr_groups{$sec})) {
4099: $disallowed{$sec} = $url;
4100: next;
4101: }
4102: my $securl = $url.'/'.$sec;
1.240 raeburn 4103: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end,$context));
1.88 raeburn 4104: }
4105: }
1.225 raeburn 4106: if (!grep(/^cr$/,@rolechanges)) {
4107: push(@rolechanges,'cr');
4108: }
1.142 raeburn 4109: } elsif ($key=~/^form\.act\_($match_domain)\_($match_name)\_([^\_]+)$/) {
1.27 matthew 4110: # Activate roles for sections with 3 id numbers
4111: # set start, end times, and the url for the class
1.83 albertel 4112: my ($one,$two,$three)=($1,$2,$3);
1.101 albertel 4113: my $start = ( $env{'form.start_'.$one.'_'.$two.'_'.$three} ?
4114: $env{'form.start_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 4115: $now );
1.101 albertel 4116: my $end = ( $env{'form.end_'.$one.'_'.$two.'_'.$three} ?
4117: $env{'form.end_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 4118: 0 );
1.83 albertel 4119: my $url='/'.$one.'/'.$two;
1.88 raeburn 4120: my $type = 'three';
4121: # split multiple sections
4122: my %sections = ();
1.101 albertel 4123: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections,$three);
1.375 raeburn 4124: my $credits;
4125: if ($three eq 'st') {
4126: if ($showcredits) {
4127: my $defaultcredits =
4128: &Apache::lonuserutils::get_defaultcredits($one,$two);
4129: $credits = $env{'form.credits_'.$one.'_'.$two.'_'.$three};
4130: $credits =~ s/[^\d\.]//g;
4131: if ($credits eq $defaultcredits) {
4132: undef($credits);
4133: }
4134: }
4135: }
1.88 raeburn 4136: if ($num_sections == 0) {
1.375 raeburn 4137: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 4138: } else {
1.114 albertel 4139: my %curr_groups =
1.117 raeburn 4140: &Apache::longroup::coursegroups($one,$two);
1.88 raeburn 4141: my $emptysec = 0;
1.404 raeburn 4142: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.88 raeburn 4143: $sec =~ s/\W//g;
1.113 raeburn 4144: if ($sec ne '') {
4145: if (($sec eq 'none') || ($sec eq 'all') ||
4146: exists($curr_groups{$sec})) {
4147: $disallowed{$sec} = $url;
4148: next;
4149: }
1.88 raeburn 4150: my $securl = $url.'/'.$sec;
1.375 raeburn 4151: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec,$context,$credits));
1.88 raeburn 4152: } else {
4153: $emptysec = 1;
4154: }
4155: }
4156: if ($emptysec) {
1.375 raeburn 4157: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 4158: }
1.225 raeburn 4159: }
4160: if (!grep(/^\Q$three\E$/,@rolechanges)) {
4161: push(@rolechanges,$three);
4162: }
1.135 raeburn 4163: } elsif ($key=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
1.27 matthew 4164: # Activate roles for sections with two id numbers
4165: # set start, end times, and the url for the class
1.101 albertel 4166: my $start = ( $env{'form.start_'.$1.'_'.$2} ?
4167: $env{'form.start_'.$1.'_'.$2} :
1.27 matthew 4168: $now );
1.101 albertel 4169: my $end = ( $env{'form.end_'.$1.'_'.$2} ?
4170: $env{'form.end_'.$1.'_'.$2} :
1.27 matthew 4171: 0 );
1.225 raeburn 4172: my $one = $1;
4173: my $two = $2;
4174: my $url='/'.$one.'/';
1.88 raeburn 4175: # split multiple sections
4176: my %sections = ();
1.225 raeburn 4177: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two},\%sections,$two);
1.88 raeburn 4178: if ($num_sections == 0) {
1.240 raeburn 4179: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 4180: } else {
4181: my $emptysec = 0;
1.404 raeburn 4182: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.88 raeburn 4183: if ($sec ne '') {
4184: my $securl = $url.'/'.$sec;
1.240 raeburn 4185: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$two,$start,$end,$one,undef,$sec,$context));
1.88 raeburn 4186: } else {
4187: $emptysec = 1;
4188: }
4189: }
4190: if ($emptysec) {
1.240 raeburn 4191: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 4192: }
4193: }
1.225 raeburn 4194: if (!grep(/^\Q$two\E$/,@rolechanges)) {
4195: push(@rolechanges,$two);
4196: }
1.64 www 4197: } else {
1.190 raeburn 4198: $r->print('<p><span class="LC_error">'.&mt('ERROR').': '.&mt('Unknown command').' <tt>'.$key.'</tt></span></p><br />');
1.64 www 4199: }
1.113 raeburn 4200: foreach my $key (sort(keys(%disallowed))) {
1.274 bisitz 4201: $r->print('<p class="LC_warning">');
1.113 raeburn 4202: if (($key eq 'none') || ($key eq 'all')) {
1.274 bisitz 4203: $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 4204: } else {
1.274 bisitz 4205: $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 4206: }
1.274 bisitz 4207: $r->print('</p><p>'
4208: .&mt('Please [_1]go back[_2] and choose a different section name.'
4209: ,'<a href="javascript:history.go(-1)'
4210: ,'</a>')
4211: .'</p><br />'
4212: );
1.113 raeburn 4213: }
4214: }
1.101 albertel 4215: } # End of foreach (keys(%env))
1.75 www 4216: # Flush the course logs so reverse user roles immediately updated
1.349 raeburn 4217: $r->register_cleanup(\&Apache::lonnet::flushcourselogs);
1.225 raeburn 4218: if (@rolechanges == 0) {
1.372 raeburn 4219: $r->print('<p>'.&mt('No roles to modify').'</p>');
1.193 raeburn 4220: }
1.225 raeburn 4221: return @rolechanges;
1.220 raeburn 4222: }
4223:
1.375 raeburn 4224: sub get_user_credits {
4225: my ($uname,$udom,$defaultcredits,$cdom,$cnum) = @_;
4226: if ($cdom eq '' || $cnum eq '') {
4227: return unless ($env{'request.course.id'});
4228: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4229: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
4230: }
4231: my $credits;
4232: my %currhash =
4233: &Apache::lonnet::get('classlist',[$uname.':'.$udom],$cdom,$cnum);
4234: if (keys(%currhash) > 0) {
4235: my @items = split(/:/,$currhash{$uname.':'.$udom});
4236: my $crdidx = &Apache::loncoursedata::CL_CREDITS() - 3;
4237: $credits = $items[$crdidx];
4238: $credits =~ s/[^\d\.]//g;
4239: }
4240: if ($credits eq $defaultcredits) {
4241: undef($credits);
4242: }
4243: return $credits;
4244: }
4245:
1.220 raeburn 4246: sub enroll_single_student {
1.375 raeburn 4247: my ($r,$uhome,$amode,$genpwd,$now,$newuser,$context,$crstype,
4248: $showcredits,$defaultcredits) = @_;
1.318 raeburn 4249: $r->print('<h3>');
4250: if ($crstype eq 'Community') {
4251: $r->print(&mt('Enrolling Member'));
4252: } else {
4253: $r->print(&mt('Enrolling Student'));
4254: }
4255: $r->print('</h3>');
1.220 raeburn 4256:
4257: # Remove non alphanumeric values from section
4258: $env{'form.sections'}=~s/\W//g;
4259:
1.375 raeburn 4260: my $credits;
4261: if (($showcredits) && ($env{'form.credits'} ne '')) {
4262: $credits = $env{'form.credits'};
4263: $credits =~ s/[^\d\.]//g;
4264: if ($credits ne '') {
4265: if ($credits eq $defaultcredits) {
4266: undef($credits);
4267: }
4268: }
4269: }
4270:
1.220 raeburn 4271: # Clean out any old student roles the user has in this class.
4272: &Apache::lonuserutils::modifystudent($env{'form.ccdomain'},
4273: $env{'form.ccuname'},$env{'request.course.id'},undef,$uhome);
4274: my ($startdate,$enddate) = &Apache::lonuserutils::get_dates_from_form();
4275: my $enroll_result =
4276: &Apache::lonnet::modify_student_enrollment($env{'form.ccdomain'},
4277: $env{'form.ccuname'},$env{'form.cid'},$env{'form.cfirstname'},
4278: $env{'form.cmiddlename'},$env{'form.clastname'},
4279: $env{'form.generation'},$env{'form.sections'},$enddate,
1.375 raeburn 4280: $startdate,'manual',undef,$env{'request.course.id'},'',$context,
4281: $credits);
1.220 raeburn 4282: if ($enroll_result =~ /^ok/) {
1.381 bisitz 4283: $r->print(&mt('[_1] enrolled','<b>'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.'</b>'));
1.220 raeburn 4284: if ($env{'form.sections'} ne '') {
4285: $r->print(' '.&mt('in section [_1]',$env{'form.sections'}));
4286: }
4287: my ($showstart,$showend);
4288: if ($startdate <= $now) {
4289: $showstart = &mt('Access starts immediately');
4290: } else {
4291: $showstart = &mt('Access starts: ').&Apache::lonlocal::locallocaltime($startdate);
4292: }
4293: if ($enddate == 0) {
4294: $showend = &mt('ends: no ending date');
4295: } else {
4296: $showend = &mt('ends: ').&Apache::lonlocal::locallocaltime($enddate);
4297: }
4298: $r->print('.<br />'.$showstart.'; '.$showend);
4299: if ($startdate <= $now && !$newuser) {
1.386 bisitz 4300: $r->print('<p class="LC_info">');
1.318 raeburn 4301: if ($crstype eq 'Community') {
1.392 raeburn 4302: $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 4303: } else {
1.392 raeburn 4304: $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 4305: }
4306: $r->print('</p>');
1.220 raeburn 4307: }
4308: } else {
4309: $r->print(&mt('unable to enroll').": ".$enroll_result);
4310: }
4311: return;
1.188 raeburn 4312: }
4313:
1.204 raeburn 4314: sub get_defaultquota_text {
4315: my ($settingstatus) = @_;
4316: my $defquotatext;
4317: if ($settingstatus eq '') {
1.383 raeburn 4318: $defquotatext = &mt('default');
1.204 raeburn 4319: } else {
4320: my ($usertypes,$order) =
4321: &Apache::lonnet::retrieve_inst_usertypes($env{'form.ccdomain'});
4322: if ($usertypes->{$settingstatus} eq '') {
1.383 raeburn 4323: $defquotatext = &mt('default');
1.204 raeburn 4324: } else {
1.383 raeburn 4325: $defquotatext = &mt('default for [_1]',$usertypes->{$settingstatus});
1.204 raeburn 4326: }
4327: }
4328: return $defquotatext;
4329: }
4330:
1.188 raeburn 4331: sub update_result_form {
4332: my ($uhome) = @_;
4333: my $outcome =
1.367 golterma 4334: '<form name="userupdate" method="post" action="">'."\n";
1.160 raeburn 4335: foreach my $item ('srchby','srchin','srchtype','srchterm','srchdomain','ccuname','ccdomain') {
1.188 raeburn 4336: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 4337: }
1.207 raeburn 4338: if ($env{'form.origname'} ne '') {
4339: $outcome .= '<input type="hidden" name="origname" value="'.$env{'form.origname'}.'" />'."\n";
4340: }
1.160 raeburn 4341: foreach my $item ('sortby','seluname','seludom') {
4342: if (exists($env{'form.'.$item})) {
1.188 raeburn 4343: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 4344: }
4345: }
1.188 raeburn 4346: if ($uhome eq 'no_host') {
4347: $outcome .= '<input type="hidden" name="forcenewuser" value="1" />'."\n";
4348: }
4349: $outcome .= '<input type="hidden" name="phase" value="" />'."\n".
1.383 raeburn 4350: '<input type="hidden" name="currstate" value="" />'."\n".
4351: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
1.188 raeburn 4352: '</form>';
4353: return $outcome;
1.4 www 4354: }
4355:
1.149 raeburn 4356: sub quota_admin {
1.378 raeburn 4357: my ($setquota,$changeHash,$name) = @_;
1.149 raeburn 4358: my $quotachanged;
4359: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
4360: # Current user has quota modification privileges
1.267 raeburn 4361: if (ref($changeHash) eq 'HASH') {
4362: $quotachanged = 1;
1.378 raeburn 4363: $changeHash->{$name.'quota'} = $setquota;
1.267 raeburn 4364: }
1.149 raeburn 4365: }
4366: return $quotachanged;
4367: }
4368:
1.267 raeburn 4369: sub tool_admin {
1.275 raeburn 4370: my ($tool,$settool,$changeHash,$context) = @_;
4371: my $canchange = 0;
1.279 raeburn 4372: if ($context eq 'requestcourses') {
1.275 raeburn 4373: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
4374: $canchange = 1;
4375: }
1.300 raeburn 4376: } elsif ($context eq 'reqcrsotherdom') {
4377: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
4378: $canchange = 1;
4379: }
1.362 raeburn 4380: } elsif ($context eq 'requestauthor') {
4381: if (&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) {
4382: $canchange = 1;
4383: }
1.275 raeburn 4384: } elsif (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
4385: # Current user has quota modification privileges
4386: $canchange = 1;
4387: }
1.267 raeburn 4388: my $toolchanged;
1.275 raeburn 4389: if ($canchange) {
1.267 raeburn 4390: if (ref($changeHash) eq 'HASH') {
4391: $toolchanged = 1;
1.362 raeburn 4392: if ($tool eq 'requestauthor') {
4393: $changeHash->{$context} = $settool;
4394: } else {
4395: $changeHash->{$context.'.'.$tool} = $settool;
4396: }
1.267 raeburn 4397: }
4398: }
4399: return $toolchanged;
4400: }
4401:
1.88 raeburn 4402: sub build_roles {
1.89 raeburn 4403: my ($sectionstr,$sections,$role) = @_;
1.88 raeburn 4404: my $num_sections = 0;
4405: if ($sectionstr=~ /,/) {
4406: my @secnums = split/,/,$sectionstr;
1.89 raeburn 4407: if ($role eq 'st') {
4408: $secnums[0] =~ s/\W//g;
4409: $$sections{$secnums[0]} = 1;
4410: $num_sections = 1;
4411: } else {
4412: foreach my $sec (@secnums) {
4413: $sec =~ ~s/\W//g;
1.150 banghart 4414: if (!($sec eq "")) {
1.89 raeburn 4415: if (exists($$sections{$sec})) {
4416: $$sections{$sec} ++;
4417: } else {
4418: $$sections{$sec} = 1;
4419: $num_sections ++;
4420: }
1.88 raeburn 4421: }
4422: }
4423: }
4424: } else {
4425: $sectionstr=~s/\W//g;
4426: unless ($sectionstr eq '') {
4427: $$sections{$sectionstr} = 1;
4428: $num_sections ++;
4429: }
4430: }
1.129 albertel 4431:
1.88 raeburn 4432: return $num_sections;
4433: }
4434:
1.58 www 4435: # ========================================================== Custom Role Editor
4436:
4437: sub custom_role_editor {
1.406.2.14 raeburn 4438: my ($r,$context,$brcrum,$prefix,$permission) = @_;
1.324 raeburn 4439: my $action = $env{'form.customroleaction'};
1.406.2.14 raeburn 4440: my ($rolename,$helpitem);
1.324 raeburn 4441: if ($action eq 'new') {
4442: $rolename=$env{'form.newrolename'};
4443: } else {
4444: $rolename=$env{'form.rolename'};
1.59 www 4445: }
4446:
1.324 raeburn 4447: my ($crstype,$context);
4448: if ($env{'request.course.id'}) {
4449: $crstype = &Apache::loncommon::course_type();
4450: $context = 'course';
1.406.2.14 raeburn 4451: $helpitem = 'Course_Editing_Custom_Roles';
1.324 raeburn 4452: } else {
4453: $context = 'domain';
1.406.2.5 raeburn 4454: $crstype = 'course';
1.406.2.14 raeburn 4455: $helpitem = 'Domain_Editing_Custom_Roles';
1.324 raeburn 4456: }
1.351 raeburn 4457:
4458: $rolename=~s/[^A-Za-z0-9]//gs;
4459: if (!$rolename || $env{'form.phase'} eq 'pickrole') {
1.406.2.14 raeburn 4460: &print_username_entry_form($r,$context,undef,undef,undef,$crstype,$brcrum,
4461: $permission);
1.351 raeburn 4462: return;
4463: }
4464:
1.406.2.5 raeburn 4465: my $formname = 'form1';
4466: my %privs=();
4467: my $body_top = '<h2>';
4468: # ------------------------------------------------------- Does this role exist?
1.59 www 4469: my ($rdummy,$roledef)=
4470: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
4471: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.406.2.5 raeburn 4472: $body_top .= &mt('Existing Role').' "';
1.61 www 4473: # ------------------------------------------------- Get current role privileges
1.406.2.5 raeburn 4474: ($privs{'system'},$privs{'domain'},$privs{'course'})=split(/\_/,$roledef);
4475: if ($privs{'system'} =~ /bre\&S/) {
4476: if ($context eq 'domain') {
4477: $crstype = 'Course';
4478: } elsif ($crstype eq 'Community') {
4479: $privs{'system'} =~ s/bre\&S//;
4480: }
4481: } elsif ($context eq 'domain') {
4482: $crstype = 'Course';
1.324 raeburn 4483: }
1.59 www 4484: } else {
1.406.2.5 raeburn 4485: $body_top .= &mt('New Role').' "';
4486: $roledef='';
1.59 www 4487: }
1.153 banghart 4488: $body_top .= $rolename.'"</h2>';
1.406.2.5 raeburn 4489:
4490: # ------------------------------------------------------- What can be assigned?
4491: my %full=();
4492: my %levels=(
4493: course => {},
4494: domain => {},
4495: system => {},
4496: );
4497: my %levelscurrent=(
4498: course => {},
4499: domain => {},
4500: system => {},
4501: );
4502: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
1.160 raeburn 4503: my ($jsback,$elements) = &crumb_utilities();
1.406.2.5 raeburn 4504: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
4505: my $head_script =
4506: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,
4507: \%full,\@templateroles,$jsback);
1.351 raeburn 4508: push (@{$brcrum},
1.406.2.5 raeburn 4509: {href => "javascript:backPage(document.$formname,'pickrole','')",
1.351 raeburn 4510: text => "Pick custom role",
4511: faq => 282,bug=>'Instructor Interface',},
1.406.2.5 raeburn 4512: {href => "javascript:backPage(document.$formname,'','')",
1.351 raeburn 4513: text => "Edit custom role",
4514: faq => 282,
4515: bug => 'Instructor Interface',
1.406.2.14 raeburn 4516: help => $helpitem}
1.351 raeburn 4517: );
4518: my $args = { bread_crumbs => $brcrum,
4519: bread_crumbs_component => 'User Management'};
4520: $r->print(&Apache::loncommon::start_page('Custom Role Editor',
4521: $head_script,$args).
4522: $body_top);
1.406.2.5 raeburn 4523: $r->print('<form name="'.$formname.'" method="post" action="">'."\n".
4524: &Apache::lonuserutils::custom_role_header($context,$crstype,
4525: \@templateroles,$prefix));
1.264 bisitz 4526:
1.61 www 4527: $r->print(<<ENDCCF);
4528: <input type="hidden" name="phase" value="set_custom_roles" />
4529: <input type="hidden" name="rolename" value="$rolename" />
4530: ENDCCF
1.406.2.5 raeburn 4531: $r->print(&Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
4532: \%levelscurrent,$prefix));
1.135 raeburn 4533: $r->print(&Apache::loncommon::end_data_table().
1.190 raeburn 4534: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
1.160 raeburn 4535: '<input type="hidden" name="startrolename" value="'.$env{'form.rolename'}.
1.406.2.5 raeburn 4536: '" />'."\n".'<input type="hidden" name="currstate" value="" />'."\n".
1.160 raeburn 4537: '<input type="reset" value="'.&mt("Reset").'" />'."\n".
1.351 raeburn 4538: '<input type="submit" value="'.&mt('Save').'" /></form>');
1.61 www 4539: }
1.406.2.5 raeburn 4540:
1.61 www 4541: # ---------------------------------------------------------- Call to definerole
4542: sub set_custom_role {
1.406.2.14 raeburn 4543: my ($r,$context,$brcrum,$prefix,$permission) = @_;
1.101 albertel 4544: my $rolename=$env{'form.rolename'};
1.63 www 4545: $rolename=~s/[^A-Za-z0-9]//gs;
1.150 banghart 4546: if (!$rolename) {
1.406.2.14 raeburn 4547: &custom_role_editor($r,$context,$brcrum,$prefix,$permission);
1.61 www 4548: return;
4549: }
1.160 raeburn 4550: my ($jsback,$elements) = &crumb_utilities();
1.301 bisitz 4551: my $jscript = '<script type="text/javascript">'
4552: .'// <![CDATA['."\n"
4553: .$jsback."\n"
4554: .'// ]]>'."\n"
4555: .'</script>'."\n";
1.406.2.14 raeburn 4556: my $helpitem = 'Course_Editing_Custom_Roles';
4557: if ($context eq 'domain') {
4558: $helpitem = 'Domain_Editing_Custom_Roles';
4559: }
1.352 raeburn 4560: push(@{$brcrum},
4561: {href => "javascript:backPage(document.customresult,'pickrole','')",
4562: text => "Pick custom role",
4563: faq => 282,
4564: bug => 'Instructor Interface',},
4565: {href => "javascript:backPage(document.customresult,'selected_custom_edit','')",
4566: text => "Edit custom role",
4567: faq => 282,
4568: bug => 'Instructor Interface',},
4569: {href => "javascript:backPage(document.customresult,'set_custom_roles','')",
4570: text => "Result",
4571: faq => 282,
4572: bug => 'Instructor Interface',
1.406.2.14 raeburn 4573: help => $helpitem,}
1.352 raeburn 4574: );
4575: my $args = { bread_crumbs => $brcrum,
1.406.2.5 raeburn 4576: bread_crumbs_component => 'User Management'};
1.351 raeburn 4577: $r->print(&Apache::loncommon::start_page('Save Custom Role',$jscript,$args));
1.160 raeburn 4578:
1.393 raeburn 4579: my $newrole;
1.61 www 4580: my ($rdummy,$roledef)=
1.110 albertel 4581: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
4582:
1.61 www 4583: # ------------------------------------------------------- Does this role exist?
1.188 raeburn 4584: $r->print('<h3>');
1.61 www 4585: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.73 sakharuk 4586: $r->print(&mt('Existing Role').' "');
1.61 www 4587: } else {
1.73 sakharuk 4588: $r->print(&mt('New Role').' "');
1.61 www 4589: $roledef='';
1.393 raeburn 4590: $newrole = 1;
1.61 www 4591: }
1.188 raeburn 4592: $r->print($rolename.'"</h3>');
1.406.2.5 raeburn 4593: # ------------------------------------------------- Assign role and show result
1.61 www 4594:
1.387 bisitz 4595: my $errmsg;
1.406.2.5 raeburn 4596: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$prefix);
4597: # Assign role and return result
4598: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
4599: $newprivs{'c'});
1.387 bisitz 4600: if ($result ne 'ok') {
4601: $errmsg = ': '.$result;
4602: }
4603: my $message =
4604: &Apache::lonhtmlcommon::confirm_success(
4605: &mt('Defining Role').$errmsg, ($result eq 'ok' ? 0 : 1));
1.101 albertel 4606: if ($env{'request.course.id'}) {
4607: my $url='/'.$env{'request.course.id'};
1.63 www 4608: $url=~s/\_/\//g;
1.387 bisitz 4609: $result =
4610: &Apache::lonnet::assigncustomrole(
4611: $env{'user.domain'},$env{'user.name'},
4612: $url,
4613: $env{'user.domain'},$env{'user.name'},
4614: $rolename,undef,undef,undef,$context);
4615: if ($result ne 'ok') {
4616: $errmsg = ': '.$result;
4617: }
4618: $message .=
4619: '<br />'
4620: .&Apache::lonhtmlcommon::confirm_success(
4621: &mt('Assigning Role to Self').$errmsg, ($result eq 'ok' ? 0 : 1));
1.63 www 4622: }
1.380 bisitz 4623: $r->print(
1.387 bisitz 4624: &Apache::loncommon::confirmwrapper($message)
4625: .'<br />'
4626: .&Apache::lonhtmlcommon::actionbox([
4627: '<a href="javascript:backPage(document.customresult,'."'pickrole'".')">'
4628: .&mt('Create or edit another custom role')
4629: .'</a>'])
1.380 bisitz 4630: .'<form name="customresult" method="post" action="">'
1.387 bisitz 4631: .&Apache::lonhtmlcommon::echo_form_input([])
4632: .'</form>'
1.380 bisitz 4633: );
1.58 www 4634: }
4635:
1.2 www 4636: # ================================================================ Main Handler
4637: sub handler {
4638: my $r = shift;
4639: if ($r->header_only) {
1.68 www 4640: &Apache::loncommon::content_type($r,'text/html');
1.2 www 4641: $r->send_http_header;
4642: return OK;
4643: }
1.406.2.14 raeburn 4644: my ($context,$crstype,$cid,$cnum,$cdom,$allhelpitems);
4645:
1.190 raeburn 4646: if ($env{'request.course.id'}) {
4647: $context = 'course';
1.318 raeburn 4648: $crstype = &Apache::loncommon::course_type();
1.190 raeburn 4649: } elsif ($env{'request.role'} =~ /^au\./) {
1.206 raeburn 4650: $context = 'author';
1.190 raeburn 4651: } else {
4652: $context = 'domain';
4653: }
1.375 raeburn 4654:
1.406.2.14 raeburn 4655: my ($permission,$allowed) =
4656: &Apache::lonuserutils::get_permission($context,$crstype);
4657:
4658: if ($allowed) {
4659: my @allhelp;
4660: if ($context eq 'course') {
4661: $cid = $env{'request.course.id'};
4662: $cdom = $env{'course.'.$cid.'.domain'};
4663: $cnum = $env{'course.'.$cid.'.num'};
4664:
4665: if ($permission->{'cusr'}) {
4666: push(@allhelp,'Course_Create_Class_List');
4667: }
4668: if ($permission->{'view'} || $permission->{'cusr'}) {
4669: push(@allhelp,('Course_Change_Privileges','Course_View_Class_List'));
4670: }
4671: if ($permission->{'custom'}) {
4672: push(@allhelp,'Course_Editing_Custom_Roles');
4673: }
4674: if ($permission->{'cusr'}) {
4675: push(@allhelp,('Course_Add_Student','Course_Drop_Student'));
4676: }
4677: unless ($permission->{'cusr_section'}) {
4678: if (&Apache::lonnet::auto_run($cnum,$cdom) && (($permission->{'cusr'}) || ($permission->{'view'}))) {
4679: push(@allhelp,'Course_Automated_Enrollment');
4680: }
4681: if ($permission->{'selfenrolladmin'}) {
4682: push(@allhelp,'Course_Approve_Selfenroll');
4683: }
4684: }
4685: if ($permission->{'grp_manage'}) {
4686: push(@allhelp,'Course_Manage_Group');
4687: }
4688: if ($permission->{'view'} || $permission->{'cusr'}) {
4689: push(@allhelp,'Course_User_Logs');
4690: }
4691: } elsif ($context eq 'author') {
4692: push(@allhelp,('Author_Change_Privileges','Author_Create_Coauthor_List',
4693: 'Author_View_Coauthor_List','Author_User_Logs'));
4694: } else {
4695: if ($permission->{'cusr'}) {
4696: push(@allhelp,'Domain_Change_Privileges');
4697: if ($permission->{'activity'}) {
4698: push(@allhelp,'Domain_User_Access_Logs');
4699: }
4700: push(@allhelp,('Domain_Create_Users','Domain_View_Users_List'));
4701: if ($permission->{'custom'}) {
4702: push(@allhelp,'Domain_Editing_Custom_Roles');
4703: }
4704: push(@allhelp,('Domain_Role_Approvals','Domain_Username_Approvals','Domain_Change_Logs'));
4705: } elsif ($permission->{'view'}) {
4706: push(@allhelp,'Domain_View_Privileges');
4707: if ($permission->{'activity'}) {
4708: push(@allhelp,'Domain_User_Access_Logs');
4709: }
4710: push(@allhelp,('Domain_View_Users_List','Domain_Change_Logs'));
4711: }
4712: }
4713: if (@allhelp) {
4714: $allhelpitems = join(',',@allhelp);
4715: }
4716: }
4717:
1.190 raeburn 4718: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.233 raeburn 4719: ['action','state','callingform','roletype','showrole','bulkaction','popup','phase',
1.391 raeburn 4720: 'username','domain','srchterm','srchdomain','srchin','srchby','srchtype','queue']);
1.190 raeburn 4721: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.351 raeburn 4722: my $args;
4723: my $brcrum = [];
4724: my $bread_crumbs_component = 'User Management';
1.391 raeburn 4725: if (($env{'form.action'} ne 'dateselect') && ($env{'form.action'} ne 'displayuserreq')) {
1.351 raeburn 4726: $brcrum = [{href=>"/adm/createuser",
4727: text=>"User Management",
1.406.2.14 raeburn 4728: help=>$allhelpitems}
1.351 raeburn 4729: ];
1.202 raeburn 4730: }
1.190 raeburn 4731: if (!$allowed) {
1.358 raeburn 4732: if ($context eq 'course') {
4733: $r->internal_redirect('/adm/viewclasslist');
4734: return OK;
4735: }
1.190 raeburn 4736: $env{'user.error.msg'}=
4737: "/adm/createuser:cst:0:0:Cannot create/modify user data ".
4738: "or view user status.";
4739: return HTTP_NOT_ACCEPTABLE;
4740: }
4741:
4742: &Apache::loncommon::content_type($r,'text/html');
4743: $r->send_http_header;
4744:
1.375 raeburn 4745: my $showcredits;
4746: if ((($context eq 'course') && ($crstype eq 'Course')) ||
4747: ($context eq 'domain')) {
4748: my %domdefaults =
4749: &Apache::lonnet::get_domain_defaults($env{'request.role.domain'});
4750: if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'}) {
4751: $showcredits = 1;
4752: }
4753: }
4754:
1.190 raeburn 4755: # Main switch on form.action and form.state, as appropriate
4756: if (! exists($env{'form.action'})) {
1.351 raeburn 4757: $args = {bread_crumbs => $brcrum,
4758: bread_crumbs_component => $bread_crumbs_component};
4759: $r->print(&header(undef,$args));
1.318 raeburn 4760: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 4761: } elsif ($env{'form.action'} eq 'upload' && $permission->{'cusr'}) {
1.406.2.14 raeburn 4762: my $helpitem = 'Course_Create_Class_List';
4763: if ($context eq 'author') {
4764: $helpitem = 'Author_Create_Coauthor_List';
4765: } elsif ($context eq 'domain') {
4766: $helpitem = 'Domain_Create_Users';
4767: }
1.351 raeburn 4768: push(@{$brcrum},
4769: { href => '/adm/createuser?action=upload&state=',
4770: text => 'Upload Users List',
1.406.2.14 raeburn 4771: help => $helpitem,
1.351 raeburn 4772: });
4773: $bread_crumbs_component = 'Upload Users List';
4774: $args = {bread_crumbs => $brcrum,
4775: bread_crumbs_component => $bread_crumbs_component};
4776: $r->print(&header(undef,$args));
1.190 raeburn 4777: $r->print('<form name="studentform" method="post" '.
4778: 'enctype="multipart/form-data" '.
4779: ' action="/adm/createuser">'."\n");
4780: if (! exists($env{'form.state'})) {
4781: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4782: } elsif ($env{'form.state'} eq 'got_file') {
1.406.2.15 raeburn 4783: my $result =
4784: &Apache::lonuserutils::print_upload_manager_form($r,$context,
4785: $permission,
4786: $crstype,$showcredits);
4787: if ($result eq 'missingdata') {
4788: delete($env{'form.state'});
4789: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4790: }
1.190 raeburn 4791: } elsif ($env{'form.state'} eq 'enrolling') {
4792: if ($env{'form.datatoken'}) {
1.406.2.15 raeburn 4793: my $result = &Apache::lonuserutils::upfile_drop_add($r,$context,
4794: $permission,
4795: $showcredits);
4796: if ($result eq 'missingdata') {
4797: delete($env{'form.state'});
4798: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4799: } elsif ($result eq 'invalidhome') {
4800: $env{'form.state'} = 'got_file';
4801: delete($env{'form.lcserver'});
4802: my $result =
4803: &Apache::lonuserutils::print_upload_manager_form($r,$context,$permission,
4804: $crstype,$showcredits);
4805: if ($result eq 'missingdata') {
4806: delete($env{'form.state'});
4807: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4808: }
4809: }
4810: } else {
4811: delete($env{'form.state'});
4812: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
1.190 raeburn 4813: }
4814: } else {
4815: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4816: }
1.406.2.15 raeburn 4817: $r->print('</form>');
1.406.2.5 raeburn 4818: } elsif (((($env{'form.action'} eq 'singleuser') || ($env{'form.action'}
4819: eq 'singlestudent')) && ($permission->{'cusr'})) ||
1.406.2.6 raeburn 4820: (($env{'form.action'} eq 'singleuser') && ($permission->{'view'})) ||
1.406.2.5 raeburn 4821: (($env{'form.action'} eq 'accesslogs') && ($permission->{'activity'}))) {
1.190 raeburn 4822: my $phase = $env{'form.phase'};
4823: my @search = ('srchterm','srchby','srchin','srchtype','srchdomain');
1.192 albertel 4824: &Apache::loncreateuser::restore_prev_selections();
4825: my $srch;
4826: foreach my $item (@search) {
4827: $srch->{$item} = $env{'form.'.$item};
4828: }
1.207 raeburn 4829: if (($phase eq 'get_user_info') || ($phase eq 'userpicked') ||
1.406.2.5 raeburn 4830: ($phase eq 'createnewuser') || ($phase eq 'activity')) {
1.207 raeburn 4831: if ($env{'form.phase'} eq 'createnewuser') {
4832: my $response;
4833: if ($env{'form.srchterm'} !~ /^$match_username$/) {
1.366 bisitz 4834: my $response =
4835: '<span class="LC_warning">'
4836: .&mt('You must specify a valid username. Only the following are allowed:'
4837: .' letters numbers - . @')
4838: .'</span>';
1.221 raeburn 4839: $env{'form.phase'} = '';
1.375 raeburn 4840: &print_username_entry_form($r,$context,$response,$srch,undef,
1.406.2.14 raeburn 4841: $crstype,$brcrum,$permission);
1.207 raeburn 4842: } else {
4843: my $ccuname =&LONCAPA::clean_username($srch->{'srchterm'});
4844: my $ccdomain=&LONCAPA::clean_domain($srch->{'srchdomain'});
4845: &print_user_modification_page($r,$ccuname,$ccdomain,
1.221 raeburn 4846: $srch,$response,$context,
1.375 raeburn 4847: $permission,$crstype,$brcrum,
4848: $showcredits);
1.207 raeburn 4849: }
4850: } elsif ($env{'form.phase'} eq 'get_user_info') {
1.190 raeburn 4851: my ($currstate,$response,$forcenewuser,$results) =
1.221 raeburn 4852: &user_search_result($context,$srch);
1.190 raeburn 4853: if ($env{'form.currstate'} eq 'modify') {
4854: $currstate = $env{'form.currstate'};
4855: }
4856: if ($currstate eq 'select') {
4857: &print_user_selection_page($r,$response,$srch,$results,
1.351 raeburn 4858: \@search,$context,undef,$crstype,
4859: $brcrum);
1.406.2.5 raeburn 4860: } elsif (($currstate eq 'modify') || ($env{'form.action'} eq 'accesslogs')) {
4861: my ($ccuname,$ccdomain,$uhome);
1.190 raeburn 4862: if (($srch->{'srchby'} eq 'uname') &&
4863: ($srch->{'srchtype'} eq 'exact')) {
4864: $ccuname = $srch->{'srchterm'};
4865: $ccdomain= $srch->{'srchdomain'};
4866: } else {
4867: my @matchedunames = keys(%{$results});
4868: ($ccuname,$ccdomain) = split(/:/,$matchedunames[0]);
4869: }
4870: $ccuname =&LONCAPA::clean_username($ccuname);
4871: $ccdomain=&LONCAPA::clean_domain($ccdomain);
1.406.2.5 raeburn 4872: if ($env{'form.action'} eq 'accesslogs') {
4873: my $uhome;
4874: if (($ccuname ne '') && ($ccdomain ne '')) {
4875: $uhome = &Apache::lonnet::homeserver($ccuname,$ccdomain);
4876: }
4877: if (($uhome eq '') || ($uhome eq 'no_host')) {
4878: $env{'form.phase'} = '';
4879: undef($forcenewuser);
4880: #if ($response) {
4881: # unless ($response =~ m{\Q<br /><br />\E$}) {
4882: # $response .= '<br /><br />';
4883: # }
4884: #}
4885: &print_username_entry_form($r,$context,$response,$srch,
1.406.2.14 raeburn 4886: $forcenewuser,$crstype,$brcrum,
4887: $permission);
1.406.2.5 raeburn 4888: } else {
4889: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
4890: }
4891: } else {
4892: if ($env{'form.forcenewuser'}) {
4893: $response = '';
4894: }
4895: &print_user_modification_page($r,$ccuname,$ccdomain,
4896: $srch,$response,$context,
4897: $permission,$crstype,$brcrum);
1.190 raeburn 4898: }
4899: } elsif ($currstate eq 'query') {
1.351 raeburn 4900: &print_user_query_page($r,'createuser',$brcrum);
1.190 raeburn 4901: } else {
1.229 raeburn 4902: $env{'form.phase'} = '';
1.207 raeburn 4903: &print_username_entry_form($r,$context,$response,$srch,
1.406.2.14 raeburn 4904: $forcenewuser,$crstype,$brcrum,
4905: $permission);
1.190 raeburn 4906: }
4907: } elsif ($env{'form.phase'} eq 'userpicked') {
4908: my $ccuname = &LONCAPA::clean_username($env{'form.seluname'});
4909: my $ccdomain = &LONCAPA::clean_domain($env{'form.seludom'});
1.406.2.5 raeburn 4910: if ($env{'form.action'} eq 'accesslogs') {
4911: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
4912: } else {
4913: &print_user_modification_page($r,$ccuname,$ccdomain,$srch,'',
4914: $context,$permission,$crstype,
4915: $brcrum);
4916: }
4917: } elsif ($env{'form.action'} eq 'accesslogs') {
4918: my $ccuname = &LONCAPA::clean_username($env{'form.accessuname'});
4919: my $ccdomain = &LONCAPA::clean_domain($env{'form.accessudom'});
4920: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
1.190 raeburn 4921: }
4922: } elsif ($env{'form.phase'} eq 'update_user_data') {
1.406.2.17 raeburn 4923: &update_user_data($r,$context,$crstype,$brcrum,$showcredits,$permission);
1.190 raeburn 4924: } else {
1.351 raeburn 4925: &print_username_entry_form($r,$context,undef,$srch,undef,$crstype,
1.406.2.14 raeburn 4926: $brcrum,$permission);
1.190 raeburn 4927: }
4928: } elsif ($env{'form.action'} eq 'custom' && $permission->{'custom'}) {
1.406.2.5 raeburn 4929: my $prefix;
1.190 raeburn 4930: if ($env{'form.phase'} eq 'set_custom_roles') {
1.406.2.14 raeburn 4931: &set_custom_role($r,$context,$brcrum,$prefix,$permission);
1.190 raeburn 4932: } else {
1.406.2.14 raeburn 4933: &custom_role_editor($r,$context,$brcrum,$prefix,$permission);
1.190 raeburn 4934: }
1.362 raeburn 4935: } elsif (($env{'form.action'} eq 'processauthorreq') &&
4936: ($permission->{'cusr'}) &&
4937: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
4938: push(@{$brcrum},
4939: {href => '/adm/createuser?action=processauthorreq',
1.385 bisitz 4940: text => 'Authoring Space requests',
1.362 raeburn 4941: help => 'Domain_Role_Approvals'});
4942: $bread_crumbs_component = 'Authoring requests';
4943: if ($env{'form.state'} eq 'done') {
4944: push(@{$brcrum},
4945: {href => '/adm/createuser?action=authorreqqueue',
4946: text => 'Result',
4947: help => 'Domain_Role_Approvals'});
4948: $bread_crumbs_component = 'Authoring request result';
4949: }
4950: $args = { bread_crumbs => $brcrum,
4951: bread_crumbs_component => $bread_crumbs_component};
1.391 raeburn 4952: my $js = &usernamerequest_javascript();
4953: $r->print(&header(&add_script($js),$args));
1.362 raeburn 4954: if (!exists($env{'form.state'})) {
4955: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestauthor',
4956: $env{'request.role.domain'}));
4957: } elsif ($env{'form.state'} eq 'done') {
4958: $r->print('<h3>'.&mt('Authoring request processing').'</h3>'."\n");
4959: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestauthor',
4960: $env{'request.role.domain'}));
4961: }
1.391 raeburn 4962: } elsif (($env{'form.action'} eq 'processusernamereq') &&
4963: ($permission->{'cusr'}) &&
4964: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
4965: push(@{$brcrum},
4966: {href => '/adm/createuser?action=processusernamereq',
4967: text => 'LON-CAPA account requests',
4968: help => 'Domain_Username_Approvals'});
4969: $bread_crumbs_component = 'Account requests';
4970: if ($env{'form.state'} eq 'done') {
4971: push(@{$brcrum},
4972: {href => '/adm/createuser?action=usernamereqqueue',
4973: text => 'Result',
4974: help => 'Domain_Username_Approvals'});
4975: $bread_crumbs_component = 'LON-CAPA account request result';
4976: }
4977: $args = { bread_crumbs => $brcrum,
4978: bread_crumbs_component => $bread_crumbs_component};
4979: my $js = &usernamerequest_javascript();
4980: $r->print(&header(&add_script($js),$args));
4981: if (!exists($env{'form.state'})) {
4982: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestusername',
4983: $env{'request.role.domain'}));
4984: } elsif ($env{'form.state'} eq 'done') {
4985: $r->print('<h3>'.&mt('LON-CAPA account request processing').'</h3>'."\n");
4986: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestusername',
4987: $env{'request.role.domain'}));
4988: }
4989: } elsif (($env{'form.action'} eq 'displayuserreq') &&
4990: ($permission->{'cusr'})) {
4991: my $dom = $env{'form.domain'};
4992: my $uname = $env{'form.username'};
4993: my $warning;
4994: if (($dom =~ /^$match_domain$/) && (&Apache::lonnet::domain($dom) ne '')) {
4995: if (($dom eq $env{'request.role.domain'}) && (&Apache::lonnet::allowed('ccc',$dom))) {
4996: if (($uname =~ /^$match_username$/) && ($env{'form.queue'} eq 'approval')) {
4997: my $uhome = &Apache::lonnet::homeserver($uname,$dom);
4998: if ($uhome eq 'no_host') {
4999: my $queue = $env{'form.queue'};
5000: my $reqkey = &escape($uname).'_'.$queue;
5001: my $namespace = 'usernamequeue';
5002: my $domconfig = &Apache::lonnet::get_domainconfiguser($dom);
5003: my %queued =
5004: &Apache::lonnet::get($namespace,[$reqkey],$dom,$domconfig);
5005: unless ($queued{$reqkey}) {
5006: $warning = &mt('No information was found for this LON-CAPA account request.');
5007: }
5008: } else {
5009: $warning = &mt('A LON-CAPA account already exists for the requested username and domain.');
5010: }
5011: } else {
5012: $warning = &mt('LON-CAPA account request status check is for an invalid username.');
5013: }
5014: } else {
5015: $warning = &mt('You do not have rights to view LON-CAPA account requests in the domain specified.');
5016: }
5017: } else {
5018: $warning = &mt('LON-CAPA account request status check is for an invalid domain.');
5019: }
5020: my $args = { only_body => 1 };
5021: $r->print(&header(undef,$args).
5022: '<h3>'.&mt('LON-CAPA Account Request Details').'</h3>');
5023: if ($warning ne '') {
5024: $r->print('<div class="LC_warning">'.$warning.'</div>');
5025: } else {
5026: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
5027: my $domconfiguser = &Apache::lonnet::get_domainconfiguser($dom);
5028: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
5029: if (ref($domconfig{'usercreation'}) eq 'HASH') {
5030: if (ref($domconfig{'usercreation'}{'cancreate'}) eq 'HASH') {
5031: if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}) eq 'HASH') {
5032: my %info =
5033: &Apache::lonnet::get('nohist_requestedusernames',[$uname],$dom,$domconfiguser);
5034: if (ref($info{$uname}) eq 'HASH') {
1.396 raeburn 5035: my $usertype = $info{$uname}{'inststatus'};
5036: unless ($usertype) {
5037: $usertype = 'default';
5038: }
1.406.2.16 raeburn 5039: my ($showstatus,$showemail,$pickstart);
5040: my $numextras = 0;
5041: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5042: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
5043: if (ref($usertypes) eq 'HASH') {
5044: if ($usertypes->{$usertype}) {
5045: $showstatus = $usertypes->{$usertype};
5046: } else {
5047: $showstatus = $othertitle;
5048: }
5049: if ($showstatus) {
5050: $numextras ++;
5051: }
5052: }
5053: }
5054: if (($info{$uname}{'email'} ne '') && ($info{$uname}{'email'} ne $uname)) {
5055: $showemail = $info{$uname}{'email'};
5056: $numextras ++;
5057: }
1.396 raeburn 5058: if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}) eq 'HASH') {
5059: if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
1.406.2.16 raeburn 5060: $pickstart = 1;
1.396 raeburn 5061: $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box());
1.406.2.16 raeburn 5062: my ($num,$count);
1.396 raeburn 5063: $count = scalar(keys(%{$domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}}));
1.406.2.16 raeburn 5064: $count += $numextras;
1.396 raeburn 5065: foreach my $field (@{$infofields}) {
5066: next unless ($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}{$field});
5067: next unless ($infotitles->{$field});
5068: $r->print(&Apache::lonhtmlcommon::row_title($infotitles->{$field}).
5069: $info{$uname}{$field});
5070: $num ++;
1.406.2.16 raeburn 5071: unless ($count == $num) {
1.396 raeburn 5072: $r->print(&Apache::lonhtmlcommon::row_closure());
5073: }
5074: }
1.406.2.16 raeburn 5075: }
5076: }
5077: if ($numextras) {
5078: unless ($pickstart) {
5079: $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box());
5080: $pickstart = 1;
5081: }
5082: if ($showemail) {
5083: my $closure = '';
5084: unless ($showstatus) {
5085: $closure = 1;
1.391 raeburn 5086: }
1.406.2.16 raeburn 5087: $r->print(&Apache::lonhtmlcommon::row_title(&mt('E-mail address')).
5088: $showemail.
5089: &Apache::lonhtmlcommon::row_closure($closure));
5090: }
5091: if ($showstatus) {
5092: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Status type[_1](self-reported)','<br />')).
5093: $showstatus.
5094: &Apache::lonhtmlcommon::row_closure(1));
1.391 raeburn 5095: }
5096: }
1.406.2.16 raeburn 5097: if ($pickstart) {
5098: $r->print(&Apache::lonhtmlcommon::end_pick_box().'</div>');
5099: } else {
5100: $r->print('<div>'.&mt('No information to display for this account request.').'</div>');
5101: }
5102: } else {
5103: $r->print('<div>'.&mt('No information available for this account request.').'</div>');
1.391 raeburn 5104: }
5105: }
5106: }
5107: }
5108: }
1.406.2.16 raeburn 5109: $r->print(&close_popup_form());
1.207 raeburn 5110: } elsif (($env{'form.action'} eq 'listusers') &&
5111: ($permission->{'view'} || $permission->{'cusr'})) {
1.406.2.14 raeburn 5112: my $helpitem = 'Course_View_Class_List';
5113: if ($context eq 'author') {
5114: $helpitem = 'Author_View_Coauthor_List';
5115: } elsif ($context eq 'domain') {
5116: $helpitem = 'Domain_View_Users_List';
5117: }
1.202 raeburn 5118: if ($env{'form.phase'} eq 'bulkchange') {
1.351 raeburn 5119: push(@{$brcrum},
5120: {href => '/adm/createuser?action=listusers',
5121: text => "List Users"},
5122: {href => "/adm/createuser",
5123: text => "Result",
1.406.2.14 raeburn 5124: help => $helpitem});
1.351 raeburn 5125: $bread_crumbs_component = 'Update Users';
5126: $args = {bread_crumbs => $brcrum,
5127: bread_crumbs_component => $bread_crumbs_component};
5128: $r->print(&header(undef,$args));
1.202 raeburn 5129: my $setting = $env{'form.roletype'};
5130: my $choice = $env{'form.bulkaction'};
5131: if ($permission->{'cusr'}) {
1.336 raeburn 5132: &Apache::lonuserutils::update_user_list($r,$context,$setting,$choice,$crstype);
1.221 raeburn 5133: } else {
5134: $r->print(&mt('You are not authorized to make bulk changes to user roles'));
1.223 raeburn 5135: $r->print('<p><a href="/adm/createuser?action=listusers">'.&mt('Display User Lists').'</a>');
1.202 raeburn 5136: }
5137: } else {
1.351 raeburn 5138: push(@{$brcrum},
5139: {href => '/adm/createuser?action=listusers',
5140: text => "List Users",
1.406.2.14 raeburn 5141: help => $helpitem});
1.351 raeburn 5142: $bread_crumbs_component = 'List Users';
5143: $args = {bread_crumbs => $brcrum,
5144: bread_crumbs_component => $bread_crumbs_component};
1.202 raeburn 5145: my ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles);
5146: my $formname = 'studentform';
1.364 raeburn 5147: my $hidecall = "hide_searching();";
1.321 raeburn 5148: if (($context eq 'domain') && (($env{'form.roletype'} eq 'course') ||
5149: ($env{'form.roletype'} eq 'community'))) {
5150: if ($env{'form.roletype'} eq 'course') {
5151: ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles) =
5152: &Apache::lonuserutils::courses_selector($env{'request.role.domain'},
5153: $formname);
5154: } elsif ($env{'form.roletype'} eq 'community') {
5155: $cb_jscript =
5156: &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
5157: my %elements = (
5158: coursepick => 'radio',
5159: coursetotal => 'text',
5160: courselist => 'text',
5161: );
5162: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements);
5163: }
1.364 raeburn 5164: $jscript .= &verify_user_display($context)."\n".
5165: &Apache::loncommon::check_uncheck_jscript();
1.202 raeburn 5166: my $js = &add_script($jscript).$cb_jscript;
5167: my $loadcode =
5168: &Apache::lonuserutils::course_selector_loadcode($formname);
5169: if ($loadcode ne '') {
1.364 raeburn 5170: $args->{add_entries} = {onload => "$loadcode;$hidecall"};
5171: } else {
5172: $args->{add_entries} = {onload => $hidecall};
1.202 raeburn 5173: }
1.351 raeburn 5174: $r->print(&header($js,$args));
1.191 raeburn 5175: } else {
1.364 raeburn 5176: $args->{add_entries} = {onload => $hidecall};
5177: $jscript = &verify_user_display($context).
5178: &Apache::loncommon::check_uncheck_jscript();
5179: $r->print(&header(&add_script($jscript),$args));
1.191 raeburn 5180: }
1.202 raeburn 5181: &Apache::lonuserutils::print_userlist($r,undef,$permission,$context,
1.375 raeburn 5182: $formname,$totcodes,$codetitles,$idlist,$idlist_titles,
5183: $showcredits);
1.191 raeburn 5184: }
1.213 raeburn 5185: } elsif ($env{'form.action'} eq 'drop' && $permission->{'cusr'}) {
1.318 raeburn 5186: my $brtext;
5187: if ($crstype eq 'Community') {
5188: $brtext = 'Drop Members';
5189: } else {
5190: $brtext = 'Drop Students';
5191: }
1.351 raeburn 5192: push(@{$brcrum},
5193: {href => '/adm/createuser?action=drop',
5194: text => $brtext,
5195: help => 'Course_Drop_Student'});
5196: if ($env{'form.state'} eq 'done') {
5197: push(@{$brcrum},
5198: {href=>'/adm/createuser?action=drop',
5199: text=>"Result"});
5200: }
5201: $bread_crumbs_component = $brtext;
5202: $args = {bread_crumbs => $brcrum,
5203: bread_crumbs_component => $bread_crumbs_component};
5204: $r->print(&header(undef,$args));
1.213 raeburn 5205: if (!exists($env{'form.state'})) {
1.318 raeburn 5206: &Apache::lonuserutils::print_drop_menu($r,$context,$permission,$crstype);
1.213 raeburn 5207: } elsif ($env{'form.state'} eq 'done') {
5208: &Apache::lonuserutils::update_user_list($r,$context,undef,
5209: $env{'form.action'});
5210: }
1.202 raeburn 5211: } elsif ($env{'form.action'} eq 'dateselect') {
5212: if ($permission->{'cusr'}) {
1.351 raeburn 5213: $r->print(&header(undef,{'no_nav_bar' => 1}).
1.375 raeburn 5214: &Apache::lonuserutils::date_section_selector($context,$permission,
5215: $crstype,$showcredits));
1.202 raeburn 5216: } else {
1.351 raeburn 5217: $r->print(&header(undef,{'no_nav_bar' => 1}).
5218: '<span class="LC_error">'.&mt('You do not have permission to modify dates or sections for users').'</span>');
1.202 raeburn 5219: }
1.237 raeburn 5220: } elsif ($env{'form.action'} eq 'selfenroll') {
1.398 raeburn 5221: if ($permission->{selfenrolladmin}) {
5222: my %currsettings = (
5223: selfenroll_types => $env{'course.'.$cid.'.internal.selfenroll_types'},
5224: selfenroll_registered => $env{'course.'.$cid.'.internal.selfenroll_registered'},
5225: selfenroll_section => $env{'course.'.$cid.'.internal.selfenroll_section'},
5226: selfenroll_notifylist => $env{'course.'.$cid.'.internal.selfenroll_notifylist'},
5227: selfenroll_approval => $env{'course.'.$cid.'.internal.selfenroll_approval'},
5228: selfenroll_limit => $env{'course.'.$cid.'.internal.selfenroll_limit'},
5229: selfenroll_cap => $env{'course.'.$cid.'.internal.selfenroll_cap'},
5230: selfenroll_start_date => $env{'course.'.$cid.'.internal.selfenroll_start_date'},
5231: selfenroll_end_date => $env{'course.'.$cid.'.internal.selfenroll_end_date'},
5232: selfenroll_start_access => $env{'course.'.$cid.'.internal.selfenroll_start_access'},
5233: selfenroll_end_access => $env{'course.'.$cid.'.internal.selfenroll_end_access'},
5234: default_enrollment_start_date => $env{'course.'.$cid.'.default_enrollment_start_date'},
5235: default_enrollment_end_date => $env{'course.'.$cid.'.default_enrollment_end_date'},
1.400 raeburn 5236: uniquecode => $env{'course.'.$cid.'.internal.uniquecode'},
1.398 raeburn 5237: );
5238: push(@{$brcrum},
5239: {href => '/adm/createuser?action=selfenroll',
5240: text => "Configure Self-enrollment",
5241: help => 'Course_Self_Enrollment'});
5242: if (!exists($env{'form.state'})) {
5243: $args = { bread_crumbs => $brcrum,
5244: bread_crumbs_component => 'Configure Self-enrollment'};
5245: $r->print(&header(undef,$args));
5246: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
5247: &print_selfenroll_menu($r,'course',$cid,$cdom,$cnum,\%currsettings);
5248: } elsif ($env{'form.state'} eq 'done') {
5249: push (@{$brcrum},
5250: {href=>'/adm/createuser?action=selfenroll',
5251: text=>"Result"});
5252: $args = { bread_crumbs => $brcrum,
5253: bread_crumbs_component => 'Self-enrollment result'};
5254: $r->print(&header(undef,$args));
5255: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
1.400 raeburn 5256: &update_selfenroll_config($r,$cid,$cdom,$cnum,$context,$crstype,\%currsettings);
1.398 raeburn 5257: }
5258: } else {
5259: $r->print(&header(undef,{'no_nav_bar' => 1}).
5260: '<span class="LC_error">'.&mt('You do not have permission to configure self-enrollment').'</span>');
1.237 raeburn 5261: }
1.277 raeburn 5262: } elsif ($env{'form.action'} eq 'selfenrollqueue') {
1.406.2.6 raeburn 5263: if ($permission->{selfenrolladmin}) {
1.351 raeburn 5264: push(@{$brcrum},
5265: {href => '/adm/createuser?action=selfenrollqueue',
1.406.2.6 raeburn 5266: text => 'Enrollment requests',
1.406.2.14 raeburn 5267: help => 'Course_Approve_Selfenroll'});
1.406.2.6 raeburn 5268: $bread_crumbs_component = 'Enrollment requests';
5269: if ($env{'form.state'} eq 'done') {
5270: push(@{$brcrum},
5271: {href => '/adm/createuser?action=selfenrollqueue',
5272: text => 'Result',
1.406.2.14 raeburn 5273: help => 'Course_Approve_Selfenroll'});
1.406.2.6 raeburn 5274: $bread_crumbs_component = 'Enrollment result';
5275: }
5276: $args = { bread_crumbs => $brcrum,
5277: bread_crumbs_component => $bread_crumbs_component};
5278: $r->print(&header(undef,$args));
5279: my $coursedesc = $env{'course.'.$cid.'.description'};
5280: if (!exists($env{'form.state'})) {
5281: $r->print('<h3>'.&mt('Pending enrollment requests').'</h3>'."\n");
5282: $r->print(&Apache::loncoursequeueadmin::display_queued_requests($context,
5283: $cdom,$cnum));
5284: } elsif ($env{'form.state'} eq 'done') {
5285: $r->print('<h3>'.&mt('Enrollment request processing').'</h3>'."\n");
5286: $r->print(&Apache::loncoursequeueadmin::update_request_queue($context,
5287: $cdom,$cnum,$coursedesc));
5288: }
5289: } else {
5290: $r->print(&header(undef,{'no_nav_bar' => 1}).
5291: '<span class="LC_error">'.&mt('You do not have permission to manage self-enrollment').'</span>');
1.277 raeburn 5292: }
1.239 raeburn 5293: } elsif ($env{'form.action'} eq 'changelogs') {
1.406.2.6 raeburn 5294: if ($permission->{cusr} || $permission->{view}) {
5295: &print_userchangelogs_display($r,$context,$permission,$brcrum);
5296: } else {
5297: $r->print(&header(undef,{'no_nav_bar' => 1}).
5298: '<span class="LC_error">'.&mt('You do not have permission to view change logs').'</span>');
5299: }
1.406.2.10 raeburn 5300: } elsif ($env{'form.action'} eq 'helpdesk') {
1.406.2.20.2. (raeburn 5301:): if (($permission->{'owner'} || $permission->{'co-owner'}) &&
5302:): ($permission->{'cusr'} || $permission->{'view'})) {
1.406.2.10 raeburn 5303: if ($env{'form.state'} eq 'process') {
5304: if ($permission->{'owner'}) {
5305: &update_helpdeskaccess($r,$permission,$brcrum);
5306: } else {
5307: &print_helpdeskaccess_display($r,$permission,$brcrum);
5308: }
5309: } else {
5310: &print_helpdeskaccess_display($r,$permission,$brcrum);
5311: }
5312: } else {
5313: $r->print(&header(undef,{'no_nav_bar' => 1}).
5314: '<span class="LC_error">'.&mt('You do not have permission to view helpdesk access').'</span>');
5315: }
1.190 raeburn 5316: } else {
1.351 raeburn 5317: $bread_crumbs_component = 'User Management';
5318: $args = { bread_crumbs => $brcrum,
5319: bread_crumbs_component => $bread_crumbs_component};
5320: $r->print(&header(undef,$args));
1.318 raeburn 5321: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 5322: }
1.351 raeburn 5323: $r->print(&Apache::loncommon::end_page());
1.190 raeburn 5324: return OK;
5325: }
5326:
5327: sub header {
1.351 raeburn 5328: my ($jscript,$args) = @_;
1.190 raeburn 5329: my $start_page;
1.351 raeburn 5330: if (ref($args) eq 'HASH') {
5331: $start_page=&Apache::loncommon::start_page('User Management',$jscript,$args);
1.190 raeburn 5332: } else {
1.351 raeburn 5333: $start_page=&Apache::loncommon::start_page('User Management',$jscript);
1.190 raeburn 5334: }
5335: return $start_page;
5336: }
1.2 www 5337:
1.191 raeburn 5338: sub add_script {
5339: my ($js) = @_;
1.301 bisitz 5340: return '<script type="text/javascript">'."\n"
5341: .'// <![CDATA['."\n"
5342: .$js."\n"
5343: .'// ]]>'."\n"
5344: .'</script>'."\n";
1.191 raeburn 5345: }
5346:
1.391 raeburn 5347: sub usernamerequest_javascript {
5348: my $js = <<ENDJS;
5349:
5350: function openusernamereqdisplay(dom,uname,queue) {
5351: var url = '/adm/createuser?action=displayuserreq';
5352: url += '&domain='+dom+'&username='+uname+'&queue='+queue;
5353: var title = 'Account_Request_Browser';
5354: var options = 'scrollbars=1,resizable=1,menubar=0';
5355: options += ',width=700,height=600';
5356: var stdeditbrowser = open(url,title,options,'1');
5357: stdeditbrowser.focus();
5358: return;
5359: }
5360:
5361: ENDJS
5362: }
5363:
5364: sub close_popup_form {
5365: my $close= &mt('Close Window');
5366: return << "END";
5367: <p><form name="displayreq" action="" method="post">
5368: <input type="button" name="closeme" value="$close" onclick="javascript:self.close();" />
5369: </form></p>
5370: END
5371: }
5372:
1.202 raeburn 5373: sub verify_user_display {
1.364 raeburn 5374: my ($context) = @_;
1.374 raeburn 5375: my %lt = &Apache::lonlocal::texthash (
5376: course => 'course(s): description, section(s), status',
5377: community => 'community(s): description, section(s), status',
5378: author => 'author',
5379: );
1.364 raeburn 5380: my $photos;
5381: if (($context eq 'course') && $env{'request.course.id'}) {
5382: $photos = $env{'course.'.$env{'request.course.id'}.'.internal.showphoto'};
5383: }
1.202 raeburn 5384: my $output = <<"END";
5385:
1.364 raeburn 5386: function hide_searching() {
5387: if (document.getElementById('searching')) {
5388: document.getElementById('searching').style.display = 'none';
5389: }
5390: return;
5391: }
5392:
1.202 raeburn 5393: function display_update() {
5394: document.studentform.action.value = 'listusers';
5395: document.studentform.phase.value = 'display';
5396: document.studentform.submit();
5397: }
5398:
1.364 raeburn 5399: function updateCols(caller) {
5400: var context = '$context';
5401: var photos = '$photos';
5402: if (caller == 'Status') {
1.374 raeburn 5403: if ((context == 'domain') &&
5404: ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
5405: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community'))) {
1.364 raeburn 5406: document.getElementById('showcolstatus').checked = false;
5407: document.getElementById('showcolstatus').disabled = 'disabled';
5408: document.getElementById('showcolstart').checked = false;
5409: document.getElementById('showcolend').checked = false;
1.374 raeburn 5410: } else {
5411: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
5412: document.getElementById('showcolstatus').checked = true;
5413: document.getElementById('showcolstatus').disabled = '';
5414: document.getElementById('showcolstart').checked = true;
5415: document.getElementById('showcolend').checked = true;
5416: } else {
5417: document.getElementById('showcolstatus').checked = false;
5418: document.getElementById('showcolstatus').disabled = 'disabled';
5419: document.getElementById('showcolstart').checked = false;
5420: document.getElementById('showcolend').checked = false;
5421: }
1.364 raeburn 5422: }
5423: }
5424: if (caller == 'output') {
5425: if (photos == 1) {
5426: if (document.getElementById('showcolphoto')) {
5427: var photoitem = document.getElementById('showcolphoto');
5428: if (document.studentform.output.options[document.studentform.output.selectedIndex].value == 'html') {
5429: photoitem.checked = true;
5430: photoitem.disabled = '';
5431: } else {
5432: photoitem.checked = false;
5433: photoitem.disabled = 'disabled';
5434: }
5435: }
5436: }
5437: }
5438: if (caller == 'showrole') {
1.371 raeburn 5439: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any') ||
5440: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'cr')) {
1.364 raeburn 5441: document.getElementById('showcolrole').checked = true;
5442: document.getElementById('showcolrole').disabled = '';
5443: } else {
5444: document.getElementById('showcolrole').checked = false;
5445: document.getElementById('showcolrole').disabled = 'disabled';
5446: }
1.374 raeburn 5447: if (context == 'domain') {
1.382 raeburn 5448: var quotausageshow = 0;
1.374 raeburn 5449: if ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
5450: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community')) {
5451: document.getElementById('showcolstatus').checked = false;
5452: document.getElementById('showcolstatus').disabled = 'disabled';
5453: document.getElementById('showcolstart').checked = false;
5454: document.getElementById('showcolend').checked = false;
5455: } else {
5456: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
5457: document.getElementById('showcolstatus').checked = true;
5458: document.getElementById('showcolstatus').disabled = '';
5459: document.getElementById('showcolstart').checked = true;
5460: document.getElementById('showcolend').checked = true;
5461: }
5462: }
5463: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'domain') {
5464: document.getElementById('showcolextent').disabled = 'disabled';
5465: document.getElementById('showcolextent').checked = 'false';
5466: document.getElementById('showextent').style.display='none';
5467: document.getElementById('showcoltextextent').innerHTML = '';
1.382 raeburn 5468: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'au') ||
5469: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any')) {
5470: if (document.getElementById('showcolauthorusage')) {
5471: document.getElementById('showcolauthorusage').disabled = '';
5472: }
5473: if (document.getElementById('showcolauthorquota')) {
5474: document.getElementById('showcolauthorquota').disabled = '';
5475: }
5476: quotausageshow = 1;
5477: }
1.374 raeburn 5478: } else {
5479: document.getElementById('showextent').style.display='block';
5480: document.getElementById('showextent').style.textAlign='left';
5481: document.getElementById('showextent').style.textFace='normal';
5482: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'author') {
5483: document.getElementById('showcolextent').disabled = '';
5484: document.getElementById('showcolextent').checked = 'true';
5485: document.getElementById('showcoltextextent').innerHTML="$lt{'author'}";
5486: } else {
5487: document.getElementById('showcolextent').disabled = '';
5488: document.getElementById('showcolextent').checked = 'true';
5489: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community') {
5490: document.getElementById('showcoltextextent').innerHTML="$lt{'community'}";
5491: } else {
5492: document.getElementById('showcoltextextent').innerHTML="$lt{'course'}";
5493: }
5494: }
5495: }
1.382 raeburn 5496: if (quotausageshow == 0) {
5497: if (document.getElementById('showcolauthorusage')) {
5498: document.getElementById('showcolauthorusage').checked = false;
5499: document.getElementById('showcolauthorusage').disabled = 'disabled';
5500: }
5501: if (document.getElementById('showcolauthorquota')) {
5502: document.getElementById('showcolauthorquota').checked = false;
5503: document.getElementById('showcolauthorquota').disabled = 'disabled';
5504: }
5505: }
1.374 raeburn 5506: }
1.364 raeburn 5507: }
5508: return;
5509: }
5510:
1.202 raeburn 5511: END
5512: return $output;
5513:
5514: }
5515:
1.190 raeburn 5516: ###############################################################
5517: ###############################################################
5518: # Menu Phase One
5519: sub print_main_menu {
1.318 raeburn 5520: my ($permission,$context,$crstype) = @_;
5521: my $linkcontext = $context;
5522: my $stuterm = lc(&Apache::lonnet::plaintext('st',$crstype));
5523: if (($context eq 'course') && ($crstype eq 'Community')) {
5524: $linkcontext = lc($crstype);
5525: $stuterm = 'Members';
5526: }
1.208 raeburn 5527: my %links = (
1.298 droeschl 5528: domain => {
5529: upload => 'Upload a File of Users',
5530: singleuser => 'Add/Modify a User',
5531: listusers => 'Manage Users',
5532: },
5533: author => {
5534: upload => 'Upload a File of Co-authors',
5535: singleuser => 'Add/Modify a Co-author',
5536: listusers => 'Manage Co-authors',
5537: },
5538: course => {
5539: upload => 'Upload a File of Course Users',
5540: singleuser => 'Add/Modify a Course User',
1.354 www 5541: listusers => 'List and Modify Multiple Course Users',
1.298 droeschl 5542: },
1.318 raeburn 5543: community => {
5544: upload => 'Upload a File of Community Users',
5545: singleuser => 'Add/Modify a Community User',
1.354 www 5546: listusers => 'List and Modify Multiple Community Users',
1.318 raeburn 5547: },
5548: );
5549: my %linktitles = (
5550: domain => {
5551: singleuser => 'Add a user to the domain, and/or a course or community in the domain.',
5552: listusers => 'Show and manage users in this domain.',
5553: },
5554: author => {
5555: singleuser => 'Add a user with a co- or assistant author role.',
5556: listusers => 'Show and manage co- or assistant authors.',
5557: },
5558: course => {
5559: singleuser => 'Add a user with a certain role to this course.',
5560: listusers => 'Show and manage users in this course.',
5561: },
5562: community => {
5563: singleuser => 'Add a user with a certain role to this community.',
5564: listusers => 'Show and manage users in this community.',
5565: },
1.298 droeschl 5566: );
1.406.2.6 raeburn 5567: if ($linkcontext eq 'domain') {
5568: unless ($permission->{'cusr'}) {
5569: $links{'domain'}{'singleuser'} = 'View a User';
5570: $linktitles{'domain'}{'singleuser'} = 'View information about a user in the domain';
5571: }
5572: } elsif ($linkcontext eq 'course') {
5573: unless ($permission->{'cusr'}) {
5574: $links{'course'}{'singleuser'} = 'View a Course User';
5575: $linktitles{'course'}{'singleuser'} = 'View information about a user in this course';
5576: $links{'course'}{'listusers'} = 'List Course Users';
5577: $linktitles{'course'}{'listusers'} = 'Show information about users in this course';
5578: }
5579: } elsif ($linkcontext eq 'community') {
5580: unless ($permission->{'cusr'}) {
5581: $links{'community'}{'singleuser'} = 'View a Community User';
5582: $linktitles{'community'}{'singleuser'} = 'View information about a user in this community';
5583: $links{'community'}{'listusers'} = 'List Community Users';
5584: $linktitles{'community'}{'listusers'} = 'Show information about users in this community';
5585: }
5586: }
1.298 droeschl 5587: my @menu = ( {categorytitle => 'Single Users',
5588: items =>
5589: [
5590: {
1.318 raeburn 5591: linktext => $links{$linkcontext}{'singleuser'},
1.298 droeschl 5592: icon => 'edit-redo.png',
5593: #help => 'Course_Change_Privileges',
5594: url => '/adm/createuser?action=singleuser',
1.406.2.6 raeburn 5595: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.318 raeburn 5596: linktitle => $linktitles{$linkcontext}{'singleuser'},
1.298 droeschl 5597: },
5598: ]},
5599:
5600: {categorytitle => 'Multiple Users',
5601: items =>
5602: [
5603: {
1.318 raeburn 5604: linktext => $links{$linkcontext}{'upload'},
1.340 wenzelju 5605: icon => 'uplusr.png',
1.298 droeschl 5606: #help => 'Course_Create_Class_List',
5607: url => '/adm/createuser?action=upload',
5608: permission => $permission->{'cusr'},
5609: linktitle => 'Upload a CSV or a text file containing users.',
5610: },
5611: {
1.318 raeburn 5612: linktext => $links{$linkcontext}{'listusers'},
1.340 wenzelju 5613: icon => 'mngcu.png',
1.298 droeschl 5614: #help => 'Course_View_Class_List',
5615: url => '/adm/createuser?action=listusers',
5616: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.318 raeburn 5617: linktitle => $linktitles{$linkcontext}{'listusers'},
1.298 droeschl 5618: },
5619:
5620: ]},
5621:
5622: {categorytitle => 'Administration',
5623: items => [ ]},
5624: );
1.406.2.5 raeburn 5625:
1.265 mielkec 5626: if ($context eq 'domain'){
1.406.2.5 raeburn 5627: push(@{ $menu[0]->{items} }, # Single Users
5628: {
5629: linktext => 'User Access Log',
5630: icon => 'document-properties.png',
1.406.2.8 raeburn 5631: #help => 'Domain_User_Access_Logs',
1.406.2.5 raeburn 5632: url => '/adm/createuser?action=accesslogs',
5633: permission => $permission->{'activity'},
5634: linktitle => 'View user access log.',
5635: }
5636: );
1.298 droeschl 5637:
5638: push(@{ $menu[2]->{items} }, #Category: Administration
5639: {
5640: linktext => 'Custom Roles',
5641: icon => 'emblem-photos.png',
5642: #help => 'Course_Editing_Custom_Roles',
5643: url => '/adm/createuser?action=custom',
5644: permission => $permission->{'custom'},
5645: linktitle => 'Configure a custom role.',
5646: },
1.362 raeburn 5647: {
5648: linktext => 'Authoring Space Requests',
5649: icon => 'selfenrl-queue.png',
5650: #help => 'Domain_Role_Approvals',
5651: url => '/adm/createuser?action=processauthorreq',
5652: permission => $permission->{'cusr'},
5653: linktitle => 'Approve or reject author role requests',
5654: },
1.363 raeburn 5655: {
1.391 raeburn 5656: linktext => 'LON-CAPA Account Requests',
5657: icon => 'list-add.png',
5658: #help => 'Domain_Username_Approvals',
5659: url => '/adm/createuser?action=processusernamereq',
5660: permission => $permission->{'cusr'},
5661: linktitle => 'Approve or reject LON-CAPA account requests',
5662: },
5663: {
1.363 raeburn 5664: linktext => 'Change Log',
5665: icon => 'document-properties.png',
5666: #help => 'Course_User_Logs',
5667: url => '/adm/createuser?action=changelogs',
1.406.2.6 raeburn 5668: permission => ($permission->{'cusr'} || $permission->{'view'}),
1.363 raeburn 5669: linktitle => 'View change log.',
5670: },
1.298 droeschl 5671: );
5672:
1.265 mielkec 5673: }elsif ($context eq 'course'){
1.298 droeschl 5674: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity();
1.318 raeburn 5675:
5676: my %linktext = (
5677: 'Course' => {
5678: single => 'Add/Modify a Student',
5679: drop => 'Drop Students',
5680: groups => 'Course Groups',
5681: },
5682: 'Community' => {
5683: single => 'Add/Modify a Member',
5684: drop => 'Drop Members',
5685: groups => 'Community Groups',
5686: },
5687: );
5688:
5689: my %linktitle = (
5690: 'Course' => {
5691: single => 'Add a user with the role of student to this course',
5692: drop => 'Remove a student from this course.',
5693: groups => 'Manage course groups',
5694: },
5695: 'Community' => {
5696: single => 'Add a user with the role of member to this community',
5697: drop => 'Remove a member from this community.',
5698: groups => 'Manage community groups',
5699: },
5700: );
5701:
1.298 droeschl 5702: push(@{ $menu[0]->{items} }, #Category: Single Users
5703: {
1.318 raeburn 5704: linktext => $linktext{$crstype}{'single'},
1.298 droeschl 5705: #help => 'Course_Add_Student',
5706: icon => 'list-add.png',
5707: url => '/adm/createuser?action=singlestudent',
5708: permission => $permission->{'cusr'},
1.318 raeburn 5709: linktitle => $linktitle{$crstype}{'single'},
1.298 droeschl 5710: },
5711: );
5712:
5713: push(@{ $menu[1]->{items} }, #Category: Multiple Users
5714: {
1.318 raeburn 5715: linktext => $linktext{$crstype}{'drop'},
1.298 droeschl 5716: icon => 'edit-undo.png',
5717: #help => 'Course_Drop_Student',
5718: url => '/adm/createuser?action=drop',
5719: permission => $permission->{'cusr'},
1.318 raeburn 5720: linktitle => $linktitle{$crstype}{'drop'},
1.298 droeschl 5721: },
5722: );
5723: push(@{ $menu[2]->{items} }, #Category: Administration
1.406.2.11 raeburn 5724: {
5725: linktext => 'Helpdesk Access',
5726: icon => 'helpdesk-access.png',
5727: #help => 'Course_Helpdesk_Access',
5728: url => '/adm/createuser?action=helpdesk',
1.406.2.20.2. (raeburn 5729:): permission => (($permission->{'owner'} || $permission->{'co-owner'}) &&
5730:): ($permission->{'view'} || $permission->{'cusr'})),
1.406.2.11 raeburn 5731: linktitle => 'Helpdesk access options',
5732: },
5733: {
1.298 droeschl 5734: linktext => 'Custom Roles',
5735: icon => 'emblem-photos.png',
5736: #help => 'Course_Editing_Custom_Roles',
5737: url => '/adm/createuser?action=custom',
5738: permission => $permission->{'custom'},
5739: linktitle => 'Configure a custom role.',
5740: },
5741: {
1.318 raeburn 5742: linktext => $linktext{$crstype}{'groups'},
1.333 wenzelju 5743: icon => 'grps.png',
1.298 droeschl 5744: #help => 'Course_Manage_Group',
5745: url => '/adm/coursegroups?refpage=cusr',
5746: permission => $permission->{'grp_manage'},
1.318 raeburn 5747: linktitle => $linktitle{$crstype}{'groups'},
1.298 droeschl 5748: },
5749: {
1.328 wenzelju 5750: linktext => 'Change Log',
1.298 droeschl 5751: icon => 'document-properties.png',
5752: #help => 'Course_User_Logs',
5753: url => '/adm/createuser?action=changelogs',
1.406.2.6 raeburn 5754: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.298 droeschl 5755: linktitle => 'View change log.',
5756: },
5757: );
1.277 raeburn 5758: if ($env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'}) {
1.298 droeschl 5759: push(@{ $menu[2]->{items} },
1.398 raeburn 5760: {
1.298 droeschl 5761: linktext => 'Enrollment Requests',
5762: icon => 'selfenrl-queue.png',
5763: #help => 'Course_Approve_Selfenroll',
5764: url => '/adm/createuser?action=selfenrollqueue',
1.398 raeburn 5765: permission => $permission->{'selfenrolladmin'},
1.298 droeschl 5766: linktitle =>'Approve or reject enrollment requests.',
5767: },
5768: );
1.277 raeburn 5769: }
1.298 droeschl 5770:
1.265 mielkec 5771: if (!exists($permission->{'cusr_section'})){
1.320 raeburn 5772: if ($crstype ne 'Community') {
5773: push(@{ $menu[2]->{items} },
5774: {
5775: linktext => 'Automated Enrollment',
5776: icon => 'roles.png',
5777: #help => 'Course_Automated_Enrollment',
5778: permission => (&Apache::lonnet::auto_run($cnum,$cdom)
1.406.2.6 raeburn 5779: && (($permission->{'cusr'}) ||
5780: ($permission->{'view'}))),
1.320 raeburn 5781: url => '/adm/populate',
5782: linktitle => 'Automated enrollment manager.',
5783: }
5784: );
5785: }
5786: push(@{ $menu[2]->{items} },
1.298 droeschl 5787: {
5788: linktext => 'User Self-Enrollment',
1.342 wenzelju 5789: icon => 'self_enroll.png',
1.298 droeschl 5790: #help => 'Course_Self_Enrollment',
5791: url => '/adm/createuser?action=selfenroll',
1.398 raeburn 5792: permission => $permission->{'selfenrolladmin'},
1.317 bisitz 5793: linktitle => 'Configure user self-enrollment.',
1.298 droeschl 5794: },
5795: );
5796: }
1.363 raeburn 5797: } elsif ($context eq 'author') {
1.370 raeburn 5798: push(@{ $menu[2]->{items} }, #Category: Administration
1.363 raeburn 5799: {
5800: linktext => 'Change Log',
5801: icon => 'document-properties.png',
5802: #help => 'Course_User_Logs',
5803: url => '/adm/createuser?action=changelogs',
5804: permission => $permission->{'cusr'},
5805: linktitle => 'View change log.',
5806: },
1.370 raeburn 5807: );
1.363 raeburn 5808: }
5809: return Apache::lonhtmlcommon::generate_menu(@menu);
1.250 raeburn 5810: # { text => 'View Log-in History',
5811: # help => 'Course_User_Logins',
5812: # action => 'logins',
5813: # permission => $permission->{'cusr'},
5814: # });
1.190 raeburn 5815: }
5816:
1.189 albertel 5817: sub restore_prev_selections {
5818: my %saveable_parameters = ('srchby' => 'scalar',
5819: 'srchin' => 'scalar',
5820: 'srchtype' => 'scalar',
5821: );
5822: &Apache::loncommon::store_settings('user','user_picker',
5823: \%saveable_parameters);
5824: &Apache::loncommon::restore_settings('user','user_picker',
5825: \%saveable_parameters);
5826: }
5827:
1.237 raeburn 5828: sub print_selfenroll_menu {
1.406.2.6 raeburn 5829: my ($r,$context,$cid,$cdom,$cnum,$currsettings,$additional,$readonly) = @_;
1.322 raeburn 5830: my $crstype = &Apache::loncommon::course_type();
1.398 raeburn 5831: my $formname = 'selfenroll';
1.237 raeburn 5832: my $nolink = 1;
1.398 raeburn 5833: my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles();
1.237 raeburn 5834: my $groupslist = &Apache::lonuserutils::get_groupslist();
5835: my $setsec_js =
5836: &Apache::lonuserutils::setsections_javascript($formname,$groupslist);
1.249 raeburn 5837: my %alerts = &Apache::lonlocal::texthash(
5838: acto => 'Activation of self-enrollment was selected for the following domain(s)',
5839: butn => 'but no user types have been checked.',
5840: wilf => "Please uncheck 'activate' or check at least one type.",
5841: );
1.406.2.6 raeburn 5842: my $disabled;
5843: if ($readonly) {
5844: $disabled = ' disabled="disabled"';
5845: }
1.405 damieng 5846: &js_escape(\%alerts);
1.249 raeburn 5847: my $selfenroll_js = <<"ENDSCRIPT";
5848: function update_types(caller,num) {
5849: var delidx = getIndexByName('selfenroll_delete');
5850: var actidx = getIndexByName('selfenroll_activate');
5851: if (caller == 'selfenroll_all') {
5852: var selall;
5853: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5854: if (document.$formname.selfenroll_all[i].checked) {
5855: selall = document.$formname.selfenroll_all[i].value;
5856: }
5857: }
5858: if (selall == 1) {
5859: if (delidx != -1) {
5860: if (document.$formname.selfenroll_delete.length) {
5861: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
5862: document.$formname.selfenroll_delete[j].checked = true;
5863: }
5864: } else {
5865: document.$formname.elements[delidx].checked = true;
5866: }
5867: }
5868: if (actidx != -1) {
5869: if (document.$formname.selfenroll_activate.length) {
5870: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5871: document.$formname.selfenroll_activate[j].checked = false;
5872: }
5873: } else {
5874: document.$formname.elements[actidx].checked = false;
5875: }
5876: }
5877: document.$formname.selfenroll_newdom.selectedIndex = 0;
5878: }
5879: }
5880: if (caller == 'selfenroll_activate') {
5881: if (document.$formname.selfenroll_activate.length) {
5882: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5883: if (document.$formname.selfenroll_activate[j].value == num) {
5884: if (document.$formname.selfenroll_activate[j].checked) {
5885: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5886: if (document.$formname.selfenroll_all[i].value == '1') {
5887: document.$formname.selfenroll_all[i].checked = false;
5888: }
5889: if (document.$formname.selfenroll_all[i].value == '0') {
5890: document.$formname.selfenroll_all[i].checked = true;
5891: }
5892: }
5893: }
5894: }
5895: }
5896: } else {
5897: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5898: if (document.$formname.selfenroll_all[i].value == '1') {
5899: document.$formname.selfenroll_all[i].checked = false;
5900: }
5901: if (document.$formname.selfenroll_all[i].value == '0') {
5902: document.$formname.selfenroll_all[i].checked = true;
5903: }
5904: }
5905: }
5906: }
5907: if (caller == 'selfenroll_delete') {
5908: if (document.$formname.selfenroll_delete.length) {
5909: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
5910: if (document.$formname.selfenroll_delete[j].value == num) {
5911: if (document.$formname.selfenroll_delete[j].checked) {
5912: var delindex = getIndexByName('selfenroll_types_'+num);
5913: if (delindex != -1) {
5914: if (document.$formname.elements[delindex].length) {
5915: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
5916: document.$formname.elements[delindex][k].checked = false;
5917: }
5918: } else {
5919: document.$formname.elements[delindex].checked = false;
5920: }
5921: }
5922: }
5923: }
5924: }
5925: } else {
5926: if (document.$formname.selfenroll_delete.checked) {
5927: var delindex = getIndexByName('selfenroll_types_'+num);
5928: if (delindex != -1) {
5929: if (document.$formname.elements[delindex].length) {
5930: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
5931: document.$formname.elements[delindex][k].checked = false;
5932: }
5933: } else {
5934: document.$formname.elements[delindex].checked = false;
5935: }
5936: }
5937: }
5938: }
5939: }
5940: return;
5941: }
5942:
5943: function validate_types(form) {
5944: var needaction = new Array();
5945: var countfail = 0;
5946: var actidx = getIndexByName('selfenroll_activate');
5947: if (actidx != -1) {
5948: if (document.$formname.selfenroll_activate.length) {
5949: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5950: var num = document.$formname.selfenroll_activate[j].value;
5951: if (document.$formname.selfenroll_activate[j].checked) {
5952: countfail = check_types(num,countfail,needaction)
5953: }
5954: }
5955: } else {
5956: if (document.$formname.selfenroll_activate.checked) {
1.398 raeburn 5957: var num = document.$formname.selfenroll_activate.value;
1.249 raeburn 5958: countfail = check_types(num,countfail,needaction)
5959: }
5960: }
5961: }
5962: if (countfail > 0) {
5963: var msg = "$alerts{'acto'}\\n";
5964: var loopend = needaction.length -1;
5965: if (loopend > 0) {
5966: for (var m=0; m<loopend; m++) {
5967: msg += needaction[m]+", ";
5968: }
5969: }
5970: msg += needaction[loopend]+"\\n$alerts{'butn'}\\n$alerts{'wilf'}";
5971: alert(msg);
5972: return;
5973: }
5974: setSections(form);
5975: }
5976:
5977: function check_types(num,countfail,needaction) {
1.406.2.15 raeburn 5978: var boxname = 'selfenroll_types_'+num;
5979: var typeidx = getIndexByName(boxname);
1.249 raeburn 5980: var count = 0;
5981: if (typeidx != -1) {
1.406.2.15 raeburn 5982: if (document.$formname.elements[boxname].length) {
5983: for (var k=0; k<document.$formname.elements[boxname].length; k++) {
5984: if (document.$formname.elements[boxname][k].checked) {
1.249 raeburn 5985: count ++;
5986: }
5987: }
5988: } else {
5989: if (document.$formname.elements[typeidx].checked) {
5990: count ++;
5991: }
5992: }
5993: if (count == 0) {
5994: var domidx = getIndexByName('selfenroll_dom_'+num);
5995: if (domidx != -1) {
5996: var domname = document.$formname.elements[domidx].value;
5997: needaction[countfail] = domname;
5998: countfail ++;
5999: }
6000: }
6001: }
6002: return countfail;
6003: }
6004:
1.398 raeburn 6005: function toggleNotify() {
6006: var selfenrollApproval = 0;
6007: if (document.$formname.selfenroll_approval.length) {
6008: for (var i=0; i<document.$formname.selfenroll_approval.length; i++) {
6009: if (document.$formname.selfenroll_approval[i].checked) {
6010: selfenrollApproval = document.$formname.selfenroll_approval[i].value;
6011: break;
6012: }
6013: }
6014: }
6015: if (document.getElementById('notified')) {
6016: if (selfenrollApproval == 0) {
6017: document.getElementById('notified').style.display='none';
6018: } else {
6019: document.getElementById('notified').style.display='block';
6020: }
6021: }
6022: return;
6023: }
6024:
1.249 raeburn 6025: function getIndexByName(item) {
6026: for (var i=0;i<document.$formname.elements.length;i++) {
6027: if (document.$formname.elements[i].name == item) {
6028: return i;
6029: }
6030: }
6031: return -1;
6032: }
6033: ENDSCRIPT
1.256 raeburn 6034:
1.237 raeburn 6035: my $output = '<script type="text/javascript">'."\n".
1.301 bisitz 6036: '// <![CDATA['."\n".
1.249 raeburn 6037: $setsec_js."\n".$selfenroll_js."\n".
1.301 bisitz 6038: '// ]]>'."\n".
1.237 raeburn 6039: '</script>'."\n".
1.256 raeburn 6040: '<h3>'.$lt->{'selfenroll'}.'</h3>'."\n";
1.400 raeburn 6041:
6042: my $visactions = &cat_visibility();
6043: my ($cathash,%cattype);
6044: my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
6045: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
6046: $cathash = $domconfig{'coursecategories'}{'cats'};
6047: $cattype{'auth'} = $domconfig{'coursecategories'}{'auth'};
6048: $cattype{'unauth'} = $domconfig{'coursecategories'}{'unauth'};
1.406 raeburn 6049: if ($cattype{'auth'} eq '') {
6050: $cattype{'auth'} = 'std';
6051: }
6052: if ($cattype{'unauth'} eq '') {
6053: $cattype{'unauth'} = 'std';
6054: }
1.400 raeburn 6055: } else {
6056: $cathash = {};
6057: $cattype{'auth'} = 'std';
6058: $cattype{'unauth'} = 'std';
6059: }
6060: if (($cattype{'auth'} eq 'none') && ($cattype{'unauth'} eq 'none')) {
6061: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
6062: '<br />'.
6063: '<br />'.$visactions->{'take'}.'<ul>'.
6064: '<li>'.$visactions->{'dc_chgconf'}.'</li>'.
6065: '</ul>');
6066: } elsif (($cattype{'auth'} !~ /^(std|domonly)$/) && ($cattype{'unauth'} !~ /^(std|domonly)$/)) {
6067: if ($currsettings->{'uniquecode'}) {
6068: $r->print('<span class="LC_info">'.$visactions->{'vis'}.'</span>');
6069: } else {
6070: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
6071: '<br />'.
6072: '<br />'.$visactions->{'take'}.'<ul>'.
6073: '<li>'.$visactions->{'dc_setcode'}.'</li>'.
6074: '</ul><br />');
6075: }
6076: } else {
6077: my ($visible,$cansetvis,$vismsgs) = &visible_in_stdcat($cdom,$cnum,\%domconfig);
6078: if (ref($visactions) eq 'HASH') {
6079: if ($visible) {
6080: $output .= '<p class="LC_info">'.$visactions->{'vis'}.'</p>';
6081: } else {
6082: $output .= '<p class="LC_warning">'.$visactions->{'miss'}.'</p>'
6083: .$visactions->{'yous'}.
6084: '<p>'.$visactions->{'gen'}.'<br />'.$visactions->{'coca'};
6085: if (ref($vismsgs) eq 'ARRAY') {
6086: $output .= '<br />'.$visactions->{'make'}.'<ul>';
6087: foreach my $item (@{$vismsgs}) {
6088: $output .= '<li>'.$visactions->{$item}.'</li>';
6089: }
6090: $output .= '</ul>';
1.256 raeburn 6091: }
1.400 raeburn 6092: $output .= '</p>';
1.256 raeburn 6093: }
6094: }
6095: }
1.398 raeburn 6096: my $actionhref = '/adm/createuser';
6097: if ($context eq 'domain') {
6098: $actionhref = '/adm/modifycourse';
6099: }
1.400 raeburn 6100:
6101: my %noedit;
6102: unless ($context eq 'domain') {
6103: %noedit = &get_noedit_fields($cdom,$cnum,$crstype,$row);
6104: }
1.398 raeburn 6105: $output .= '<form name="'.$formname.'" method="post" action="'.$actionhref.'">'."\n".
1.256 raeburn 6106: &Apache::lonhtmlcommon::start_pick_box();
1.237 raeburn 6107: if (ref($row) eq 'ARRAY') {
6108: foreach my $item (@{$row}) {
6109: my $title = $item;
6110: if (ref($lt) eq 'HASH') {
6111: $title = $lt->{$item};
6112: }
1.297 bisitz 6113: $output .= &Apache::lonhtmlcommon::row_title($title);
1.237 raeburn 6114: if ($item eq 'types') {
1.398 raeburn 6115: my $curr_types;
6116: if (ref($currsettings) eq 'HASH') {
6117: $curr_types = $currsettings->{'selfenroll_types'};
6118: }
1.400 raeburn 6119: if ($noedit{$item}) {
6120: if ($curr_types eq '*') {
6121: $output .= &mt('Any user in any domain');
6122: } else {
6123: my @entries = split(/;/,$curr_types);
6124: if (@entries > 0) {
6125: $output .= '<ul>';
6126: foreach my $entry (@entries) {
6127: my ($currdom,$typestr) = split(/:/,$entry);
6128: next if ($typestr eq '');
6129: my $domdesc = &Apache::lonnet::domain($currdom);
6130: my @currinsttypes = split(',',$typestr);
6131: my ($othertitle,$usertypes,$types) =
6132: &Apache::loncommon::sorted_inst_types($currdom);
6133: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
6134: $usertypes->{'any'} = &mt('any user');
6135: if (keys(%{$usertypes}) > 0) {
6136: $usertypes->{'other'} = &mt('other users');
6137: }
6138: my @longinsttypes = map { $usertypes->{$_}; } @currinsttypes;
6139: $output .= '<li>'.$domdesc.':'.join(', ',@longinsttypes).'</li>';
6140: }
6141: }
6142: $output .= '</ul>';
6143: } else {
6144: $output .= &mt('None');
6145: }
6146: }
6147: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6148: next;
6149: }
1.241 raeburn 6150: my $showdomdesc = 1;
6151: my $includeempty = 1;
6152: my $num = 0;
6153: $output .= &Apache::loncommon::start_data_table().
6154: &Apache::loncommon::start_data_table_row()
6155: .'<td colspan="2"><span class="LC_nobreak"><label>'
6156: .&mt('Any user in any domain:')
6157: .' <input type="radio" name="selfenroll_all" value="1" ';
6158: if ($curr_types eq '*') {
6159: $output .= ' checked="checked" ';
6160: }
1.249 raeburn 6161: $output .= 'onchange="javascript:update_types('.
1.406.2.6 raeburn 6162: "'selfenroll_all'".');"'.$disabled.' />'.&mt('Yes').'</label>'.
1.249 raeburn 6163: ' <input type="radio" name="selfenroll_all" value="0" ';
1.241 raeburn 6164: if ($curr_types ne '*') {
6165: $output .= ' checked="checked" ';
6166: }
1.249 raeburn 6167: $output .= ' onchange="javascript:update_types('.
1.406.2.6 raeburn 6168: "'selfenroll_all'".');"'.$disabled.' />'.&mt('No').'</label></td>'.
1.249 raeburn 6169: &Apache::loncommon::end_data_table_row().
6170: &Apache::loncommon::end_data_table().
6171: &mt('Or').'<br />'.
6172: &Apache::loncommon::start_data_table();
1.241 raeburn 6173: my %currdoms;
1.249 raeburn 6174: if ($curr_types eq '') {
1.241 raeburn 6175: $output .= &new_selfenroll_dom_row($cdom,'0');
6176: } elsif ($curr_types ne '*') {
6177: my @entries = split(/;/,$curr_types);
6178: if (@entries > 0) {
6179: foreach my $entry (@entries) {
6180: my ($currdom,$typestr) = split(/:/,$entry);
6181: $currdoms{$currdom} = 1;
6182: my $domdesc = &Apache::lonnet::domain($currdom);
1.249 raeburn 6183: my @currinsttypes = split(',',$typestr);
1.241 raeburn 6184: $output .= &Apache::loncommon::start_data_table_row()
6185: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').'<b>'
6186: .' '.$domdesc.' ('.$currdom.')'
6187: .'</b><input type="hidden" name="selfenroll_dom_'.$num
6188: .'" value="'.$currdom.'" /></span><br />'
6189: .'<span class="LC_nobreak"><label><input type="checkbox" '
1.406.2.6 raeburn 6190: .'name="selfenroll_delete" value="'.$num.'" onchange="javascript:update_types('."'selfenroll_delete','$num'".');"'.$disabled.' />'
1.241 raeburn 6191: .&mt('Delete').'</label></span></td>';
1.249 raeburn 6192: $output .= '<td valign="top"> '.&mt('User types:').'<br />'
1.406.2.6 raeburn 6193: .&selfenroll_inst_types($num,$currdom,\@currinsttypes,$readonly).'</td>'
1.241 raeburn 6194: .&Apache::loncommon::end_data_table_row();
6195: $num ++;
6196: }
6197: }
6198: }
1.249 raeburn 6199: my $add_domtitle = &mt('Users in additional domain:');
1.241 raeburn 6200: if ($curr_types eq '*') {
1.249 raeburn 6201: $add_domtitle = &mt('Users in specific domain:');
1.241 raeburn 6202: } elsif ($curr_types eq '') {
1.249 raeburn 6203: $add_domtitle = &mt('Users in other domain:');
1.241 raeburn 6204: }
6205: $output .= &Apache::loncommon::start_data_table_row()
6206: .'<td colspan="2"><span class="LC_nobreak">'.$add_domtitle.'</span><br />'
6207: .&Apache::loncommon::select_dom_form('','selfenroll_newdom',
1.406.2.6 raeburn 6208: $includeempty,$showdomdesc,'','','',$readonly)
1.241 raeburn 6209: .'<input type="hidden" name="selfenroll_types_total" value="'.$num.'" />'
6210: .'</td>'.&Apache::loncommon::end_data_table_row()
6211: .&Apache::loncommon::end_data_table();
1.237 raeburn 6212: } elsif ($item eq 'registered') {
6213: my ($regon,$regoff);
1.398 raeburn 6214: my $registered;
6215: if (ref($currsettings) eq 'HASH') {
6216: $registered = $currsettings->{'selfenroll_registered'};
6217: }
1.400 raeburn 6218: if ($noedit{$item}) {
6219: if ($registered) {
6220: $output .= &mt('Must be registered in course');
6221: } else {
6222: $output .= &mt('No requirement');
6223: }
6224: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6225: next;
6226: }
1.398 raeburn 6227: if ($registered) {
1.237 raeburn 6228: $regon = ' checked="checked" ';
1.406.2.6 raeburn 6229: $regoff = '';
1.237 raeburn 6230: } else {
1.406.2.6 raeburn 6231: $regon = '';
1.237 raeburn 6232: $regoff = ' checked="checked" ';
6233: }
6234: $output .= '<label>'.
1.406.2.6 raeburn 6235: '<input type="radio" name="selfenroll_registered" value="1"'.$regon.$disabled.' />'.
1.244 bisitz 6236: &mt('Yes').'</label> <label>'.
1.406.2.6 raeburn 6237: '<input type="radio" name="selfenroll_registered" value="0"'.$regoff.$disabled.' />'.
1.244 bisitz 6238: &mt('No').'</label>';
1.237 raeburn 6239: } elsif ($item eq 'enroll_dates') {
1.398 raeburn 6240: my ($starttime,$endtime);
6241: if (ref($currsettings) eq 'HASH') {
6242: $starttime = $currsettings->{'selfenroll_start_date'};
6243: $endtime = $currsettings->{'selfenroll_end_date'};
6244: if ($starttime eq '') {
6245: $starttime = $currsettings->{'default_enrollment_start_date'};
6246: }
6247: if ($endtime eq '') {
6248: $endtime = $currsettings->{'default_enrollment_end_date'};
6249: }
1.237 raeburn 6250: }
1.400 raeburn 6251: if ($noedit{$item}) {
6252: $output .= &mt('From: [_1], to: [_2]',&Apache::lonlocal::locallocaltime($starttime),
6253: &Apache::lonlocal::locallocaltime($endtime));
6254: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6255: next;
6256: }
1.237 raeburn 6257: my $startform =
6258: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_date',$starttime,
1.406.2.6 raeburn 6259: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6260: my $endform =
6261: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_date',$endtime,
1.406.2.6 raeburn 6262: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6263: $output .= &selfenroll_date_forms($startform,$endform);
6264: } elsif ($item eq 'access_dates') {
1.398 raeburn 6265: my ($starttime,$endtime);
6266: if (ref($currsettings) eq 'HASH') {
6267: $starttime = $currsettings->{'selfenroll_start_access'};
6268: $endtime = $currsettings->{'selfenroll_end_access'};
6269: if ($starttime eq '') {
6270: $starttime = $currsettings->{'default_enrollment_start_date'};
6271: }
6272: if ($endtime eq '') {
6273: $endtime = $currsettings->{'default_enrollment_end_date'};
6274: }
1.237 raeburn 6275: }
1.400 raeburn 6276: if ($noedit{$item}) {
6277: $output .= &mt('From: [_1], to: [_2]',&Apache::lonlocal::locallocaltime($starttime),
6278: &Apache::lonlocal::locallocaltime($endtime));
6279: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6280: next;
6281: }
1.237 raeburn 6282: my $startform =
6283: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_access',$starttime,
1.406.2.6 raeburn 6284: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6285: my $endform =
6286: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_access',$endtime,
1.406.2.6 raeburn 6287: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6288: $output .= &selfenroll_date_forms($startform,$endform);
6289: } elsif ($item eq 'section') {
1.398 raeburn 6290: my $currsec;
6291: if (ref($currsettings) eq 'HASH') {
6292: $currsec = $currsettings->{'selfenroll_section'};
6293: }
1.237 raeburn 6294: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
6295: my $newsecval;
6296: if ($currsec ne 'none' && $currsec ne '') {
6297: if (!defined($sections_count{$currsec})) {
6298: $newsecval = $currsec;
6299: }
6300: }
1.400 raeburn 6301: if ($noedit{$item}) {
6302: if ($currsec ne '') {
6303: $output .= $currsec;
6304: } else {
6305: $output .= &mt('No specific section');
6306: }
6307: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6308: next;
6309: }
1.237 raeburn 6310: my $sections_select =
1.406.2.6 raeburn 6311: &Apache::lonuserutils::course_sections(\%sections_count,'st',$currsec,$disabled);
1.237 raeburn 6312: $output .= '<table class="LC_createuser">'."\n".
6313: '<tr class="LC_section_row">'."\n".
6314: '<td align="center">'.&mt('Existing sections')."\n".
6315: '<br />'.$sections_select.'</td><td align="center">'.
6316: &mt('New section').'<br />'."\n".
1.406.2.6 raeburn 6317: '<input type="text" name="newsec" size="15" value="'.$newsecval.'"'.$disabled.' />'."\n".
1.237 raeburn 6318: '<input type="hidden" name="sections" value="" />'."\n".
6319: '</td></tr></table>'."\n";
1.276 raeburn 6320: } elsif ($item eq 'approval') {
1.398 raeburn 6321: my ($currnotified,$currapproval,%appchecked);
6322: my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs();
1.406.2.6 raeburn 6323: if (ref($currsettings) eq 'HASH') {
1.398 raeburn 6324: $currnotified = $currsettings->{'selfenroll_notifylist'};
6325: $currapproval = $currsettings->{'selfenroll_approval'};
6326: }
6327: if ($currapproval !~ /^[012]$/) {
6328: $currapproval = 0;
6329: }
1.400 raeburn 6330: if ($noedit{$item}) {
6331: $output .= $selfdescs{'approval'}{$currapproval}.
6332: '<br />'.&mt('(Set by Domain Coordinator)');
6333: next;
6334: }
1.398 raeburn 6335: $appchecked{$currapproval} = ' checked="checked"';
6336: for my $i (0..2) {
6337: $output .= '<label>'.
6338: '<input type="radio" name="selfenroll_approval" value="'.$i.'"'.
1.406.2.6 raeburn 6339: $appchecked{$i}.' onclick="toggleNotify();"'.$disabled.' />'.
6340: $selfdescs{'approval'}{$i}.'</label>'.(' 'x2);
1.276 raeburn 6341: }
6342: my %advhash = &Apache::lonnet::get_course_adv_roles($cid,1);
6343: my (@ccs,%notified);
1.322 raeburn 6344: my $ccrole = 'cc';
6345: if ($crstype eq 'Community') {
6346: $ccrole = 'co';
6347: }
6348: if ($advhash{$ccrole}) {
6349: @ccs = split(/,/,$advhash{$ccrole});
1.276 raeburn 6350: }
6351: if ($currnotified) {
6352: foreach my $current (split(/,/,$currnotified)) {
6353: $notified{$current} = 1;
6354: if (!grep(/^\Q$current\E$/,@ccs)) {
6355: push(@ccs,$current);
6356: }
6357: }
6358: }
6359: if (@ccs) {
1.398 raeburn 6360: my $style;
6361: unless ($currapproval) {
6362: $style = ' style="display: none;"';
6363: }
6364: $output .= '<br /><div id="notified"'.$style.'>'.
6365: &mt('Personnel to be notified when an enrollment request needs approval, or has been approved:').' '.
6366: &Apache::loncommon::start_data_table().
1.276 raeburn 6367: &Apache::loncommon::start_data_table_row();
6368: my $count = 0;
6369: my $numcols = 4;
6370: foreach my $cc (sort(@ccs)) {
6371: my $notifyon;
6372: my ($ccuname,$ccudom) = split(/:/,$cc);
6373: if ($notified{$cc}) {
6374: $notifyon = ' checked="checked" ';
6375: }
6376: if ($count && !$count%$numcols) {
6377: $output .= &Apache::loncommon::end_data_table_row().
6378: &Apache::loncommon::start_data_table_row()
6379: }
6380: $output .= '<td><span class="LC_nobreak"><label>'.
1.406.2.6 raeburn 6381: '<input type="checkbox" name="selfenroll_notify"'.$notifyon.' value="'.$cc.'"'.$disabled.' />'.
1.276 raeburn 6382: &Apache::loncommon::plainname($ccuname,$ccudom).
6383: '</label></span></td>';
1.343 raeburn 6384: $count ++;
1.276 raeburn 6385: }
6386: my $rem = $count%$numcols;
6387: if ($rem) {
6388: my $emptycols = $numcols - $rem;
6389: for (my $i=0; $i<$emptycols; $i++) {
6390: $output .= '<td> </td>';
6391: }
6392: }
6393: $output .= &Apache::loncommon::end_data_table_row().
1.398 raeburn 6394: &Apache::loncommon::end_data_table().
6395: '</div>';
1.276 raeburn 6396: }
6397: } elsif ($item eq 'limit') {
1.398 raeburn 6398: my ($crslimit,$selflimit,$nolimit,$currlim,$currcap);
6399: if (ref($currsettings) eq 'HASH') {
6400: $currlim = $currsettings->{'selfenroll_limit'};
6401: $currcap = $currsettings->{'selfenroll_cap'};
6402: }
1.400 raeburn 6403: if ($noedit{$item}) {
6404: if (($currlim eq 'allstudents') || ($currlim eq 'selfenrolled')) {
6405: if ($currlim eq 'allstudents') {
6406: $output .= &mt('Limit by total students');
6407: } elsif ($currlim eq 'selfenrolled') {
6408: $output .= &mt('Limit by total self-enrolled students');
6409: }
6410: $output .= ' '.&mt('Maximum: [_1]',$currcap).
6411: '<br />'.&mt('(Set by Domain Coordinator)');
6412: } else {
6413: $output .= &mt('No limit').'<br />'.&mt('(Set by Domain Coordinator)');
6414: }
6415: next;
6416: }
1.276 raeburn 6417: if ($currlim eq 'allstudents') {
6418: $crslimit = ' checked="checked" ';
6419: $selflimit = ' ';
6420: $nolimit = ' ';
6421: } elsif ($currlim eq 'selfenrolled') {
6422: $crslimit = ' ';
6423: $selflimit = ' checked="checked" ';
6424: $nolimit = ' ';
6425: } else {
6426: $crslimit = ' ';
6427: $selflimit = ' ';
1.398 raeburn 6428: $nolimit = ' checked="checked" ';
1.276 raeburn 6429: }
6430: $output .= '<table><tr><td><label>'.
1.406.2.6 raeburn 6431: '<input type="radio" name="selfenroll_limit" value="none"'.$nolimit.$disabled.'/>'.
1.276 raeburn 6432: &mt('No limit').'</label></td><td><label>'.
1.406.2.6 raeburn 6433: '<input type="radio" name="selfenroll_limit" value="allstudents"'.$crslimit.$disabled.'/>'.
1.276 raeburn 6434: &mt('Limit by total students').'</label></td><td><label>'.
1.406.2.6 raeburn 6435: '<input type="radio" name="selfenroll_limit" value="selfenrolled"'.$selflimit.$disabled.'/>'.
1.276 raeburn 6436: &mt('Limit by total self-enrolled students').
6437: '</td></tr><tr>'.
6438: '<td> </td><td colspan="2"><span class="LC_nobreak">'.
6439: (' 'x3).&mt('Maximum number allowed: ').
1.406.2.6 raeburn 6440: '<input type="text" name="selfenroll_cap" size = "5" value="'.$currcap.'"'.$disabled.' /></td></tr></table>';
1.237 raeburn 6441: }
6442: $output .= &Apache::lonhtmlcommon::row_closure(1);
6443: }
6444: }
1.406.2.6 raeburn 6445: $output .= &Apache::lonhtmlcommon::end_pick_box().'<br />';
6446: unless ($readonly) {
6447: $output .= '<input type="button" name="selfenrollconf" value="'
6448: .&mt('Save').'" onclick="validate_types(this.form);" />';
6449: }
6450: $output .= '<input type="hidden" name="action" value="selfenroll" />'
1.406.2.11 raeburn 6451: .'<input type="hidden" name="state" value="done" />'."\n"
6452: .$additional.'</form>';
1.237 raeburn 6453: $r->print($output);
6454: return;
6455: }
6456:
1.400 raeburn 6457: sub get_noedit_fields {
6458: my ($cdom,$cnum,$crstype,$row) = @_;
6459: my %noedit;
6460: if (ref($row) eq 'ARRAY') {
6461: my %settings = &Apache::lonnet::get('environment',['internal.coursecode','internal.textbook',
6462: 'internal.selfenrollmgrdc',
6463: 'internal.selfenrollmgrcc'],$cdom,$cnum);
6464: my $type = &Apache::lonuserutils::get_extended_type($cdom,$cnum,$crstype,\%settings);
6465: my (%specific_managebydc,%specific_managebycc,%default_managebydc);
6466: map { $specific_managebydc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrdc'}));
6467: map { $specific_managebycc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrcc'}));
6468: my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
6469: map { $default_managebydc{$_} = 1; } (split(/,/,$domdefaults{$type.'selfenrolladmdc'}));
6470:
6471: foreach my $item (@{$row}) {
6472: next if ($specific_managebycc{$item});
6473: if (($specific_managebydc{$item}) || ($default_managebydc{$item})) {
6474: $noedit{$item} = 1;
6475: }
6476: }
6477: }
6478: return %noedit;
6479: }
6480:
6481: sub visible_in_stdcat {
6482: my ($cdom,$cnum,$domconf) = @_;
6483: my ($cathash,%settable,@vismsgs,$cansetvis,$visible);
6484: unless (ref($domconf) eq 'HASH') {
6485: return ($visible,$cansetvis,\@vismsgs);
6486: }
6487: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6488: if ($domconf->{'coursecategories'}{'togglecats'} eq 'crs') {
1.256 raeburn 6489: $settable{'togglecats'} = 1;
6490: }
1.400 raeburn 6491: if ($domconf->{'coursecategories'}{'categorize'} eq 'crs') {
1.256 raeburn 6492: $settable{'categorize'} = 1;
6493: }
1.400 raeburn 6494: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6495: }
1.260 raeburn 6496: if ($settable{'togglecats'} && $settable{'categorize'}) {
1.256 raeburn 6497: $cansetvis = &mt('You are able to both assign a course category and choose to exclude this course from the catalog.');
6498: } elsif ($settable{'togglecats'}) {
6499: $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 6500: } elsif ($settable{'categorize'}) {
1.256 raeburn 6501: $cansetvis = &mt('You may assign a course category, but only a Domain Coordinator may choose to exclude this course from the catalog.');
6502: } else {
6503: $cansetvis = &mt('Only a Domain Coordinator may assign a course category or choose to exclude this course from the catalog.');
6504: }
6505:
6506: my %currsettings =
6507: &Apache::lonnet::get('environment',['hidefromcat','categories','internal.coursecode'],
6508: $cdom,$cnum);
1.400 raeburn 6509: $visible = 0;
1.256 raeburn 6510: if ($currsettings{'internal.coursecode'} ne '') {
1.400 raeburn 6511: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6512: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6513: if (ref($cathash) eq 'HASH') {
6514: if ($cathash->{'instcode::0'} eq '') {
6515: push(@vismsgs,'dc_addinst');
6516: } else {
6517: $visible = 1;
6518: }
6519: } else {
6520: $visible = 1;
6521: }
6522: } else {
6523: $visible = 1;
6524: }
6525: } else {
6526: if (ref($cathash) eq 'HASH') {
6527: if ($cathash->{'instcode::0'} ne '') {
6528: push(@vismsgs,'dc_instcode');
6529: }
6530: } else {
6531: push(@vismsgs,'dc_instcode');
6532: }
6533: }
6534: if ($currsettings{'categories'} ne '') {
6535: my $cathash;
1.400 raeburn 6536: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6537: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6538: if (ref($cathash) eq 'HASH') {
6539: if (keys(%{$cathash}) == 0) {
6540: push(@vismsgs,'dc_catalog');
6541: } elsif ((keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} ne '')) {
6542: push(@vismsgs,'dc_categories');
6543: } else {
6544: my @currcategories = split('&',$currsettings{'categories'});
6545: my $matched = 0;
6546: foreach my $cat (@currcategories) {
6547: if ($cathash->{$cat} ne '') {
6548: $visible = 1;
6549: $matched = 1;
6550: last;
6551: }
6552: }
6553: if (!$matched) {
1.260 raeburn 6554: if ($settable{'categorize'}) {
1.256 raeburn 6555: push(@vismsgs,'chgcat');
6556: } else {
6557: push(@vismsgs,'dc_chgcat');
6558: }
6559: }
6560: }
6561: }
6562: }
6563: } else {
6564: if (ref($cathash) eq 'HASH') {
6565: if ((keys(%{$cathash}) > 1) ||
6566: (keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} eq '')) {
1.260 raeburn 6567: if ($settable{'categorize'}) {
1.256 raeburn 6568: push(@vismsgs,'addcat');
6569: } else {
6570: push(@vismsgs,'dc_addcat');
6571: }
6572: }
6573: }
6574: }
6575: if ($currsettings{'hidefromcat'} eq 'yes') {
6576: $visible = 0;
6577: if ($settable{'togglecats'}) {
6578: unshift(@vismsgs,'unhide');
6579: } else {
6580: unshift(@vismsgs,'dc_unhide')
6581: }
6582: }
1.400 raeburn 6583: return ($visible,$cansetvis,\@vismsgs);
6584: }
6585:
6586: sub cat_visibility {
6587: my %visactions = &Apache::lonlocal::texthash(
6588: vis => 'This course/community currently appears in the Course/Community Catalog for this domain.',
6589: 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.',
6590: miss => 'This course/community does not currently appear in the Course/Community Catalog for this domain.',
6591: none => 'Display of a course catalog is disabled for this domain.',
6592: yous => 'You should remedy this if you plan to allow self-enrollment, otherwise students will have difficulty finding this course.',
6593: 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.',
6594: make => 'Make any changes to self-enrollment settings below, click "Save", then take action to include the course in the Catalog:',
6595: take => 'Take the following action to ensure the course appears in the Catalog:',
6596: dc_chgconf => 'Ask a domain coordinator to change the Catalog type for this domain.',
6597: dc_setcode => 'Ask a domain coordinator to assign a six character code to the course',
6598: dc_unhide => 'Ask a domain coordinator to change the "Exclude from course catalog" setting.',
6599: dc_addinst => 'Ask a domain coordinator to enable display the catalog of "Official courses (with institutional codes)".',
6600: dc_instcode => 'Ask a domain coordinator to assign an institutional code (if this is an official course).',
6601: dc_catalog => 'Ask a domain coordinator to enable or create at least one course category in the domain.',
6602: dc_categories => 'Ask a domain coordinator to create a hierarchy of categories and sub categories for courses in the domain.',
6603: 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',
6604: dc_addcat => 'Ask a domain coordinator to assign a category to the course.',
6605: );
6606: $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>"');
6607: $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>"');
6608: $visactions{'addcat'} = &mt('Use [_1]Categorize course[_2] to assign a category to the course.','"<a href="/adm/courseprefs?phase=display&actions=courseinfo">','</a>"');
6609: return \%visactions;
1.256 raeburn 6610: }
6611:
1.241 raeburn 6612: sub new_selfenroll_dom_row {
6613: my ($newdom,$num) = @_;
6614: my $domdesc = &Apache::lonnet::domain($newdom);
6615: my $output;
6616: if ($domdesc ne '') {
6617: $output .= &Apache::loncommon::start_data_table_row()
6618: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').' <b>'.$domdesc
6619: .' ('.$newdom.')</b><input type="hidden" name="selfenroll_dom_'.$num
1.249 raeburn 6620: .'" value="'.$newdom.'" /></span><br />'
6621: .'<span class="LC_nobreak"><label><input type="checkbox" '
6622: .'name="selfenroll_activate" value="'.$num.'" '
6623: .'onchange="javascript:update_types('
6624: ."'selfenroll_activate','$num'".');" />'
6625: .&mt('Activate').'</label></span></td>';
1.241 raeburn 6626: my @currinsttypes;
6627: $output .= '<td>'.&mt('User types:').'<br />'
6628: .&selfenroll_inst_types($num,$newdom,\@currinsttypes).'</td>'
6629: .&Apache::loncommon::end_data_table_row();
6630: }
6631: return $output;
6632: }
6633:
6634: sub selfenroll_inst_types {
1.406.2.6 raeburn 6635: my ($num,$currdom,$currinsttypes,$readonly) = @_;
1.241 raeburn 6636: my $output;
6637: my $numinrow = 4;
6638: my $count = 0;
6639: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($currdom);
1.247 raeburn 6640: my $othervalue = 'any';
1.406.2.6 raeburn 6641: my $disabled;
6642: if ($readonly) {
6643: $disabled = ' disabled="disabled"';
6644: }
1.241 raeburn 6645: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
1.251 raeburn 6646: if (keys(%{$usertypes}) > 0) {
1.247 raeburn 6647: $othervalue = 'other';
6648: }
1.241 raeburn 6649: $output .= '<table><tr>';
6650: foreach my $type (@{$types}) {
6651: if (($count > 0) && ($count%$numinrow == 0)) {
6652: $output .= '</tr><tr>';
6653: }
6654: if (defined($usertypes->{$type})) {
1.257 raeburn 6655: my $esc_type = &escape($type);
1.241 raeburn 6656: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.
1.257 raeburn 6657: $esc_type.'" ';
1.241 raeburn 6658: if (ref($currinsttypes) eq 'ARRAY') {
6659: if (@{$currinsttypes} > 0) {
1.249 raeburn 6660: if (grep(/^any$/,@{$currinsttypes})) {
6661: $output .= 'checked="checked"';
1.257 raeburn 6662: } elsif (grep(/^\Q$esc_type\E$/,@{$currinsttypes})) {
1.241 raeburn 6663: $output .= 'checked="checked"';
6664: }
1.249 raeburn 6665: } else {
6666: $output .= 'checked="checked"';
1.241 raeburn 6667: }
6668: }
1.406.2.6 raeburn 6669: $output .= ' name="selfenroll_types_'.$num.'"'.$disabled.' />'.$usertypes->{$type}.'</label></span></td>';
1.241 raeburn 6670: }
6671: $count ++;
6672: }
6673: if (($count > 0) && ($count%$numinrow == 0)) {
6674: $output .= '</tr><tr>';
6675: }
1.249 raeburn 6676: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.$othervalue.'"';
1.241 raeburn 6677: if (ref($currinsttypes) eq 'ARRAY') {
6678: if (@{$currinsttypes} > 0) {
1.249 raeburn 6679: if (grep(/^any$/,@{$currinsttypes})) {
6680: $output .= ' checked="checked"';
6681: } elsif ($othervalue eq 'other') {
6682: if (grep(/^\Q$othervalue\E$/,@{$currinsttypes})) {
6683: $output .= ' checked="checked"';
6684: }
1.241 raeburn 6685: }
1.249 raeburn 6686: } else {
6687: $output .= ' checked="checked"';
1.241 raeburn 6688: }
1.249 raeburn 6689: } else {
6690: $output .= ' checked="checked"';
1.241 raeburn 6691: }
1.406.2.6 raeburn 6692: $output .= ' name="selfenroll_types_'.$num.'"'.$disabled.' />'.$othertitle.'</label></span></td></tr></table>';
1.241 raeburn 6693: }
6694: return $output;
6695: }
6696:
1.237 raeburn 6697: sub selfenroll_date_forms {
6698: my ($startform,$endform) = @_;
6699: my $output .= &Apache::lonhtmlcommon::start_pick_box()."\n".
1.244 bisitz 6700: &Apache::lonhtmlcommon::row_title(&mt('Start date'),
1.237 raeburn 6701: 'LC_oddrow_value')."\n".
6702: $startform."\n".
6703: &Apache::lonhtmlcommon::row_closure(1).
1.244 bisitz 6704: &Apache::lonhtmlcommon::row_title(&mt('End date'),
1.237 raeburn 6705: 'LC_oddrow_value')."\n".
6706: $endform."\n".
6707: &Apache::lonhtmlcommon::row_closure(1).
6708: &Apache::lonhtmlcommon::end_pick_box();
6709: return $output;
6710: }
6711:
1.239 raeburn 6712: sub print_userchangelogs_display {
1.406.2.5 raeburn 6713: my ($r,$context,$permission,$brcrum) = @_;
1.363 raeburn 6714: my $formname = 'rolelog';
1.406.2.6 raeburn 6715: my ($username,$domain,$crstype,$viewablesec,%roleslog);
1.363 raeburn 6716: if ($context eq 'domain') {
6717: $domain = $env{'request.role.domain'};
6718: %roleslog=&Apache::lonnet::dump_dom('nohist_rolelog',$domain);
6719: } else {
6720: if ($context eq 'course') {
6721: $domain = $env{'course.'.$env{'request.course.id'}.'.domain'};
6722: $username = $env{'course.'.$env{'request.course.id'}.'.num'};
6723: $crstype = &Apache::loncommon::course_type();
1.406.2.6 raeburn 6724: $viewablesec = &Apache::lonuserutils::viewable_section($permission);
1.363 raeburn 6725: my %saveable_parameters = ('show' => 'scalar',);
6726: &Apache::loncommon::store_course_settings('roles_log',
6727: \%saveable_parameters);
6728: &Apache::loncommon::restore_course_settings('roles_log',
6729: \%saveable_parameters);
6730: } elsif ($context eq 'author') {
6731: $domain = $env{'user.domain'};
6732: if ($env{'request.role'} =~ m{^au\./\Q$domain\E/$}) {
6733: $username = $env{'user.name'};
6734: } else {
6735: undef($domain);
6736: }
6737: }
6738: if ($domain ne '' && $username ne '') {
6739: %roleslog=&Apache::lonnet::dump('nohist_rolelog',$domain,$username);
6740: }
6741: }
1.239 raeburn 6742: if ((keys(%roleslog))[0]=~/^error\:/) { undef(%roleslog); }
6743:
1.406.2.5 raeburn 6744: my $helpitem;
6745: if ($context eq 'course') {
6746: $helpitem = 'Course_User_Logs';
1.406.2.14 raeburn 6747: } elsif ($context eq 'domain') {
6748: $helpitem = 'Domain_Role_Logs';
6749: } elsif ($context eq 'author') {
6750: $helpitem = 'Author_User_Logs';
1.406.2.5 raeburn 6751: }
6752: push (@{$brcrum},
6753: {href => '/adm/createuser?action=changelogs',
6754: text => 'User Management Logs',
6755: help => $helpitem});
6756: my $bread_crumbs_component = 'User Changes';
6757: my $args = { bread_crumbs => $brcrum,
6758: bread_crumbs_component => $bread_crumbs_component};
6759:
6760: # Create navigation javascript
6761: my $jsnav = &userlogdisplay_js($formname);
6762:
6763: my $jscript = (<<ENDSCRIPT);
6764: <script type="text/javascript">
6765: // <![CDATA[
6766: $jsnav
6767: // ]]>
6768: </script>
6769: ENDSCRIPT
6770:
6771: # print page header
6772: $r->print(&header($jscript,$args));
6773:
1.239 raeburn 6774: # set defaults
6775: my $now = time();
6776: my $defstart = $now - (7*24*3600); #7 days ago
6777: my %defaults = (
6778: page => '1',
6779: show => '10',
6780: role => 'any',
6781: chgcontext => 'any',
6782: rolelog_start_date => $defstart,
6783: rolelog_end_date => $now,
6784: );
6785: my $more_records = 0;
6786:
6787: # set current
6788: my %curr;
6789: foreach my $item ('show','page','role','chgcontext') {
6790: $curr{$item} = $env{'form.'.$item};
6791: }
6792: my ($startdate,$enddate) =
6793: &Apache::lonuserutils::get_dates_from_form('rolelog_start_date','rolelog_end_date');
6794: $curr{'rolelog_start_date'} = $startdate;
6795: $curr{'rolelog_end_date'} = $enddate;
6796: foreach my $key (keys(%defaults)) {
6797: if ($curr{$key} eq '') {
6798: $curr{$key} = $defaults{$key};
6799: }
6800: }
1.248 raeburn 6801: my (%whodunit,%changed,$version);
6802: ($version) = ($r->dir_config('lonVersion') =~ /^([\d\.]+)\-/);
1.239 raeburn 6803: my ($minshown,$maxshown);
1.255 raeburn 6804: $minshown = 1;
1.239 raeburn 6805: my $count = 0;
1.406.2.5 raeburn 6806: if ($curr{'show'} =~ /\D/) {
6807: $curr{'page'} = 1;
6808: } else {
1.239 raeburn 6809: $maxshown = $curr{'page'} * $curr{'show'};
6810: if ($curr{'page'} > 1) {
6811: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
6812: }
6813: }
1.301 bisitz 6814:
1.327 raeburn 6815: # Form Header
6816: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
1.363 raeburn 6817: &role_display_filter($context,$formname,$domain,$username,\%curr,
6818: $version,$crstype));
1.327 raeburn 6819:
6820: my $showntableheader = 0;
6821:
6822: # Table Header
6823: my $tableheader =
6824: &Apache::loncommon::start_data_table_header_row()
6825: .'<th> </th>'
6826: .'<th>'.&mt('When').'</th>'
6827: .'<th>'.&mt('Who made the change').'</th>'
6828: .'<th>'.&mt('Changed User').'</th>'
1.363 raeburn 6829: .'<th>'.&mt('Role').'</th>';
6830:
6831: if ($context eq 'course') {
6832: $tableheader .= '<th>'.&mt('Section').'</th>';
6833: }
6834: $tableheader .=
6835: '<th>'.&mt('Context').'</th>'
1.327 raeburn 6836: .'<th>'.&mt('Start').'</th>'
6837: .'<th>'.&mt('End').'</th>'
6838: .&Apache::loncommon::end_data_table_header_row();
6839:
6840: # Display user change log data
1.239 raeburn 6841: foreach my $id (sort { $roleslog{$b}{'exe_time'}<=>$roleslog{$a}{'exe_time'} } (keys(%roleslog))) {
6842: next if (($roleslog{$id}{'exe_time'} < $curr{'rolelog_start_date'}) ||
6843: ($roleslog{$id}{'exe_time'} > $curr{'rolelog_end_date'}));
1.406.2.5 raeburn 6844: if ($curr{'show'} !~ /\D/) {
1.239 raeburn 6845: if ($count >= $curr{'page'} * $curr{'show'}) {
6846: $more_records = 1;
6847: last;
6848: }
6849: }
6850: if ($curr{'role'} ne 'any') {
6851: next if ($roleslog{$id}{'logentry'}{'role'} ne $curr{'role'});
6852: }
6853: if ($curr{'chgcontext'} ne 'any') {
6854: if ($curr{'chgcontext'} eq 'selfenroll') {
6855: next if (!$roleslog{$id}{'logentry'}{'selfenroll'});
6856: } else {
6857: next if ($roleslog{$id}{'logentry'}{'context'} ne $curr{'chgcontext'});
6858: }
6859: }
1.406.2.6 raeburn 6860: if (($context eq 'course') && ($viewablesec ne '')) {
6861: next if ($roleslog{$id}{'logentry'}{'section'} ne $viewablesec);
6862: }
1.239 raeburn 6863: $count ++;
6864: next if ($count < $minshown);
1.327 raeburn 6865: unless ($showntableheader) {
1.406.2.5 raeburn 6866: $r->print(&Apache::loncommon::start_data_table()
1.327 raeburn 6867: .$tableheader);
6868: $r->rflush();
6869: $showntableheader = 1;
6870: }
1.239 raeburn 6871: if ($whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} eq '') {
6872: $whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} =
6873: &Apache::loncommon::plainname($roleslog{$id}{'exe_uname'},$roleslog{$id}{'exe_udom'});
6874: }
6875: if ($changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} eq '') {
6876: $changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} =
6877: &Apache::loncommon::plainname($roleslog{$id}{'uname'},$roleslog{$id}{'udom'});
6878: }
6879: my $sec = $roleslog{$id}{'logentry'}{'section'};
6880: if ($sec eq '') {
6881: $sec = &mt('None');
6882: }
6883: my ($rolestart,$roleend);
6884: if ($roleslog{$id}{'delflag'}) {
6885: $rolestart = &mt('deleted');
6886: $roleend = &mt('deleted');
6887: } else {
6888: $rolestart = $roleslog{$id}{'logentry'}{'start'};
6889: $roleend = $roleslog{$id}{'logentry'}{'end'};
6890: if ($rolestart eq '' || $rolestart == 0) {
6891: $rolestart = &mt('No start date');
6892: } else {
6893: $rolestart = &Apache::lonlocal::locallocaltime($rolestart);
6894: }
6895: if ($roleend eq '' || $roleend == 0) {
6896: $roleend = &mt('No end date');
6897: } else {
6898: $roleend = &Apache::lonlocal::locallocaltime($roleend);
6899: }
6900: }
6901: my $chgcontext = $roleslog{$id}{'logentry'}{'context'};
6902: if ($roleslog{$id}{'logentry'}{'selfenroll'}) {
6903: $chgcontext = 'selfenroll';
6904: }
1.363 raeburn 6905: my %lt = &rolechg_contexts($context,$crstype);
1.239 raeburn 6906: if ($chgcontext ne '' && $lt{$chgcontext} ne '') {
6907: $chgcontext = $lt{$chgcontext};
6908: }
1.327 raeburn 6909: $r->print(
1.301 bisitz 6910: &Apache::loncommon::start_data_table_row()
6911: .'<td>'.$count.'</td>'
6912: .'<td>'.&Apache::lonlocal::locallocaltime($roleslog{$id}{'exe_time'}).'</td>'
6913: .'<td>'.$whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}}.'</td>'
6914: .'<td>'.$changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}}.'</td>'
1.363 raeburn 6915: .'<td>'.&Apache::lonnet::plaintext($roleslog{$id}{'logentry'}{'role'},$crstype).'</td>');
6916: if ($context eq 'course') {
6917: $r->print('<td>'.$sec.'</td>');
6918: }
6919: $r->print(
6920: '<td>'.$chgcontext.'</td>'
1.301 bisitz 6921: .'<td>'.$rolestart.'</td>'
6922: .'<td>'.$roleend.'</td>'
1.327 raeburn 6923: .&Apache::loncommon::end_data_table_row()."\n");
1.301 bisitz 6924: }
6925:
1.327 raeburn 6926: if ($showntableheader) { # Table footer, if content displayed above
1.406.2.5 raeburn 6927: $r->print(&Apache::loncommon::end_data_table().
6928: &userlogdisplay_navlinks(\%curr,$more_records));
1.327 raeburn 6929: } else { # No content displayed above
1.301 bisitz 6930: $r->print('<p class="LC_info">'
6931: .&mt('There are no records to display.')
6932: .'</p>'
6933: );
1.239 raeburn 6934: }
1.301 bisitz 6935:
1.327 raeburn 6936: # Form Footer
6937: $r->print(
6938: '<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
6939: .'<input type="hidden" name="action" value="changelogs" />'
6940: .'</form>');
6941: return;
6942: }
1.301 bisitz 6943:
1.406.2.5 raeburn 6944: sub print_useraccesslogs_display {
6945: my ($r,$uname,$udom,$permission,$brcrum) = @_;
6946: my $formname = 'accesslog';
6947: my $form = 'document.accesslog';
6948:
6949: # set breadcrumbs
1.406.2.7 raeburn 6950: my %breadcrumb_text = &singleuser_breadcrumb('','domain',$udom);
1.406.2.12 raeburn 6951: my $prevphasestr;
6952: if ($env{'form.popup'}) {
6953: $brcrum = [];
6954: } else {
6955: push (@{$brcrum},
6956: {href => "javascript:backPage($form)",
6957: text => $breadcrumb_text{'search'}});
6958: my @prevphases;
6959: if ($env{'form.prevphases'}) {
6960: @prevphases = split(/,/,$env{'form.prevphases'});
6961: $prevphasestr = $env{'form.prevphases'};
6962: }
6963: if (($env{'form.phase'} eq 'userpicked') || (grep(/^userpicked$/,@prevphases))) {
6964: push(@{$brcrum},
6965: {href => "javascript:backPage($form,'get_user_info','select')",
6966: text => $breadcrumb_text{'userpicked'}});
6967: if ($env{'form.phase'} eq 'userpicked') {
6968: $prevphasestr = 'userpicked';
6969: }
1.406.2.5 raeburn 6970: }
6971: }
6972: push(@{$brcrum},
6973: {href => '/adm/createuser?action=accesslogs',
6974: text => 'User access logs',
1.406.2.8 raeburn 6975: help => 'Domain_User_Access_Logs'});
1.406.2.5 raeburn 6976: my $bread_crumbs_component = 'User Access Logs';
6977: my $args = { bread_crumbs => $brcrum,
6978: bread_crumbs_component => 'User Management'};
1.406.2.8 raeburn 6979: if ($env{'form.popup'}) {
6980: $args->{'no_nav_bar'} = 1;
1.406.2.12 raeburn 6981: $args->{'bread_crumbs_nomenu'} = 1;
1.406.2.8 raeburn 6982: }
1.406.2.5 raeburn 6983:
6984: # set javascript
6985: my ($jsback,$elements) = &crumb_utilities();
6986: my $jsnav = &userlogdisplay_js($formname);
6987:
6988: my $jscript = (<<ENDSCRIPT);
1.239 raeburn 6989: <script type="text/javascript">
1.301 bisitz 6990: // <![CDATA[
1.406.2.5 raeburn 6991:
6992: $jsback
6993: $jsnav
6994:
6995: // ]]>
6996: </script>
6997:
6998: ENDSCRIPT
6999:
7000: # print page header
7001: $r->print(&header($jscript,$args));
7002:
7003: # early out unless log data can be displayed.
7004: unless ($permission->{'activity'}) {
7005: $r->print('<p class="LC_warning">'
7006: .&mt('You do not have rights to display user access logs.')
1.406.2.12 raeburn 7007: .'</p>');
7008: if ($env{'form.popup'}) {
7009: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
7010: } else {
7011: $r->print(&earlyout_accesslog_form($formname,$prevphasestr,$udom));
7012: }
1.406.2.5 raeburn 7013: return;
7014: }
7015:
7016: unless ($udom eq $env{'request.role.domain'}) {
7017: $r->print('<p class="LC_warning">'
7018: .&mt("User's domain must match role's domain")
7019: .'</p>'
7020: .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
7021: return;
7022: }
7023:
7024: if (($uname eq '') || ($udom eq '')) {
7025: $r->print('<p class="LC_warning">'
7026: .&mt('Invalid username or domain')
7027: .'</p>'
7028: .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
7029: return;
7030: }
7031:
1.406.2.13 raeburn 7032: if (&Apache::lonnet::privileged($uname,$udom,
7033: [$env{'request.role.domain'}],['dc','su'])) {
7034: unless (&Apache::lonnet::privileged($env{'user.name'},$env{'user.domain'},
7035: [$env{'request.role.domain'}],['dc','su'])) {
7036: $r->print('<p class="LC_warning">'
7037: .&mt('You need to be a privileged user to display user access logs for [_1]',
7038: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),
7039: $uname,$udom))
7040: .'</p>');
7041: if ($env{'form.popup'}) {
7042: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
7043: } else {
7044: $r->print(&earlyout_accesslog_form($formname,$prevphasestr,$udom));
7045: }
7046: return;
7047: }
7048: }
7049:
1.406.2.5 raeburn 7050: # set defaults
7051: my $now = time();
7052: my $defstart = $now - (7*24*3600);
7053: my %defaults = (
7054: page => '1',
7055: show => '10',
7056: activity => 'any',
7057: accesslog_start_date => $defstart,
7058: accesslog_end_date => $now,
7059: );
7060: my $more_records = 0;
7061:
7062: # set current
7063: my %curr;
7064: foreach my $item ('show','page','activity') {
7065: $curr{$item} = $env{'form.'.$item};
7066: }
7067: my ($startdate,$enddate) =
7068: &Apache::lonuserutils::get_dates_from_form('accesslog_start_date','accesslog_end_date');
7069: $curr{'accesslog_start_date'} = $startdate;
7070: $curr{'accesslog_end_date'} = $enddate;
7071: foreach my $key (keys(%defaults)) {
7072: if ($curr{$key} eq '') {
7073: $curr{$key} = $defaults{$key};
7074: }
7075: }
7076: my ($minshown,$maxshown);
7077: $minshown = 1;
7078: my $count = 0;
7079: if ($curr{'show'} =~ /\D/) {
7080: $curr{'page'} = 1;
7081: } else {
7082: $maxshown = $curr{'page'} * $curr{'show'};
7083: if ($curr{'page'} > 1) {
7084: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
7085: }
7086: }
7087:
7088: # form header
7089: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
7090: &activity_display_filter($formname,\%curr));
7091:
7092: my $showntableheader = 0;
7093: my ($nav_script,$nav_links);
7094:
7095: # table header
1.406.2.18 raeburn 7096: my $heading = '<h3>'.
1.406.2.12 raeburn 7097: &mt('User access logs for: [_1]',
1.406.2.18 raeburn 7098: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom)).'</h3>';
7099: my $tableheader = $heading
1.406.2.12 raeburn 7100: .&Apache::loncommon::start_data_table_header_row()
1.406.2.5 raeburn 7101: .'<th> </th>'
7102: .'<th>'.&mt('When').'</th>'
7103: .'<th>'.&mt('HostID').'</th>'
7104: .'<th>'.&mt('Event').'</th>'
7105: .'<th>'.&mt('Other data').'</th>'
7106: .&Apache::loncommon::end_data_table_header_row();
7107:
7108: my %filters=(
7109: start => $curr{'accesslog_start_date'},
7110: end => $curr{'accesslog_end_date'},
7111: action => $curr{'activity'},
7112: );
7113:
7114: my $reply = &Apache::lonnet::userlog_query($uname,$udom,%filters);
7115: unless ( ($reply =~/^timeout/) || ($reply =~/^error/) ) {
7116: my (%courses,%missing);
7117: my @results = split(/\&/,$reply);
7118: foreach my $item (reverse(@results)) {
7119: my ($timestamp,$host,$event) = split(/:/,$item);
7120: next unless ($event =~ /^(Log|Role)/);
7121: if ($curr{'show'} !~ /\D/) {
7122: if ($count >= $curr{'page'} * $curr{'show'}) {
7123: $more_records = 1;
7124: last;
7125: }
7126: }
7127: $count ++;
7128: next if ($count < $minshown);
7129: unless ($showntableheader) {
7130: $r->print($nav_script
7131: .&Apache::loncommon::start_data_table()
7132: .$tableheader);
7133: $r->rflush();
7134: $showntableheader = 1;
7135: }
1.406.2.6 raeburn 7136: my ($shown,$extra);
1.406.2.13 raeburn 7137: my ($event,$data) = split(/\s+/,&unescape($event),2);
1.406.2.5 raeburn 7138: if ($event eq 'Role') {
7139: my ($rolecode,$extent) = split(/\./,$data,2);
7140: next if ($extent eq '');
7141: my ($crstype,$desc,$info);
1.406.2.6 raeburn 7142: if ($extent =~ m{^/($match_domain)/($match_courseid)(?:/(\w+)|)$}) {
7143: my ($cdom,$cnum,$sec) = ($1,$2,$3);
1.406.2.5 raeburn 7144: my $cid = $cdom.'_'.$cnum;
7145: if (exists($courses{$cid})) {
7146: $crstype = $courses{$cid}{'type'};
7147: $desc = $courses{$cid}{'description'};
7148: } elsif ($missing{$cid}) {
7149: $crstype = 'Course';
7150: $desc = 'Course/Community';
7151: } else {
7152: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',$cnum,undef,undef,'.');
7153: if (ref($crsinfo{$cdom.'_'.$cnum}) eq 'HASH') {
7154: $courses{$cid} = $crsinfo{$cid};
7155: $crstype = $crsinfo{$cid}{'type'};
7156: $desc = $crsinfo{$cid}{'description'};
7157: } else {
7158: $missing{$cid} = 1;
7159: }
7160: }
7161: $extra = &mt($crstype).': <a href="/public/'.$cdom.'/'.$cnum.'/syllabus">'.$desc.'</a>';
1.406.2.6 raeburn 7162: if ($sec ne '') {
7163: $extra .= ' ('.&mt('Section: [_1]',$sec).')';
7164: }
1.406.2.5 raeburn 7165: } elsif ($extent =~ m{^/($match_domain)/($match_username|$)}) {
7166: my ($dom,$name) = ($1,$2);
7167: if ($rolecode eq 'au') {
7168: $extra = '';
7169: } elsif ($rolecode =~ /^(ca|aa)$/) {
7170: $extra = &mt('Authoring Space: [_1]',$name.':'.$dom);
7171: } elsif ($rolecode =~ /^(li|dg|dh|dc|sc)$/) {
7172: $extra = &mt('Domain: [_1]',$dom);
7173: }
7174: }
7175: my $rolename;
7176: if ($rolecode =~ m{^cr/($match_domain)/($match_username)/(\w+)}) {
7177: my $role = $3;
7178: my $owner = "($2:$1)";
7179: if ($2 eq $1.'-domainconfig') {
7180: $owner = '(ad hoc)';
7181: }
7182: $rolename = &mt('Custom role: [_1]',$role.' '.$owner);
7183: } else {
7184: $rolename = &Apache::lonnet::plaintext($rolecode,$crstype);
7185: }
7186: $shown = &mt('Role selection: [_1]',$rolename);
7187: } else {
7188: $shown = &mt($event);
1.406.2.13 raeburn 7189: if ($data =~ /^webdav/) {
7190: my ($path,$clientip) = split(/\s+/,$data,2);
7191: $path =~ s/^webdav//;
7192: if ($clientip ne '') {
7193: $extra = &mt('Client IP address: [_1]',$clientip);
7194: }
7195: if ($path ne '') {
7196: $shown .= ' '.&mt('(WebDAV access to [_1])',$path);
7197: }
7198: } elsif ($data ne '') {
7199: $extra = &mt('Client IP address: [_1]',$data);
1.406.2.5 raeburn 7200: }
7201: }
7202: $r->print(
7203: &Apache::loncommon::start_data_table_row()
7204: .'<td>'.$count.'</td>'
7205: .'<td>'.&Apache::lonlocal::locallocaltime($timestamp).'</td>'
7206: .'<td>'.$host.'</td>'
7207: .'<td>'.$shown.'</td>'
7208: .'<td>'.$extra.'</td>'
7209: .&Apache::loncommon::end_data_table_row()."\n");
7210: }
7211: }
7212:
7213: if ($showntableheader) { # Table footer, if content displayed above
7214: $r->print(&Apache::loncommon::end_data_table().
7215: &userlogdisplay_navlinks(\%curr,$more_records));
7216: } else { # No content displayed above
1.406.2.18 raeburn 7217: $r->print($heading.'<p class="LC_info">'
1.406.2.5 raeburn 7218: .&mt('There are no records to display.')
7219: .'</p>');
7220: }
7221:
1.406.2.8 raeburn 7222: if ($env{'form.popup'} == 1) {
7223: $r->print('<input type="hidden" name="popup" value="1" />'."\n");
7224: }
7225:
1.406.2.5 raeburn 7226: # Form Footer
7227: $r->print(
7228: '<input type="hidden" name="currstate" value="" />'
7229: .'<input type="hidden" name="accessuname" value="'.$uname.'" />'
7230: .'<input type="hidden" name="accessudom" value="'.$udom.'" />'
7231: .'<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
7232: .'<input type="hidden" name="prevphases" value="'.$prevphasestr.'" />'
7233: .'<input type="hidden" name="phase" value="activity" />'
7234: .'<input type="hidden" name="action" value="accesslogs" />'
7235: .'<input type="hidden" name="srchdomain" value="'.$udom.'" />'
7236: .'<input type="hidden" name="srchby" value="'.$env{'form.srchby'}.'" />'
7237: .'<input type="hidden" name="srchtype" value="'.$env{'form.srchtype'}.'" />'
7238: .'<input type="hidden" name="srchterm" value="'.&HTML::Entities::encode($env{'form.srchterm'},'<>"&').'" />'
7239: .'<input type="hidden" name="srchin" value="'.$env{'form.srchin'}.'" />'
7240: .'</form>');
7241: return;
7242: }
7243:
7244: sub earlyout_accesslog_form {
7245: my ($formname,$prevphasestr,$udom) = @_;
7246: my $srchterm = &HTML::Entities::encode($env{'form.srchterm'},'<>"&');
7247: return <<"END";
7248: <form action="/adm/createuser" method="post" name="$formname">
7249: <input type="hidden" name="currstate" value="" />
7250: <input type="hidden" name="prevphases" value="$prevphasestr" />
7251: <input type="hidden" name="phase" value="activity" />
7252: <input type="hidden" name="action" value="accesslogs" />
7253: <input type="hidden" name="srchdomain" value="$udom" />
7254: <input type="hidden" name="srchby" value="$env{'form.srchby'}" />
7255: <input type="hidden" name="srchtype" value="$env{'form.srchtype'}" />
7256: <input type="hidden" name="srchterm" value="$srchterm" />
7257: <input type="hidden" name="srchin" value="$env{'form.srchin'}" />
7258: </form>
7259: END
7260: }
7261:
7262: sub activity_display_filter {
7263: my ($formname,$curr) = @_;
7264: my $nolink = 1;
7265: my $output = '<table><tr><td valign="top">'.
7266: '<span class="LC_nobreak"><b>'.&mt('Actions/page:').'</b></span><br />'.
7267: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
7268: (&mt('all'),5,10,20,50,100,1000,10000)).
7269: '</td><td> </td>';
7270: my $startform =
7271: &Apache::lonhtmlcommon::date_setter($formname,'accesslog_start_date',
7272: $curr->{'accesslog_start_date'},undef,
7273: undef,undef,undef,undef,undef,undef,$nolink);
7274: my $endform =
7275: &Apache::lonhtmlcommon::date_setter($formname,'accesslog_end_date',
7276: $curr->{'accesslog_end_date'},undef,
7277: undef,undef,undef,undef,undef,undef,$nolink);
7278: my %lt = &Apache::lonlocal::texthash (
7279: activity => 'Activity',
7280: Role => 'Role selection',
7281: log => 'Log-in or Logout',
7282: );
7283: $output .= '<td valign="top"><b>'.&mt('Window during which actions occurred:').'</b><br />'.
7284: '<table><tr><td>'.&mt('After:').
7285: '</td><td>'.$startform.'</td></tr>'.
7286: '<tr><td>'.&mt('Before:').'</td>'.
7287: '<td>'.$endform.'</td></tr></table>'.
7288: '</td>'.
7289: '<td> </td>'.
7290: '<td valign="top"><b>'.&mt('Activities').'</b><br />'.
7291: '<select name="activity"><option value="any"';
7292: if ($curr->{'activity'} eq 'any') {
7293: $output .= ' selected="selected"';
7294: }
7295: $output .= '>'.&mt('Any').'</option>'."\n";
7296: foreach my $activity ('Role','log') {
7297: my $selstr = '';
7298: if ($activity eq $curr->{'activity'}) {
7299: $selstr = ' selected="selected"';
7300: }
7301: $output .= '<option value="'.$activity.'"'.$selstr.'>'.$lt{$activity}.'</option>';
7302: }
7303: $output .= '</select></td>'.
7304: '</tr></table>';
7305: # Update Display button
7306: $output .= '<p>'
7307: .'<input type="submit" value="'.&mt('Update Display').'" />'
1.406.2.12 raeburn 7308: .'</p><hr />';
1.406.2.5 raeburn 7309: return $output;
7310: }
7311:
7312: sub userlogdisplay_js {
7313: my ($formname) = @_;
7314: return <<"ENDSCRIPT";
7315:
1.239 raeburn 7316: function chgPage(caller) {
7317: if (caller == 'previous') {
7318: document.$formname.page.value --;
7319: }
7320: if (caller == 'next') {
7321: document.$formname.page.value ++;
7322: }
1.327 raeburn 7323: document.$formname.submit();
1.239 raeburn 7324: return;
7325: }
7326: ENDSCRIPT
1.406.2.5 raeburn 7327: }
7328:
7329: sub userlogdisplay_navlinks {
7330: my ($curr,$more_records) = @_;
7331: return unless(ref($curr) eq 'HASH');
7332: # Navigation Buttons
7333: my $nav_links = '<p>';
7334: if (($curr->{'page'} > 1) || ($more_records)) {
7335: if (($curr->{'page'} > 1) && ($curr->{'show'} !~ /\D/)) {
7336: $nav_links .= '<input type="button"'
7337: .' onclick="javascript:chgPage('."'previous'".');"'
7338: .' value="'.&mt('Previous [_1] changes',$curr->{'show'})
7339: .'" /> ';
7340: }
7341: if ($more_records) {
7342: $nav_links .= '<input type="button"'
7343: .' onclick="javascript:chgPage('."'next'".');"'
7344: .' value="'.&mt('Next [_1] changes',$curr->{'show'})
7345: .'" />';
1.301 bisitz 7346: }
7347: }
1.406.2.5 raeburn 7348: $nav_links .= '</p>';
7349: return $nav_links;
1.239 raeburn 7350: }
7351:
7352: sub role_display_filter {
1.363 raeburn 7353: my ($context,$formname,$cdom,$cnum,$curr,$version,$crstype) = @_;
7354: my $lctype;
7355: if ($context eq 'course') {
7356: $lctype = lc($crstype);
7357: }
1.239 raeburn 7358: my $nolink = 1;
7359: my $output = '<table><tr><td valign="top">'.
1.301 bisitz 7360: '<span class="LC_nobreak"><b>'.&mt('Changes/page:').'</b></span><br />'.
1.239 raeburn 7361: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
7362: (&mt('all'),5,10,20,50,100,1000,10000)).
7363: '</td><td> </td>';
7364: my $startform =
7365: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_start_date',
7366: $curr->{'rolelog_start_date'},undef,
7367: undef,undef,undef,undef,undef,undef,$nolink);
7368: my $endform =
7369: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_end_date',
7370: $curr->{'rolelog_end_date'},undef,
7371: undef,undef,undef,undef,undef,undef,$nolink);
1.363 raeburn 7372: my %lt = &rolechg_contexts($context,$crstype);
1.301 bisitz 7373: $output .= '<td valign="top"><b>'.&mt('Window during which changes occurred:').'</b><br />'.
7374: '<table><tr><td>'.&mt('After:').
7375: '</td><td>'.$startform.'</td></tr>'.
7376: '<tr><td>'.&mt('Before:').'</td>'.
7377: '<td>'.$endform.'</td></tr></table>'.
7378: '</td>'.
7379: '<td> </td>'.
1.239 raeburn 7380: '<td valign="top"><b>'.&mt('Role:').'</b><br />'.
7381: '<select name="role"><option value="any"';
7382: if ($curr->{'role'} eq 'any') {
7383: $output .= ' selected="selected"';
7384: }
7385: $output .= '>'.&mt('Any').'</option>'."\n";
1.363 raeburn 7386: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
1.239 raeburn 7387: foreach my $role (@roles) {
7388: my $plrole;
7389: if ($role eq 'cr') {
7390: $plrole = &mt('Custom Role');
7391: } else {
1.318 raeburn 7392: $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.239 raeburn 7393: }
7394: my $selstr = '';
7395: if ($role eq $curr->{'role'}) {
7396: $selstr = ' selected="selected"';
7397: }
7398: $output .= ' <option value="'.$role.'"'.$selstr.'>'.$plrole.'</option>';
7399: }
1.301 bisitz 7400: $output .= '</select></td>'.
7401: '<td> </td>'.
7402: '<td valign="top"><b>'.
1.239 raeburn 7403: &mt('Context:').'</b><br /><select name="chgcontext">';
1.363 raeburn 7404: my @posscontexts;
7405: if ($context eq 'course') {
1.406.2.20 raeburn 7406: @posscontexts = ('any','automated','updatenow','createcourse','course','domain','selfenroll','requestcourses','chgtype');
1.363 raeburn 7407: } elsif ($context eq 'domain') {
7408: @posscontexts = ('any','domain','requestauthor','domconfig','server');
7409: } else {
7410: @posscontexts = ('any','author','domain');
1.406.2.20 raeburn 7411: }
1.363 raeburn 7412: foreach my $chgtype (@posscontexts) {
1.239 raeburn 7413: my $selstr = '';
7414: if ($curr->{'chgcontext'} eq $chgtype) {
1.301 bisitz 7415: $selstr = ' selected="selected"';
1.239 raeburn 7416: }
1.363 raeburn 7417: if ($context eq 'course') {
1.376 raeburn 7418: if (($chgtype eq 'automated') || ($chgtype eq 'updatenow')) {
1.363 raeburn 7419: next if (!&Apache::lonnet::auto_run($cnum,$cdom));
7420: }
1.239 raeburn 7421: }
7422: $output .= '<option value="'.$chgtype.'"'.$selstr.'>'.$lt{$chgtype}.'</option>'."\n";
1.248 raeburn 7423: }
1.303 bisitz 7424: $output .= '</select></td>'
7425: .'</tr></table>';
7426:
7427: # Update Display button
7428: $output .= '<p>'
7429: .'<input type="submit" value="'.&mt('Update Display').'" />'
7430: .'</p>';
7431:
7432: # Server version info
1.363 raeburn 7433: my $needsrev = '2.11.0';
7434: if ($context eq 'course') {
7435: $needsrev = '2.7.0';
7436: }
7437:
1.303 bisitz 7438: $output .= '<p class="LC_info">'
7439: .&mt('Only changes made from servers running LON-CAPA [_1] or later are displayed.'
1.363 raeburn 7440: ,$needsrev);
1.248 raeburn 7441: if ($version) {
1.303 bisitz 7442: $output .= ' '.&mt('This LON-CAPA server is version [_1]',$version);
7443: }
7444: $output .= '</p><hr />';
1.239 raeburn 7445: return $output;
7446: }
7447:
7448: sub rolechg_contexts {
1.363 raeburn 7449: my ($context,$crstype) = @_;
7450: my %lt;
7451: if ($context eq 'course') {
7452: %lt = &Apache::lonlocal::texthash (
1.239 raeburn 7453: any => 'Any',
1.376 raeburn 7454: automated => 'Automated Enrollment',
1.406.2.20 raeburn 7455: chgtype => 'Enrollment Type/Lock Change',
1.239 raeburn 7456: updatenow => 'Roster Update',
7457: createcourse => 'Course Creation',
7458: course => 'User Management in course',
7459: domain => 'User Management in domain',
1.313 raeburn 7460: selfenroll => 'Self-enrolled',
1.318 raeburn 7461: requestcourses => 'Course Request',
1.239 raeburn 7462: );
1.363 raeburn 7463: if ($crstype eq 'Community') {
7464: $lt{'createcourse'} = &mt('Community Creation');
7465: $lt{'course'} = &mt('User Management in community');
7466: $lt{'requestcourses'} = &mt('Community Request');
7467: }
7468: } elsif ($context eq 'domain') {
7469: %lt = &Apache::lonlocal::texthash (
7470: any => 'Any',
7471: domain => 'User Management in domain',
7472: requestauthor => 'Authoring Request',
7473: server => 'Command line script (DC role)',
7474: domconfig => 'Self-enrolled',
7475: );
7476: } else {
7477: %lt = &Apache::lonlocal::texthash (
7478: any => 'Any',
7479: domain => 'User Management in domain',
7480: author => 'User Management by author',
7481: );
7482: }
1.239 raeburn 7483: return %lt;
7484: }
7485:
1.406.2.10 raeburn 7486: sub print_helpdeskaccess_display {
7487: my ($r,$permission,$brcrum) = @_;
7488: my $formname = 'helpdeskaccess';
7489: my $helpitem = 'Course_Helpdesk_Access';
7490: push (@{$brcrum},
7491: {href => '/adm/createuser?action=helpdesk',
7492: text => 'Helpdesk Access',
7493: help => $helpitem});
7494: my $bread_crumbs_component = 'Helpdesk Staff Access';
7495: my $args = { bread_crumbs => $brcrum,
7496: bread_crumbs_component => $bread_crumbs_component};
7497:
7498: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
7499: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
7500: my $confname = $cdom.'-domainconfig';
7501: my $crstype = &Apache::loncommon::course_type();
7502:
1.406.2.12 raeburn 7503: my @accesstypes = ('all','dh','da','none');
1.406.2.10 raeburn 7504: my ($numstatustypes,@jsarray);
7505: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($cdom);
7506: if (ref($types) eq 'ARRAY') {
7507: if (@{$types} > 0) {
7508: $numstatustypes = scalar(@{$types});
7509: push(@accesstypes,'status');
7510: @jsarray = ('bystatus');
7511: }
7512: }
7513: my %customroles = &get_domain_customroles($cdom,$confname);
1.406.2.12 raeburn 7514: my %domhelpdesk = &Apache::lonnet::get_active_domroles($cdom,['dh','da']);
1.406.2.10 raeburn 7515: if (keys(%domhelpdesk)) {
7516: push(@accesstypes,('inc','exc'));
7517: push(@jsarray,('notinc','notexc'));
7518: }
7519: push(@jsarray,'privs');
7520: my $hiddenstr = join("','",@jsarray);
7521: my $rolestr = join("','",sort(keys(%customroles)));
7522:
7523: my $jscript;
7524: my (%settings,%overridden);
7525: if (keys(%customroles)) {
7526: &get_adhocrole_settings($env{'request.course.id'},\@accesstypes,
7527: $types,\%customroles,\%settings,\%overridden);
7528: my %jsfull=();
7529: my %jslevels= (
7530: course => {},
7531: domain => {},
7532: system => {},
7533: );
7534: my %jslevelscurrent=(
7535: course => {},
7536: domain => {},
7537: system => {},
7538: );
7539: my (%privs,%jsprivs);
7540: &Apache::lonuserutils::custom_role_privs(\%privs,\%jsfull,\%jslevels,\%jslevelscurrent);
7541: foreach my $priv (keys(%jsfull)) {
7542: if ($jslevels{'course'}{$priv}) {
7543: $jsprivs{$priv} = 1;
7544: }
7545: }
7546: my (%elements,%stored);
7547: foreach my $role (keys(%customroles)) {
7548: $elements{$role.'_access'} = 'radio';
7549: $elements{$role.'_incrs'} = 'radio';
7550: if ($numstatustypes) {
7551: $elements{$role.'_status'} = 'checkbox';
7552: }
7553: if (keys(%domhelpdesk) > 0) {
7554: $elements{$role.'_staff_inc'} = 'checkbox';
7555: $elements{$role.'_staff_exc'} = 'checkbox';
7556: }
7557: $elements{$role.'_override'} = 'checkbox';
7558: if (ref($settings{$role}) eq 'HASH') {
7559: if ($settings{$role}{'access'} ne '') {
7560: my $curraccess = $settings{$role}{'access'};
7561: $stored{$role.'_access'} = $curraccess;
7562: $stored{$role.'_incrs'} = 1;
7563: if ($curraccess eq 'status') {
7564: if (ref($settings{$role}{'status'}) eq 'ARRAY') {
7565: $stored{$role.'_status'} = $settings{$role}{'status'};
7566: }
7567: } elsif (($curraccess eq 'exc') || ($curraccess eq 'inc')) {
7568: if (ref($settings{$role}{$curraccess}) eq 'ARRAY') {
7569: $stored{$role.'_staff_'.$curraccess} = $settings{$role}{$curraccess};
7570: }
7571: }
7572: } else {
7573: $stored{$role.'_incrs'} = 0;
7574: }
7575: $stored{$role.'_override'} = [];
7576: if ($env{'course.'.$env{'request.course.id'}.'.internal.adhocpriv.'.$role}) {
7577: if (ref($settings{$role}{'off'}) eq 'ARRAY') {
7578: foreach my $priv (@{$settings{$role}{'off'}}) {
7579: push(@{$stored{$role.'_override'}},$priv);
7580: }
7581: }
7582: if (ref($settings{$role}{'on'}) eq 'ARRAY') {
7583: foreach my $priv (@{$settings{$role}{'on'}}) {
7584: unless (grep(/^$priv$/,@{$stored{$role.'_override'}})) {
7585: push(@{$stored{$role.'_override'}},$priv);
7586: }
7587: }
7588: }
7589: }
7590: } else {
7591: $stored{$role.'_incrs'} = 0;
7592: }
7593: }
7594: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements,\%stored);
7595: }
7596:
7597: my $js = <<"ENDJS";
7598: <script type="text/javascript">
7599: // <![CDATA[
7600: $jscript;
7601:
7602: function switchRoleTab(caller,role) {
7603: if (document.getElementById(role+'_maindiv')) {
7604: if (caller.id != 'LC_current_minitab') {
7605: if (document.getElementById('LC_current_minitab')) {
7606: document.getElementById('LC_current_minitab').id=null;
7607: }
7608: var roledivs = Array('$rolestr');
7609: if (roledivs.length > 0) {
7610: for (var i=0; i<roledivs.length; i++) {
7611: if (document.getElementById(roledivs[i]+'_maindiv')) {
7612: document.getElementById(roledivs[i]+'_maindiv').style.display='none';
7613: }
7614: }
7615: }
7616: caller.id = 'LC_current_minitab';
7617: document.getElementById(role+'_maindiv').style.display='block';
7618: }
7619: }
7620: return false;
7621: }
7622:
7623: function helpdeskAccess(role) {
7624: var curraccess = null;
7625: if (document.$formname.elements[role+'_access'].length) {
7626: for (var i=0; i<document.$formname.elements[role+'_access'].length; i++) {
7627: if (document.$formname.elements[role+'_access'][i].checked) {
7628: curraccess = document.$formname.elements[role+'_access'][i].value;
7629: }
7630: }
7631: }
7632: var shown = Array();
7633: var hidden = Array();
7634: if (curraccess == 'none') {
7635: hidden = Array ('$hiddenstr');
7636: } else {
7637: if (curraccess == 'status') {
7638: shown = Array ('bystatus','privs');
7639: hidden = Array ('notinc','notexc');
7640: } else {
7641: if (curraccess == 'exc') {
7642: shown = Array ('notexc','privs');
7643: hidden = Array ('notinc','bystatus');
7644: }
7645: if (curraccess == 'inc') {
7646: shown = Array ('notinc','privs');
7647: hidden = Array ('notexc','bystatus');
7648: }
7649: if (curraccess == 'all') {
7650: shown = Array ('privs');
7651: hidden = Array ('notinc','notexc','bystatus');
7652: }
7653: }
7654: }
7655: if (hidden.length > 0) {
7656: for (var i=0; i<hidden.length; i++) {
7657: if (document.getElementById(role+'_'+hidden[i])) {
7658: document.getElementById(role+'_'+hidden[i]).style.display = 'none';
7659: }
7660: }
7661: }
7662: if (shown.length > 0) {
7663: for (var i=0; i<shown.length; i++) {
7664: if (document.getElementById(role+'_'+shown[i])) {
7665: if (shown[i] == 'privs') {
7666: document.getElementById(role+'_'+shown[i]).style.display = 'block';
7667: } else {
7668: document.getElementById(role+'_'+shown[i]).style.display = 'inline';
7669: }
7670: }
7671: }
7672: }
7673: return;
7674: }
7675:
7676: function toggleAccess(role) {
7677: if ((document.getElementById(role+'_setincrs')) &&
7678: (document.getElementById(role+'_setindom'))) {
7679: for (var i=0; i<document.$formname.elements[role+'_incrs'].length; i++) {
7680: if (document.$formname.elements[role+'_incrs'][i].checked) {
7681: if (document.$formname.elements[role+'_incrs'][i].value == 1) {
7682: document.getElementById(role+'_setindom').style.display = 'none';
7683: document.getElementById(role+'_setincrs').style.display = 'block';
7684: } else {
7685: document.getElementById(role+'_setincrs').style.display = 'none';
7686: document.getElementById(role+'_setindom').style.display = 'block';
7687: }
7688: break;
7689: }
7690: }
7691: }
7692: return;
7693: }
7694:
7695: // ]]>
7696: </script>
7697: ENDJS
7698:
7699: $args->{add_entries} = {onload => "javascript:setFormElements(document.$formname)"};
7700:
7701: # print page header
7702: $r->print(&header($js,$args));
7703: # print form header
7704: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">');
7705:
7706: if (keys(%customroles)) {
7707: my %lt = &Apache::lonlocal::texthash(
7708: 'aco' => 'As course owner you may override the defaults set in the domain for role usage and/or privileges.',
7709: 'rou' => 'Role usage',
7710: 'whi' => 'Which helpdesk personnel may use this role?',
7711: 'udd' => 'Use domain default',
1.406.2.12 raeburn 7712: 'all' => 'All with domain helpdesk or helpdesk assistant role',
7713: 'dh' => 'All with domain helpdesk role',
7714: 'da' => 'All with domain helpdesk assistant role',
1.406.2.10 raeburn 7715: 'none' => 'None',
7716: 'status' => 'Determined based on institutional status',
7717: 'inc' => 'Include all, but exclude specific personnel',
7718: 'exc' => 'Exclude all, but include specific personnel',
7719: 'hel' => 'Helpdesk',
7720: 'rpr' => 'Role privileges',
7721: );
7722: $lt{'tfh'} = &mt("Custom [_1]ad hoc[_2] course roles available for use by the domain's helpdesk are as follows",'<i>','</i>');
7723: my %domconfig = &Apache::lonnet::get_dom('configuration',['helpsettings'],$cdom);
7724: my (%domcurrent,%ordered,%description,%domusage,$disabled);
7725: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
7726: if (ref($domconfig{'helpsettings'}{'adhoc'}) eq 'HASH') {
7727: %domcurrent = %{$domconfig{'helpsettings'}{'adhoc'}};
7728: }
7729: }
7730: my $count = 0;
7731: foreach my $role (sort(keys(%customroles))) {
7732: my ($order,$desc,$access_in_dom);
7733: if (ref($domcurrent{$role}) eq 'HASH') {
7734: $order = $domcurrent{$role}{'order'};
7735: $desc = $domcurrent{$role}{'desc'};
7736: $access_in_dom = $domcurrent{$role}{'access'};
7737: }
7738: if ($order eq '') {
7739: $order = $count;
7740: }
7741: $ordered{$order} = $role;
7742: if ($desc ne '') {
7743: $description{$role} = $desc;
7744: } else {
7745: $description{$role}= $role;
7746: }
7747: $count++;
7748: }
7749: %domusage = &domain_adhoc_access(\%customroles,\%domcurrent,\@accesstypes,$usertypes,$othertitle);
7750: my @roles_by_num = ();
7751: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
7752: push(@roles_by_num,$ordered{$item});
7753: }
7754: $r->print('<p>'.$lt{'tfh'}.': <i>'.join('</i>, <i>',map { $description{$_}; } @roles_by_num).'</i>.');
7755: if ($permission->{'owner'}) {
7756: $r->print('<br />'.$lt{'aco'}.'</p><p>');
7757: $r->print('<input type="hidden" name="state" value="process" />'.
7758: '<input type="submit" value="'.&mt('Save changes').'" />');
7759: } else {
7760: if ($env{'course.'.$env{'request.course.id'}.'.internal.courseowner'}) {
7761: my ($ownername,$ownerdom) = split(/:/,$env{'course.'.$env{'request.course.id'}.'.internal.courseowner'});
7762: $r->print('<br />'.&mt('The course owner -- [_1] -- can override the default access and/or privileges for these ad hoc roles.',
7763: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($ownername,$ownerdom),$ownername,$ownerdom)));
7764: }
7765: $disabled = ' disabled="disabled"';
7766: }
7767: $r->print('</p>');
7768:
7769: $r->print('<div id="LC_minitab_header"><ul>');
7770: my $count = 0;
7771: my %visibility;
7772: foreach my $role (@roles_by_num) {
7773: my $id;
7774: if ($count == 0) {
7775: $id=' id="LC_current_minitab"';
7776: $visibility{$role} = ' style="display:block"';
7777: } else {
7778: $visibility{$role} = ' style="display:none"';
7779: }
7780: $count ++;
7781: $r->print('<li'.$id.'><a href="#" onclick="javascript:switchRoleTab(this.parentNode,'."'$role'".');">'.$description{$role}.'</a></li>');
7782: }
7783: $r->print('</ul></div>');
7784:
7785: foreach my $role (@roles_by_num) {
7786: my %usecheck = (
7787: all => ' checked="checked"',
7788: );
7789: my %displaydiv = (
7790: status => 'none',
7791: inc => 'none',
7792: exc => 'none',
7793: priv => 'block',
7794: );
7795: my (%selected,$overridden,$incrscheck,$indomcheck,$indomvis,$incrsvis);
7796: if (ref($settings{$role}) eq 'HASH') {
7797: if ($settings{$role}{'access'} ne '') {
7798: $indomvis = ' style="display:none"';
7799: $incrsvis = ' style="display:block"';
7800: $incrscheck = ' checked="checked"';
7801: if ($settings{$role}{'access'} ne 'all') {
7802: $usecheck{$settings{$role}{'access'}} = $usecheck{'all'};
7803: delete($usecheck{'all'});
7804: if ($settings{$role}{'access'} eq 'status') {
7805: my $access = 'status';
7806: $displaydiv{$access} = 'inline';
7807: if (ref($settings{$role}{$access}) eq 'ARRAY') {
7808: $selected{$access} = $settings{$role}{$access};
7809: }
7810: } elsif ($settings{$role}{'access'} =~ /^(inc|exc)$/) {
7811: my $access = $1;
7812: $displaydiv{$access} = 'inline';
7813: if (ref($settings{$role}{$access}) eq 'ARRAY') {
7814: $selected{$access} = $settings{$role}{$access};
7815: }
7816: } elsif ($settings{$role}{'access'} eq 'none') {
7817: $displaydiv{'priv'} = 'none';
7818: }
7819: }
7820: } else {
7821: $indomcheck = ' checked="checked"';
7822: $indomvis = ' style="display:block"';
7823: $incrsvis = ' style="display:none"';
7824: }
7825: } else {
7826: $indomcheck = ' checked="checked"';
7827: $indomvis = ' style="display:block"';
7828: $incrsvis = ' style="display:none"';
7829: }
7830: $r->print('<div class="LC_left_float" id="'.$role.'_maindiv"'.$visibility{$role}.'>'.
7831: '<fieldset><legend>'.$lt{'rou'}.'</legend>'.
7832: '<p>'.$lt{'whi'}.' <span class="LC_nobreak">'.
7833: '<label><input type="radio" name="'.$role.'_incrs" value="1"'.$incrscheck.' onclick="toggleAccess('."'$role'".');"'.$disabled.'>'.
7834: &mt('Set here in [_1]',lc($crstype)).'</label>'.
7835: '<span>'.(' 'x2).
7836: '<label><input type="radio" name="'.$role.'_incrs" value="0"'.$indomcheck.' onclick="toggleAccess('."'$role'".');"'.$disabled.'>'.
7837: $lt{'udd'}.'</label><span></p>'.
7838: '<div id="'.$role.'_setindom"'.$indomvis.'>'.
7839: '<span class="LC_cusr_emph">'.$domusage{$role}.'</span></div>'.
7840: '<div id="'.$role.'_setincrs"'.$incrsvis.'>');
7841: foreach my $access (@accesstypes) {
7842: $r->print('<p><label><input type="radio" name="'.$role.'_access" value="'.$access.'" '.$usecheck{$access}.
7843: ' onclick="helpdeskAccess('."'$role'".');"'.$disabled.' />'.$lt{$access}.'</label>');
7844: if ($access eq 'status') {
7845: $r->print('<div id="'.$role.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
7846: &Apache::lonuserutils::adhoc_status_types($cdom,undef,$role,$selected{$access},
7847: $othertitle,$usertypes,$types,$disabled).
7848: '</div>');
7849: } elsif (($access eq 'inc') && (keys(%domhelpdesk) > 0)) {
7850: $r->print('<div id="'.$role.'_notinc" style="display:'.$displaydiv{$access}.'">'.
7851: &Apache::lonuserutils::adhoc_staff($access,undef,$role,$selected{$access},
7852: \%domhelpdesk,$disabled).
7853: '</div>');
7854: } elsif (($access eq 'exc') && (keys(%domhelpdesk) > 0)) {
7855: $r->print('<div id="'.$role.'_notexc" style="display:'.$displaydiv{$access}.'">'.
7856: &Apache::lonuserutils::adhoc_staff($access,undef,$role,$selected{$access},
7857: \%domhelpdesk,$disabled).
7858: '</div>');
7859: }
7860: $r->print('</p>');
7861: }
7862: $r->print('</div></fieldset>');
7863: my %full=();
7864: my %levels= (
7865: course => {},
7866: domain => {},
7867: system => {},
7868: );
7869: my %levelscurrent=(
7870: course => {},
7871: domain => {},
7872: system => {},
7873: );
7874: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
7875: $r->print('<fieldset id="'.$role.'_privs" style="display:'.$displaydiv{'priv'}.'">'.
7876: '<legend>'.$lt{'rpr'}.'</legend>'.
7877: &role_priv_table($role,$permission,$crstype,\%full,\%levels,\%levelscurrent,$overridden{$role}).
7878: '</fieldset></div><div style="padding:0;clear:both;margin:0;border:0"></div>');
7879: }
7880: if ($permission->{'owner'}) {
7881: $r->print('<p><input type="submit" value="'.&mt('Save changes').'" /></p>');
7882: }
7883: } else {
7884: $r->print(&mt('Helpdesk roles have not yet been created in this domain.'));
7885: }
7886: # Form Footer
7887: $r->print('<input type="hidden" name="action" value="helpdesk" />'
7888: .'</form>');
7889: return;
7890: }
7891:
7892: sub domain_adhoc_access {
7893: my ($roles,$domcurrent,$accesstypes,$usertypes,$othertitle) = @_;
7894: my %domusage;
7895: return unless ((ref($roles) eq 'HASH') && (ref($domcurrent) eq 'HASH') && (ref($accesstypes) eq 'ARRAY'));
7896: foreach my $role (keys(%{$roles})) {
7897: if (ref($domcurrent->{$role}) eq 'HASH') {
7898: my $access = $domcurrent->{$role}{'access'};
7899: if (($access eq '') || (!grep(/^\Q$access\E$/,@{$accesstypes}))) {
7900: $access = 'all';
1.406.2.12 raeburn 7901: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',&Apache::lonnet::plaintext('dh'),
7902: &Apache::lonnet::plaintext('da'));
1.406.2.10 raeburn 7903: } elsif ($access eq 'status') {
7904: if (ref($domcurrent->{$role}{$access}) eq 'ARRAY') {
7905: my @shown;
7906: foreach my $type (@{$domcurrent->{$role}{$access}}) {
7907: unless ($type eq 'default') {
7908: if ($usertypes->{$type}) {
7909: push(@shown,$usertypes->{$type});
7910: }
7911: }
7912: }
7913: if (grep(/^default$/,@{$domcurrent->{$role}{$access}})) {
7914: push(@shown,$othertitle);
7915: }
7916: if (@shown) {
7917: my $shownstatus = join(' '.&mt('or').' ',@shown);
1.406.2.12 raeburn 7918: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role, and institutional status: [_3]',
7919: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$shownstatus);
1.406.2.10 raeburn 7920: } else {
7921: $domusage{$role} = &mt('No one in the domain');
7922: }
7923: }
7924: } elsif ($access eq 'inc') {
7925: my @dominc = ();
7926: if (ref($domcurrent->{$role}{'inc'}) eq 'ARRAY') {
7927: foreach my $user (@{$domcurrent->{$role}{'inc'}}) {
7928: my ($uname,$udom) = split(/:/,$user);
7929: push(@dominc,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom));
7930: }
7931: my $showninc = join(', ',@dominc);
7932: if ($showninc ne '') {
1.406.2.12 raeburn 7933: $domusage{$role} = &mt('Include any user in domain with active [_1] or [_2] role, except: [_3]',
7934: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$showninc);
1.406.2.10 raeburn 7935: } else {
1.406.2.12 raeburn 7936: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
7937: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.406.2.10 raeburn 7938: }
7939: }
7940: } elsif ($access eq 'exc') {
7941: my @domexc = ();
7942: if (ref($domcurrent->{$role}{'exc'}) eq 'ARRAY') {
7943: foreach my $user (@{$domcurrent->{$role}{'exc'}}) {
7944: my ($uname,$udom) = split(/:/,$user);
7945: push(@domexc,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom));
7946: }
7947: }
7948: my $shownexc = join(', ',@domexc);
7949: if ($shownexc ne '') {
1.406.2.12 raeburn 7950: $domusage{$role} = &mt('Only the following in the domain with active [_1] or [_2] role: [_3]',
7951: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$shownexc);
1.406.2.10 raeburn 7952: } else {
7953: $domusage{$role} = &mt('No one in the domain');
7954: }
7955: } elsif ($access eq 'none') {
7956: $domusage{$role} = &mt('No one in the domain');
1.406.2.12 raeburn 7957: } elsif ($access eq 'dh') {
1.406.2.10 raeburn 7958: $domusage{$role} = &mt('Any user in domain with active [_1] role',&Apache::lonnet::plaintext('dh'));
1.406.2.12 raeburn 7959: } elsif ($access eq 'da') {
7960: $domusage{$role} = &mt('Any user in domain with active [_1] role',&Apache::lonnet::plaintext('da'));
7961: } elsif ($access eq 'all') {
7962: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
7963: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.406.2.10 raeburn 7964: }
7965: } else {
1.406.2.12 raeburn 7966: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
7967: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.406.2.10 raeburn 7968: }
7969: }
7970: return %domusage;
7971: }
7972:
7973: sub get_domain_customroles {
7974: my ($cdom,$confname) = @_;
7975: my %existing=&Apache::lonnet::dump('roles',$cdom,$confname,'rolesdef_');
7976: my %customroles;
7977: foreach my $key (keys(%existing)) {
7978: if ($key=~/^rolesdef\_(\w+)$/) {
7979: my $rolename = $1;
7980: my %privs;
7981: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
7982: $customroles{$rolename} = \%privs;
7983: }
7984: }
7985: return %customroles;
7986: }
7987:
7988: sub role_priv_table {
7989: my ($role,$permission,$crstype,$full,$levels,$levelscurrent,$overridden) = @_;
7990: return unless ((ref($full) eq 'HASH') && (ref($levels) eq 'HASH') &&
7991: (ref($levelscurrent) eq 'HASH'));
7992: my %lt=&Apache::lonlocal::texthash (
7993: 'crl' => 'Course Level Privilege',
7994: 'def' => 'Domain Defaults',
7995: 'ove' => 'Override in Course',
7996: 'ine' => 'In effect',
7997: 'dis' => 'Disabled',
7998: 'ena' => 'Enabled',
7999: );
8000: if ($crstype eq 'Community') {
8001: $lt{'ove'} = 'Override in Community',
8002: }
8003: my @status = ('Disabled','Enabled');
8004: my (%on,%off);
8005: if (ref($overridden) eq 'HASH') {
8006: if (ref($overridden->{'on'}) eq 'ARRAY') {
8007: map { $on{$_} = 1; } (@{$overridden->{'on'}});
8008: }
8009: if (ref($overridden->{'off'}) eq 'ARRAY') {
8010: map { $off{$_} = 1; } (@{$overridden->{'off'}});
8011: }
8012: }
8013: my $output=&Apache::loncommon::start_data_table().
8014: &Apache::loncommon::start_data_table_header_row().
8015: '<th>'.$lt{'crl'}.'</th><th>'.$lt{'def'}.'</th><th>'.$lt{'ove'}.
8016: '</th><th>'.$lt{'ine'}.'</th>'.
8017: &Apache::loncommon::end_data_table_header_row();
8018: foreach my $priv (sort(keys(%{$full}))) {
8019: next unless ($levels->{'course'}{$priv});
8020: my $privtext = &Apache::lonnet::plaintext($priv,$crstype);
8021: my ($default,$ineffect);
8022: if ($levelscurrent->{'course'}{$priv}) {
8023: $default = '<img src="/adm/lonIcons/navmap.correct.gif" alt="'.$lt{'ena'}.'" />';
8024: $ineffect = $default;
8025: }
8026: my ($customstatus,$checked);
8027: $output .= &Apache::loncommon::start_data_table_row().
8028: '<td>'.$privtext.'</td>'.
8029: '<td>'.$default.'</td><td>';
8030: if (($levelscurrent->{'course'}{$priv}) && ($off{$priv})) {
8031: if ($permission->{'owner'}) {
8032: $checked = ' checked="checked"';
8033: }
8034: $customstatus = '<img src="/adm/lonIcons/navmap.wrong.gif" alt="'.$lt{'dis'}.'" />';
8035: $ineffect = $customstatus;
8036: } elsif ((!$levelscurrent->{'course'}{$priv}) && ($on{$priv})) {
8037: if ($permission->{'owner'}) {
8038: $checked = ' checked="checked"';
8039: }
8040: $customstatus = '<img src="/adm/lonIcons/navmap.correct.gif" alt="'.$lt{'ena'}.'" />';
8041: $ineffect = $customstatus;
8042: }
8043: if ($permission->{'owner'}) {
8044: $output .= '<input type="checkbox" name="'.$role.'_override" value="'.$priv.'"'.$checked.' />';
8045: } else {
8046: $output .= $customstatus;
8047: }
8048: $output .= '</td><td>'.$ineffect.'</td>'.
8049: &Apache::loncommon::end_data_table_row();
8050: }
8051: $output .= &Apache::loncommon::end_data_table();
8052: return $output;
8053: }
8054:
8055: sub get_adhocrole_settings {
8056: my ($cid,$accesstypes,$types,$customroles,$settings,$overridden) = @_;
8057: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($customroles) eq 'HASH') &&
8058: (ref($settings) eq 'HASH') && (ref($overridden) eq 'HASH'));
8059: foreach my $role (split(/,/,$env{'course.'.$cid.'.internal.adhocaccess'})) {
8060: my ($curraccess,$rest) = split(/=/,$env{'course.'.$cid.'.internal.adhoc.'.$role});
8061: if (($curraccess ne '') && (grep(/^\Q$curraccess\E$/,@{$accesstypes}))) {
8062: $settings->{$role}{'access'} = $curraccess;
8063: if (($curraccess eq 'status') && (ref($types) eq 'ARRAY')) {
8064: my @status = split(/,/,$rest);
8065: my @currstatus;
8066: foreach my $type (@status) {
8067: if ($type eq 'default') {
8068: push(@currstatus,$type);
8069: } elsif (grep(/^\Q$type\E$/,@{$types})) {
8070: push(@currstatus,$type);
8071: }
8072: }
8073: if (@currstatus) {
8074: $settings->{$role}{$curraccess} = \@currstatus;
8075: } elsif (($curraccess eq 'exc') || ($curraccess eq 'inc')) {
8076: my @personnel = split(/,/,$rest);
8077: $settings->{$role}{$curraccess} = \@personnel;
8078: }
8079: }
8080: }
8081: }
8082: foreach my $role (keys(%{$customroles})) {
8083: if ($env{'course.'.$cid.'.internal.adhocpriv.'.$role}) {
8084: my %currentprivs;
8085: if (ref($customroles->{$role}) eq 'HASH') {
8086: if (exists($customroles->{$role}{'course'})) {
8087: my %full=();
8088: my %levels= (
8089: course => {},
8090: domain => {},
8091: system => {},
8092: );
8093: my %levelscurrent=(
8094: course => {},
8095: domain => {},
8096: system => {},
8097: );
8098: &Apache::lonuserutils::custom_role_privs($customroles->{$role},\%full,\%levels,\%levelscurrent);
8099: %currentprivs = %{$levelscurrent{'course'}};
8100: }
8101: }
8102: foreach my $item (split(/,/,$env{'course.'.$cid.'.internal.adhocpriv.'.$role})) {
8103: next if ($item eq '');
8104: my ($rule,$rest) = split(/=/,$item);
8105: next unless (($rule eq 'off') || ($rule eq 'on'));
8106: foreach my $priv (split(/:/,$rest)) {
8107: if ($priv ne '') {
8108: if ($rule eq 'off') {
8109: push(@{$overridden->{$role}{'off'}},$priv);
8110: if ($currentprivs{$priv}) {
8111: push(@{$settings->{$role}{'off'}},$priv);
8112: }
8113: } else {
8114: push(@{$overridden->{$role}{'on'}},$priv);
8115: unless ($currentprivs{$priv}) {
8116: push(@{$settings->{$role}{'on'}},$priv);
8117: }
8118: }
8119: }
8120: }
8121: }
8122: }
8123: }
8124: return;
8125: }
8126:
8127: sub update_helpdeskaccess {
8128: my ($r,$permission,$brcrum) = @_;
8129: my $helpitem = 'Course_Helpdesk_Access';
8130: push (@{$brcrum},
8131: {href => '/adm/createuser?action=helpdesk',
8132: text => 'Helpdesk Access',
8133: help => $helpitem},
8134: {href => '/adm/createuser?action=helpdesk',
8135: text => 'Result',
8136: help => $helpitem}
8137: );
8138: my $bread_crumbs_component = 'Helpdesk Staff Access';
8139: my $args = { bread_crumbs => $brcrum,
8140: bread_crumbs_component => $bread_crumbs_component};
8141:
8142: # print page header
8143: $r->print(&header('',$args));
8144: unless ((ref($permission) eq 'HASH') && ($permission->{'owner'})) {
8145: $r->print('<p class="LC_error">'.&mt('You do not have permission to change helpdesk access.').'</p>');
8146: return;
8147: }
1.406.2.12 raeburn 8148: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.406.2.10 raeburn 8149: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8150: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
8151: my $confname = $cdom.'-domainconfig';
8152: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($cdom);
8153: my $crstype = &Apache::loncommon::course_type();
8154: my %customroles = &get_domain_customroles($cdom,$confname);
8155: my (%settings,%overridden);
8156: &get_adhocrole_settings($env{'request.course.id'},\@accesstypes,
8157: $types,\%customroles,\%settings,\%overridden);
1.406.2.12 raeburn 8158: my %domhelpdesk = &Apache::lonnet::get_active_domroles($cdom,['dh','da']);
1.406.2.10 raeburn 8159: my (%changed,%storehash,@todelete);
8160:
8161: if (keys(%customroles)) {
8162: my (%newsettings,@incrs);
8163: foreach my $role (keys(%customroles)) {
8164: $newsettings{$role} = {
8165: access => '',
8166: status => '',
8167: exc => '',
8168: inc => '',
8169: on => '',
8170: off => '',
8171: };
8172: my %current;
8173: if (ref($settings{$role}) eq 'HASH') {
8174: %current = %{$settings{$role}};
8175: }
8176: if (ref($overridden{$role}) eq 'HASH') {
8177: $current{'overridden'} = $overridden{$role};
8178: }
8179: if ($env{'form.'.$role.'_incrs'}) {
8180: my $access = $env{'form.'.$role.'_access'};
8181: if (grep(/^\Q$access\E$/,@accesstypes)) {
8182: push(@incrs,$role);
8183: unless ($current{'access'} eq $access) {
8184: $changed{$role}{'access'} = 1;
8185: $storehash{'internal.adhoc.'.$role} = $access;
8186: }
8187: if ($access eq 'status') {
8188: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$role.'_status');
8189: my @stored;
8190: my @shownstatus;
8191: if (ref($types) eq 'ARRAY') {
8192: foreach my $type (sort(@statuses)) {
8193: if ($type eq 'default') {
8194: push(@stored,$type);
8195: } elsif (grep(/^\Q$type\E$/,@{$types})) {
8196: push(@stored,$type);
8197: push(@shownstatus,$usertypes->{$type});
8198: }
8199: }
8200: if (grep(/^default$/,@statuses)) {
8201: push(@shownstatus,$othertitle);
8202: }
8203: $storehash{'internal.adhoc.'.$role} .= '='.join(',',@stored);
8204: }
8205: $newsettings{$role}{'status'} = join(' '.&mt('or').' ',@shownstatus);
8206: if (ref($current{'status'}) eq 'ARRAY') {
8207: my @diffs = &Apache::loncommon::compare_arrays(\@stored,$current{'status'});
8208: if (@diffs) {
8209: $changed{$role}{'status'} = 1;
8210: }
8211: } elsif (@stored) {
8212: $changed{$role}{'status'} = 1;
8213: }
8214: } elsif (($access eq 'inc') || ($access eq 'exc')) {
8215: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$role.'_staff_'.$access);
8216: my @newspecstaff;
8217: my @stored;
8218: my @currstaff;
8219: foreach my $person (sort(@personnel)) {
8220: if ($domhelpdesk{$person}) {
8221: push(@stored,$person);
8222: }
8223: }
8224: if (ref($current{$access}) eq 'ARRAY') {
8225: my @diffs = &Apache::loncommon::compare_arrays(\@stored,$current{$access});
8226: if (@diffs) {
8227: $changed{$role}{$access} = 1;
8228: }
8229: } elsif (@stored) {
8230: $changed{$role}{$access} = 1;
8231: }
8232: $storehash{'internal.adhoc.'.$role} .= '='.join(',',@stored);
8233: foreach my $person (@stored) {
8234: my ($uname,$udom) = split(/:/,$person);
8235: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
8236: }
8237: $newsettings{$role}{$access} = join(', ',sort(@newspecstaff));
8238: }
8239: $newsettings{$role}{'access'} = $access;
8240: }
8241: } else {
8242: if (($current{'access'} ne '') && (grep(/^\Q$current{'access'}\E$/,@accesstypes))) {
8243: $changed{$role}{'access'} = 1;
8244: $newsettings{$role} = {};
8245: push(@todelete,'internal.adhoc.'.$role);
8246: }
8247: }
8248: if (($env{'form.'.$role.'_incrs'}) && ($env{'form.'.$role.'_access'} eq 'none')) {
8249: if (ref($current{'overridden'}) eq 'HASH') {
8250: push(@todelete,'internal.adhocpriv.'.$role);
8251: }
8252: } else {
8253: my %full=();
8254: my %levels= (
8255: course => {},
8256: domain => {},
8257: system => {},
8258: );
8259: my %levelscurrent=(
8260: course => {},
8261: domain => {},
8262: system => {},
8263: );
8264: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
8265: my (@updatedon,@updatedoff,@override);
8266: @override = &Apache::loncommon::get_env_multiple('form.'.$role.'_override');
8267: if (@override) {
8268: foreach my $priv (sort(keys(%full))) {
8269: next unless ($levels{'course'}{$priv});
8270: if (grep(/^\Q$priv\E$/,@override)) {
8271: if ($levelscurrent{'course'}{$priv}) {
8272: push(@updatedoff,$priv);
8273: } else {
8274: push(@updatedon,$priv);
8275: }
8276: }
8277: }
8278: }
8279: if (@updatedon) {
8280: $newsettings{$role}{'on'} = join('</li><li>', map { &Apache::lonnet::plaintext($_,$crstype) } (@updatedon));
8281: }
8282: if (@updatedoff) {
8283: $newsettings{$role}{'off'} = join('</li><li>', map { &Apache::lonnet::plaintext($_,$crstype) } (@updatedoff));
8284: }
8285: if (ref($current{'overridden'}) eq 'HASH') {
8286: if (ref($current{'overridden'}{'on'}) eq 'ARRAY') {
8287: if (@updatedon) {
8288: my @diffs = &Apache::loncommon::compare_arrays(\@updatedon,$current{'overridden'}{'on'});
8289: if (@diffs) {
8290: $changed{$role}{'on'} = 1;
8291: }
8292: } else {
8293: $changed{$role}{'on'} = 1;
8294: }
8295: } elsif (@updatedon) {
8296: $changed{$role}{'on'} = 1;
8297: }
8298: if (ref($current{'overridden'}{'off'}) eq 'ARRAY') {
8299: if (@updatedoff) {
8300: my @diffs = &Apache::loncommon::compare_arrays(\@updatedoff,$current{'overridden'}{'off'});
8301: if (@diffs) {
8302: $changed{$role}{'off'} = 1;
8303: }
8304: } else {
8305: $changed{$role}{'off'} = 1;
8306: }
8307: } elsif (@updatedoff) {
8308: $changed{$role}{'off'} = 1;
8309: }
8310: } else {
8311: if (@updatedon) {
8312: $changed{$role}{'on'} = 1;
8313: }
8314: if (@updatedoff) {
8315: $changed{$role}{'off'} = 1;
8316: }
8317: }
8318: if (ref($changed{$role}) eq 'HASH') {
8319: if (($changed{$role}{'on'} || $changed{$role}{'off'})) {
8320: my $newpriv;
8321: if (@updatedon) {
8322: $newpriv = 'on='.join(':',@updatedon);
8323: }
8324: if (@updatedoff) {
8325: $newpriv .= ($newpriv ? ',' : '' ).'off='.join(':',@updatedoff);
8326: }
8327: if ($newpriv eq '') {
8328: push(@todelete,'internal.adhocpriv.'.$role);
8329: } else {
8330: $storehash{'internal.adhocpriv.'.$role} = $newpriv;
8331: }
8332: }
8333: }
8334: }
8335: }
8336: if (@incrs) {
8337: $storehash{'internal.adhocaccess'} = join(',',@incrs);
8338: } elsif (@todelete) {
8339: push(@todelete,'internal.adhocaccess');
8340: }
8341: if (keys(%changed)) {
8342: my ($putres,$delres);
8343: if (keys(%storehash)) {
8344: $putres = &Apache::lonnet::put('environment',\%storehash,$cdom,$cnum);
8345: my %newenvhash;
8346: foreach my $key (keys(%storehash)) {
8347: $newenvhash{'course.'.$env{'request.course.id'}.'.'.$key} = $storehash{$key};
8348: }
8349: &Apache::lonnet::appenv(\%newenvhash);
8350: }
8351: if (@todelete) {
8352: $delres = &Apache::lonnet::del('environment',\@todelete,$cdom,$cnum);
8353: foreach my $key (@todelete) {
8354: &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.'.$key);
8355: }
8356: }
8357: if (($putres eq 'ok') || ($delres eq 'ok')) {
8358: my %domconfig = &Apache::lonnet::get_dom('configuration',['helpsettings'],$cdom);
8359: my (%domcurrent,%ordered,%description,%domusage);
8360: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
8361: if (ref($domconfig{'helpsettings'}{'adhoc'}) eq 'HASH') {
8362: %domcurrent = %{$domconfig{'helpsettings'}{'adhoc'}};
8363: }
8364: }
8365: my $count = 0;
8366: foreach my $role (sort(keys(%customroles))) {
8367: my ($order,$desc);
8368: if (ref($domcurrent{$role}) eq 'HASH') {
8369: $order = $domcurrent{$role}{'order'};
8370: $desc = $domcurrent{$role}{'desc'};
8371: }
8372: if ($order eq '') {
8373: $order = $count;
8374: }
8375: $ordered{$order} = $role;
8376: if ($desc ne '') {
8377: $description{$role} = $desc;
8378: } else {
8379: $description{$role}= $role;
8380: }
8381: $count++;
8382: }
8383: my @roles_by_num = ();
8384: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
8385: push(@roles_by_num,$ordered{$item});
8386: }
8387: %domusage = &domain_adhoc_access(\%changed,\%domcurrent,\@accesstypes,$usertypes,$othertitle);
8388: $r->print(&mt('Helpdesk access settings have been changed as follows').'<br />');
8389: $r->print('<ul>');
8390: foreach my $role (@roles_by_num) {
8391: next unless (ref($changed{$role}) eq 'HASH');
8392: $r->print('<li>'.&mt('Ad hoc role').': <b>'.$description{$role}.'</b>'.
8393: '<ul>');
8394: if ($changed{$role}{'access'} || $changed{$role}{'status'} || $changed{$role}{'inc'} || $changed{$role}{'exc'}) {
8395: $r->print('<li>');
8396: if ($env{'form.'.$role.'_incrs'}) {
8397: if ($newsettings{$role}{'access'} eq 'all') {
8398: $r->print(&mt('All helpdesk staff can access '.lc($crstype).' with this role.'));
1.406.2.12 raeburn 8399: } elsif ($newsettings{$role}{'access'} eq 'dh') {
8400: $r->print(&mt('Helpdesk staff can use this role if they have an active [_1] role',
8401: &Apache::lonnet::plaintext('dh')));
8402: } elsif ($newsettings{$role}{'access'} eq 'da') {
8403: $r->print(&mt('Helpdesk staff can use this role if they have an active [_1] role',
8404: &Apache::lonnet::plaintext('da')));
1.406.2.10 raeburn 8405: } elsif ($newsettings{$role}{'access'} eq 'none') {
8406: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
8407: } elsif ($newsettings{$role}{'access'} eq 'status') {
8408: if ($newsettings{$role}{'status'}) {
8409: my ($access,$rest) = split(/=/,$storehash{'internal.adhoc.'.$role});
8410: if (split(/,/,$rest) > 1) {
8411: $r->print(&mt('Helpdesk staff can use this role if their institutional type is one of: [_1].',
8412: $newsettings{$role}{'status'}));
8413: } else {
8414: $r->print(&mt('Helpdesk staff can use this role if their institutional type is: [_1].',
8415: $newsettings{$role}{'status'}));
8416: }
8417: } else {
8418: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
8419: }
8420: } elsif ($newsettings{$role}{'access'} eq 'exc') {
8421: if ($newsettings{$role}{'exc'}) {
8422: $r->print(&mt('Helpdesk staff who can use this role are as follows:').' '.$newsettings{$role}{'exc'}.'.');
8423: } else {
8424: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
8425: }
8426: } elsif ($newsettings{$role}{'access'} eq 'inc') {
8427: if ($newsettings{$role}{'inc'}) {
8428: $r->print(&mt('All helpdesk staff may use this role except the following:').' '.$newsettings{$role}{'inc'}.'.');
8429: } else {
8430: $r->print(&mt('All helpdesk staff may use this role.'));
8431: }
8432: }
8433: } else {
8434: $r->print(&mt('Default access set in the domain now applies.').'<br />'.
8435: '<span class="LC_cusr_emph">'.$domusage{$role}.'</span>');
8436: }
8437: $r->print('</li>');
8438: }
8439: unless ($newsettings{$role}{'access'} eq 'none') {
8440: if ($changed{$role}{'off'}) {
8441: if ($newsettings{$role}{'off'}) {
8442: $r->print('<li>'.&mt('Privileges which are available by default for this ad hoc role, but are disabled for this specific '.lc($crstype).':').
8443: '<ul><li>'.$newsettings{$role}{'off'}.'</li></ul></li>');
8444: } else {
8445: $r->print('<li>'.&mt('All privileges available by default for this ad hoc role are enabled.').'</li>');
8446: }
8447: }
8448: if ($changed{$role}{'on'}) {
8449: if ($newsettings{$role}{'on'}) {
8450: $r->print('<li>'.&mt('Privileges which are not available by default for this ad hoc role, but are enabled for this specific '.lc($crstype).':').
8451: '<ul><li>'.$newsettings{$role}{'on'}.'</li></ul></li>');
8452: } else {
8453: $r->print('<li>'.&mt('None of the privileges unavailable by default for this ad hoc role are enabled.').'</li>');
8454: }
8455: }
8456: }
8457: $r->print('</ul></li>');
8458: }
8459: $r->print('</ul>');
8460: }
8461: } else {
8462: $r->print(&mt('No changes made to helpdesk access settings.'));
8463: }
8464: }
8465: return;
8466: }
8467:
1.27 matthew 8468: #-------------------------------------------------- functions for &phase_two
1.160 raeburn 8469: sub user_search_result {
1.221 raeburn 8470: my ($context,$srch) = @_;
1.160 raeburn 8471: my %allhomes;
8472: my %inst_matches;
8473: my %srch_results;
1.181 raeburn 8474: my ($response,$currstate,$forcenewuser,$dirsrchres);
1.183 raeburn 8475: $srch->{'srchterm'} =~ s/\s+/ /g;
1.176 raeburn 8476: if ($srch->{'srchby'} !~ /^(uname|lastname|lastfirst)$/) {
1.160 raeburn 8477: $response = &mt('Invalid search.');
8478: }
8479: if ($srch->{'srchin'} !~ /^(crs|dom|alc|instd)$/) {
8480: $response = &mt('Invalid search.');
8481: }
1.177 raeburn 8482: if ($srch->{'srchtype'} !~ /^(exact|contains|begins)$/) {
1.160 raeburn 8483: $response = &mt('Invalid search.');
8484: }
8485: if ($srch->{'srchterm'} eq '') {
8486: $response = &mt('You must enter a search term.');
8487: }
1.183 raeburn 8488: if ($srch->{'srchterm'} =~ /^\s+$/) {
8489: $response = &mt('Your search term must contain more than just spaces.');
8490: }
1.160 raeburn 8491: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'instd')) {
8492: if (($srch->{'srchdomain'} eq '') ||
1.163 albertel 8493: ! (&Apache::lonnet::domain($srch->{'srchdomain'}))) {
1.160 raeburn 8494: $response = &mt('You must specify a valid domain when searching in a domain or institutional directory.')
8495: }
8496: }
8497: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs') ||
8498: ($srch->{'srchin'} eq 'alc')) {
1.176 raeburn 8499: if ($srch->{'srchby'} eq 'uname') {
1.243 raeburn 8500: my $unamecheck = $srch->{'srchterm'};
8501: if ($srch->{'srchtype'} eq 'contains') {
8502: if ($unamecheck !~ /^\w/) {
8503: $unamecheck = 'a'.$unamecheck;
8504: }
8505: }
8506: if ($unamecheck !~ /^$match_username$/) {
1.176 raeburn 8507: $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
8508: }
1.160 raeburn 8509: }
8510: }
1.180 raeburn 8511: if ($response ne '') {
1.406.2.4 raeburn 8512: $response = '<span class="LC_warning">'.$response.'</span><br />';
1.180 raeburn 8513: }
1.160 raeburn 8514: if ($srch->{'srchin'} eq 'instd') {
1.406.2.3 raeburn 8515: my $instd_chk = &instdirectorysrch_check($srch);
1.160 raeburn 8516: if ($instd_chk ne 'ok') {
1.406.2.3 raeburn 8517: my $domd_chk = &domdirectorysrch_check($srch);
1.406.2.4 raeburn 8518: $response .= '<span class="LC_warning">'.$instd_chk.'</span><br />';
1.406.2.3 raeburn 8519: if ($domd_chk eq 'ok') {
1.406.2.4 raeburn 8520: $response .= &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.');
1.406.2.3 raeburn 8521: }
1.406.2.5 raeburn 8522: $response .= '<br />';
1.406.2.3 raeburn 8523: }
8524: } else {
8525: unless (($context eq 'requestcrs') && ($srch->{'srchtype'} eq 'exact')) {
8526: my $domd_chk = &domdirectorysrch_check($srch);
1.406.2.14 raeburn 8527: if (($domd_chk ne 'ok') && ($env{'form.action'} ne 'accesslogs')) {
1.406.2.3 raeburn 8528: my $instd_chk = &instdirectorysrch_check($srch);
1.406.2.4 raeburn 8529: $response .= '<span class="LC_warning">'.$domd_chk.'</span><br />';
1.406.2.3 raeburn 8530: if ($instd_chk eq 'ok') {
1.406.2.4 raeburn 8531: $response .= &mt('You may want to search in the institutional directory instead of the LON-CAPA domain.');
1.406.2.3 raeburn 8532: }
1.406.2.5 raeburn 8533: $response .= '<br />';
1.406.2.3 raeburn 8534: }
1.160 raeburn 8535: }
8536: }
8537: if ($response ne '') {
1.180 raeburn 8538: return ($currstate,$response);
1.160 raeburn 8539: }
8540: if ($srch->{'srchby'} eq 'uname') {
8541: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs')) {
8542: if ($env{'form.forcenew'}) {
8543: if ($srch->{'srchdomain'} ne $env{'request.role.domain'}) {
8544: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
8545: if ($uhome eq 'no_host') {
8546: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
1.180 raeburn 8547: my $showdom = &display_domain_info($env{'request.role.domain'});
8548: $response = &mt('New users can only be created in the domain to which your current role belongs - [_1].',$showdom);
1.160 raeburn 8549: } else {
1.179 raeburn 8550: $currstate = 'modify';
1.160 raeburn 8551: }
8552: } else {
1.179 raeburn 8553: $currstate = 'modify';
1.160 raeburn 8554: }
8555: } else {
8556: if ($srch->{'srchin'} eq 'dom') {
1.162 raeburn 8557: if ($srch->{'srchtype'} eq 'exact') {
8558: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
8559: if ($uhome eq 'no_host') {
1.179 raeburn 8560: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8561: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 8562: } else {
1.179 raeburn 8563: $currstate = 'modify';
1.406.2.5 raeburn 8564: if ($env{'form.action'} eq 'accesslogs') {
8565: $currstate = 'activity';
8566: }
1.310 raeburn 8567: my $uname = $srch->{'srchterm'};
8568: my $udom = $srch->{'srchdomain'};
8569: $srch_results{$uname.':'.$udom} =
8570: { &Apache::lonnet::get('environment',
8571: ['firstname',
8572: 'lastname',
8573: 'permanentemail'],
8574: $udom,$uname)
8575: };
1.162 raeburn 8576: }
8577: } else {
8578: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 8579: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8580: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8581: }
8582: } else {
1.167 albertel 8583: my $courseusers = &get_courseusers();
1.162 raeburn 8584: if ($srch->{'srchtype'} eq 'exact') {
1.167 albertel 8585: if (exists($courseusers->{$srch->{'srchterm'}.':'.$srch->{'srchdomain'}})) {
1.179 raeburn 8586: $currstate = 'modify';
1.162 raeburn 8587: } else {
1.179 raeburn 8588: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8589: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 8590: }
1.160 raeburn 8591: } else {
1.167 albertel 8592: foreach my $user (keys(%$courseusers)) {
1.162 raeburn 8593: my ($cuname,$cudomain) = split(/:/,$user);
8594: if ($cudomain eq $srch->{'srchdomain'}) {
1.177 raeburn 8595: my $matched = 0;
8596: if ($srch->{'srchtype'} eq 'begins') {
8597: if ($cuname =~ /^\Q$srch->{'srchterm'}\E/i) {
8598: $matched = 1;
8599: }
8600: } else {
8601: if ($cuname =~ /\Q$srch->{'srchterm'}\E/i) {
8602: $matched = 1;
8603: }
8604: }
8605: if ($matched) {
1.167 albertel 8606: $srch_results{$user} =
8607: {&Apache::lonnet::get('environment',
8608: ['firstname',
8609: 'lastname',
1.194 albertel 8610: 'permanentemail'],
8611: $cudomain,$cuname)};
1.162 raeburn 8612: }
8613: }
8614: }
1.179 raeburn 8615: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8616: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8617: }
8618: }
8619: }
8620: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 8621: $currstate = 'query';
1.160 raeburn 8622: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 8623: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
8624: if ($dirsrchres eq 'ok') {
8625: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8626: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 8627: } else {
8628: my $showdom = &display_domain_info($srch->{'srchdomain'});
8629: $response = '<span class="LC_warning">'.
8630: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
8631: '</span><br />'.
8632: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
1.406.2.5 raeburn 8633: '<br />';
1.181 raeburn 8634: }
1.160 raeburn 8635: }
8636: } else {
8637: if ($srch->{'srchin'} eq 'dom') {
8638: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 8639: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8640: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8641: } elsif ($srch->{'srchin'} eq 'crs') {
1.167 albertel 8642: my $courseusers = &get_courseusers();
8643: foreach my $user (keys(%$courseusers)) {
1.160 raeburn 8644: my ($uname,$udom) = split(/:/,$user);
8645: my %names = &Apache::loncommon::getnames($uname,$udom);
8646: my %emails = &Apache::loncommon::getemails($uname,$udom);
8647: if ($srch->{'srchby'} eq 'lastname') {
8648: if ((($srch->{'srchtype'} eq 'exact') &&
8649: ($names{'lastname'} eq $srch->{'srchterm'})) ||
1.177 raeburn 8650: (($srch->{'srchtype'} eq 'begins') &&
8651: ($names{'lastname'} =~ /^\Q$srch->{'srchterm'}\E/i)) ||
1.160 raeburn 8652: (($srch->{'srchtype'} eq 'contains') &&
8653: ($names{'lastname'} =~ /\Q$srch->{'srchterm'}\E/i))) {
8654: $srch_results{$user} = {firstname => $names{'firstname'},
8655: lastname => $names{'lastname'},
8656: permanentemail => $emails{'permanentemail'},
8657: };
8658: }
8659: } elsif ($srch->{'srchby'} eq 'lastfirst') {
8660: my ($srchlast,$srchfirst) = split(/,/,$srch->{'srchterm'});
1.177 raeburn 8661: $srchlast =~ s/\s+$//;
8662: $srchfirst =~ s/^\s+//;
1.160 raeburn 8663: if ($srch->{'srchtype'} eq 'exact') {
8664: if (($names{'lastname'} eq $srchlast) &&
8665: ($names{'firstname'} eq $srchfirst)) {
8666: $srch_results{$user} = {firstname => $names{'firstname'},
8667: lastname => $names{'lastname'},
8668: permanentemail => $emails{'permanentemail'},
8669:
8670: };
8671: }
1.177 raeburn 8672: } elsif ($srch->{'srchtype'} eq 'begins') {
8673: if (($names{'lastname'} =~ /^\Q$srchlast\E/i) &&
8674: ($names{'firstname'} =~ /^\Q$srchfirst\E/i)) {
8675: $srch_results{$user} = {firstname => $names{'firstname'},
8676: lastname => $names{'lastname'},
8677: permanentemail => $emails{'permanentemail'},
8678: };
8679: }
8680: } else {
1.160 raeburn 8681: if (($names{'lastname'} =~ /\Q$srchlast\E/i) &&
8682: ($names{'firstname'} =~ /\Q$srchfirst\E/i)) {
8683: $srch_results{$user} = {firstname => $names{'firstname'},
8684: lastname => $names{'lastname'},
8685: permanentemail => $emails{'permanentemail'},
8686: };
8687: }
8688: }
8689: }
8690: }
1.179 raeburn 8691: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8692: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8693: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 8694: $currstate = 'query';
1.160 raeburn 8695: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 8696: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
8697: if ($dirsrchres eq 'ok') {
8698: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8699: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 8700: } else {
1.406.2.5 raeburn 8701: my $showdom = &display_domain_info($srch->{'srchdomain'});
8702: $response = '<span class="LC_warning">'.
1.181 raeburn 8703: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
8704: '</span><br />'.
8705: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
1.406.2.5 raeburn 8706: '<br />';
1.181 raeburn 8707: }
1.160 raeburn 8708: }
8709: }
1.179 raeburn 8710: return ($currstate,$response,$forcenewuser,\%srch_results);
1.160 raeburn 8711: }
8712:
1.406.2.3 raeburn 8713: sub domdirectorysrch_check {
8714: my ($srch) = @_;
8715: my $response;
8716: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
8717: ['directorysrch'],$srch->{'srchdomain'});
8718: my $showdom = &display_domain_info($srch->{'srchdomain'});
8719: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
8720: if ($dom_inst_srch{'directorysrch'}{'lcavailable'} eq '0') {
8721: return &mt('LON-CAPA directory search is not available in domain: [_1]',$showdom);
8722: }
8723: if ($dom_inst_srch{'directorysrch'}{'lclocalonly'}) {
8724: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
8725: return &mt('LON-CAPA directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
8726: }
8727: }
8728: }
8729: return 'ok';
8730: }
8731:
8732: sub instdirectorysrch_check {
1.160 raeburn 8733: my ($srch) = @_;
8734: my $can_search = 0;
8735: my $response;
8736: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
8737: ['directorysrch'],$srch->{'srchdomain'});
1.180 raeburn 8738: my $showdom = &display_domain_info($srch->{'srchdomain'});
1.160 raeburn 8739: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
8740: if (!$dom_inst_srch{'directorysrch'}{'available'}) {
1.180 raeburn 8741: return &mt('Institutional directory search is not available in domain: [_1]',$showdom);
1.160 raeburn 8742: }
8743: if ($dom_inst_srch{'directorysrch'}{'localonly'}) {
8744: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
1.180 raeburn 8745: return &mt('Institutional directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
1.160 raeburn 8746: }
8747: my @usertypes = split(/:/,$env{'environment.inststatus'});
8748: if (!@usertypes) {
8749: push(@usertypes,'default');
8750: }
8751: if (ref($dom_inst_srch{'directorysrch'}{'cansearch'}) eq 'ARRAY') {
8752: foreach my $type (@usertypes) {
8753: if (grep(/^\Q$type\E$/,@{$dom_inst_srch{'directorysrch'}{'cansearch'}})) {
8754: $can_search = 1;
8755: last;
8756: }
8757: }
8758: }
8759: if (!$can_search) {
8760: my ($insttypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($srch->{'srchdomain'});
8761: my @longtypes;
8762: foreach my $item (@usertypes) {
1.229 raeburn 8763: if (defined($insttypes->{$item})) {
8764: push (@longtypes,$insttypes->{$item});
8765: } elsif ($item eq 'default') {
8766: push (@longtypes,&mt('other'));
8767: }
1.160 raeburn 8768: }
8769: my $insttype_str = join(', ',@longtypes);
1.180 raeburn 8770: return &mt('Institutional directory search in domain: [_1] is not available to your user type: ',$showdom).$insttype_str;
1.229 raeburn 8771: }
1.160 raeburn 8772: } else {
8773: $can_search = 1;
8774: }
8775: } else {
1.180 raeburn 8776: return &mt('Institutional directory search has not been configured for domain: [_1]',$showdom);
1.160 raeburn 8777: }
8778: my %longtext = &Apache::lonlocal::texthash (
1.167 albertel 8779: uname => 'username',
1.160 raeburn 8780: lastfirst => 'last name, first name',
1.167 albertel 8781: lastname => 'last name',
1.172 raeburn 8782: contains => 'contains',
1.178 raeburn 8783: exact => 'as exact match to',
8784: begins => 'begins with',
1.160 raeburn 8785: );
8786: if ($can_search) {
8787: if (ref($dom_inst_srch{'directorysrch'}{'searchby'}) eq 'ARRAY') {
8788: if (!grep(/^\Q$srch->{'srchby'}\E$/,@{$dom_inst_srch{'directorysrch'}{'searchby'}})) {
1.180 raeburn 8789: return &mt('Institutional directory search in domain: [_1] is not available for searching by "[_2]"',$showdom,$longtext{$srch->{'srchby'}});
1.160 raeburn 8790: }
8791: } else {
1.180 raeburn 8792: return &mt('Institutional directory search in domain: [_1] is not available.', $showdom);
1.160 raeburn 8793: }
8794: }
8795: if ($can_search) {
1.178 raeburn 8796: if (ref($dom_inst_srch{'directorysrch'}{'searchtypes'}) eq 'ARRAY') {
8797: if (grep(/^\Q$srch->{'srchtype'}\E/,@{$dom_inst_srch{'directorysrch'}{'searchtypes'}})) {
8798: return 'ok';
8799: } else {
1.180 raeburn 8800: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 8801: }
8802: } else {
8803: if ((($dom_inst_srch{'directorysrch'}{'searchtypes'} eq 'specify') &&
8804: ($srch->{'srchtype'} eq 'exact' || $srch->{'srchtype'} eq 'contains')) ||
8805: ($dom_inst_srch{'directorysrch'}{'searchtypes'} eq $srch->{'srchtype'})) {
8806: return 'ok';
8807: } else {
1.180 raeburn 8808: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 8809: }
1.160 raeburn 8810: }
8811: }
8812: }
8813:
8814: sub get_courseusers {
8815: my %advhash;
1.167 albertel 8816: my $classlist = &Apache::loncoursedata::get_classlist();
1.160 raeburn 8817: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles();
8818: foreach my $role (sort(keys(%coursepersonnel))) {
8819: foreach my $user (split(/\,/,$coursepersonnel{$role})) {
1.167 albertel 8820: if (!exists($classlist->{$user})) {
8821: $classlist->{$user} = [];
8822: }
1.160 raeburn 8823: }
8824: }
1.167 albertel 8825: return $classlist;
1.160 raeburn 8826: }
8827:
8828: sub build_search_response {
1.221 raeburn 8829: my ($context,$srch,%srch_results) = @_;
1.179 raeburn 8830: my ($currstate,$response,$forcenewuser);
1.160 raeburn 8831: my %names = (
1.330 bisitz 8832: 'uname' => 'username',
8833: 'lastname' => 'last name',
1.160 raeburn 8834: 'lastfirst' => 'last name, first name',
1.330 bisitz 8835: 'crs' => 'this course',
8836: 'dom' => 'LON-CAPA domain',
8837: 'instd' => 'the institutional directory for domain',
1.160 raeburn 8838: );
8839:
8840: my %single = (
1.180 raeburn 8841: begins => 'A match',
1.160 raeburn 8842: contains => 'A match',
1.180 raeburn 8843: exact => 'An exact match',
1.160 raeburn 8844: );
8845: my %nomatch = (
1.180 raeburn 8846: begins => 'No match',
1.160 raeburn 8847: contains => 'No match',
1.180 raeburn 8848: exact => 'No exact match',
1.160 raeburn 8849: );
8850: if (keys(%srch_results) > 1) {
1.179 raeburn 8851: $currstate = 'select';
1.160 raeburn 8852: } else {
8853: if (keys(%srch_results) == 1) {
1.406.2.5 raeburn 8854: if ($env{'form.action'} eq 'accesslogs') {
8855: $currstate = 'activity';
8856: } else {
8857: $currstate = 'modify';
8858: }
1.180 raeburn 8859: $response = &mt("$single{$srch->{'srchtype'}} was found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}.",$srch->{'srchterm'});
8860: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 8861: $response .= ': '.&display_domain_info($srch->{'srchdomain'});
1.180 raeburn 8862: }
1.330 bisitz 8863: } else { # Search has nothing found. Prepare message to user.
8864: $response = '<span class="LC_warning">';
1.180 raeburn 8865: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 8866: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}: [_2]",
8867: '<b>'.$srch->{'srchterm'}.'</b>',
8868: &display_domain_info($srch->{'srchdomain'}));
8869: } else {
8870: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}.",
8871: '<b>'.$srch->{'srchterm'}.'</b>');
1.180 raeburn 8872: }
8873: $response .= '</span>';
1.330 bisitz 8874:
1.160 raeburn 8875: if ($srch->{'srchin'} ne 'alc') {
8876: $forcenewuser = 1;
8877: my $cansrchinst = 0;
1.406.2.14 raeburn 8878: if (($srch->{'srchdomain'}) && ($env{'form.action'} ne 'accesslogs')) {
1.160 raeburn 8879: my %domconfig = &Apache::lonnet::get_dom('configuration',['directorysrch'],$srch->{'srchdomain'});
8880: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
8881: if ($domconfig{'directorysrch'}{'available'}) {
8882: $cansrchinst = 1;
8883: }
8884: }
8885: }
1.180 raeburn 8886: if ((($srch->{'srchby'} eq 'lastfirst') ||
8887: ($srch->{'srchby'} eq 'lastname')) &&
8888: ($srch->{'srchin'} eq 'dom')) {
8889: if ($cansrchinst) {
8890: $response .= '<br />'.&mt('You may want to broaden your search to a search of the institutional directory for the domain.');
1.160 raeburn 8891: }
8892: }
1.180 raeburn 8893: if ($srch->{'srchin'} eq 'crs') {
8894: $response .= '<br />'.&mt('You may want to broaden your search to the selected LON-CAPA domain.');
8895: }
8896: }
1.305 raeburn 8897: my $createdom = $env{'request.role.domain'};
8898: if ($context eq 'requestcrs') {
8899: if ($env{'form.coursedom'} ne '') {
8900: $createdom = $env{'form.coursedom'};
8901: }
8902: }
1.406.2.5 raeburn 8903: unless (($env{'form.action'} eq 'accesslogs') || (($srch->{'srchby'} eq 'uname') && ($srch->{'srchin'} eq 'dom') &&
8904: ($srch->{'srchtype'} eq 'exact') && ($srch->{'srchdomain'} eq $createdom))) {
1.221 raeburn 8905: my $cancreate =
1.305 raeburn 8906: &Apache::lonuserutils::can_create_user($createdom,$context);
8907: my $targetdom = '<span class="LC_cusr_emph">'.$createdom.'</span>';
1.221 raeburn 8908: if ($cancreate) {
1.305 raeburn 8909: my $showdom = &display_domain_info($createdom);
1.266 bisitz 8910: $response .= '<br /><br />'
8911: .'<b>'.&mt('To add a new user:').'</b>'
1.305 raeburn 8912: .'<br />';
8913: if ($context eq 'requestcrs') {
8914: $response .= &mt("(You can only define new users in the new course's domain - [_1])",$targetdom);
8915: } else {
8916: $response .= &mt("(You can only create new users in your current role's domain - [_1])",$targetdom);
8917: }
8918: $response .='<ul><li>'
1.266 bisitz 8919: .&mt("Set 'Domain/institution to search' to: [_1]",'<span class="LC_cusr_emph">'.$showdom.'</span>')
8920: .'</li><li>'
8921: .&mt("Set 'Search criteria' to: [_1]username is ..... in selected LON-CAPA domain[_2]",'<span class="LC_cusr_emph">','</span>')
8922: .'</li><li>'
8923: .&mt('Provide the proposed username')
8924: .'</li><li>'
8925: .&mt("Click 'Search'")
8926: .'</li></ul><br />';
1.221 raeburn 8927: } else {
1.406.2.7 raeburn 8928: unless (($context eq 'domain') && ($env{'form.action'} eq 'singleuser')) {
8929: my $helplink = ' href="javascript:helpMenu('."'display'".')"';
8930: $response .= '<br /><br />';
8931: if ($context eq 'requestcrs') {
8932: $response .= &mt("You are not authorized to define new users in the new course's domain - [_1].",$targetdom);
8933: } else {
8934: $response .= &mt("You are not authorized to create new users in your current role's domain - [_1].",$targetdom);
8935: }
8936: $response .= '<br />'
8937: .&mt('Please contact the [_1]helpdesk[_2] if you need to create a new user.'
8938: ,' <a'.$helplink.'>'
8939: ,'</a>')
8940: .'<br />';
1.305 raeburn 8941: }
1.221 raeburn 8942: }
1.160 raeburn 8943: }
8944: }
8945: }
1.179 raeburn 8946: return ($currstate,$response,$forcenewuser);
1.160 raeburn 8947: }
8948:
1.180 raeburn 8949: sub display_domain_info {
8950: my ($dom) = @_;
8951: my $output = $dom;
8952: if ($dom ne '') {
8953: my $domdesc = &Apache::lonnet::domain($dom,'description');
8954: if ($domdesc ne '') {
8955: $output .= ' <span class="LC_cusr_emph">('.$domdesc.')</span>';
8956: }
8957: }
8958: return $output;
8959: }
8960:
1.160 raeburn 8961: sub crumb_utilities {
8962: my %elements = (
8963: crtuser => {
8964: srchterm => 'text',
1.172 raeburn 8965: srchin => 'selectbox',
1.160 raeburn 8966: srchby => 'selectbox',
8967: srchtype => 'selectbox',
8968: srchdomain => 'selectbox',
8969: },
1.207 raeburn 8970: crtusername => {
8971: srchterm => 'text',
8972: srchdomain => 'selectbox',
8973: },
1.160 raeburn 8974: docustom => {
8975: rolename => 'selectbox',
8976: newrolename => 'textbox',
8977: },
1.179 raeburn 8978: studentform => {
8979: srchterm => 'text',
8980: srchin => 'selectbox',
8981: srchby => 'selectbox',
8982: srchtype => 'selectbox',
8983: srchdomain => 'selectbox',
8984: },
1.160 raeburn 8985: );
8986:
8987: my $jsback .= qq|
8988: function backPage(formname,prevphase,prevstate) {
1.211 raeburn 8989: if (typeof prevphase == 'undefined') {
8990: formname.phase.value = '';
8991: }
8992: else {
8993: formname.phase.value = prevphase;
8994: }
8995: if (typeof prevstate == 'undefined') {
8996: formname.currstate.value = '';
8997: }
8998: else {
8999: formname.currstate.value = prevstate;
9000: }
1.160 raeburn 9001: formname.submit();
9002: }
9003: |;
9004: return ($jsback,\%elements);
9005: }
9006:
1.26 matthew 9007: sub course_level_table {
1.375 raeburn 9008: my ($inccourses,$showcredits,$defaultcredits) = @_;
9009: return unless (ref($inccourses) eq 'HASH');
1.26 matthew 9010: my $table = '';
1.62 www 9011: # Custom Roles?
9012:
1.190 raeburn 9013: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.89 raeburn 9014: my %lt=&Apache::lonlocal::texthash(
9015: 'exs' => "Existing sections",
9016: 'new' => "Define new section",
9017: 'ssd' => "Set Start Date",
9018: 'sed' => "Set End Date",
1.131 raeburn 9019: 'crl' => "Course Level",
1.89 raeburn 9020: 'act' => "Activate",
9021: 'rol' => "Role",
9022: 'ext' => "Extent",
1.113 raeburn 9023: 'grs' => "Section",
1.375 raeburn 9024: 'crd' => "Credits",
1.89 raeburn 9025: 'sta' => "Start",
9026: 'end' => "End"
9027: );
1.62 www 9028:
1.375 raeburn 9029: foreach my $protectedcourse (sort(keys(%{$inccourses}))) {
1.135 raeburn 9030: my $thiscourse=$protectedcourse;
1.26 matthew 9031: $thiscourse=~s:_:/:g;
9032: my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
1.365 raeburn 9033: my $isowner = &Apache::lonuserutils::is_courseowner($protectedcourse,$coursedata{'internal.courseowner'});
1.26 matthew 9034: my $area=$coursedata{'description'};
1.321 raeburn 9035: my $crstype=$coursedata{'type'};
1.135 raeburn 9036: if (!defined($area)) { $area=&mt('Unavailable course').': '.$protectedcourse; }
1.89 raeburn 9037: my ($domain,$cnum)=split(/\//,$thiscourse);
1.115 albertel 9038: my %sections_count;
1.101 albertel 9039: if (defined($env{'request.course.id'})) {
9040: if ($env{'request.course.id'} eq $domain.'_'.$cnum) {
1.115 albertel 9041: %sections_count =
9042: &Apache::loncommon::get_sections($domain,$cnum);
1.92 raeburn 9043: }
9044: }
1.321 raeburn 9045: my @roles = &Apache::lonuserutils::roles_by_context('course','',$crstype);
1.213 raeburn 9046: foreach my $role (@roles) {
1.321 raeburn 9047: my $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.329 raeburn 9048: if ((&Apache::lonnet::allowed('c'.$role,$thiscourse)) ||
9049: ((($role eq 'cc') || ($role eq 'co')) && ($isowner))) {
1.221 raeburn 9050: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 9051: $plrole,\%sections_count,\%lt,
1.402 raeburn 9052: $showcredits,$defaultcredits,$crstype);
1.221 raeburn 9053: } elsif ($env{'request.course.sec'} ne '') {
9054: if (&Apache::lonnet::allowed('c'.$role,$thiscourse.'/'.
9055: $env{'request.course.sec'})) {
9056: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 9057: $plrole,\%sections_count,\%lt,
1.402 raeburn 9058: $showcredits,$defaultcredits,$crstype);
1.26 matthew 9059: }
9060: }
9061: }
1.221 raeburn 9062: if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
1.324 raeburn 9063: foreach my $cust (sort(keys(%customroles))) {
9064: next if ($crstype eq 'Community' && $customroles{$cust} =~ /bre\&S/);
1.221 raeburn 9065: my $role = 'cr_cr_'.$env{'user.domain'}.'_'.$env{'user.name'}.'_'.$cust;
9066: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.402 raeburn 9067: $cust,\%sections_count,\%lt,
9068: $showcredits,$defaultcredits,$crstype);
1.221 raeburn 9069: }
1.62 www 9070: }
1.26 matthew 9071: }
9072: return '' if ($table eq ''); # return nothing if there is nothing
9073: # in the table
1.188 raeburn 9074: my $result;
9075: if (!$env{'request.course.id'}) {
9076: $result = '<h4>'.$lt{'crl'}.'</h4>'."\n";
9077: }
9078: $result .=
1.136 raeburn 9079: &Apache::loncommon::start_data_table().
9080: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 9081: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
1.402 raeburn 9082: '<th>'.$lt{'ext'}.'</th><th>'."\n";
9083: if ($showcredits) {
9084: $result .= $lt{'crd'}.'</th>';
9085: }
9086: $result .=
1.375 raeburn 9087: '<th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th>'."\n".
9088: '<th>'.$lt{'end'}.'</th>'.
1.136 raeburn 9089: &Apache::loncommon::end_data_table_header_row().
9090: $table.
9091: &Apache::loncommon::end_data_table();
1.26 matthew 9092: return $result;
9093: }
1.88 raeburn 9094:
1.221 raeburn 9095: sub course_level_row {
1.375 raeburn 9096: my ($protectedcourse,$role,$area,$domain,$plrole,$sections_count,
1.402 raeburn 9097: $lt,$showcredits,$defaultcredits,$crstype) = @_;
1.375 raeburn 9098: my $creditem;
1.222 raeburn 9099: my $row = &Apache::loncommon::start_data_table_row().
9100: ' <td><input type="checkbox" name="act_'.
9101: $protectedcourse.'_'.$role.'" /></td>'."\n".
9102: ' <td>'.$plrole.'</td>'."\n".
9103: ' <td>'.$area.'<br />Domain: '.$domain.'</td>'."\n";
1.402 raeburn 9104: if (($showcredits) && ($role eq 'st') && ($crstype eq 'Course')) {
1.375 raeburn 9105: $row .=
9106: '<td><input type="text" name="credits_'.$protectedcourse.'_'.
9107: $role.'" size="3" value="'.$defaultcredits.'" /></td>';
9108: } else {
9109: $row .= '<td> </td>';
9110: }
1.322 raeburn 9111: if (($role eq 'cc') || ($role eq 'co')) {
1.222 raeburn 9112: $row .= '<td> </td>';
1.221 raeburn 9113: } elsif ($env{'request.course.sec'} ne '') {
1.222 raeburn 9114: $row .= ' <td><input type="hidden" value="'.
9115: $env{'request.course.sec'}.'" '.
9116: 'name="sec_'.$protectedcourse.'_'.$role.'" />'.
9117: $env{'request.course.sec'}.'</td>';
1.221 raeburn 9118: } else {
9119: if (ref($sections_count) eq 'HASH') {
9120: my $currsec =
9121: &Apache::lonuserutils::course_sections($sections_count,
9122: $protectedcourse.'_'.$role);
1.222 raeburn 9123: $row .= '<td><table class="LC_createuser">'."\n".
9124: '<tr class="LC_section_row">'."\n".
9125: ' <td valign="top">'.$lt->{'exs'}.'<br />'.
9126: $currsec.'</td>'."\n".
9127: ' <td> </td>'."\n".
9128: ' <td valign="top"> '.$lt->{'new'}.'<br />'.
1.221 raeburn 9129: '<input type="text" name="newsec_'.$protectedcourse.'_'.$role.
9130: '" value="" />'.
9131: '<input type="hidden" '.
9132: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n".
1.222 raeburn 9133: '</tr></table></td>'."\n";
1.221 raeburn 9134: } else {
1.222 raeburn 9135: $row .= '<td><input type="text" size="10" '.
1.375 raeburn 9136: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n";
1.221 raeburn 9137: }
9138: }
1.222 raeburn 9139: $row .= <<ENDTIMEENTRY;
9140: <td><input type="hidden" name="start_$protectedcourse\_$role" value="" />
1.221 raeburn 9141: <a href=
9142: "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 9143: <td><input type="hidden" name="end_$protectedcourse\_$role" value="" />
1.221 raeburn 9144: <a href=
9145: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$role.value,'end_$protectedcourse\_$role','cu.pres','dateset')">$lt->{'sed'}</a></td>
9146: ENDTIMEENTRY
1.222 raeburn 9147: $row .= &Apache::loncommon::end_data_table_row();
9148: return $row;
1.221 raeburn 9149: }
9150:
1.88 raeburn 9151: sub course_level_dc {
1.375 raeburn 9152: my ($dcdom,$showcredits) = @_;
1.190 raeburn 9153: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.213 raeburn 9154: my @roles = &Apache::lonuserutils::roles_by_context('course');
1.88 raeburn 9155: my $hiddenitems = '<input type="hidden" name="dcdomain" value="'.$dcdom.'" />'.
9156: '<input type="hidden" name="origdom" value="'.$dcdom.'" />'.
1.133 raeburn 9157: '<input type="hidden" name="dccourse" value="" />';
1.355 www 9158: my $courseform=&Apache::loncommon::selectcourse_link
1.356 raeburn 9159: ('cu','dccourse','dcdomain','coursedesc',undef,undef,'Select','crstype');
1.375 raeburn 9160: my $credit_elem;
9161: if ($showcredits) {
9162: $credit_elem = 'credits';
9163: }
9164: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,'currsec','cu','role','Course/Community Browser',$credit_elem);
1.88 raeburn 9165: my %lt=&Apache::lonlocal::texthash(
9166: 'rol' => "Role",
1.113 raeburn 9167: 'grs' => "Section",
1.88 raeburn 9168: 'exs' => "Existing sections",
9169: 'new' => "Define new section",
9170: 'sta' => "Start",
9171: 'end' => "End",
9172: 'ssd' => "Set Start Date",
1.355 www 9173: 'sed' => "Set End Date",
1.375 raeburn 9174: 'scc' => "Course/Community",
9175: 'crd' => "Credits",
1.88 raeburn 9176: );
1.323 raeburn 9177: my $header = '<h4>'.&mt('Course/Community Level').'</h4>'.
1.136 raeburn 9178: &Apache::loncommon::start_data_table().
9179: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 9180: '<th>'.$lt{'scc'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
1.397 bisitz 9181: '<th>'.$lt{'grs'}.'</th>'."\n";
9182: $header .= '<th>'.$lt{'crd'}.'</th>'."\n" if ($showcredits);
9183: $header .= '<th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'."\n".
1.136 raeburn 9184: &Apache::loncommon::end_data_table_header_row();
1.143 raeburn 9185: my $otheritems = &Apache::loncommon::start_data_table_row()."\n".
1.356 raeburn 9186: '<td><br /><span class="LC_nobreak"><input type="text" name="coursedesc" value="" onfocus="this.blur();opencrsbrowser('."'cu','dccourse','dcdomain','coursedesc','','','','crstype'".')" />'.
9187: $courseform.(' ' x4).'</span></td>'."\n".
1.389 bisitz 9188: '<td valign="top"><br /><select name="role">'."\n";
1.213 raeburn 9189: foreach my $role (@roles) {
1.135 raeburn 9190: my $plrole=&Apache::lonnet::plaintext($role);
1.389 bisitz 9191: $otheritems .= ' <option value="'.$role.'">'.$plrole.'</option>';
1.88 raeburn 9192: }
1.404 raeburn 9193: if ( keys(%customroles) > 0) {
9194: foreach my $cust (sort(keys(%customroles))) {
1.101 albertel 9195: my $custrole='cr_cr_'.$env{'user.domain'}.
1.135 raeburn 9196: '_'.$env{'user.name'}.'_'.$cust;
1.389 bisitz 9197: $otheritems .= ' <option value="'.$custrole.'">'.$cust.'</option>';
1.88 raeburn 9198: }
9199: }
9200: $otheritems .= '</select></td><td>'.
9201: '<table border="0" cellspacing="0" cellpadding="0">'.
9202: '<tr><td valign="top"><b>'.$lt{'exs'}.'</b><br /><select name="currsec">'.
1.389 bisitz 9203: ' <option value=""><--'.&mt('Pick course first').'</option></select></td>'.
1.88 raeburn 9204: '<td> </td>'.
9205: '<td valign="top"> <b>'.$lt{'new'}.'</b><br />'.
1.113 raeburn 9206: '<input type="text" name="newsec" value="" />'.
1.237 raeburn 9207: '<input type="hidden" name="section" value="" />'.
1.323 raeburn 9208: '<input type="hidden" name="groups" value="" />'.
9209: '<input type="hidden" name="crstype" value="" /></td>'.
1.375 raeburn 9210: '</tr></table></td>'."\n";
9211: if ($showcredits) {
9212: $otheritems .= '<td><br />'."\n".
1.397 bisitz 9213: '<input type="text" size="3" name="credits" value="" /></td>'."\n";
1.375 raeburn 9214: }
1.88 raeburn 9215: $otheritems .= <<ENDTIMEENTRY;
1.323 raeburn 9216: <td><br /><input type="hidden" name="start" value='' />
1.88 raeburn 9217: <a href=
9218: "javascript:pjump('date_start','Start Date',document.cu.start.value,'start','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.323 raeburn 9219: <td><br /><input type="hidden" name="end" value='' />
1.88 raeburn 9220: <a href=
9221: "javascript:pjump('date_end','End Date',document.cu.end.value,'end','cu.pres','dateset')">$lt{'sed'}</a></td>
9222: ENDTIMEENTRY
1.136 raeburn 9223: $otheritems .= &Apache::loncommon::end_data_table_row().
9224: &Apache::loncommon::end_data_table()."\n";
1.88 raeburn 9225: return $cb_jscript.$header.$hiddenitems.$otheritems;
9226: }
9227:
1.237 raeburn 9228: sub update_selfenroll_config {
1.400 raeburn 9229: my ($r,$cid,$cdom,$cnum,$context,$crstype,$currsettings) = @_;
1.398 raeburn 9230: return unless (ref($currsettings) eq 'HASH');
9231: my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles();
9232: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
1.237 raeburn 9233: my (%changes,%warning);
1.241 raeburn 9234: my $curr_types;
1.400 raeburn 9235: my %noedit;
9236: unless ($context eq 'domain') {
9237: %noedit = &get_noedit_fields($cdom,$cnum,$crstype,$row);
9238: }
1.237 raeburn 9239: if (ref($row) eq 'ARRAY') {
9240: foreach my $item (@{$row}) {
1.400 raeburn 9241: next if ($noedit{$item});
1.237 raeburn 9242: if ($item eq 'enroll_dates') {
9243: my (%currenrolldate,%newenrolldate);
9244: foreach my $type ('start','end') {
1.398 raeburn 9245: $currenrolldate{$type} = $currsettings->{'selfenroll_'.$type.'_date'};
1.237 raeburn 9246: $newenrolldate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_date');
9247: if ($newenrolldate{$type} ne $currenrolldate{$type}) {
9248: $changes{'internal.selfenroll_'.$type.'_date'} = $newenrolldate{$type};
9249: }
9250: }
9251: } elsif ($item eq 'access_dates') {
9252: my (%currdate,%newdate);
9253: foreach my $type ('start','end') {
1.398 raeburn 9254: $currdate{$type} = $currsettings->{'selfenroll_'.$type.'_access'};
1.237 raeburn 9255: $newdate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_access');
9256: if ($newdate{$type} ne $currdate{$type}) {
9257: $changes{'internal.selfenroll_'.$type.'_access'} = $newdate{$type};
9258: }
9259: }
1.241 raeburn 9260: } elsif ($item eq 'types') {
1.398 raeburn 9261: $curr_types = $currsettings->{'selfenroll_'.$item};
1.241 raeburn 9262: if ($env{'form.selfenroll_all'}) {
9263: if ($curr_types ne '*') {
9264: $changes{'internal.selfenroll_types'} = '*';
9265: } else {
9266: next;
9267: }
9268: } else {
1.249 raeburn 9269: my %currdoms;
1.241 raeburn 9270: my @entries = split(/;/,$curr_types);
9271: my @deletedoms = &Apache::loncommon::get_env_multiple('form.selfenroll_delete');
1.249 raeburn 9272: my @activations = &Apache::loncommon::get_env_multiple('form.selfenroll_activate');
1.241 raeburn 9273: my $newnum = 0;
1.249 raeburn 9274: my @latesttypes;
9275: foreach my $num (@activations) {
9276: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$num);
9277: if (@types > 0) {
1.241 raeburn 9278: @types = sort(@types);
9279: my $typestr = join(',',@types);
1.249 raeburn 9280: my $typedom = $env{'form.selfenroll_dom_'.$num};
9281: $latesttypes[$newnum] = $typedom.':'.$typestr;
9282: $currdoms{$typedom} = 1;
1.241 raeburn 9283: $newnum ++;
9284: }
9285: }
1.338 raeburn 9286: for (my $j=0; $j<$env{'form.selfenroll_types_total'}; $j++) {
9287: if ((!grep(/^$j$/,@deletedoms)) && (!grep(/^$j$/,@activations))) {
1.249 raeburn 9288: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$j);
9289: if (@types > 0) {
9290: @types = sort(@types);
9291: my $typestr = join(',',@types);
9292: my $typedom = $env{'form.selfenroll_dom_'.$j};
9293: $latesttypes[$newnum] = $typedom.':'.$typestr;
9294: $currdoms{$typedom} = 1;
9295: $newnum ++;
9296: }
9297: }
9298: }
9299: if ($env{'form.selfenroll_newdom'} ne '') {
9300: my $typedom = $env{'form.selfenroll_newdom'};
9301: if ((!defined($currdoms{$typedom})) &&
9302: (&Apache::lonnet::domain($typedom) ne '')) {
9303: my $typestr;
9304: my ($othertitle,$usertypes,$types) =
9305: &Apache::loncommon::sorted_inst_types($typedom);
9306: my $othervalue = 'any';
9307: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
9308: if (@{$types} > 0) {
1.257 raeburn 9309: my @esc_types = map { &escape($_); } @{$types};
1.249 raeburn 9310: $othervalue = 'other';
1.258 raeburn 9311: $typestr = join(',',(@esc_types,$othervalue));
1.249 raeburn 9312: }
9313: $typestr = $othervalue;
9314: } else {
9315: $typestr = $othervalue;
9316: }
9317: $latesttypes[$newnum] = $typedom.':'.$typestr;
9318: $newnum ++ ;
9319: }
9320: }
1.241 raeburn 9321: my $selfenroll_types = join(';',@latesttypes);
9322: if ($selfenroll_types ne $curr_types) {
9323: $changes{'internal.selfenroll_types'} = $selfenroll_types;
9324: }
9325: }
1.276 raeburn 9326: } elsif ($item eq 'limit') {
9327: my $newlimit = $env{'form.selfenroll_limit'};
9328: my $newcap = $env{'form.selfenroll_cap'};
9329: $newcap =~s/\s+//g;
1.398 raeburn 9330: my $currlimit = $currsettings->{'selfenroll_limit'};
1.276 raeburn 9331: $currlimit = 'none' if ($currlimit eq '');
1.398 raeburn 9332: my $currcap = $currsettings->{'selfenroll_cap'};
1.276 raeburn 9333: if ($newlimit ne $currlimit) {
9334: if ($newlimit ne 'none') {
9335: if ($newcap =~ /^\d+$/) {
9336: if ($newcap ne $currcap) {
9337: $changes{'internal.selfenroll_cap'} = $newcap;
9338: }
9339: $changes{'internal.selfenroll_limit'} = $newlimit;
9340: } else {
1.398 raeburn 9341: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.
9342: &mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
1.276 raeburn 9343: }
9344: } elsif ($currcap ne '') {
9345: $changes{'internal.selfenroll_cap'} = '';
9346: $changes{'internal.selfenroll_limit'} = $newlimit;
9347: }
9348: } elsif ($currlimit ne 'none') {
9349: if ($newcap =~ /^\d+$/) {
9350: if ($newcap ne $currcap) {
9351: $changes{'internal.selfenroll_cap'} = $newcap;
9352: }
9353: } else {
1.398 raeburn 9354: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.
9355: &mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
1.276 raeburn 9356: }
9357: }
9358: } elsif ($item eq 'approval') {
9359: my (@currnotified,@newnotified);
1.398 raeburn 9360: my $currapproval = $currsettings->{'selfenroll_approval'};
9361: my $currnotifylist = $currsettings->{'selfenroll_notifylist'};
1.276 raeburn 9362: if ($currnotifylist ne '') {
9363: @currnotified = split(/,/,$currnotifylist);
9364: @currnotified = sort(@currnotified);
9365: }
9366: my $newapproval = $env{'form.selfenroll_approval'};
9367: @newnotified = &Apache::loncommon::get_env_multiple('form.selfenroll_notify');
9368: @newnotified = sort(@newnotified);
9369: if ($newapproval ne $currapproval) {
9370: $changes{'internal.selfenroll_approval'} = $newapproval;
9371: if (!$newapproval) {
9372: if ($currnotifylist ne '') {
9373: $changes{'internal.selfenroll_notifylist'} = '';
9374: }
9375: } else {
9376: my @differences =
1.295 raeburn 9377: &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 9378: if (@differences > 0) {
9379: if (@newnotified > 0) {
9380: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
9381: } else {
9382: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
9383: }
9384: }
9385: }
9386: } else {
1.295 raeburn 9387: my @differences = &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 9388: if (@differences > 0) {
9389: if (@newnotified > 0) {
9390: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
9391: } else {
9392: $changes{'internal.selfenroll_notifylist'} = '';
9393: }
9394: }
9395: }
1.237 raeburn 9396: } else {
1.398 raeburn 9397: my $curr_val = $currsettings->{'selfenroll_'.$item};
1.237 raeburn 9398: my $newval = $env{'form.selfenroll_'.$item};
9399: if ($item eq 'section') {
9400: $newval = $env{'form.sections'};
1.241 raeburn 9401: if (defined($curr_groups{$newval})) {
1.237 raeburn 9402: $newval = $curr_val;
1.398 raeburn 9403: $warning{$item} = &mt('Section for self-enrolled users unchanged as the proposed section is a group').'<br />'.
9404: &mt('Group names and section names must be distinct');
1.237 raeburn 9405: } elsif ($newval eq 'all') {
9406: $newval = $curr_val;
1.274 bisitz 9407: $warning{$item} = &mt('Section for self-enrolled users unchanged, as "all" is a reserved section name.');
1.237 raeburn 9408: }
9409: if ($newval eq '') {
9410: $newval = 'none';
9411: }
9412: }
9413: if ($newval ne $curr_val) {
9414: $changes{'internal.selfenroll_'.$item} = $newval;
9415: }
1.241 raeburn 9416: }
1.237 raeburn 9417: }
9418: if (keys(%warning) > 0) {
9419: foreach my $item (@{$row}) {
9420: if (exists($warning{$item})) {
9421: $r->print($warning{$item}.'<br />');
9422: }
9423: }
9424: }
9425: if (keys(%changes) > 0) {
9426: my $putresult = &Apache::lonnet::put('environment',\%changes,$cdom,$cnum);
9427: if ($putresult eq 'ok') {
9428: if ((exists($changes{'internal.selfenroll_types'})) ||
9429: (exists($changes{'internal.selfenroll_start_date'})) ||
9430: (exists($changes{'internal.selfenroll_end_date'}))) {
9431: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',
9432: $cnum,undef,undef,'Course');
9433: my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
1.398 raeburn 9434: if (ref($crsinfo{$cid}) eq 'HASH') {
1.237 raeburn 9435: foreach my $item ('selfenroll_types','selfenroll_start_date','selfenroll_end_date') {
9436: if (exists($changes{'internal.'.$item})) {
1.398 raeburn 9437: $crsinfo{$cid}{$item} = $changes{'internal.'.$item};
1.237 raeburn 9438: }
9439: }
9440: my $crsputresult =
9441: &Apache::lonnet::courseidput($cdom,\%crsinfo,
9442: $chome,'notime');
9443: }
9444: }
9445: $r->print(&mt('The following changes were made to self-enrollment settings:').'<ul>');
9446: foreach my $item (@{$row}) {
9447: my $title = $item;
9448: if (ref($lt) eq 'HASH') {
9449: $title = $lt->{$item};
9450: }
9451: if ($item eq 'enroll_dates') {
9452: foreach my $type ('start','end') {
9453: if (exists($changes{'internal.selfenroll_'.$type.'_date'})) {
9454: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_date'});
1.244 bisitz 9455: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 9456: $title,$type,$newdate).'</li>');
9457: }
9458: }
9459: } elsif ($item eq 'access_dates') {
9460: foreach my $type ('start','end') {
9461: if (exists($changes{'internal.selfenroll_'.$type.'_access'})) {
9462: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_access'});
1.244 bisitz 9463: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 9464: $title,$type,$newdate).'</li>');
9465: }
9466: }
1.276 raeburn 9467: } elsif ($item eq 'limit') {
9468: if ((exists($changes{'internal.selfenroll_limit'})) ||
9469: (exists($changes{'internal.selfenroll_cap'}))) {
9470: my ($newval,$newcap);
9471: if ($changes{'internal.selfenroll_cap'} ne '') {
9472: $newcap = $changes{'internal.selfenroll_cap'}
9473: } else {
1.398 raeburn 9474: $newcap = $currsettings->{'selfenroll_cap'};
1.276 raeburn 9475: }
9476: if ($changes{'internal.selfenroll_limit'} eq 'none') {
9477: $newval = &mt('No limit');
9478: } elsif ($changes{'internal.selfenroll_limit'} eq
9479: 'allstudents') {
9480: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
9481: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
9482: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
9483: } else {
1.398 raeburn 9484: my $currlimit = $currsettings->{'selfenroll_limit'};
1.276 raeburn 9485: if ($currlimit eq 'allstudents') {
9486: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
9487: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
1.308 raeburn 9488: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
1.276 raeburn 9489: }
9490: }
9491: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
9492: }
9493: } elsif ($item eq 'approval') {
9494: if ((exists($changes{'internal.selfenroll_approval'})) ||
9495: (exists($changes{'internal.selfenroll_notifylist'}))) {
1.398 raeburn 9496: my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs();
1.276 raeburn 9497: my ($newval,$newnotify);
9498: if (exists($changes{'internal.selfenroll_notifylist'})) {
9499: $newnotify = $changes{'internal.selfenroll_notifylist'};
9500: } else {
1.398 raeburn 9501: $newnotify = $currsettings->{'selfenroll_notifylist'};
1.276 raeburn 9502: }
1.398 raeburn 9503: if (exists($changes{'internal.selfenroll_approval'})) {
9504: if ($changes{'internal.selfenroll_approval'} !~ /^[012]$/) {
9505: $changes{'internal.selfenroll_approval'} = '0';
9506: }
9507: $newval = $selfdescs{'approval'}{$changes{'internal.selfenroll_approval'}};
1.276 raeburn 9508: } else {
1.398 raeburn 9509: my $currapproval = $currsettings->{'selfenroll_approval'};
9510: if ($currapproval !~ /^[012]$/) {
9511: $currapproval = 0;
1.276 raeburn 9512: }
1.398 raeburn 9513: $newval = $selfdescs{'approval'}{$currapproval};
1.276 raeburn 9514: }
9515: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval));
9516: if ($newnotify) {
1.277 raeburn 9517: $r->print('<br />'.&mt('The following will be notified when an enrollment request needs approval, or has been approved: [_1].',$newnotify));
1.276 raeburn 9518: } else {
1.277 raeburn 9519: $r->print('<br />'.&mt('No notifications sent when an enrollment request needs approval, or has been approved.'));
1.276 raeburn 9520: }
9521: $r->print('</li>'."\n");
9522: }
1.237 raeburn 9523: } else {
9524: if (exists($changes{'internal.selfenroll_'.$item})) {
1.241 raeburn 9525: my $newval = $changes{'internal.selfenroll_'.$item};
9526: if ($item eq 'types') {
9527: if ($newval eq '') {
9528: $newval = &mt('None');
9529: } elsif ($newval eq '*') {
9530: $newval = &mt('Any user in any domain');
9531: }
1.245 raeburn 9532: } elsif ($item eq 'registered') {
9533: if ($newval eq '1') {
9534: $newval = &mt('Yes');
9535: } elsif ($newval eq '0') {
9536: $newval = &mt('No');
9537: }
1.241 raeburn 9538: }
1.244 bisitz 9539: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
1.237 raeburn 9540: }
9541: }
9542: }
9543: $r->print('</ul>');
1.398 raeburn 9544: if ($env{'course.'.$cid.'.description'} ne '') {
9545: my %newenvhash;
9546: foreach my $key (keys(%changes)) {
9547: $newenvhash{'course.'.$cid.'.'.$key} = $changes{$key};
9548: }
9549: &Apache::lonnet::appenv(\%newenvhash);
1.237 raeburn 9550: }
9551: } else {
1.398 raeburn 9552: $r->print(&mt('An error occurred when saving changes to self-enrollment settings in this course.').'<br />'.
9553: &mt('The error was: [_1].',$putresult));
1.237 raeburn 9554: }
9555: } else {
1.249 raeburn 9556: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.237 raeburn 9557: }
9558: } else {
1.249 raeburn 9559: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.241 raeburn 9560: }
1.400 raeburn 9561: my $visactions = &cat_visibility();
9562: my ($cathash,%cattype);
9563: my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
9564: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
9565: $cathash = $domconfig{'coursecategories'}{'cats'};
9566: $cattype{'auth'} = $domconfig{'coursecategories'}{'auth'};
9567: $cattype{'unauth'} = $domconfig{'coursecategories'}{'unauth'};
9568: } else {
9569: $cathash = {};
9570: $cattype{'auth'} = 'std';
9571: $cattype{'unauth'} = 'std';
9572: }
9573: if (($cattype{'auth'} eq 'none') && ($cattype{'unauth'} eq 'none')) {
9574: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
9575: '<br />'.
9576: '<br />'.$visactions->{'take'}.'<ul>'.
9577: '<li>'.$visactions->{'dc_chgconf'}.'</li>'.
9578: '</ul>');
9579: } elsif (($cattype{'auth'} !~ /^(std|domonly)$/) && ($cattype{'unauth'} !~ /^(std|domonly)$/)) {
9580: if ($currsettings->{'uniquecode'}) {
9581: $r->print('<span class="LC_info">'.$visactions->{'vis'}.'</span>');
9582: } else {
1.366 bisitz 9583: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
1.400 raeburn 9584: '<br />'.
9585: '<br />'.$visactions->{'take'}.'<ul>'.
9586: '<li>'.$visactions->{'dc_setcode'}.'</li>'.
9587: '</ul><br />');
9588: }
9589: } else {
9590: my ($visible,$cansetvis,$vismsgs) = &visible_in_stdcat($cdom,$cnum,\%domconfig);
9591: if (ref($visactions) eq 'HASH') {
9592: if (!$visible) {
9593: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
9594: '<br />');
9595: if (ref($vismsgs) eq 'ARRAY') {
9596: $r->print('<br />'.$visactions->{'take'}.'<ul>');
9597: foreach my $item (@{$vismsgs}) {
9598: $r->print('<li>'.$visactions->{$item}.'</li>');
9599: }
9600: $r->print('</ul>');
1.256 raeburn 9601: }
1.400 raeburn 9602: $r->print($cansetvis);
1.256 raeburn 9603: }
9604: }
9605: }
1.237 raeburn 9606: return;
9607: }
9608:
1.27 matthew 9609: #---------------------------------------------- end functions for &phase_two
1.29 matthew 9610:
9611: #--------------------------------- functions for &phase_two and &phase_three
9612:
9613: #--------------------------end of functions for &phase_two and &phase_three
1.372 raeburn 9614:
1.1 www 9615: 1;
9616: __END__
1.2 www 9617:
9618:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>