Annotation of loncom/interface/loncreateuser.pm, revision 1.406.2.22
1.20 harris41 1: # The LearningOnline Network with CAPA
1.1 www 2: # Create a user
3: #
1.406.2.22! raeburn 4: # $Id: loncreateuser.pm,v 1.406.2.21 2024/07/04 00:56:21 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",
247: 'avai' => "Available",
248: 'cusa' => "availability",
249: 'chse' => "Change setting",
250: 'usde' => "Use default",
251: 'uscu' => "Use custom",
252: 'official' => 'Can request creation of official courses',
1.299 raeburn 253: 'unofficial' => 'Can request creation of unofficial courses',
254: 'community' => 'Can request creation of communities',
1.384 raeburn 255: 'textbook' => 'Can request creation of textbook courses',
1.362 raeburn 256: 'requestauthor' => 'Can request author space',
1.275 raeburn 257: );
1.279 raeburn 258: if ($context eq 'requestcourses') {
1.275 raeburn 259: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
1.299 raeburn 260: 'requestcourses.official','requestcourses.unofficial',
1.384 raeburn 261: 'requestcourses.community','requestcourses.textbook');
262: @usertools = ('official','unofficial','community','textbook');
1.309 raeburn 263: @options =('norequest','approval','autolimit','validate');
1.306 raeburn 264: %validations = &Apache::lonnet::auto_courserequest_checks($ccdomain);
265: %reqtitles = &courserequest_titles();
266: %reqdisplay = &courserequest_display();
267: $colspan = ' colspan="2"';
1.332 raeburn 268: %domconfig =
269: &Apache::lonnet::get_dom('configuration',['requestcourses'],$ccdomain);
1.406.2.6 raeburn 270: $isadv = &Apache::lonnet::is_advanced_user($ccdomain,$ccuname);
1.362 raeburn 271: } elsif ($context eq 'requestauthor') {
272: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
273: 'requestauthor');
274: @usertools = ('requestauthor');
275: @options =('norequest','approval','automatic');
276: %reqtitles = &requestauthor_titles();
277: %reqdisplay = &requestauthor_display();
278: $colspan = ' colspan="2"';
279: %domconfig =
280: &Apache::lonnet::get_dom('configuration',['requestauthor'],$ccdomain);
1.275 raeburn 281: } else {
282: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
1.361 raeburn 283: 'tools.aboutme','tools.portfolio','tools.blog',
284: 'tools.webdav');
285: @usertools = ('aboutme','blog','webdav','portfolio');
1.275 raeburn 286: }
287: foreach my $item (@usertools) {
1.306 raeburn 288: my ($custom_access,$curr_access,$cust_on,$cust_off,$tool_on,$tool_off,
289: $currdisp,$custdisp,$custradio);
1.275 raeburn 290: $cust_off = 'checked="checked" ';
291: $tool_on = 'checked="checked" ';
292: $curr_access =
293: &Apache::lonnet::usertools_access($ccuname,$ccdomain,$item,undef,
294: $context);
1.362 raeburn 295: if ($context eq 'requestauthor') {
296: if ($userenv{$context} ne '') {
297: $cust_on = ' checked="checked" ';
298: $cust_off = '';
299: }
300: } elsif ($userenv{$context.'.'.$item} ne '') {
1.306 raeburn 301: $cust_on = ' checked="checked" ';
302: $cust_off = '';
303: }
304: if ($context eq 'requestcourses') {
305: if ($userenv{$context.'.'.$item} eq '') {
1.314 raeburn 306: $custom_access = &mt('Currently from default setting.');
1.306 raeburn 307: } else {
308: $custom_access = &mt('Currently from custom setting.');
1.275 raeburn 309: }
1.362 raeburn 310: } elsif ($context eq 'requestauthor') {
311: if ($userenv{$context} eq '') {
312: $custom_access = &mt('Currently from default setting.');
313: } else {
314: $custom_access = &mt('Currently from custom setting.');
315: }
1.275 raeburn 316: } else {
1.306 raeburn 317: if ($userenv{$context.'.'.$item} eq '') {
1.314 raeburn 318: $custom_access =
1.306 raeburn 319: &mt('Availability determined currently from default setting.');
320: if (!$curr_access) {
321: $tool_off = 'checked="checked" ';
322: $tool_on = '';
323: }
324: } else {
1.314 raeburn 325: $custom_access =
1.306 raeburn 326: &mt('Availability determined currently from custom setting.');
327: if ($userenv{$context.'.'.$item} == 0) {
328: $tool_off = 'checked="checked" ';
329: $tool_on = '';
330: }
1.275 raeburn 331: }
332: }
333: $output .= ' <tr class="LC_info_row">'."\n".
1.306 raeburn 334: ' <td'.$colspan.'>'.$lt{$item}.'</td>'."\n".
1.275 raeburn 335: ' </tr>'."\n".
1.306 raeburn 336: &Apache::loncommon::start_data_table_row()."\n";
1.362 raeburn 337: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.306 raeburn 338: my ($curroption,$currlimit);
1.362 raeburn 339: my $envkey = $context.'.'.$item;
340: if ($context eq 'requestauthor') {
341: $envkey = $context;
342: }
343: if ($userenv{$envkey} ne '') {
344: $curroption = $userenv{$envkey};
1.332 raeburn 345: } else {
346: my (@inststatuses);
1.362 raeburn 347: if ($context eq 'requestcourses') {
348: $curroption =
349: &Apache::loncoursequeueadmin::get_processtype('course',$ccuname,$ccdomain,
350: $isadv,$ccdomain,$item,
351: \@inststatuses,\%domconfig);
352: } else {
353: $curroption =
354: &Apache::loncoursequeueadmin::get_processtype('requestauthor',$ccuname,$ccdomain,
355: $isadv,$ccdomain,undef,
356: \@inststatuses,\%domconfig);
357: }
1.332 raeburn 358: }
1.306 raeburn 359: if (!$curroption) {
360: $curroption = 'norequest';
361: }
362: if ($curroption =~ /^autolimit=(\d*)$/) {
363: $currlimit = $1;
1.314 raeburn 364: if ($currlimit eq '') {
365: $currdisp = &mt('Yes, automatic creation');
366: } else {
367: $currdisp = &mt('Yes, up to [quant,_1,request]/user',$currlimit);
368: }
1.306 raeburn 369: } else {
370: $currdisp = $reqdisplay{$curroption};
371: }
372: $custdisp = '<table>';
373: foreach my $option (@options) {
374: my $val = $option;
375: if ($option eq 'norequest') {
376: $val = 0;
377: }
378: if ($option eq 'validate') {
379: my $canvalidate = 0;
380: if (ref($validations{$item}) eq 'HASH') {
381: if ($validations{$item}{'_custom_'}) {
382: $canvalidate = 1;
383: }
384: }
385: next if (!$canvalidate);
386: }
387: my $checked = '';
388: if ($option eq $curroption) {
389: $checked = ' checked="checked"';
390: } elsif ($option eq 'autolimit') {
391: if ($curroption =~ /^autolimit/) {
392: $checked = ' checked="checked"';
393: }
394: }
1.362 raeburn 395: my $name = 'crsreq_'.$item;
396: if ($context eq 'requestauthor') {
397: $name = $item;
398: }
1.306 raeburn 399: $custdisp .= '<tr><td><span class="LC_nobreak"><label>'.
1.362 raeburn 400: '<input type="radio" name="'.$name.'" '.
401: 'value="'.$val.'"'.$checked.' />'.
1.306 raeburn 402: $reqtitles{$option}.'</label> ';
403: if ($option eq 'autolimit') {
1.362 raeburn 404: $custdisp .= '<input type="text" name="'.$name.
405: '_limit" size="1" '.
1.314 raeburn 406: 'value="'.$currlimit.'" /></span><br />'.
407: $reqtitles{'unlimited'};
1.362 raeburn 408: } else {
409: $custdisp .= '</span>';
410: }
411: $custdisp .= '</td></tr>';
1.306 raeburn 412: }
413: $custdisp .= '</table>';
414: $custradio = '</span></td><td>'.&mt('Custom setting').'<br />'.$custdisp;
415: } else {
416: $currdisp = ($curr_access?&mt('Yes'):&mt('No'));
1.362 raeburn 417: my $name = $context.'_'.$item;
418: if ($context eq 'requestauthor') {
419: $name = $context;
420: }
1.306 raeburn 421: $custdisp = '<span class="LC_nobreak"><label>'.
1.362 raeburn 422: '<input type="radio" name="'.$name.'"'.
1.361 raeburn 423: ' value="1" '.$tool_on.'/>'.&mt('On').'</label> <label>'.
1.362 raeburn 424: '<input type="radio" name="'.$name.'" value="0" '.
1.306 raeburn 425: $tool_off.'/>'.&mt('Off').'</label></span>';
426: $custradio = (' 'x2).'--'.$lt{'cusa'}.': '.$custdisp.
427: '</span>';
428: }
429: $output .= ' <td'.$colspan.'>'.$custom_access.(' 'x4).
430: $lt{'avai'}.': '.$currdisp.'</td>'."\n".
1.406.2.6 raeburn 431: &Apache::loncommon::end_data_table_row()."\n";
432: unless (&Apache::lonnet::allowed('udp',$ccdomain)) {
433: $output .=
1.275 raeburn 434: &Apache::loncommon::start_data_table_row()."\n".
1.306 raeburn 435: ' <td style="vertical-align:top;"><span class="LC_nobreak">'.
436: $lt{'chse'}.': <label>'.
1.275 raeburn 437: '<input type="radio" name="custom'.$item.'" value="0" '.
1.306 raeburn 438: $cust_off.'/>'.$lt{'usde'}.'</label>'.(' ' x3).
439: '<label><input type="radio" name="custom'.$item.'" value="1" '.
440: $cust_on.'/>'.$lt{'uscu'}.'</label>'.$custradio.'</td>'.
1.275 raeburn 441: &Apache::loncommon::end_data_table_row()."\n";
1.406.2.6 raeburn 442: }
1.275 raeburn 443: }
444: return $output;
445: }
446:
1.300 raeburn 447: sub coursereq_externaluser {
448: my ($ccuname,$ccdomain,$cdom) = @_;
1.306 raeburn 449: my (@usertools,@options,%validations,%userenv,$output);
1.300 raeburn 450: my %lt = &Apache::lonlocal::texthash (
451: 'official' => 'Can request creation of official courses',
452: 'unofficial' => 'Can request creation of unofficial courses',
453: 'community' => 'Can request creation of communities',
1.384 raeburn 454: 'textbook' => 'Can request creation of textbook courses',
1.300 raeburn 455: );
456:
457: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
458: 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
1.384 raeburn 459: 'reqcrsotherdom.community','reqcrsotherdom.textbook');
460: @usertools = ('official','unofficial','community','textbook');
1.309 raeburn 461: @options = ('approval','validate','autolimit');
1.306 raeburn 462: %validations = &Apache::lonnet::auto_courserequest_checks($cdom);
463: my $optregex = join('|',@options);
464: my %reqtitles = &courserequest_titles();
1.300 raeburn 465: foreach my $item (@usertools) {
1.306 raeburn 466: my ($curroption,$currlimit,$tooloff);
1.300 raeburn 467: if ($userenv{'reqcrsotherdom.'.$item} ne '') {
468: my @curr = split(',',$userenv{'reqcrsotherdom.'.$item});
1.314 raeburn 469: foreach my $req (@curr) {
470: if ($req =~ /^\Q$cdom\E\:($optregex)=?(\d*)$/) {
471: $curroption = $1;
472: $currlimit = $2;
473: last;
1.306 raeburn 474: }
475: }
1.314 raeburn 476: if (!$curroption) {
477: $curroption = 'norequest';
478: $tooloff = ' checked="checked"';
479: }
1.306 raeburn 480: } else {
481: $curroption = 'norequest';
482: $tooloff = ' checked="checked"';
483: }
484: $output.= &Apache::loncommon::start_data_table_row()."\n".
1.314 raeburn 485: ' <td><span class="LC_nobreak">'.$lt{$item}.': </span></td><td>'.
486: '<table><tr><td valign="top">'."\n".
1.306 raeburn 487: '<label><input type="radio" name="reqcrsotherdom_'.$item.
1.314 raeburn 488: '" value=""'.$tooloff.' />'.$reqtitles{'norequest'}.
489: '</label></td>';
1.306 raeburn 490: foreach my $option (@options) {
491: if ($option eq 'validate') {
492: my $canvalidate = 0;
493: if (ref($validations{$item}) eq 'HASH') {
494: if ($validations{$item}{'_external_'}) {
495: $canvalidate = 1;
496: }
497: }
498: next if (!$canvalidate);
499: }
500: my $checked = '';
501: if ($option eq $curroption) {
502: $checked = ' checked="checked"';
503: }
1.314 raeburn 504: $output .= '<td valign="top"><span class="LC_nobreak"><label>'.
1.306 raeburn 505: '<input type="radio" name="reqcrsotherdom_'.$item.
506: '" value="'.$option.'"'.$checked.' />'.
1.314 raeburn 507: $reqtitles{$option}.'</label>';
1.306 raeburn 508: if ($option eq 'autolimit') {
1.314 raeburn 509: $output .= ' <input type="text" name="reqcrsotherdom_'.
1.306 raeburn 510: $item.'_limit" size="1" '.
1.314 raeburn 511: 'value="'.$currlimit.'" /></span>'.
512: '<br />'.$reqtitles{'unlimited'};
513: } else {
514: $output .= '</span>';
1.300 raeburn 515: }
1.314 raeburn 516: $output .= '</td>';
1.300 raeburn 517: }
1.314 raeburn 518: $output .= '</td></tr></table></td>'."\n".
1.300 raeburn 519: &Apache::loncommon::end_data_table_row()."\n";
520: }
521: return $output;
522: }
523:
1.362 raeburn 524: sub domainrole_req {
525: my ($ccuname,$ccdomain) = @_;
526: return '<br /><h3>'.
527: &mt('User Can Request Assignment of Domain Roles?').
528: '</h3>'."\n".
529: &Apache::loncommon::start_data_table().
530: &build_tools_display($ccuname,$ccdomain,
531: 'requestauthor').
532: &Apache::loncommon::end_data_table();
533: }
534:
1.306 raeburn 535: sub courserequest_titles {
536: my %titles = &Apache::lonlocal::texthash (
537: official => 'Official',
538: unofficial => 'Unofficial',
539: community => 'Communities',
1.384 raeburn 540: textbook => 'Textbook',
1.306 raeburn 541: norequest => 'Not allowed',
1.309 raeburn 542: approval => 'Approval by Dom. Coord.',
1.306 raeburn 543: validate => 'With validation',
544: autolimit => 'Numerical limit',
1.314 raeburn 545: unlimited => '(blank for unlimited)',
1.306 raeburn 546: );
547: return %titles;
548: }
549:
550: sub courserequest_display {
551: my %titles = &Apache::lonlocal::texthash (
1.309 raeburn 552: approval => 'Yes, need approval',
1.306 raeburn 553: validate => 'Yes, with validation',
554: norequest => 'No',
555: );
556: return %titles;
557: }
558:
1.362 raeburn 559: sub requestauthor_titles {
560: my %titles = &Apache::lonlocal::texthash (
561: norequest => 'Not allowed',
562: approval => 'Approval by Dom. Coord.',
563: automatic => 'Automatic approval',
564: );
565: return %titles;
566:
567: }
568:
569: sub requestauthor_display {
570: my %titles = &Apache::lonlocal::texthash (
571: approval => 'Yes, need approval',
572: automatic => 'Yes, automatic approval',
573: norequest => 'No',
574: );
575: return %titles;
576: }
577:
1.383 raeburn 578: sub requestchange_display {
579: my %titles = &Apache::lonlocal::texthash (
580: approval => "availability set to 'on' (approval required)",
581: automatic => "availability set to 'on' (automatic approval)",
582: norequest => "availability set to 'off'",
583: );
584: return %titles;
585: }
586:
1.362 raeburn 587: sub curr_requestauthor {
588: my ($uname,$udom,$isadv,$inststatuses,$domconfig) = @_;
589: return unless ((ref($inststatuses) eq 'ARRAY') && (ref($domconfig) eq 'HASH'));
590: if ($uname eq '' || $udom eq '') {
591: $uname = $env{'user.name'};
592: $udom = $env{'user.domain'};
593: $isadv = $env{'user.adv'};
594: }
595: my (%userenv,%settings,$val);
596: my @options = ('automatic','approval');
597: %userenv =
598: &Apache::lonnet::userenvironment($udom,$uname,'requestauthor','inststatus');
599: if ($userenv{'requestauthor'}) {
600: $val = $userenv{'requestauthor'};
601: @{$inststatuses} = ('_custom_');
602: } else {
603: my %alltasks;
604: if (ref($domconfig->{'requestauthor'}) eq 'HASH') {
605: %settings = %{$domconfig->{'requestauthor'}};
606: if (($isadv) && ($settings{'_LC_adv'} ne '')) {
607: $val = $settings{'_LC_adv'};
608: @{$inststatuses} = ('_LC_adv_');
609: } else {
610: if ($userenv{'inststatus'} ne '') {
611: @{$inststatuses} = split(',',$userenv{'inststatus'});
612: } else {
613: @{$inststatuses} = ('default');
614: }
615: foreach my $status (@{$inststatuses}) {
616: if (exists($settings{$status})) {
617: my $value = $settings{$status};
618: next unless ($value);
619: unless (exists($alltasks{$value})) {
620: if (ref($alltasks{$value}) eq 'ARRAY') {
621: unless(grep(/^\Q$status\E$/,@{$alltasks{$value}})) {
622: push(@{$alltasks{$value}},$status);
623: }
624: } else {
625: @{$alltasks{$value}} = ($status);
626: }
627: }
628: }
629: }
630: foreach my $option (@options) {
631: if ($alltasks{$option}) {
632: $val = $option;
633: last;
634: }
635: }
636: }
637: }
638: }
639: return $val;
640: }
641:
1.2 www 642: # =================================================================== Phase one
1.1 www 643:
1.42 matthew 644: sub print_username_entry_form {
1.406.2.14 raeburn 645: my ($r,$context,$response,$srch,$forcenewuser,$crstype,$brcrum,
646: $permission) = @_;
1.101 albertel 647: my $defdom=$env{'request.role.domain'};
1.160 raeburn 648: my $formtoset = 'crtuser';
649: if (exists($env{'form.startrolename'})) {
650: $formtoset = 'docustom';
651: $env{'form.rolename'} = $env{'form.startrolename'};
1.207 raeburn 652: } elsif ($env{'form.origform'} eq 'crtusername') {
653: $formtoset = $env{'form.origform'};
1.160 raeburn 654: }
655:
656: my ($jsback,$elements) = &crumb_utilities();
657:
658: my $jscript = &Apache::loncommon::studentbrowser_javascript()."\n".
1.165 albertel 659: '<script type="text/javascript">'."\n".
1.301 bisitz 660: '// <![CDATA['."\n".
661: &Apache::lonhtmlcommon::set_form_elements($elements->{$formtoset})."\n".
662: '// ]]>'."\n".
1.162 raeburn 663: '</script>'."\n";
1.160 raeburn 664:
1.324 raeburn 665: my %existingroles=&Apache::lonuserutils::my_custom_roles($crstype);
666: if (($env{'form.action'} eq 'custom') && (keys(%existingroles) > 0)
667: && (&Apache::lonnet::allowed('mcr','/'))) {
668: $jscript .= &customrole_javascript();
669: }
1.224 raeburn 670: my $helpitem = 'Course_Change_Privileges';
671: if ($env{'form.action'} eq 'custom') {
1.406.2.14 raeburn 672: if ($context eq 'course') {
673: $helpitem = 'Course_Editing_Custom_Roles';
674: } elsif ($context eq 'domain') {
675: $helpitem = 'Domain_Editing_Custom_Roles';
676: }
1.224 raeburn 677: } elsif ($env{'form.action'} eq 'singlestudent') {
678: $helpitem = 'Course_Add_Student';
1.406.2.5 raeburn 679: } elsif ($env{'form.action'} eq 'accesslogs') {
680: $helpitem = 'Domain_User_Access_Logs';
1.406.2.14 raeburn 681: } elsif ($context eq 'author') {
682: $helpitem = 'Author_Change_Privileges';
683: } elsif ($context eq 'domain') {
684: if ($permission->{'cusr'}) {
685: $helpitem = 'Domain_Change_Privileges';
686: } elsif ($permission->{'view'}) {
687: $helpitem = 'Domain_View_Privileges';
688: } else {
689: undef($helpitem);
690: }
1.224 raeburn 691: }
1.406.2.7 raeburn 692: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$defdom);
1.351 raeburn 693: if ($env{'form.action'} eq 'custom') {
694: push(@{$brcrum},
695: {href=>"javascript:backPage(document.crtuser)",
696: text=>"Pick custom role",
697: help => $helpitem,}
698: );
699: } else {
700: push (@{$brcrum},
701: {href => "javascript:backPage(document.crtuser)",
702: text => $breadcrumb_text{'search'},
703: help => $helpitem,
704: faq => 282,
705: bug => 'Instructor Interface',}
706: );
707: }
708: my %loaditems = (
709: 'onload' => "javascript:setFormElements(document.$formtoset)",
710: );
711: my $args = {bread_crumbs => $brcrum,
712: bread_crumbs_component => 'User Management',
713: add_entries => \%loaditems,};
714: $r->print(&Apache::loncommon::start_page('User Management',$jscript,$args));
715:
1.71 sakharuk 716: my %lt=&Apache::lonlocal::texthash(
1.229 raeburn 717: 'srst' => 'Search for a user and enroll as a student',
1.318 raeburn 718: 'srme' => 'Search for a user and enroll as a member',
1.229 raeburn 719: 'srad' => 'Search for a user and modify/add user information or roles',
1.406.2.7 raeburn 720: 'srvu' => 'Search for a user and view user information and roles',
1.406.2.5 raeburn 721: 'srva' => 'Search for a user and view access log information',
1.71 sakharuk 722: 'usr' => "Username",
723: 'dom' => "Domain",
1.324 raeburn 724: 'ecrp' => "Define or Edit Custom Role",
725: 'nr' => "role name",
1.282 schafran 726: 'cre' => "Next",
1.71 sakharuk 727: );
1.351 raeburn 728:
1.214 raeburn 729: if ($env{'form.action'} eq 'custom') {
1.190 raeburn 730: if (&Apache::lonnet::allowed('mcr','/')) {
1.324 raeburn 731: my $newroletext = &mt('Define new custom role:');
732: $r->print('<form action="/adm/createuser" method="post" name="docustom">'.
733: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
734: '<input type="hidden" name="phase" value="selected_custom_edit" />'.
735: '<h3>'.$lt{'ecrp'}.'</h3>'.
736: &Apache::loncommon::start_data_table().
737: &Apache::loncommon::start_data_table_row().
738: '<td>');
739: if (keys(%existingroles) > 0) {
740: $r->print('<br /><label><input type="radio" name="customroleaction" value="new" checked="checked" onclick="setCustomFields();" /><b>'.$newroletext.'</b></label>');
741: } else {
742: $r->print('<br /><input type="hidden" name="customroleaction" value="new" /><b>'.$newroletext.'</b>');
743: }
744: $r->print('</td><td align="center">'.$lt{'nr'}.'<br /><input type="text" size="15" name="newrolename" onfocus="setCustomAction('."'new'".');" /></td>'.
745: &Apache::loncommon::end_data_table_row());
746: if (keys(%existingroles) > 0) {
747: $r->print(&Apache::loncommon::start_data_table_row().'<td><br />'.
748: '<label><input type="radio" name="customroleaction" value="edit" onclick="setCustomFields();"/><b>'.
749: &mt('View/Modify existing role:').'</b></label></td>'.
750: '<td align="center"><br />'.
751: '<select name="rolename" onchange="setCustomAction('."'edit'".');">'.
1.326 raeburn 752: '<option value="" selected="selected">'.
1.324 raeburn 753: &mt('Select'));
754: foreach my $role (sort(keys(%existingroles))) {
1.326 raeburn 755: $r->print('<option value="'.$role.'">'.$role.'</option>');
1.324 raeburn 756: }
757: $r->print('</select>'.
758: '</td>'.
759: &Apache::loncommon::end_data_table_row());
760: }
761: $r->print(&Apache::loncommon::end_data_table().'<p>'.
762: '<input name="customeditor" type="submit" value="'.
763: $lt{'cre'}.'" /></p>'.
764: '</form>');
1.190 raeburn 765: }
1.213 raeburn 766: } else {
1.229 raeburn 767: my $actiontext = $lt{'srad'};
1.406.2.13 raeburn 768: my $fixeddom;
1.213 raeburn 769: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 770: if ($crstype eq 'Community') {
771: $actiontext = $lt{'srme'};
772: } else {
773: $actiontext = $lt{'srst'};
774: }
1.406.2.5 raeburn 775: } elsif ($env{'form.action'} eq 'accesslogs') {
776: $actiontext = $lt{'srva'};
1.406.2.13 raeburn 777: $fixeddom = 1;
1.406.2.7 raeburn 778: } elsif (($env{'form.action'} eq 'singleuser') &&
779: ($context eq 'domain') && (!&Apache::lonnet::allowed('mau',$defdom))) {
780: $actiontext = $lt{'srvu'};
1.406.2.14 raeburn 781: $fixeddom = 1;
1.213 raeburn 782: }
1.324 raeburn 783: $r->print("<h3>$actiontext</h3>");
1.213 raeburn 784: if ($env{'form.origform'} ne 'crtusername') {
1.406.2.5 raeburn 785: if ($response) {
786: $r->print("\n<div>$response</div>".
787: '<br clear="all" />');
788: }
1.213 raeburn 789: }
1.406.2.13 raeburn 790: $r->print(&entry_form($defdom,$srch,$forcenewuser,$context,$response,$crstype,$fixeddom));
1.107 www 791: }
1.110 albertel 792: }
793:
1.324 raeburn 794: sub customrole_javascript {
795: my $js = <<"END";
796: <script type="text/javascript">
797: // <![CDATA[
798:
799: function setCustomFields() {
800: if (document.docustom.customroleaction.length > 0) {
801: for (var i=0; i<document.docustom.customroleaction.length; i++) {
802: if (document.docustom.customroleaction[i].checked) {
803: if (document.docustom.customroleaction[i].value == 'new') {
804: document.docustom.rolename.selectedIndex = 0;
805: } else {
806: document.docustom.newrolename.value = '';
807: }
808: }
809: }
810: }
811: return;
812: }
813:
814: function setCustomAction(caller) {
815: if (document.docustom.customroleaction.length > 0) {
816: for (var i=0; i<document.docustom.customroleaction.length; i++) {
817: if (document.docustom.customroleaction[i].value == caller) {
818: document.docustom.customroleaction[i].checked = true;
819: }
820: }
821: }
822: setCustomFields();
823: return;
824: }
825:
826: // ]]>
827: </script>
828: END
829: return $js;
830: }
831:
1.160 raeburn 832: sub entry_form {
1.406.2.5 raeburn 833: my ($dom,$srch,$forcenewuser,$context,$responsemsg,$crstype,$fixeddom) = @_;
1.229 raeburn 834: my ($usertype,$inexact);
1.214 raeburn 835: if (ref($srch) eq 'HASH') {
836: if (($srch->{'srchin'} eq 'dom') &&
837: ($srch->{'srchby'} eq 'uname') &&
838: ($srch->{'srchtype'} eq 'exact') &&
839: ($srch->{'srchdomain'} ne '') &&
840: ($srch->{'srchterm'} ne '')) {
1.353 raeburn 841: my (%curr_rules,%got_rules);
1.214 raeburn 842: my ($rules,$ruleorder) =
843: &Apache::lonnet::inst_userrules($srch->{'srchdomain'},'username');
1.353 raeburn 844: $usertype = &Apache::lonuserutils::check_usertype($srch->{'srchdomain'},$srch->{'srchterm'},$rules,\%curr_rules,\%got_rules);
1.229 raeburn 845: } else {
846: $inexact = 1;
1.214 raeburn 847: }
1.207 raeburn 848: }
1.406.2.14 raeburn 849: my ($cancreate,$noinstd);
850: if ($env{'form.action'} eq 'accesslogs') {
851: $noinstd = 1;
852: } else {
853: $cancreate =
854: &Apache::lonuserutils::can_create_user($dom,$context,$usertype);
855: }
1.406.2.3 raeburn 856: my ($userpicker,$cansearch) =
1.179 raeburn 857: &Apache::loncommon::user_picker($dom,$srch,$forcenewuser,
1.406.2.14 raeburn 858: 'document.crtuser',$cancreate,$usertype,$context,$fixeddom,$noinstd);
1.160 raeburn 859: my $srchbutton = &mt('Search');
1.229 raeburn 860: if ($env{'form.action'} eq 'singlestudent') {
861: $srchbutton = &mt('Search and Enroll');
1.406.2.5 raeburn 862: } elsif ($env{'form.action'} eq 'accesslogs') {
863: $srchbutton = &mt('Search');
1.229 raeburn 864: } elsif ($cancreate && $responsemsg ne '' && $inexact) {
865: $srchbutton = &mt('Search or Add New User');
866: }
1.406.2.3 raeburn 867: my $output;
868: if ($cansearch) {
869: $output = <<"ENDBLOCK";
1.160 raeburn 870: <form action="/adm/createuser" method="post" name="crtuser">
1.190 raeburn 871: <input type="hidden" name="action" value="$env{'form.action'}" />
1.160 raeburn 872: <input type="hidden" name="phase" value="get_user_info" />
873: $userpicker
1.179 raeburn 874: <input name="userrole" type="button" value="$srchbutton" onclick="javascript:validateEntry(document.crtuser)" />
1.160 raeburn 875: </form>
1.207 raeburn 876: ENDBLOCK
1.406.2.3 raeburn 877: } else {
878: $output = '<p>'.$userpicker.'</p>';
879: }
1.406.2.7 raeburn 880: if (($env{'form.phase'} eq '') && ($env{'form.action'} ne 'accesslogs') &&
881: (!(($env{'form.action'} eq 'singleuser') && ($context eq 'domain') &&
882: (!&Apache::lonnet::allowed('mau',$env{'request.role.domain'}))))) {
1.207 raeburn 883: my $defdom=$env{'request.role.domain'};
884: my $domform = &Apache::loncommon::select_dom_form($defdom,'srchdomain');
885: my %lt=&Apache::lonlocal::texthash(
1.229 raeburn 886: 'enro' => 'Enroll one student',
1.318 raeburn 887: 'enrm' => 'Enroll one member',
1.229 raeburn 888: 'admo' => 'Add/modify a single user',
889: 'crea' => 'create new user if required',
890: 'uskn' => "username is known",
1.207 raeburn 891: 'crnu' => 'Create a new user',
892: 'usr' => 'Username',
893: 'dom' => 'in domain',
1.229 raeburn 894: 'enrl' => 'Enroll',
895: 'cram' => 'Create/Modify user',
1.207 raeburn 896: );
1.229 raeburn 897: my $sellink=&Apache::loncommon::selectstudent_link('crtusername','srchterm','srchdomain');
898: my ($title,$buttontext,$showresponse);
1.318 raeburn 899: if ($env{'form.action'} eq 'singlestudent') {
900: if ($crstype eq 'Community') {
901: $title = $lt{'enrm'};
902: } else {
903: $title = $lt{'enro'};
904: }
1.229 raeburn 905: $buttontext = $lt{'enrl'};
906: } else {
907: $title = $lt{'admo'};
908: $buttontext = $lt{'cram'};
909: }
910: if ($cancreate) {
911: $title .= ' <span class="LC_cusr_subheading">('.$lt{'crea'}.')</span>';
912: } else {
913: $title .= ' <span class="LC_cusr_subheading">('.$lt{'uskn'}.')</span>';
914: }
915: if ($env{'form.origform'} eq 'crtusername') {
916: $showresponse = $responsemsg;
917: }
1.207 raeburn 918: $output .= <<"ENDDOCUMENT";
1.229 raeburn 919: <br />
1.207 raeburn 920: <form action="/adm/createuser" method="post" name="crtusername">
921: <input type="hidden" name="action" value="$env{'form.action'}" />
922: <input type="hidden" name="phase" value="createnewuser" />
923: <input type="hidden" name="srchtype" value="exact" />
1.233 raeburn 924: <input type="hidden" name="srchby" value="uname" />
1.207 raeburn 925: <input type="hidden" name="srchin" value="dom" />
926: <input type="hidden" name="forcenewuser" value="1" />
927: <input type="hidden" name="origform" value="crtusername" />
1.229 raeburn 928: <h3>$title</h3>
929: $showresponse
1.207 raeburn 930: <table>
931: <tr>
932: <td>$lt{'usr'}:</td>
933: <td><input type="text" size="15" name="srchterm" /></td>
934: <td> $lt{'dom'}:</td><td>$domform</td>
1.229 raeburn 935: <td> $sellink </td>
936: <td> <input name="userrole" type="submit" value="$buttontext" /></td>
1.207 raeburn 937: </tr>
938: </table>
939: </form>
1.160 raeburn 940: ENDDOCUMENT
1.207 raeburn 941: }
1.160 raeburn 942: return $output;
943: }
1.110 albertel 944:
945: sub user_modification_js {
1.113 raeburn 946: my ($pjump_def,$dc_setcourse_code,$nondc_setsection_code,$groupslist)=@_;
947:
1.110 albertel 948: return <<END;
949: <script type="text/javascript" language="Javascript">
1.301 bisitz 950: // <![CDATA[
1.314 raeburn 951:
1.110 albertel 952: $pjump_def
953: $dc_setcourse_code
954:
955: function dateset() {
956: eval("document.cu."+document.cu.pres_marker.value+
957: ".value=document.cu.pres_value.value");
1.359 www 958: modalWindow.close();
1.110 albertel 959: }
960:
1.113 raeburn 961: $nondc_setsection_code
1.301 bisitz 962: // ]]>
1.110 albertel 963: </script>
964: END
1.2 www 965: }
966:
967: # =================================================================== Phase two
1.160 raeburn 968: sub print_user_selection_page {
1.351 raeburn 969: my ($r,$response,$srch,$srch_results,$srcharray,$context,$opener_elements,$crstype,$brcrum) = @_;
1.160 raeburn 970: my @fields = ('username','domain','lastname','firstname','permanentemail');
971: my $sortby = $env{'form.sortby'};
972:
973: if (!grep(/^\Q$sortby\E$/,@fields)) {
974: $sortby = 'lastname';
975: }
976:
977: my ($jsback,$elements) = &crumb_utilities();
978:
979: my $jscript = (<<ENDSCRIPT);
980: <script type="text/javascript">
1.301 bisitz 981: // <![CDATA[
1.160 raeburn 982: function pickuser(uname,udom) {
983: document.usersrchform.seluname.value=uname;
984: document.usersrchform.seludom.value=udom;
985: document.usersrchform.phase.value="userpicked";
986: document.usersrchform.submit();
987: }
988:
989: $jsback
1.301 bisitz 990: // ]]>
1.160 raeburn 991: </script>
992: ENDSCRIPT
993:
994: my %lt=&Apache::lonlocal::texthash(
1.179 raeburn 995: 'usrch' => "User Search to add/modify roles",
996: 'stusrch' => "User Search to enroll student",
1.318 raeburn 997: 'memsrch' => "User Search to enroll member",
1.406.2.5 raeburn 998: 'srcva' => "Search for a user and view access log information",
1.406.2.7 raeburn 999: 'usrvu' => "User Search to view user roles",
1.179 raeburn 1000: 'usel' => "Select a user to add/modify roles",
1.406.2.7 raeburn 1001: 'suvr' => "Select a user to view roles",
1.318 raeburn 1002: 'stusel' => "Select a user to enroll as a student",
1003: 'memsel' => "Select a user to enroll as a member",
1.406.2.5 raeburn 1004: 'vacsel' => "Select a user to view access log",
1.160 raeburn 1005: 'username' => "username",
1006: 'domain' => "domain",
1007: 'lastname' => "last name",
1008: 'firstname' => "first name",
1009: 'permanentemail' => "permanent e-mail",
1010: );
1.302 raeburn 1011: if ($context eq 'requestcrs') {
1012: $r->print('<div>');
1013: } else {
1.406.2.7 raeburn 1014: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$srch->{'srchdomain'});
1.351 raeburn 1015: my $helpitem;
1016: if ($env{'form.action'} eq 'singleuser') {
1017: $helpitem = 'Course_Change_Privileges';
1018: } elsif ($env{'form.action'} eq 'singlestudent') {
1019: $helpitem = 'Course_Add_Student';
1.406.2.14 raeburn 1020: } elsif ($context eq 'author') {
1021: $helpitem = 'Author_Change_Privileges';
1022: } elsif ($context eq 'domain') {
1023: $helpitem = 'Domain_Change_Privileges';
1.351 raeburn 1024: }
1025: push (@{$brcrum},
1026: {href => "javascript:backPage(document.usersrchform,'','')",
1027: text => $breadcrumb_text{'search'},
1028: faq => 282,
1029: bug => 'Instructor Interface',},
1030: {href => "javascript:backPage(document.usersrchform,'get_user_info','select')",
1031: text => $breadcrumb_text{'userpicked'},
1032: faq => 282,
1033: bug => 'Instructor Interface',
1034: help => $helpitem}
1035: );
1036: $r->print(&Apache::loncommon::start_page('User Management',$jscript,{bread_crumbs => $brcrum}));
1.302 raeburn 1037: if ($env{'form.action'} eq 'singleuser') {
1.406.2.7 raeburn 1038: my $readonly;
1039: if (($context eq 'domain') && (!&Apache::lonnet::allowed('mau',$srch->{'srchdomain'}))) {
1040: $readonly = 1;
1041: $r->print("<b>$lt{'usrvu'}</b><br />");
1042: } else {
1043: $r->print("<b>$lt{'usrch'}</b><br />");
1044: }
1.318 raeburn 1045: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,$crstype));
1.406.2.7 raeburn 1046: if ($readonly) {
1047: $r->print('<h3>'.$lt{'suvr'}.'</h3>');
1048: } else {
1049: $r->print('<h3>'.$lt{'usel'}.'</h3>');
1050: }
1.302 raeburn 1051: } elsif ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1052: $r->print($jscript."<b>");
1053: if ($crstype eq 'Community') {
1054: $r->print($lt{'memsrch'});
1055: } else {
1056: $r->print($lt{'stusrch'});
1057: }
1058: $r->print("</b><br />");
1059: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,$crstype));
1060: $r->print('</form><h3>');
1061: if ($crstype eq 'Community') {
1062: $r->print($lt{'memsel'});
1063: } else {
1064: $r->print($lt{'stusel'});
1065: }
1066: $r->print('</h3>');
1.406.2.5 raeburn 1067: } elsif ($env{'form.action'} eq 'accesslogs') {
1068: $r->print("<b>$lt{'srcva'}</b><br />");
1.406.2.14 raeburn 1069: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,undef,1));
1.406.2.5 raeburn 1070: $r->print('<h3>'.$lt{'vacsel'}.'</h3>');
1.302 raeburn 1071: }
1.179 raeburn 1072: }
1.380 bisitz 1073: $r->print('<form name="usersrchform" method="post" action="">'.
1.160 raeburn 1074: &Apache::loncommon::start_data_table()."\n".
1075: &Apache::loncommon::start_data_table_header_row()."\n".
1076: ' <th> </th>'."\n");
1077: foreach my $field (@fields) {
1078: $r->print(' <th><a href="javascript:document.usersrchform.sortby.value='.
1079: "'".$field."'".';document.usersrchform.submit();">'.
1080: $lt{$field}.'</a></th>'."\n");
1081: }
1082: $r->print(&Apache::loncommon::end_data_table_header_row());
1083:
1084: my @sorted_users = sort {
1.167 albertel 1085: lc($srch_results->{$a}->{$sortby}) cmp lc($srch_results->{$b}->{$sortby})
1.160 raeburn 1086: ||
1.167 albertel 1087: lc($srch_results->{$a}->{lastname}) cmp lc($srch_results->{$b}->{lastname})
1.160 raeburn 1088: ||
1089: lc($srch_results->{$a}->{firstname}) cmp lc($srch_results->{$b}->{firstname})
1.167 albertel 1090: ||
1091: lc($a) cmp lc($b)
1.160 raeburn 1092: } (keys(%$srch_results));
1093:
1094: foreach my $user (@sorted_users) {
1095: my ($uname,$udom) = split(/:/,$user);
1.302 raeburn 1096: my $onclick;
1097: if ($context eq 'requestcrs') {
1.314 raeburn 1098: $onclick =
1.302 raeburn 1099: 'onclick="javascript:gochoose('."'$uname','$udom',".
1100: "'$srch_results->{$user}->{firstname}',".
1101: "'$srch_results->{$user}->{lastname}',".
1102: "'$srch_results->{$user}->{permanentemail}'".');"';
1103: } else {
1.314 raeburn 1104: $onclick =
1.302 raeburn 1105: ' onclick="javascript:pickuser('."'".$uname."'".','."'".$udom."'".');"';
1106: }
1.160 raeburn 1107: $r->print(&Apache::loncommon::start_data_table_row().
1.302 raeburn 1108: '<td><input type="button" name="seluser" value="'.&mt('Select').'" '.
1109: $onclick.' /></td>'.
1.160 raeburn 1110: '<td><tt>'.$uname.'</tt></td>'.
1111: '<td><tt>'.$udom.'</tt></td>');
1112: foreach my $field ('lastname','firstname','permanentemail') {
1113: $r->print('<td>'.$srch_results->{$user}->{$field}.'</td>');
1114: }
1115: $r->print(&Apache::loncommon::end_data_table_row());
1116: }
1117: $r->print(&Apache::loncommon::end_data_table().'<br /><br />');
1.179 raeburn 1118: if (ref($srcharray) eq 'ARRAY') {
1119: foreach my $item (@{$srcharray}) {
1120: $r->print('<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n");
1121: }
1122: }
1.160 raeburn 1123: $r->print(' <input type="hidden" name="sortby" value="'.$sortby.'" />'."\n".
1124: ' <input type="hidden" name="seluname" value="" />'."\n".
1125: ' <input type="hidden" name="seludom" value="" />'."\n".
1.179 raeburn 1126: ' <input type="hidden" name="currstate" value="select" />'."\n".
1.190 raeburn 1127: ' <input type="hidden" name="phase" value="get_user_info" />'."\n".
1.214 raeburn 1128: ' <input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n");
1.302 raeburn 1129: if ($context eq 'requestcrs') {
1130: $r->print($opener_elements.'</form></div>');
1131: } else {
1.351 raeburn 1132: $r->print($response.'</form>');
1.302 raeburn 1133: }
1.160 raeburn 1134: }
1135:
1136: sub print_user_query_page {
1.351 raeburn 1137: my ($r,$caller,$brcrum) = @_;
1.160 raeburn 1138: # FIXME - this is for a network-wide name search (similar to catalog search)
1139: # To use frames with similar behavior to catalog/portfolio search.
1140: # To be implemented.
1141: return;
1142: }
1143:
1.42 matthew 1144: sub print_user_modification_page {
1.375 raeburn 1145: my ($r,$ccuname,$ccdomain,$srch,$response,$context,$permission,$crstype,
1146: $brcrum,$showcredits) = @_;
1.185 raeburn 1147: if (($ccuname eq '') || ($ccdomain eq '')) {
1.215 raeburn 1148: my $usermsg = &mt('No username and/or domain provided.');
1149: $env{'form.phase'} = '';
1.406.2.14 raeburn 1150: &print_username_entry_form($r,$context,$usermsg,'','',$crstype,$brcrum,
1151: $permission);
1.58 www 1152: return;
1153: }
1.213 raeburn 1154: my ($form,$formname);
1155: if ($env{'form.action'} eq 'singlestudent') {
1156: $form = 'document.enrollstudent';
1157: $formname = 'enrollstudent';
1158: } else {
1159: $form = 'document.cu';
1160: $formname = 'cu';
1161: }
1.188 raeburn 1162: my %abv_auth = &auth_abbrev();
1.227 raeburn 1163: my (%rulematch,%inst_results,$newuser,%alerts,%curr_rules,%got_rules);
1.185 raeburn 1164: my $uhome=&Apache::lonnet::homeserver($ccuname,$ccdomain);
1165: if ($uhome eq 'no_host') {
1.215 raeburn 1166: my $usertype;
1167: my ($rules,$ruleorder) =
1168: &Apache::lonnet::inst_userrules($ccdomain,'username');
1169: $usertype =
1.353 raeburn 1170: &Apache::lonuserutils::check_usertype($ccdomain,$ccuname,$rules,
1.362 raeburn 1171: \%curr_rules,\%got_rules);
1.215 raeburn 1172: my $cancreate =
1173: &Apache::lonuserutils::can_create_user($ccdomain,$context,
1174: $usertype);
1175: if (!$cancreate) {
1.292 bisitz 1176: my $helplink = 'javascript:helpMenu('."'display'".')';
1.215 raeburn 1177: my %usertypetext = (
1178: official => 'institutional',
1179: unofficial => 'non-institutional',
1180: );
1181: my $response;
1182: if ($env{'form.origform'} eq 'crtusername') {
1.362 raeburn 1183: $response = '<span class="LC_warning">'.
1184: &mt('No match found for the username [_1] in LON-CAPA domain: [_2]',
1185: '<b>'.$ccuname.'</b>',$ccdomain).
1.215 raeburn 1186: '</span><br />';
1187: }
1.292 bisitz 1188: $response .= '<p class="LC_warning">'
1189: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
1.406.2.6 raeburn 1190: .' ';
1191: if ($context eq 'domain') {
1192: $response .= &mt('Please contact a [_1] for assistance.',
1193: &Apache::lonnet::plaintext('dc'));
1194: } else {
1195: $response .= &mt('Please contact the [_1]helpdesk[_2] for assistance.'
1196: ,'<a href="'.$helplink.'">','</a>');
1197: }
1198: $response .= '</p><br />';
1.215 raeburn 1199: $env{'form.phase'} = '';
1.406.2.14 raeburn 1200: &print_username_entry_form($r,$context,$response,undef,undef,$crstype,$brcrum,
1201: $permission);
1.215 raeburn 1202: return;
1203: }
1.188 raeburn 1204: $newuser = 1;
1.193 raeburn 1205: my $checkhash;
1206: my $checks = { 'username' => 1 };
1.196 raeburn 1207: $checkhash->{$ccuname.':'.$ccdomain} = { 'newuser' => $newuser };
1.193 raeburn 1208: &Apache::loncommon::user_rule_check($checkhash,$checks,
1.196 raeburn 1209: \%alerts,\%rulematch,\%inst_results,\%curr_rules,\%got_rules);
1210: if (ref($alerts{'username'}) eq 'HASH') {
1211: if (ref($alerts{'username'}{$ccdomain}) eq 'HASH') {
1212: my $domdesc =
1.193 raeburn 1213: &Apache::lonnet::domain($ccdomain,'description');
1.196 raeburn 1214: if ($alerts{'username'}{$ccdomain}{$ccuname}) {
1215: my $userchkmsg;
1216: if (ref($curr_rules{$ccdomain}) eq 'HASH') {
1217: $userchkmsg =
1218: &Apache::loncommon::instrule_disallow_msg('username',
1.193 raeburn 1219: $domdesc,1).
1220: &Apache::loncommon::user_rule_formats($ccdomain,
1221: $domdesc,$curr_rules{$ccdomain}{'username'},
1222: 'username');
1.196 raeburn 1223: }
1.215 raeburn 1224: $env{'form.phase'} = '';
1.406.2.14 raeburn 1225: &print_username_entry_form($r,$context,$userchkmsg,undef,undef,$crstype,$brcrum,
1226: $permission);
1.196 raeburn 1227: return;
1.215 raeburn 1228: }
1.193 raeburn 1229: }
1.185 raeburn 1230: }
1.187 raeburn 1231: } else {
1.188 raeburn 1232: $newuser = 0;
1.185 raeburn 1233: }
1.160 raeburn 1234: if ($response) {
1.215 raeburn 1235: $response = '<br />'.$response;
1.160 raeburn 1236: }
1.149 raeburn 1237:
1.52 matthew 1238: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
1.88 raeburn 1239: my $dc_setcourse_code = '';
1.119 raeburn 1240: my $nondc_setsection_code = '';
1.112 albertel 1241: my %loaditem;
1.114 albertel 1242:
1.216 raeburn 1243: my $groupslist = &Apache::lonuserutils::get_groupslist();
1.88 raeburn 1244:
1.375 raeburn 1245: my $js = &validation_javascript($context,$ccdomain,$pjump_def,$crstype,
1.216 raeburn 1246: $groupslist,$newuser,$formname,\%loaditem);
1.406.2.7 raeburn 1247: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$ccdomain);
1.224 raeburn 1248: my $helpitem = 'Course_Change_Privileges';
1249: if ($env{'form.action'} eq 'singlestudent') {
1250: $helpitem = 'Course_Add_Student';
1.406.2.14 raeburn 1251: } elsif ($context eq 'author') {
1252: $helpitem = 'Author_Change_Privileges';
1253: } elsif ($context eq 'domain') {
1254: $helpitem = 'Domain_Change_Privileges';
1.224 raeburn 1255: }
1.351 raeburn 1256: push (@{$brcrum},
1257: {href => "javascript:backPage($form)",
1258: text => $breadcrumb_text{'search'},
1259: faq => 282,
1260: bug => 'Instructor Interface',});
1261: if ($env{'form.phase'} eq 'userpicked') {
1262: push(@{$brcrum},
1263: {href => "javascript:backPage($form,'get_user_info','select')",
1264: text => $breadcrumb_text{'userpicked'},
1265: faq => 282,
1266: bug => 'Instructor Interface',});
1267: }
1268: push(@{$brcrum},
1269: {href => "javascript:backPage($form,'$env{'form.phase'}','modify')",
1270: text => $breadcrumb_text{'modify'},
1271: faq => 282,
1272: bug => 'Instructor Interface',
1273: help => $helpitem});
1274: my $args = {'add_entries' => \%loaditem,
1275: 'bread_crumbs' => $brcrum,
1276: 'bread_crumbs_component' => 'User Management'};
1277: if ($env{'form.popup'}) {
1278: $args->{'no_nav_bar'} = 1;
1.406.2.22! raeburn 1279: $args->{'add_modal'} = 1;
1.351 raeburn 1280: }
1281: my $start_page =
1282: &Apache::loncommon::start_page('User Management',$js,$args);
1.3 www 1283:
1.25 matthew 1284: my $forminfo =<<"ENDFORMINFO";
1.216 raeburn 1285: <form action="/adm/createuser" method="post" name="$formname">
1.190 raeburn 1286: <input type="hidden" name="phase" value="update_user_data" />
1.188 raeburn 1287: <input type="hidden" name="ccuname" value="$ccuname" />
1288: <input type="hidden" name="ccdomain" value="$ccdomain" />
1.157 albertel 1289: <input type="hidden" name="pres_value" value="" />
1290: <input type="hidden" name="pres_type" value="" />
1291: <input type="hidden" name="pres_marker" value="" />
1.25 matthew 1292: ENDFORMINFO
1.375 raeburn 1293: my (%inccourses,$roledom,$defaultcredits);
1.329 raeburn 1294: if ($context eq 'course') {
1295: $inccourses{$env{'request.course.id'}}=1;
1296: $roledom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1.375 raeburn 1297: if ($showcredits) {
1298: $defaultcredits = &Apache::lonuserutils::get_defaultcredits();
1299: }
1.329 raeburn 1300: } elsif ($context eq 'author') {
1301: $roledom = $env{'request.role.domain'};
1302: } elsif ($context eq 'domain') {
1303: foreach my $key (keys(%env)) {
1304: $roledom = $env{'request.role.domain'};
1305: if ($key=~/^user\.priv\.cm\.\/($roledom)\/($match_username)/) {
1306: $inccourses{$1.'_'.$2}=1;
1307: }
1308: }
1309: } else {
1310: foreach my $key (keys(%env)) {
1311: if ($key=~/^user\.priv\.cm\.\/($match_domain)\/($match_username)/) {
1312: $inccourses{$1.'_'.$2}=1;
1313: }
1.2 www 1314: }
1.24 matthew 1315: }
1.389 bisitz 1316: my $title = '';
1.216 raeburn 1317: if ($newuser) {
1.406.2.9 raeburn 1318: my ($portfolioform,$domroleform);
1.267 raeburn 1319: if ((&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) ||
1320: (&Apache::lonnet::allowed('mut',$env{'request.role.domain'}))) {
1321: # Current user has quota or user tools modification privileges
1.378 raeburn 1322: $portfolioform = '<br />'.&user_quotas($ccuname,$ccdomain);
1.134 raeburn 1323: }
1.383 raeburn 1324: if ((&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) &&
1325: ($ccdomain eq $env{'request.role.domain'})) {
1.362 raeburn 1326: $domroleform = '<br />'.&domainrole_req($ccuname,$ccdomain);
1327: }
1.227 raeburn 1328: &initialize_authen_forms($ccdomain,$formname);
1.188 raeburn 1329: my %lt=&Apache::lonlocal::texthash(
1330: 'lg' => 'Login Data',
1.190 raeburn 1331: 'hs' => "Home Server",
1.188 raeburn 1332: );
1.185 raeburn 1333: $r->print(<<ENDTITLE);
1.110 albertel 1334: $start_page
1.160 raeburn 1335: $response
1.25 matthew 1336: $forminfo
1.31 matthew 1337: <script type="text/javascript" language="Javascript">
1.301 bisitz 1338: // <![CDATA[
1.20 harris41 1339: $loginscript
1.301 bisitz 1340: // ]]>
1.31 matthew 1341: </script>
1.20 harris41 1342: <input type='hidden' name='makeuser' value='1' />
1.185 raeburn 1343: ENDTITLE
1.213 raeburn 1344: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1345: if ($crstype eq 'Community') {
1.389 bisitz 1346: $title = &mt('Create New User [_1] in domain [_2] as a member',
1347: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1348: } else {
1.389 bisitz 1349: $title = &mt('Create New User [_1] in domain [_2] as a student',
1350: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1351: }
1.389 bisitz 1352: } else {
1353: $title = &mt('Create New User [_1] in domain [_2]',
1354: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.213 raeburn 1355: }
1.389 bisitz 1356: $r->print('<h2>'.$title.'</h2>'."\n");
1357: $r->print('<div class="LC_left_float">');
1.393 raeburn 1358: $r->print(&personal_data_display($ccuname,$ccdomain,$newuser,$context,
1359: $inst_results{$ccuname.':'.$ccdomain}));
1360: # Option to disable student/employee ID conflict checking not offerred for new users.
1.187 raeburn 1361: my ($home_server_pick,$numlib) =
1362: &Apache::loncommon::home_server_form_item($ccdomain,'hserver',
1363: 'default','hide');
1364: if ($numlib > 1) {
1365: $r->print("
1.185 raeburn 1366: <br />
1.187 raeburn 1367: $lt{'hs'}: $home_server_pick
1368: <br />");
1369: } else {
1370: $r->print($home_server_pick);
1371: }
1.304 raeburn 1372: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.362 raeburn 1373: $r->print('<br /><h3>'.
1374: &mt('User Can Request Creation of Courses/Communities in this Domain?').'</h3>'.
1.304 raeburn 1375: &Apache::loncommon::start_data_table().
1376: &build_tools_display($ccuname,$ccdomain,
1377: 'requestcourses').
1378: &Apache::loncommon::end_data_table());
1379: }
1.188 raeburn 1380: $r->print('</div>'."\n".'<div class="LC_left_float"><h3>'.
1381: $lt{'lg'}.'</h3>');
1.185 raeburn 1382: my ($fixedauth,$varauth,$authmsg);
1.193 raeburn 1383: if (ref($rulematch{$ccuname.':'.$ccdomain}) eq 'HASH') {
1384: my $matchedrule = $rulematch{$ccuname.':'.$ccdomain}{'username'};
1385: my ($rules,$ruleorder) =
1386: &Apache::lonnet::inst_userrules($ccdomain,'username');
1.185 raeburn 1387: if (ref($rules) eq 'HASH') {
1.193 raeburn 1388: if (ref($rules->{$matchedrule}) eq 'HASH') {
1389: my $authtype = $rules->{$matchedrule}{'authtype'};
1.185 raeburn 1390: if ($authtype !~ /^(krb4|krb5|int|fsys|loc)$/) {
1.190 raeburn 1391: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.275 raeburn 1392: } else {
1.193 raeburn 1393: my $authparm = $rules->{$matchedrule}{'authparm'};
1.273 raeburn 1394: $authmsg = $rules->{$matchedrule}{'authmsg'};
1.185 raeburn 1395: if ($authtype =~ /^krb(4|5)$/) {
1396: my $ver = $1;
1397: if ($authparm ne '') {
1398: $fixedauth = <<"KERB";
1399: <input type="hidden" name="login" value="krb" />
1400: <input type="hidden" name="krbver" value="$ver" />
1401: <input type="hidden" name="krbarg" value="$authparm" />
1402: KERB
1403: }
1404: } else {
1405: $fixedauth =
1406: '<input type="hidden" name="login" value="'.$authtype.'" />'."\n";
1.193 raeburn 1407: if ($rules->{$matchedrule}{'authparmfixed'}) {
1.185 raeburn 1408: $fixedauth .=
1409: '<input type="hidden" name="'.$authtype.'arg" value="'.$authparm.'" />'."\n";
1410: } else {
1.273 raeburn 1411: if ($authtype eq 'int') {
1412: $varauth = '<br />'.
1.301 bisitz 1413: &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 1414: } elsif ($authtype eq 'loc') {
1415: $varauth = '<br />'.
1416: &mt('[_1] Local Authentication with argument [_2]','','<input type="text" name="'.$authtype.'arg" value="" />')."\n";
1417: } else {
1418: $varauth =
1.185 raeburn 1419: '<input type="text" name="'.$authtype.'arg" value="" />'."\n";
1.273 raeburn 1420: }
1.185 raeburn 1421: }
1422: }
1423: }
1424: } else {
1.190 raeburn 1425: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.185 raeburn 1426: }
1427: }
1428: if ($authmsg) {
1429: $r->print(<<ENDAUTH);
1430: $fixedauth
1431: $authmsg
1432: $varauth
1433: ENDAUTH
1434: }
1435: } else {
1.190 raeburn 1436: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.187 raeburn 1437: }
1.406.2.9 raeburn 1438: $r->print($portfolioform.$domroleform);
1.215 raeburn 1439: if ($env{'form.action'} eq 'singlestudent') {
1440: $r->print(&date_sections_select($context,$newuser,$formname,
1.375 raeburn 1441: $permission,$crstype,$ccuname,
1442: $ccdomain,$showcredits));
1.215 raeburn 1443: }
1444: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.216 raeburn 1445: } else { # user already exists
1.389 bisitz 1446: $r->print($start_page.$forminfo);
1.213 raeburn 1447: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1448: if ($crstype eq 'Community') {
1.389 bisitz 1449: $title = &mt('Enroll one member: [_1] in domain [_2]',
1450: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1451: } else {
1.389 bisitz 1452: $title = &mt('Enroll one student: [_1] in domain [_2]',
1453: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1454: }
1.213 raeburn 1455: } else {
1.406.2.6 raeburn 1456: if ($permission->{'cusr'}) {
1457: $title = &mt('Modify existing user: [_1] in domain [_2]',
1458: '"'.$ccuname.'"','"'.$ccdomain.'"');
1459: } else {
1460: $title = &mt('Existing user: [_1] in domain [_2]',
1.389 bisitz 1461: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.406.2.6 raeburn 1462: }
1.213 raeburn 1463: }
1.389 bisitz 1464: $r->print('<h2>'.$title.'</h2>'."\n");
1465: $r->print('<div class="LC_left_float">');
1.393 raeburn 1466: $r->print(&personal_data_display($ccuname,$ccdomain,$newuser,$context,
1467: $inst_results{$ccuname.':'.$ccdomain}));
1.406.2.6 raeburn 1468: if ((&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) ||
1469: (&Apache::lonnet::allowed('udp',$env{'request.role.domain'}))) {
1.362 raeburn 1470: $r->print('<br /><h3>'.&mt('User Can Request Creation of Courses/Communities in this Domain?').'</h3>'.
1.300 raeburn 1471: &Apache::loncommon::start_data_table());
1.314 raeburn 1472: if ($env{'request.role.domain'} eq $ccdomain) {
1.300 raeburn 1473: $r->print(&build_tools_display($ccuname,$ccdomain,'requestcourses'));
1474: } else {
1475: $r->print(&coursereq_externaluser($ccuname,$ccdomain,
1476: $env{'request.role.domain'}));
1477: }
1478: $r->print(&Apache::loncommon::end_data_table());
1.275 raeburn 1479: }
1.199 raeburn 1480: $r->print('</div>');
1.406.2.9 raeburn 1481: my @order = ('auth','quota','tools','requestauthor');
1.362 raeburn 1482: my %user_text;
1483: my ($isadv,$isauthor) =
1.406.2.6 raeburn 1484: &Apache::lonnet::is_advanced_user($ccdomain,$ccuname);
1.362 raeburn 1485: if ((!$isauthor) &&
1.406.2.6 raeburn 1486: ((&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) ||
1487: (&Apache::lonnet::allowed('udp',$env{'request.role.domain'}))) &&
1488: ($env{'request.role.domain'} eq $ccdomain)) {
1.362 raeburn 1489: $user_text{'requestauthor'} = &domainrole_req($ccuname,$ccdomain);
1490: }
1.406.2.17 raeburn 1491: $user_text{'auth'} = &user_authentication($ccuname,$ccdomain,$formname,$crstype,$permission);
1.267 raeburn 1492: if ((&Apache::lonnet::allowed('mpq',$ccdomain)) ||
1.406.2.6 raeburn 1493: (&Apache::lonnet::allowed('mut',$ccdomain)) ||
1494: (&Apache::lonnet::allowed('udp',$ccdomain))) {
1.188 raeburn 1495: # Current user has quota modification privileges
1.378 raeburn 1496: $user_text{'quota'} = &user_quotas($ccuname,$ccdomain);
1.267 raeburn 1497: }
1498: if (!&Apache::lonnet::allowed('mpq',$ccdomain)) {
1499: if (&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) {
1500: my %lt=&Apache::lonlocal::texthash(
1.385 bisitz 1501: 'dska' => "Disk quotas for user's portfolio and Authoring Space",
1502: 'youd' => "You do not have privileges to modify the portfolio and/or Authoring Space quotas for this user.",
1.267 raeburn 1503: 'ichr' => "If a change is required, contact a domain coordinator for the domain",
1504: );
1.362 raeburn 1505: $user_text{'quota'} = <<ENDNOPORTPRIV;
1.188 raeburn 1506: <h3>$lt{'dska'}</h3>
1507: $lt{'youd'} $lt{'ichr'}: $ccdomain
1508: ENDNOPORTPRIV
1.267 raeburn 1509: }
1510: }
1511: if (!&Apache::lonnet::allowed('mut',$ccdomain)) {
1512: if (&Apache::lonnet::allowed('mut',$env{'request.role.domain'})) {
1513: my %lt=&Apache::lonlocal::texthash(
1514: 'utav' => "User Tools Availability",
1.361 raeburn 1515: 'yodo' => "You do not have privileges to modify Portfolio, Blog, WebDAV, or Personal Information Page settings for this user.",
1.267 raeburn 1516: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
1517: );
1.362 raeburn 1518: $user_text{'tools'} = <<ENDNOTOOLSPRIV;
1.267 raeburn 1519: <h3>$lt{'utav'}</h3>
1520: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1521: ENDNOTOOLSPRIV
1522: }
1.188 raeburn 1523: }
1.362 raeburn 1524: my $gotdiv = 0;
1525: foreach my $item (@order) {
1526: if ($user_text{$item} ne '') {
1527: unless ($gotdiv) {
1528: $r->print('<div class="LC_left_float">');
1529: $gotdiv = 1;
1530: }
1531: $r->print('<br />'.$user_text{$item});
1532: }
1533: }
1534: if ($env{'form.action'} eq 'singlestudent') {
1535: unless ($gotdiv) {
1536: $r->print('<div class="LC_left_float">');
1.213 raeburn 1537: }
1.375 raeburn 1538: my $credits;
1539: if ($showcredits) {
1540: $credits = &get_user_credits($ccuname,$ccdomain,$defaultcredits);
1541: if ($credits eq '') {
1542: $credits = $defaultcredits;
1543: }
1544: }
1.374 raeburn 1545: $r->print(&date_sections_select($context,$newuser,$formname,
1.375 raeburn 1546: $permission,$crstype,$ccuname,
1547: $ccdomain,$showcredits));
1.374 raeburn 1548: }
1.362 raeburn 1549: if ($gotdiv) {
1550: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.188 raeburn 1551: }
1.406.2.6 raeburn 1552: my $statuses;
1553: if (($context eq 'domain') && (&Apache::lonnet::allowed('udp',$ccdomain)) &&
1554: (!&Apache::lonnet::allowed('mau',$ccdomain))) {
1555: $statuses = ['active'];
1556: } elsif (($context eq 'course') && ((&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) ||
1557: ($env{'request.course.sec'} &&
1558: &Apache::lonnet::allowed('vcl',$env{'request.course.id'}.'/'.$env{'request.course.sec'})))) {
1559: $statuses = ['active'];
1560: }
1.217 raeburn 1561: if ($env{'form.action'} ne 'singlestudent') {
1.329 raeburn 1562: &display_existing_roles($r,$ccuname,$ccdomain,\%inccourses,$context,
1.406.2.6 raeburn 1563: $roledom,$crstype,$showcredits,$statuses);
1.217 raeburn 1564: }
1.25 matthew 1565: } ## End of new user/old user logic
1.218 raeburn 1566: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1567: my $btntxt;
1568: if ($crstype eq 'Community') {
1569: $btntxt = &mt('Enroll Member');
1570: } else {
1571: $btntxt = &mt('Enroll Student');
1572: }
1573: $r->print('<br /><input type="button" value="'.$btntxt.'" onclick="setSections(this.form)" />'."\n");
1.406.2.6 raeburn 1574: } elsif ($permission->{'cusr'}) {
1.393 raeburn 1575: $r->print('<div class="LC_left_float">'.
1576: '<fieldset><legend>'.&mt('Add Roles').'</legend>');
1.218 raeburn 1577: my $addrolesdisplay = 0;
1578: if ($context eq 'domain' || $context eq 'author') {
1579: $addrolesdisplay = &new_coauthor_roles($r,$ccuname,$ccdomain);
1580: }
1581: if ($context eq 'domain') {
1.357 raeburn 1582: my $add_domainroles = &new_domain_roles($r,$ccdomain);
1.218 raeburn 1583: if (!$addrolesdisplay) {
1584: $addrolesdisplay = $add_domainroles;
1.2 www 1585: }
1.375 raeburn 1586: $r->print(&course_level_dc($env{'request.role.domain'},$showcredits));
1.393 raeburn 1587: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1588: '<br /><input type="button" value="'.&mt('Save').'" onclick="setCourse()" />'."\n");
1.218 raeburn 1589: } elsif ($context eq 'author') {
1590: if ($addrolesdisplay) {
1.393 raeburn 1591: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1592: '<br /><input type="button" value="'.&mt('Save').'"');
1.218 raeburn 1593: if ($newuser) {
1.301 bisitz 1594: $r->print(' onclick="auth_check()" \>'."\n");
1.218 raeburn 1595: } else {
1.301 bisitz 1596: $r->print('onclick="this.form.submit()" \>'."\n");
1.218 raeburn 1597: }
1.188 raeburn 1598: } else {
1.393 raeburn 1599: $r->print('</fieldset></div>'.
1600: '<div class="LC_clear_float_footer"></div>'.
1601: '<br /><a href="javascript:backPage(document.cu)">'.
1.218 raeburn 1602: &mt('Back to previous page').'</a>');
1.188 raeburn 1603: }
1604: } else {
1.375 raeburn 1605: $r->print(&course_level_table(\%inccourses,$showcredits,$defaultcredits));
1.393 raeburn 1606: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1607: '<br /><input type="button" value="'.&mt('Save').'" onclick="setSections(this.form)" />'."\n");
1.188 raeburn 1608: }
1.88 raeburn 1609: }
1.188 raeburn 1610: $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','userrole','ccdomain','prevphase','currstate','ccuname','ccdomain']));
1.179 raeburn 1611: $r->print('<input type="hidden" name="currstate" value="" />');
1.393 raeburn 1612: $r->print('<input type="hidden" name="prevphase" value="'.$env{'form.phase'}.'" /></form><br /><br />');
1.218 raeburn 1613: return;
1.2 www 1614: }
1.1 www 1615:
1.213 raeburn 1616: sub singleuser_breadcrumb {
1.406.2.7 raeburn 1617: my ($crstype,$context,$domain) = @_;
1.213 raeburn 1618: my %breadcrumb_text;
1619: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1620: if ($crstype eq 'Community') {
1621: $breadcrumb_text{'search'} = 'Enroll a member';
1622: } else {
1623: $breadcrumb_text{'search'} = 'Enroll a student';
1624: }
1.406.2.7 raeburn 1625: $breadcrumb_text{'userpicked'} = 'Select a user';
1626: $breadcrumb_text{'modify'} = 'Set section/dates';
1.406.2.5 raeburn 1627: } elsif ($env{'form.action'} eq 'accesslogs') {
1628: $breadcrumb_text{'search'} = 'View access logs for a user';
1.406.2.7 raeburn 1629: $breadcrumb_text{'userpicked'} = 'Select a user';
1630: $breadcrumb_text{'activity'} = 'Activity';
1631: } elsif (($env{'form.action'} eq 'singleuser') && ($context eq 'domain') &&
1632: (!&Apache::lonnet::allowed('mau',$domain))) {
1633: $breadcrumb_text{'search'} = "View user's roles";
1634: $breadcrumb_text{'userpicked'} = 'Select a user';
1635: $breadcrumb_text{'modify'} = 'User roles';
1.213 raeburn 1636: } else {
1.229 raeburn 1637: $breadcrumb_text{'search'} = 'Create/modify a user';
1.406.2.7 raeburn 1638: $breadcrumb_text{'userpicked'} = 'Select a user';
1639: $breadcrumb_text{'modify'} = 'Set user role';
1.213 raeburn 1640: }
1641: return %breadcrumb_text;
1642: }
1643:
1644: sub date_sections_select {
1.375 raeburn 1645: my ($context,$newuser,$formname,$permission,$crstype,$ccuname,$ccdomain,
1646: $showcredits) = @_;
1647: my $credits;
1648: if ($showcredits) {
1649: my $defaultcredits = &Apache::lonuserutils::get_defaultcredits();
1650: $credits = &get_user_credits($ccuname,$ccdomain,$defaultcredits);
1651: if ($credits eq '') {
1652: $credits = $defaultcredits;
1653: }
1654: }
1.213 raeburn 1655: my $cid = $env{'request.course.id'};
1656: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity($cid);
1657: my $date_table = '<h3>'.&mt('Starting and Ending Dates').'</h3>'."\n".
1658: &Apache::lonuserutils::date_setting_table(undef,undef,$context,
1659: undef,$formname,$permission);
1660: my $rowtitle = 'Section';
1.375 raeburn 1661: my $secbox = '<h3>'.&mt('Section and Credits').'</h3>'."\n".
1.213 raeburn 1662: &Apache::lonuserutils::section_picker($cdom,$cnum,'st',$rowtitle,
1.375 raeburn 1663: $permission,$context,'',$crstype,
1664: $showcredits,$credits);
1.213 raeburn 1665: my $output = $date_table.$secbox;
1666: return $output;
1667: }
1668:
1.216 raeburn 1669: sub validation_javascript {
1.375 raeburn 1670: my ($context,$ccdomain,$pjump_def,$crstype,$groupslist,$newuser,$formname,
1.216 raeburn 1671: $loaditem) = @_;
1672: my $dc_setcourse_code = '';
1673: my $nondc_setsection_code = '';
1674: if ($context eq 'domain') {
1675: my $dcdom = $env{'request.role.domain'};
1676: $loaditem->{'onload'} = "document.cu.coursedesc.value='';";
1.227 raeburn 1677: $dc_setcourse_code =
1678: &Apache::lonuserutils::dc_setcourse_js('cu','singleuser',$context);
1.216 raeburn 1679: } else {
1.227 raeburn 1680: my $checkauth;
1681: if (($newuser) || (&Apache::lonnet::allowed('mau',$ccdomain))) {
1682: $checkauth = 1;
1683: }
1684: if ($context eq 'course') {
1685: $nondc_setsection_code =
1686: &Apache::lonuserutils::setsections_javascript($formname,$groupslist,
1.375 raeburn 1687: undef,$checkauth,
1688: $crstype);
1.227 raeburn 1689: }
1690: if ($checkauth) {
1691: $nondc_setsection_code .=
1692: &Apache::lonuserutils::verify_authen($formname,$context);
1693: }
1.216 raeburn 1694: }
1695: my $js = &user_modification_js($pjump_def,$dc_setcourse_code,
1696: $nondc_setsection_code,$groupslist);
1697: my ($jsback,$elements) = &crumb_utilities();
1698: $js .= "\n".
1.301 bisitz 1699: '<script type="text/javascript">'."\n".
1700: '// <![CDATA['."\n".
1701: $jsback."\n".
1702: '// ]]>'."\n".
1703: '</script>'."\n";
1.216 raeburn 1704: return $js;
1705: }
1706:
1.217 raeburn 1707: sub display_existing_roles {
1.375 raeburn 1708: my ($r,$ccuname,$ccdomain,$inccourses,$context,$roledom,$crstype,
1.406.2.6 raeburn 1709: $showcredits,$statuses) = @_;
1.329 raeburn 1710: my $now=time;
1.406.2.6 raeburn 1711: my $showall = 1;
1712: my ($showexpired,$showactive);
1713: if ((ref($statuses) eq 'ARRAY') && (@{$statuses} > 0)) {
1714: $showall = 0;
1715: if (grep(/^expired$/,@{$statuses})) {
1716: $showexpired = 1;
1717: }
1718: if (grep(/^active$/,@{$statuses})) {
1719: $showactive = 1;
1720: }
1721: if ($showexpired && $showactive) {
1722: $showall = 1;
1723: }
1724: }
1.329 raeburn 1725: my %lt=&Apache::lonlocal::texthash(
1.217 raeburn 1726: 'rer' => "Existing Roles",
1727: 'rev' => "Revoke",
1728: 'del' => "Delete",
1729: 'ren' => "Re-Enable",
1730: 'rol' => "Role",
1731: 'ext' => "Extent",
1.375 raeburn 1732: 'crd' => "Credits",
1.217 raeburn 1733: 'sta' => "Start",
1734: 'end' => "End",
1735: );
1.329 raeburn 1736: my (%rolesdump,%roletext,%sortrole,%roleclass,%rolepriv);
1737: if ($context eq 'course' || $context eq 'author') {
1738: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
1739: my %roleshash =
1740: &Apache::lonnet::get_my_roles($ccuname,$ccdomain,'userroles',
1741: ['active','previous','future'],\@roles,$roledom,1);
1742: foreach my $key (keys(%roleshash)) {
1743: my ($start,$end) = split(':',$roleshash{$key});
1744: next if ($start eq '-1' || $end eq '-1');
1745: my ($rnum,$rdom,$role,$sec) = split(':',$key);
1746: if ($context eq 'course') {
1747: next unless (($rnum eq $env{'course.'.$env{'request.course.id'}.'.num'})
1748: && ($rdom eq $env{'course.'.$env{'request.course.id'}.'.domain'}));
1749: } elsif ($context eq 'author') {
1750: next unless (($rnum eq $env{'user.name'}) && ($rdom eq $env{'request.role.domain'}));
1751: }
1752: my ($newkey,$newvalue,$newrole);
1753: $newkey = '/'.$rdom.'/'.$rnum;
1754: if ($sec ne '') {
1755: $newkey .= '/'.$sec;
1756: }
1757: $newvalue = $role;
1758: if ($role =~ /^cr/) {
1759: $newrole = 'cr';
1760: } else {
1761: $newrole = $role;
1762: }
1763: $newkey .= '_'.$newrole;
1764: if ($start ne '' && $end ne '') {
1765: $newvalue .= '_'.$end.'_'.$start;
1.335 raeburn 1766: } elsif ($end ne '') {
1767: $newvalue .= '_'.$end;
1.329 raeburn 1768: }
1769: $rolesdump{$newkey} = $newvalue;
1770: }
1771: } else {
1.360 raeburn 1772: %rolesdump=&Apache::lonnet::dump('roles',$ccdomain,$ccuname);
1.329 raeburn 1773: }
1774: # Build up table of user roles to allow revocation and re-enabling of roles.
1775: my ($tmp) = keys(%rolesdump);
1776: return if ($tmp =~ /^(con_lost|error)/i);
1777: foreach my $area (sort { my $a1=join('_',(split('_',$a))[1,0]);
1778: my $b1=join('_',(split('_',$b))[1,0]);
1779: return $a1 cmp $b1;
1780: } keys(%rolesdump)) {
1781: next if ($area =~ /^rolesdef/);
1782: my $envkey=$area;
1783: my $role = $rolesdump{$area};
1784: my $thisrole=$area;
1785: $area =~ s/\_\w\w$//;
1786: my ($role_code,$role_end_time,$role_start_time) =
1787: split(/_/,$role);
1.406.2.6 raeburn 1788: my $active=1;
1789: $active=0 if (($role_end_time) && ($now>$role_end_time));
1790: if ($active) {
1791: next unless($showall || $showactive);
1792: } else {
1793: next unless($showall || $showexpired);
1794: }
1.217 raeburn 1795: # Is this a custom role? Get role owner and title.
1.329 raeburn 1796: my ($croleudom,$croleuname,$croletitle)=
1797: ($role_code=~m{^cr/($match_domain)/($match_username)/(\w+)$});
1798: my $allowed=0;
1799: my $delallowed=0;
1800: my $sortkey=$role_code;
1801: my $class='Unknown';
1.375 raeburn 1802: my $credits='';
1.406.2.6 raeburn 1803: my $csec;
1.406.2.7 raeburn 1804: if ($area =~ m{^/($match_domain)/($match_courseid)}) {
1.329 raeburn 1805: $class='Course';
1806: my ($coursedom,$coursedir) = ($1,$2);
1807: my $cid = $1.'_'.$2;
1808: # $1.'_'.$2 is the course id (eg. 103_12345abcef103l3).
1.406.2.7 raeburn 1809: next if ($envkey =~ m{^/$match_domain/$match_courseid/[A-Za-z0-9]+_gr$});
1.329 raeburn 1810: my %coursedata=
1811: &Apache::lonnet::coursedescription($cid);
1812: if ($coursedir =~ /^$match_community$/) {
1813: $class='Community';
1814: }
1815: $sortkey.="\0$coursedom";
1816: my $carea;
1817: if (defined($coursedata{'description'})) {
1818: $carea=$coursedata{'description'}.
1819: '<br />'.&mt('Domain').': '.$coursedom.(' 'x8).
1820: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$coursedir,$coursedom);
1821: $sortkey.="\0".$coursedata{'description'};
1822: } else {
1823: if ($class eq 'Community') {
1824: $carea=&mt('Unavailable community').': '.$area;
1825: $sortkey.="\0".&mt('Unavailable community').': '.$area;
1.217 raeburn 1826: } else {
1827: $carea=&mt('Unavailable course').': '.$area;
1828: $sortkey.="\0".&mt('Unavailable course').': '.$area;
1829: }
1.329 raeburn 1830: }
1831: $sortkey.="\0$coursedir";
1832: $inccourses->{$cid}=1;
1.375 raeburn 1833: if (($showcredits) && ($class eq 'Course') && ($role_code eq 'st')) {
1834: my $defaultcredits = $coursedata{'internal.defaultcredits'};
1835: $credits =
1836: &get_user_credits($ccuname,$ccdomain,$defaultcredits,
1837: $coursedom,$coursedir);
1838: if ($credits eq '') {
1839: $credits = $defaultcredits;
1840: }
1841: }
1.329 raeburn 1842: if ((&Apache::lonnet::allowed('c'.$role_code,$coursedom.'/'.$coursedir)) ||
1843: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
1844: $allowed=1;
1845: }
1846: unless ($allowed) {
1.365 raeburn 1847: my $isowner = &Apache::lonuserutils::is_courseowner($cid,$coursedata{'internal.courseowner'});
1.329 raeburn 1848: if ($isowner) {
1849: if (($role_code eq 'co') && ($class eq 'Community')) {
1850: $allowed = 1;
1851: } elsif (($role_code eq 'cc') && ($class eq 'Course')) {
1852: $allowed = 1;
1853: }
1.217 raeburn 1854: }
1.329 raeburn 1855: }
1856: if ((&Apache::lonnet::allowed('dro',$coursedom)) ||
1857: (&Apache::lonnet::allowed('dro',$ccdomain))) {
1858: $delallowed=1;
1859: }
1.217 raeburn 1860: # - custom role. Needs more info, too
1.329 raeburn 1861: if ($croletitle) {
1862: if (&Apache::lonnet::allowed('ccr',$coursedom.'/'.$coursedir)) {
1863: $allowed=1;
1864: $thisrole.='.'.$role_code;
1.217 raeburn 1865: }
1.329 raeburn 1866: }
1.406.2.6 raeburn 1867: if ($area=~m{^/($match_domain/$match_courseid/(\w+))}) {
1868: $csec = $2;
1869: $carea.='<br />'.&mt('Section: [_1]',$csec);
1870: $sortkey.="\0$csec";
1.329 raeburn 1871: if (!$allowed) {
1.406.2.6 raeburn 1872: if ($env{'request.course.sec'} eq $csec) {
1873: if (&Apache::lonnet::allowed('c'.$role_code,$1)) {
1.329 raeburn 1874: $allowed = 1;
1.217 raeburn 1875: }
1876: }
1877: }
1.329 raeburn 1878: }
1879: $area=$carea;
1880: } else {
1881: $sortkey.="\0".$area;
1882: # Determine if current user is able to revoke privileges
1883: if ($area=~m{^/($match_domain)/}) {
1884: if ((&Apache::lonnet::allowed('c'.$role_code,$1)) ||
1885: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
1886: $allowed=1;
1.217 raeburn 1887: }
1.329 raeburn 1888: if (((&Apache::lonnet::allowed('dro',$1)) ||
1889: (&Apache::lonnet::allowed('dro',$ccdomain))) &&
1890: ($role_code ne 'dc')) {
1891: $delallowed=1;
1.217 raeburn 1892: }
1.329 raeburn 1893: } else {
1894: if (&Apache::lonnet::allowed('c'.$role_code,'/')) {
1.217 raeburn 1895: $allowed=1;
1896: }
1897: }
1.363 raeburn 1898: if ($role_code eq 'ca' || $role_code eq 'au' || $role_code eq 'aa') {
1.377 raeburn 1899: $class='Authoring Space';
1.329 raeburn 1900: } elsif ($role_code eq 'su') {
1901: $class='System';
1.217 raeburn 1902: } else {
1.329 raeburn 1903: $class='Domain';
1.217 raeburn 1904: }
1.329 raeburn 1905: }
1906: if (($role_code eq 'ca') || ($role_code eq 'aa')) {
1907: $area=~m{/($match_domain)/($match_username)};
1908: if (&Apache::lonuserutils::authorpriv($2,$1)) {
1909: $allowed=1;
1.217 raeburn 1910: } else {
1.329 raeburn 1911: $allowed=0;
1.217 raeburn 1912: }
1.329 raeburn 1913: }
1914: my $row = '';
1.406.2.6 raeburn 1915: if ($showall) {
1916: $row.= '<td>';
1917: if (($active) && ($allowed)) {
1918: $row.= '<input type="checkbox" name="rev:'.$thisrole.'" />';
1.217 raeburn 1919: } else {
1.406.2.6 raeburn 1920: if ($active) {
1921: $row.=' ';
1922: } else {
1923: $row.=&mt('expired or revoked');
1924: }
1.217 raeburn 1925: }
1.406.2.6 raeburn 1926: $row.='</td><td>';
1927: if ($allowed && !$active) {
1928: $row.= '<input type="checkbox" name="ren:'.$thisrole.'" />';
1929: } else {
1930: $row.=' ';
1931: }
1932: $row.='</td><td>';
1933: if ($delallowed) {
1934: $row.= '<input type="checkbox" name="del:'.$thisrole.'" />';
1935: } else {
1936: $row.=' ';
1937: }
1938: $row.= '</td>';
1.329 raeburn 1939: }
1940: my $plaintext='';
1941: if (!$croletitle) {
1.375 raeburn 1942: $plaintext=&Apache::lonnet::plaintext($role_code,$class);
1943: if (($showcredits) && ($credits ne '')) {
1944: $plaintext .= '<br/ ><span class="LC_nobreak">'.
1945: '<span class="LC_fontsize_small">'.
1946: &mt('Credits: [_1]',$credits).
1947: '</span></span>';
1948: }
1.329 raeburn 1949: } else {
1950: $plaintext=
1.395 bisitz 1951: &mt('Custom role [_1][_2]defined by [_3]',
1.346 bisitz 1952: '"'.$croletitle.'"',
1953: '<br />',
1954: $croleuname.':'.$croleudom);
1.329 raeburn 1955: }
1.406.2.6 raeburn 1956: $row.= '<td>'.$plaintext.'</td>'.
1957: '<td>'.$area.'</td>'.
1958: '<td>'.($role_start_time?&Apache::lonlocal::locallocaltime($role_start_time)
1959: : ' ' ).'</td>'.
1960: '<td>'.($role_end_time ?&Apache::lonlocal::locallocaltime($role_end_time)
1961: : ' ' ).'</td>';
1.329 raeburn 1962: $sortrole{$sortkey}=$envkey;
1963: $roletext{$envkey}=$row;
1964: $roleclass{$envkey}=$class;
1.406.2.6 raeburn 1965: if ($allowed) {
1966: $rolepriv{$envkey}='edit';
1967: } else {
1968: if ($context eq 'domain') {
1.406.2.7 raeburn 1969: if ((&Apache::lonnet::allowed('vur',$ccdomain)) &&
1970: ($envkey=~m{^/$ccdomain/})) {
1.406.2.6 raeburn 1971: $rolepriv{$envkey}='view';
1972: }
1973: } elsif ($context eq 'course') {
1974: if ((&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) ||
1975: ($env{'request.course.sec'} && ($env{'request.course.sec'} eq $csec) &&
1976: &Apache::lonnet::allowed('vcl',$env{'request.course.id'}.'/'.$env{'request.course.sec'}))) {
1977: $rolepriv{$envkey}='view';
1978: }
1979: }
1980: }
1.329 raeburn 1981: } # end of foreach (table building loop)
1982:
1983: my $rolesdisplay = 0;
1984: my %output = ();
1.377 raeburn 1985: foreach my $type ('Authoring Space','Course','Community','Domain','System','Unknown') {
1.329 raeburn 1986: $output{$type} = '';
1987: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
1988: if ( ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/ ) && ($rolepriv{$sortrole{$which}}) ) {
1989: $output{$type}.=
1990: &Apache::loncommon::start_data_table_row().
1991: $roletext{$sortrole{$which}}.
1992: &Apache::loncommon::end_data_table_row();
1.217 raeburn 1993: }
1.329 raeburn 1994: }
1995: unless($output{$type} eq '') {
1996: $output{$type} = '<tr class="LC_info_row">'.
1997: "<td align='center' colspan='7'>".&mt($type)."</td></tr>".
1998: $output{$type};
1999: $rolesdisplay = 1;
2000: }
2001: }
2002: if ($rolesdisplay == 1) {
2003: my $contextrole='';
2004: if ($env{'request.course.id'}) {
2005: if (&Apache::loncommon::course_type() eq 'Community') {
2006: $contextrole = &mt('Existing Roles in this Community');
1.290 bisitz 2007: } else {
1.329 raeburn 2008: $contextrole = &mt('Existing Roles in this Course');
1.290 bisitz 2009: }
1.329 raeburn 2010: } elsif ($env{'request.role'} =~ /^au\./) {
1.377 raeburn 2011: $contextrole = &mt('Existing Co-Author Roles in your Authoring Space');
1.329 raeburn 2012: } else {
1.406.2.6 raeburn 2013: if ($showall) {
2014: $contextrole = &mt('Existing Roles in this Domain');
2015: } elsif ($showactive) {
2016: $contextrole = &mt('Unexpired Roles in this Domain');
2017: } elsif ($showexpired) {
2018: $contextrole = &mt('Expired or Revoked Roles in this Domain');
2019: }
1.329 raeburn 2020: }
1.393 raeburn 2021: $r->print('<div class="LC_left_float">'.
1.375 raeburn 2022: '<fieldset><legend>'.$contextrole.'</legend>'.
1.217 raeburn 2023: &Apache::loncommon::start_data_table("LC_createuser").
1.406.2.6 raeburn 2024: &Apache::loncommon::start_data_table_header_row());
2025: if ($showall) {
2026: $r->print(
2027: '<th>'.$lt{'rev'}.'</th><th>'.$lt{'ren'}.'</th><th>'.$lt{'del'}.'</th>'
2028: );
2029: } elsif ($showexpired) {
2030: $r->print('<th>'.$lt{'rev'}.'</th>');
2031: }
2032: $r->print(
2033: '<th>'.$lt{'rol'}.'</th><th>'.$lt{'ext'}.'</th>'.
2034: '<th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
1.217 raeburn 2035: &Apache::loncommon::end_data_table_header_row());
1.377 raeburn 2036: foreach my $type ('Authoring Space','Course','Community','Domain','System','Unknown') {
1.329 raeburn 2037: if ($output{$type}) {
2038: $r->print($output{$type}."\n");
1.217 raeburn 2039: }
2040: }
1.375 raeburn 2041: $r->print(&Apache::loncommon::end_data_table().
2042: '</fieldset></div>');
1.329 raeburn 2043: }
1.217 raeburn 2044: return;
2045: }
2046:
1.218 raeburn 2047: sub new_coauthor_roles {
2048: my ($r,$ccuname,$ccdomain) = @_;
2049: my $addrolesdisplay = 0;
2050: #
2051: # Co-Author
2052: #
2053: if (&Apache::lonuserutils::authorpriv($env{'user.name'},
2054: $env{'request.role.domain'}) &&
2055: ($env{'user.name'} ne $ccuname || $env{'user.domain'} ne $ccdomain)) {
2056: # No sense in assigning co-author role to yourself
2057: $addrolesdisplay = 1;
2058: my $cuname=$env{'user.name'};
2059: my $cudom=$env{'request.role.domain'};
2060: my %lt=&Apache::lonlocal::texthash(
1.377 raeburn 2061: 'cs' => "Authoring Space",
1.218 raeburn 2062: 'act' => "Activate",
2063: 'rol' => "Role",
2064: 'ext' => "Extent",
2065: 'sta' => "Start",
2066: 'end' => "End",
2067: 'cau' => "Co-Author",
2068: 'caa' => "Assistant Co-Author",
2069: 'ssd' => "Set Start Date",
2070: 'sed' => "Set End Date"
2071: );
2072: $r->print('<h4>'.$lt{'cs'}.'</h4>'."\n".
2073: &Apache::loncommon::start_data_table()."\n".
2074: &Apache::loncommon::start_data_table_header_row()."\n".
2075: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'.
2076: '<th>'.$lt{'ext'}.'</th><th>'.$lt{'sta'}.'</th>'.
2077: '<th>'.$lt{'end'}.'</th>'."\n".
2078: &Apache::loncommon::end_data_table_header_row()."\n".
2079: &Apache::loncommon::start_data_table_row().'
2080: <td>
1.291 bisitz 2081: <input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_ca" />
1.218 raeburn 2082: </td>
2083: <td>'.$lt{'cau'}.'</td>
2084: <td>'.$cudom.'_'.$cuname.'</td>
2085: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_ca" value="" />
2086: <a href=
2087: "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>
2088: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_ca" value="" />
2089: <a href=
2090: "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".
2091: &Apache::loncommon::end_data_table_row()."\n".
2092: &Apache::loncommon::start_data_table_row()."\n".
1.291 bisitz 2093: '<td><input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_aa" /></td>
1.218 raeburn 2094: <td>'.$lt{'caa'}.'</td>
2095: <td>'.$cudom.'_'.$cuname.'</td>
2096: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_aa" value="" />
2097: <a href=
2098: "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>
2099: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_aa" value="" />
2100: <a href=
2101: "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".
2102: &Apache::loncommon::end_data_table_row()."\n".
2103: &Apache::loncommon::end_data_table());
2104: } elsif ($env{'request.role'} =~ /^au\./) {
2105: if (!(&Apache::lonuserutils::authorpriv($env{'user.name'},
2106: $env{'request.role.domain'}))) {
2107: $r->print('<span class="LC_error">'.
2108: &mt('You do not have privileges to assign co-author roles.').
2109: '</span>');
2110: } elsif (($env{'user.name'} eq $ccuname) &&
2111: ($env{'user.domain'} eq $ccdomain)) {
1.377 raeburn 2112: $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 2113: }
2114: }
2115: return $addrolesdisplay;;
2116: }
2117:
2118: sub new_domain_roles {
1.357 raeburn 2119: my ($r,$ccdomain) = @_;
1.218 raeburn 2120: my $addrolesdisplay = 0;
2121: #
2122: # Domain level
2123: #
2124: my $num_domain_level = 0;
2125: my $domaintext =
2126: '<h4>'.&mt('Domain Level').'</h4>'.
2127: &Apache::loncommon::start_data_table().
2128: &Apache::loncommon::start_data_table_header_row().
2129: '<th>'.&mt('Activate').'</th><th>'.&mt('Role').'</th><th>'.
2130: &mt('Extent').'</th>'.
2131: '<th>'.&mt('Start').'</th><th>'.&mt('End').'</th>'.
2132: &Apache::loncommon::end_data_table_header_row();
1.312 raeburn 2133: my @allroles = &Apache::lonuserutils::roles_by_context('domain');
1.218 raeburn 2134: foreach my $thisdomain (sort(&Apache::lonnet::all_domains())) {
1.312 raeburn 2135: foreach my $role (@allroles) {
2136: next if ($role eq 'ad');
1.357 raeburn 2137: next if (($role eq 'au') && ($ccdomain ne $thisdomain));
1.218 raeburn 2138: if (&Apache::lonnet::allowed('c'.$role,$thisdomain)) {
2139: my $plrole=&Apache::lonnet::plaintext($role);
2140: my %lt=&Apache::lonlocal::texthash(
2141: 'ssd' => "Set Start Date",
2142: 'sed' => "Set End Date"
2143: );
2144: $num_domain_level ++;
2145: $domaintext .=
2146: &Apache::loncommon::start_data_table_row().
1.291 bisitz 2147: '<td><input type="checkbox" name="act_'.$thisdomain.'_'.$role.'" /></td>
1.218 raeburn 2148: <td>'.$plrole.'</td>
2149: <td>'.$thisdomain.'</td>
2150: <td><input type="hidden" name="start_'.$thisdomain.'_'.$role.'" value="" />
2151: <a href=
2152: "javascript:pjump('."'date_start','Start Date $plrole',document.cu.start_$thisdomain\_$role.value,'start_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'ssd'}.'</a></td>
2153: <td><input type="hidden" name="end_'.$thisdomain.'_'.$role.'" value="" />
2154: <a href=
2155: "javascript:pjump('."'date_end','End Date $plrole',document.cu.end_$thisdomain\_$role.value,'end_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'sed'}.'</a></td>'.
2156: &Apache::loncommon::end_data_table_row();
2157: }
2158: }
2159: }
2160: $domaintext.= &Apache::loncommon::end_data_table();
2161: if ($num_domain_level > 0) {
2162: $r->print($domaintext);
2163: $addrolesdisplay = 1;
2164: }
2165: return $addrolesdisplay;
2166: }
2167:
1.188 raeburn 2168: sub user_authentication {
1.406.2.17 raeburn 2169: my ($ccuname,$ccdomain,$formname,$crstype,$permission) = @_;
1.188 raeburn 2170: my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
1.227 raeburn 2171: my $outcome;
1.406.2.6 raeburn 2172: my %lt=&Apache::lonlocal::texthash(
2173: 'err' => "ERROR",
2174: 'uuas' => "This user has an unrecognized authentication scheme",
2175: 'adcs' => "Please alert a domain coordinator of this situation",
2176: 'sldb' => "Please specify login data below",
2177: 'ld' => "Login Data"
2178: );
1.188 raeburn 2179: # Check for a bad authentication type
2180: if ($currentauth !~ /^(krb4|krb5|unix|internal|localauth):/) {
2181: # bad authentication scheme
2182: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
1.227 raeburn 2183: &initialize_authen_forms($ccdomain,$formname);
2184:
1.190 raeburn 2185: my $choices = &Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc);
1.188 raeburn 2186: $outcome = <<ENDBADAUTH;
2187: <script type="text/javascript" language="Javascript">
1.301 bisitz 2188: // <![CDATA[
1.188 raeburn 2189: $loginscript
1.301 bisitz 2190: // ]]>
1.188 raeburn 2191: </script>
2192: <span class="LC_error">$lt{'err'}:
2193: $lt{'uuas'} ($currentauth). $lt{'sldb'}.</span>
2194: <h3>$lt{'ld'}</h3>
2195: $choices
2196: ENDBADAUTH
2197: } else {
2198: # This user is not allowed to modify the user's
2199: # authentication scheme, so just notify them of the problem
2200: $outcome = <<ENDBADAUTH;
2201: <span class="LC_error"> $lt{'err'}:
2202: $lt{'uuas'} ($currentauth). $lt{'adcs'}.
2203: </span>
2204: ENDBADAUTH
2205: }
2206: } else { # Authentication type is valid
1.227 raeburn 2207: &initialize_authen_forms($ccdomain,$formname,$currentauth,'modifyuser');
1.205 raeburn 2208: my ($authformcurrent,$can_modify,@authform_others) =
1.188 raeburn 2209: &modify_login_block($ccdomain,$currentauth);
2210: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
2211: # Current user has login modification privileges
2212: $outcome =
2213: '<script type="text/javascript" language="Javascript">'."\n".
1.301 bisitz 2214: '// <![CDATA['."\n".
1.188 raeburn 2215: $loginscript."\n".
1.301 bisitz 2216: '// ]]>'."\n".
1.188 raeburn 2217: '</script>'."\n".
2218: '<h3>'.$lt{'ld'}.'</h3>'.
2219: &Apache::loncommon::start_data_table().
1.205 raeburn 2220: &Apache::loncommon::start_data_table_row().
1.188 raeburn 2221: '<td>'.$authformnop;
1.406.2.6 raeburn 2222: if (($can_modify) && (&Apache::lonnet::allowed('mau',$ccdomain))) {
1.188 raeburn 2223: $outcome .= '</td>'."\n".
2224: &Apache::loncommon::end_data_table_row().
2225: &Apache::loncommon::start_data_table_row().
2226: '<td>'.$authformcurrent.'</td>'.
2227: &Apache::loncommon::end_data_table_row()."\n";
2228: } else {
1.200 raeburn 2229: $outcome .= ' ('.$authformcurrent.')</td>'.
2230: &Apache::loncommon::end_data_table_row()."\n";
1.188 raeburn 2231: }
1.406.2.6 raeburn 2232: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
2233: foreach my $item (@authform_others) {
2234: $outcome .= &Apache::loncommon::start_data_table_row().
2235: '<td>'.$item.'</td>'.
2236: &Apache::loncommon::end_data_table_row()."\n";
2237: }
1.188 raeburn 2238: }
1.205 raeburn 2239: $outcome .= &Apache::loncommon::end_data_table();
1.188 raeburn 2240: } else {
1.406.2.17 raeburn 2241: if (($currentauth =~ /^internal:/) &&
2242: (&Apache::lonuserutils::can_change_internalpass($ccuname,$ccdomain,$crstype,$permission))) {
2243: $outcome = <<"ENDJS";
2244: <script type="text/javascript">
2245: // <![CDATA[
2246: function togglePwd(form) {
2247: if (form.newintpwd.length) {
2248: if (document.getElementById('LC_ownersetpwd')) {
2249: for (var i=0; i<form.newintpwd.length; i++) {
2250: if (form.newintpwd[i].checked) {
2251: if (form.newintpwd[i].value == 1) {
2252: document.getElementById('LC_ownersetpwd').style.display = 'inline-block';
2253: } else {
2254: document.getElementById('LC_ownersetpwd').style.display = 'none';
2255: }
2256: }
2257: }
2258: }
2259: }
2260: }
2261: // ]]>
2262: </script>
2263: ENDJS
2264:
2265: $outcome .= '<h3>'.$lt{'ld'}.'</h3>'.
2266: &Apache::loncommon::start_data_table().
2267: &Apache::loncommon::start_data_table_row().
2268: '<td>'.&mt('Internally authenticated').'<br />'.&mt("Change user's password?").
2269: '<label><input type="radio" name="newintpwd" value="0" checked="checked" onclick="togglePwd(this.form);" />'.
2270: &mt('No').'</label>'.(' 'x2).
2271: '<label><input type="radio" name="newintpwd" value="1" onclick="togglePwd(this.form);" />'.&mt('Yes').'</label>'.
2272: '<div id="LC_ownersetpwd" style="display:none">'.
2273: ' '.&mt('Password').' <input type="password" size="15" name="intarg" value="" />'.
2274: '<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>'.
2275: &Apache::loncommon::end_data_table_row().
2276: &Apache::loncommon::end_data_table();
2277: }
1.406.2.6 raeburn 2278: if (&Apache::lonnet::allowed('udp',$ccdomain)) {
2279: # Current user has rights to view domain preferences for user's domain
2280: my $result;
2281: if ($currentauth =~ /^krb(4|5):([^:]*)$/) {
2282: my ($krbver,$krbrealm) = ($1,$2);
2283: if ($krbrealm eq '') {
2284: $result = &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2285: } else {
2286: $result = &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
1.406.2.9 raeburn 2287: $krbrealm,$krbver);
1.406.2.6 raeburn 2288: }
2289: } elsif ($currentauth =~ /^internal:/) {
2290: $result = &mt('Currently internally authenticated.');
2291: } elsif ($currentauth =~ /^localauth:/) {
2292: $result = &mt('Currently using local (institutional) authentication.');
2293: } elsif ($currentauth =~ /^unix:/) {
2294: $result = &mt('Currently Filesystem Authenticated.');
2295: }
2296: $outcome = '<h3>'.$lt{'ld'}.'</h3>'.
2297: &Apache::loncommon::start_data_table().
2298: &Apache::loncommon::start_data_table_row().
2299: '<td>'.$result.'</td>'.
2300: &Apache::loncommon::end_data_table_row()."\n".
2301: &Apache::loncommon::end_data_table();
2302: } elsif (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
1.188 raeburn 2303: my %lt=&Apache::lonlocal::texthash(
2304: 'ccld' => "Change Current Login Data",
2305: 'yodo' => "You do not have privileges to modify the authentication configuration for this user.",
2306: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
2307: );
2308: $outcome .= <<ENDNOPRIV;
2309: <h3>$lt{'ccld'}</h3>
2310: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1.235 raeburn 2311: <input type="hidden" name="login" value="nochange" />
1.188 raeburn 2312: ENDNOPRIV
2313: }
2314: }
2315: } ## End of "check for bad authentication type" logic
2316: return $outcome;
2317: }
2318:
1.187 raeburn 2319: sub modify_login_block {
2320: my ($dom,$currentauth) = @_;
2321: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2322: my ($authnum,%can_assign) =
2323: &Apache::loncommon::get_assignable_auth($dom);
1.205 raeburn 2324: my ($authformcurrent,@authform_others,$show_override_msg);
1.187 raeburn 2325: if ($currentauth=~/^krb(4|5):/) {
2326: $authformcurrent=$authformkrb;
2327: if ($can_assign{'int'}) {
1.205 raeburn 2328: push(@authform_others,$authformint);
1.187 raeburn 2329: }
2330: if ($can_assign{'loc'}) {
1.205 raeburn 2331: push(@authform_others,$authformloc);
1.187 raeburn 2332: }
2333: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
2334: $show_override_msg = 1;
2335: }
2336: } elsif ($currentauth=~/^internal:/) {
2337: $authformcurrent=$authformint;
2338: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2339: push(@authform_others,$authformkrb);
1.187 raeburn 2340: }
2341: if ($can_assign{'loc'}) {
1.205 raeburn 2342: push(@authform_others,$authformloc);
1.187 raeburn 2343: }
2344: if ($can_assign{'int'}) {
2345: $show_override_msg = 1;
2346: }
2347: } elsif ($currentauth=~/^unix:/) {
2348: $authformcurrent=$authformfsys;
2349: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2350: push(@authform_others,$authformkrb);
1.187 raeburn 2351: }
2352: if ($can_assign{'int'}) {
1.205 raeburn 2353: push(@authform_others,$authformint);
1.187 raeburn 2354: }
2355: if ($can_assign{'loc'}) {
1.205 raeburn 2356: push(@authform_others,$authformloc);
1.187 raeburn 2357: }
2358: if ($can_assign{'fsys'}) {
2359: $show_override_msg = 1;
2360: }
2361: } elsif ($currentauth=~/^localauth:/) {
2362: $authformcurrent=$authformloc;
2363: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2364: push(@authform_others,$authformkrb);
1.187 raeburn 2365: }
2366: if ($can_assign{'int'}) {
1.205 raeburn 2367: push(@authform_others,$authformint);
1.187 raeburn 2368: }
2369: if ($can_assign{'loc'}) {
2370: $show_override_msg = 1;
2371: }
2372: }
2373: if ($show_override_msg) {
1.205 raeburn 2374: $authformcurrent = '<table><tr><td colspan="3">'.$authformcurrent.
2375: '</td></tr>'."\n".
2376: '<tr><td> </td>'.
2377: '<td><b>'.&mt('Currently in use').'</b></td>'.
2378: '<td align="right"><span class="LC_cusr_emph">'.
1.187 raeburn 2379: &mt('will override current values').
1.205 raeburn 2380: '</span></td></tr></table>';
1.187 raeburn 2381: }
1.205 raeburn 2382: return ($authformcurrent,$show_override_msg,@authform_others);
1.187 raeburn 2383: }
2384:
1.188 raeburn 2385: sub personal_data_display {
1.406.2.20 raeburn 2386: my ($ccuname,$ccdomain,$newuser,$context,$inst_results,$rolesarray,$now,
2387: $captchaform,$emailusername,$usertype,$usernameset,$condition,$excluded,$showsubmit) = @_;
1.388 bisitz 2388: my ($output,%userenv,%canmodify,%canmodify_status);
1.219 raeburn 2389: my @userinfo = ('firstname','middlename','lastname','generation',
2390: 'permanentemail','id');
1.252 raeburn 2391: my $rowcount = 0;
2392: my $editable = 0;
1.391 raeburn 2393: my %textboxsize = (
2394: firstname => '15',
2395: middlename => '15',
2396: lastname => '15',
2397: generation => '5',
2398: permanentemail => '25',
2399: id => '15',
2400: );
2401:
2402: my %lt=&Apache::lonlocal::texthash(
2403: 'pd' => "Personal Data",
2404: 'firstname' => "First Name",
2405: 'middlename' => "Middle Name",
2406: 'lastname' => "Last Name",
2407: 'generation' => "Generation",
2408: 'permanentemail' => "Permanent e-mail address",
2409: 'id' => "Student/Employee ID",
2410: 'lg' => "Login Data",
2411: 'inststatus' => "Affiliation",
2412: 'email' => 'E-mail address',
2413: 'valid' => 'Validation',
1.406.2.16 raeburn 2414: 'username' => 'Username',
1.391 raeburn 2415: );
2416:
2417: %canmodify_status =
1.286 raeburn 2418: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
2419: ['inststatus'],$rolesarray);
1.253 raeburn 2420: if (!$newuser) {
1.188 raeburn 2421: # Get the users information
2422: %userenv = &Apache::lonnet::get('environment',
2423: ['firstname','middlename','lastname','generation',
1.286 raeburn 2424: 'permanentemail','id','inststatus'],$ccdomain,$ccuname);
1.219 raeburn 2425: %canmodify =
2426: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
1.252 raeburn 2427: \@userinfo,$rolesarray);
1.257 raeburn 2428: } elsif ($context eq 'selfcreate') {
1.391 raeburn 2429: if ($newuser eq 'email') {
1.396 raeburn 2430: if (ref($emailusername) eq 'HASH') {
2431: if (ref($emailusername->{$usertype}) eq 'HASH') {
2432: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.406.2.16 raeburn 2433: @userinfo = ();
1.396 raeburn 2434: if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
2435: foreach my $field (@{$infofields}) {
2436: if ($emailusername->{$usertype}->{$field}) {
2437: push(@userinfo,$field);
2438: $canmodify{$field} = 1;
2439: unless ($textboxsize{$field}) {
2440: $textboxsize{$field} = 25;
2441: }
2442: unless ($lt{$field}) {
2443: $lt{$field} = $infotitles->{$field};
2444: }
2445: if ($emailusername->{$usertype}->{$field} eq 'required') {
2446: $lt{$field} .= '<b>*</b>';
2447: }
1.391 raeburn 2448: }
2449: }
2450: }
2451: }
2452: }
2453: } else {
2454: %canmodify = &selfcreate_canmodify($context,$ccdomain,\@userinfo,
2455: $inst_results,$rolesarray);
2456: }
1.188 raeburn 2457: }
1.391 raeburn 2458:
1.188 raeburn 2459: my $genhelp=&Apache::loncommon::help_open_topic('Generation');
2460: $output = '<h3>'.$lt{'pd'}.'</h3>'.
2461: &Apache::lonhtmlcommon::start_pick_box();
1.391 raeburn 2462: if (($context eq 'selfcreate') && ($newuser eq 'email')) {
1.406.2.16 raeburn 2463: my $size = 25;
2464: if ($condition) {
2465: if ($condition =~ /^\@[^\@]+$/) {
2466: $size = 10;
2467: } else {
2468: undef($condition);
2469: }
2470: }
2471: if ($excluded) {
2472: unless ($excluded =~ /^\@[^\@]+$/) {
2473: undef($condition);
2474: }
2475: }
1.396 raeburn 2476: $output .= &Apache::lonhtmlcommon::row_title($lt{'email'}.'<b>*</b>',undef,
1.391 raeburn 2477: 'LC_oddrow_value')."\n".
1.406.2.16 raeburn 2478: '<input type="text" name="uname" size="'.$size.'" value="" autocomplete="off" />';
2479: if ($condition) {
2480: $output .= $condition;
2481: } elsif ($excluded) {
2482: $output .= '<br /><span style="font-size: smaller">'.&mt('You must use an e-mail address that does not end with [_1]',
2483: $excluded).'</span>';
2484: }
2485: if ($usernameset eq 'first') {
2486: $output .= '<br /><span style="font-size: smaller">';
2487: if ($condition) {
2488: $output .= &mt('Your username in LON-CAPA will be the part of your e-mail address before [_1]',
2489: $condition);
2490: } else {
2491: $output .= &mt('Your username in LON-CAPA will be the part of your e-mail address before the @');
2492: }
2493: $output .= '</span>';
2494: }
1.391 raeburn 2495: $rowcount ++;
2496: $output .= &Apache::lonhtmlcommon::row_closure(1);
1.406.2.1 raeburn 2497: my $upassone = '<input type="password" name="upass'.$now.'" size="20" autocomplete="off" />';
2498: my $upasstwo = '<input type="password" name="upasscheck'.$now.'" size="20" autocomplete="off" />';
1.396 raeburn 2499: $output .= &Apache::lonhtmlcommon::row_title(&mt('Password').'<b>*</b>',
1.391 raeburn 2500: 'LC_pick_box_title',
2501: 'LC_oddrow_value')."\n".
2502: $upassone."\n".
2503: &Apache::lonhtmlcommon::row_closure(1)."\n".
1.396 raeburn 2504: &Apache::lonhtmlcommon::row_title(&mt('Confirm password').'<b>*</b>',
1.391 raeburn 2505: 'LC_pick_box_title',
2506: 'LC_oddrow_value')."\n".
2507: $upasstwo.
2508: &Apache::lonhtmlcommon::row_closure()."\n";
1.406.2.16 raeburn 2509: if ($usernameset eq 'free') {
2510: my $onclick = "toggleUsernameDisp(this,'selfcreateusername');";
2511: $output .= &Apache::lonhtmlcommon::row_title($lt{'username'},undef,'LC_oddrow_value')."\n".
1.406.2.20 raeburn 2512: '<span class="LC_nobreak">'.&mt('Use e-mail address: ').
2513: '<label><input type="radio" name="emailused" value="1" checked="checked" onclick="'.$onclick.'" />'.
2514: &mt('Yes').'</label>'.(' 'x2).
2515: '<label><input type="radio" name="emailused" value="0" onclick="'.$onclick.'" />'.
2516: &mt('No').'</label></span>'."\n".
1.406.2.16 raeburn 2517: '<div id="selfcreateusername" style="display: none; font-size: smaller">'.
2518: '<br /><span class="LC_nobreak">'.&mt('Preferred username').
2519: ' <input type="text" name="username" value="" size="20" autocomplete="off"/>'.
2520: '</span></div>'."\n".&Apache::lonhtmlcommon::row_closure(1);
2521: $rowcount ++;
2522: }
1.391 raeburn 2523: }
1.188 raeburn 2524: foreach my $item (@userinfo) {
2525: my $rowtitle = $lt{$item};
1.252 raeburn 2526: my $hiderow = 0;
1.188 raeburn 2527: if ($item eq 'generation') {
2528: $rowtitle = $genhelp.$rowtitle;
2529: }
1.252 raeburn 2530: my $row = &Apache::lonhtmlcommon::row_title($rowtitle,undef,'LC_oddrow_value')."\n";
1.188 raeburn 2531: if ($newuser) {
1.210 raeburn 2532: if (ref($inst_results) eq 'HASH') {
2533: if ($inst_results->{$item} ne '') {
1.252 raeburn 2534: $row .= '<input type="hidden" name="c'.$item.'" value="'.$inst_results->{$item}.'" />'.$inst_results->{$item};
1.210 raeburn 2535: } else {
1.252 raeburn 2536: if ($context eq 'selfcreate') {
1.391 raeburn 2537: if ($canmodify{$item}) {
1.394 raeburn 2538: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.252 raeburn 2539: $editable ++;
2540: } else {
2541: $hiderow = 1;
2542: }
1.253 raeburn 2543: } else {
2544: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1.252 raeburn 2545: }
1.210 raeburn 2546: }
1.188 raeburn 2547: } else {
1.252 raeburn 2548: if ($context eq 'selfcreate') {
1.401 raeburn 2549: if ($canmodify{$item}) {
2550: if ($newuser eq 'email') {
2551: $row .= '<input type="text" name="'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.287 raeburn 2552: } else {
1.401 raeburn 2553: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.287 raeburn 2554: }
1.401 raeburn 2555: $editable ++;
2556: } else {
2557: $hiderow = 1;
1.252 raeburn 2558: }
1.253 raeburn 2559: } else {
2560: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1.252 raeburn 2561: }
1.188 raeburn 2562: }
2563: } else {
1.219 raeburn 2564: if ($canmodify{$item}) {
1.252 raeburn 2565: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="'.$userenv{$item}.'" />';
1.393 raeburn 2566: if (($item eq 'id') && (!$newuser)) {
2567: $row .= '<br />'.&Apache::lonuserutils::forceid_change($context);
2568: }
1.188 raeburn 2569: } else {
1.252 raeburn 2570: $row .= $userenv{$item};
1.188 raeburn 2571: }
2572: }
1.252 raeburn 2573: $row .= &Apache::lonhtmlcommon::row_closure(1);
2574: if (!$hiderow) {
2575: $output .= $row;
2576: $rowcount ++;
2577: }
1.188 raeburn 2578: }
1.286 raeburn 2579: if (($canmodify_status{'inststatus'}) || ($context ne 'selfcreate')) {
2580: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($ccdomain);
2581: if (ref($types) eq 'ARRAY') {
2582: if (@{$types} > 0) {
2583: my ($hiderow,$shown);
2584: if ($canmodify_status{'inststatus'}) {
2585: $shown = &pick_inst_statuses($userenv{'inststatus'},$usertypes,$types);
2586: } else {
2587: if ($userenv{'inststatus'} eq '') {
2588: $hiderow = 1;
1.334 raeburn 2589: } else {
2590: my @showitems;
2591: foreach my $item ( map { &unescape($_); } split(':',$userenv{'inststatus'})) {
2592: if (exists($usertypes->{$item})) {
2593: push(@showitems,$usertypes->{$item});
2594: } else {
2595: push(@showitems,$item);
2596: }
2597: }
2598: if (@showitems) {
2599: $shown = join(', ',@showitems);
2600: } else {
2601: $hiderow = 1;
2602: }
1.286 raeburn 2603: }
2604: }
2605: if (!$hiderow) {
1.389 bisitz 2606: my $row = &Apache::lonhtmlcommon::row_title(&mt('Affiliations'),undef,'LC_oddrow_value')."\n".
1.286 raeburn 2607: $shown.&Apache::lonhtmlcommon::row_closure(1);
2608: if ($context eq 'selfcreate') {
2609: $rowcount ++;
2610: }
2611: $output .= $row;
2612: }
2613: }
2614: }
2615: }
1.391 raeburn 2616: if (($context eq 'selfcreate') && ($newuser eq 'email')) {
2617: if ($captchaform) {
1.406.2.2 raeburn 2618: $output .= &Apache::lonhtmlcommon::row_title($lt{'valid'}.'*',
1.391 raeburn 2619: 'LC_pick_box_title')."\n".
2620: $captchaform."\n".'<br /><br />'.
2621: &Apache::lonhtmlcommon::row_closure(1);
2622: $rowcount ++;
2623: }
1.406.2.20 raeburn 2624: if ($showsubmit) {
2625: my $submit_text = &mt('Create account');
2626: $output .= &Apache::lonhtmlcommon::row_title()."\n".
2627: '<br /><input type="submit" name="createaccount" value="'.
2628: $submit_text.'" />';
2629: if ($usertype ne '') {
2630: $output .= '<input type="hidden" name="type" value="'.$usertype.'" />'.
2631: &Apache::lonhtmlcommon::row_closure(1);
2632: }
2633: }
1.391 raeburn 2634: }
1.188 raeburn 2635: $output .= &Apache::lonhtmlcommon::end_pick_box();
1.206 raeburn 2636: if (wantarray) {
1.252 raeburn 2637: if ($context eq 'selfcreate') {
2638: return($output,$rowcount,$editable);
2639: } else {
1.388 bisitz 2640: return $output;
1.252 raeburn 2641: }
1.206 raeburn 2642: } else {
2643: return $output;
2644: }
1.188 raeburn 2645: }
2646:
1.286 raeburn 2647: sub pick_inst_statuses {
2648: my ($curr,$usertypes,$types) = @_;
2649: my ($output,$rem,@currtypes);
2650: if ($curr ne '') {
2651: @currtypes = map { &unescape($_); } split(/:/,$curr);
2652: }
2653: my $numinrow = 2;
2654: if (ref($types) eq 'ARRAY') {
2655: $output = '<table>';
2656: my $lastcolspan;
2657: for (my $i=0; $i<@{$types}; $i++) {
2658: if (defined($usertypes->{$types->[$i]})) {
2659: my $rem = $i%($numinrow);
2660: if ($rem == 0) {
2661: if ($i<@{$types}-1) {
2662: if ($i > 0) {
2663: $output .= '</tr>';
2664: }
2665: $output .= '<tr>';
2666: }
2667: } elsif ($i==@{$types}-1) {
2668: my $colsleft = $numinrow - $rem;
2669: if ($colsleft > 1) {
2670: $lastcolspan = ' colspan="'.$colsleft.'"';
2671: }
2672: }
2673: my $check = ' ';
2674: if (grep(/^\Q$types->[$i]\E$/,@currtypes)) {
2675: $check = ' checked="checked" ';
2676: }
2677: $output .= '<td class="LC_left_item"'.$lastcolspan.'>'.
2678: '<span class="LC_nobreak"><label>'.
2679: '<input type="checkbox" name="inststatus" '.
2680: 'value="'.$types->[$i].'"'.$check.'/>'.
2681: $usertypes->{$types->[$i]}.'</label></span></td>';
2682: }
2683: }
2684: $output .= '</tr></table>';
2685: }
2686: return $output;
2687: }
2688:
1.257 raeburn 2689: sub selfcreate_canmodify {
2690: my ($context,$dom,$userinfo,$inst_results,$rolesarray) = @_;
2691: if (ref($inst_results) eq 'HASH') {
2692: my @inststatuses = &get_inststatuses($inst_results);
2693: if (@inststatuses == 0) {
2694: @inststatuses = ('default');
2695: }
2696: $rolesarray = \@inststatuses;
2697: }
2698: my %canmodify =
2699: &Apache::lonuserutils::can_modify_userinfo($context,$dom,$userinfo,
2700: $rolesarray);
2701: return %canmodify;
2702: }
2703:
1.252 raeburn 2704: sub get_inststatuses {
2705: my ($insthashref) = @_;
2706: my @inststatuses = ();
2707: if (ref($insthashref) eq 'HASH') {
2708: if (ref($insthashref->{'inststatus'}) eq 'ARRAY') {
2709: @inststatuses = @{$insthashref->{'inststatus'}};
2710: }
2711: }
2712: return @inststatuses;
2713: }
2714:
1.4 www 2715: # ================================================================= Phase Three
1.42 matthew 2716: sub update_user_data {
1.406.2.17 raeburn 2717: my ($r,$context,$crstype,$brcrum,$showcredits,$permission) = @_;
1.101 albertel 2718: my $uhome=&Apache::lonnet::homeserver($env{'form.ccuname'},
2719: $env{'form.ccdomain'});
1.27 matthew 2720: # Error messages
1.188 raeburn 2721: my $error = '<span class="LC_error">'.&mt('Error').': ';
1.193 raeburn 2722: my $end = '</span><br /><br />';
2723: my $rtnlink = '<a href="javascript:backPage(document.userupdate,'.
1.188 raeburn 2724: "'$env{'form.prevphase'}','modify')".'" />'.
1.219 raeburn 2725: &mt('Return to previous page').'</a>'.
2726: &Apache::loncommon::end_page();
2727: my $now = time;
1.40 www 2728: my $title;
1.101 albertel 2729: if (exists($env{'form.makeuser'})) {
1.40 www 2730: $title='Set Privileges for New User';
2731: } else {
2732: $title='Modify User Privileges';
2733: }
1.213 raeburn 2734: my $newuser = 0;
1.160 raeburn 2735: my ($jsback,$elements) = &crumb_utilities();
2736: my $jscript = '<script type="text/javascript">'."\n".
1.301 bisitz 2737: '// <![CDATA['."\n".
2738: $jsback."\n".
2739: '// ]]>'."\n".
2740: '</script>'."\n";
1.406.2.7 raeburn 2741: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$env{'form.ccdomain'});
1.351 raeburn 2742: push (@{$brcrum},
2743: {href => "javascript:backPage(document.userupdate)",
2744: text => $breadcrumb_text{'search'},
2745: faq => 282,
2746: bug => 'Instructor Interface',}
2747: );
2748: if ($env{'form.prevphase'} eq 'userpicked') {
2749: push(@{$brcrum},
2750: {href => "javascript:backPage(document.userupdate,'get_user_info','select')",
2751: text => $breadcrumb_text{'userpicked'},
2752: faq => 282,
2753: bug => 'Instructor Interface',});
1.233 raeburn 2754: }
1.224 raeburn 2755: my $helpitem = 'Course_Change_Privileges';
2756: if ($env{'form.action'} eq 'singlestudent') {
2757: $helpitem = 'Course_Add_Student';
1.406.2.14 raeburn 2758: } elsif ($context eq 'author') {
2759: $helpitem = 'Author_Change_Privileges';
2760: } elsif ($context eq 'domain') {
2761: $helpitem = 'Domain_Change_Privileges';
1.224 raeburn 2762: }
1.351 raeburn 2763: push(@{$brcrum},
2764: {href => "javascript:backPage(document.userupdate,'$env{'form.prevphase'}','modify')",
2765: text => $breadcrumb_text{'modify'},
2766: faq => 282,
2767: bug => 'Instructor Interface',},
2768: {href => "/adm/createuser",
2769: text => "Result",
2770: faq => 282,
2771: bug => 'Instructor Interface',
2772: help => $helpitem});
2773: my $args = {bread_crumbs => $brcrum,
2774: bread_crumbs_component => 'User Management'};
2775: if ($env{'form.popup'}) {
2776: $args->{'no_nav_bar'} = 1;
2777: }
2778: $r->print(&Apache::loncommon::start_page($title,$jscript,$args));
1.188 raeburn 2779: $r->print(&update_result_form($uhome));
1.27 matthew 2780: # Check Inputs
1.101 albertel 2781: if (! $env{'form.ccuname'} ) {
1.193 raeburn 2782: $r->print($error.&mt('No login name specified').'.'.$end.$rtnlink);
1.27 matthew 2783: return;
2784: }
1.138 albertel 2785: if ( $env{'form.ccuname'} ne
2786: &LONCAPA::clean_username($env{'form.ccuname'}) ) {
1.281 bisitz 2787: $r->print($error.&mt('Invalid login name.').' '.
2788: &mt('Only letters, numbers, periods, dashes, @, and underscores are valid.').
1.193 raeburn 2789: $end.$rtnlink);
1.27 matthew 2790: return;
2791: }
1.101 albertel 2792: if (! $env{'form.ccdomain'} ) {
1.193 raeburn 2793: $r->print($error.&mt('No domain specified').'.'.$end.$rtnlink);
1.27 matthew 2794: return;
2795: }
1.138 albertel 2796: if ( $env{'form.ccdomain'} ne
2797: &LONCAPA::clean_domain($env{'form.ccdomain'}) ) {
1.281 bisitz 2798: $r->print($error.&mt('Invalid domain name.').' '.
2799: &mt('Only letters, numbers, periods, dashes, and underscores are valid.').
1.193 raeburn 2800: $end.$rtnlink);
1.27 matthew 2801: return;
2802: }
1.219 raeburn 2803: if ($uhome eq 'no_host') {
2804: $newuser = 1;
2805: }
1.101 albertel 2806: if (! exists($env{'form.makeuser'})) {
1.29 matthew 2807: # Modifying an existing user, so check the validity of the name
2808: if ($uhome eq 'no_host') {
1.389 bisitz 2809: $r->print(
2810: $error
2811: .'<p class="LC_error">'
2812: .&mt('Unable to determine home server for [_1] in domain [_2].',
2813: '"'.$env{'form.ccuname'}.'"','"'.$env{'form.ccdomain'}.'"')
2814: .'</p>');
1.29 matthew 2815: return;
2816: }
2817: }
1.27 matthew 2818: # Determine authentication method and password for the user being modified
2819: my $amode='';
2820: my $genpwd='';
1.101 albertel 2821: if ($env{'form.login'} eq 'krb') {
1.41 albertel 2822: $amode='krb';
1.101 albertel 2823: $amode.=$env{'form.krbver'};
2824: $genpwd=$env{'form.krbarg'};
2825: } elsif ($env{'form.login'} eq 'int') {
1.27 matthew 2826: $amode='internal';
1.101 albertel 2827: $genpwd=$env{'form.intarg'};
2828: } elsif ($env{'form.login'} eq 'fsys') {
1.27 matthew 2829: $amode='unix';
1.101 albertel 2830: $genpwd=$env{'form.fsysarg'};
2831: } elsif ($env{'form.login'} eq 'loc') {
1.27 matthew 2832: $amode='localauth';
1.101 albertel 2833: $genpwd=$env{'form.locarg'};
1.27 matthew 2834: $genpwd=" " if (!$genpwd);
1.101 albertel 2835: } elsif (($env{'form.login'} eq 'nochange') ||
2836: ($env{'form.login'} eq '' )) {
1.34 matthew 2837: # There is no need to tell the user we did not change what they
2838: # did not ask us to change.
1.35 matthew 2839: # If they are creating a new user but have not specified login
2840: # information this will be caught below.
1.30 matthew 2841: } else {
1.367 golterma 2842: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
2843: return;
1.27 matthew 2844: }
1.164 albertel 2845:
1.188 raeburn 2846: $r->print('<h3>'.&mt('User [_1] in domain [_2]',
1.367 golterma 2847: $env{'form.ccuname'}.' ('.&Apache::loncommon::plainname($env{'form.ccuname'},
2848: $env{'form.ccdomain'}).')', $env{'form.ccdomain'}).'</h3>');
2849: my %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($r,2);
1.344 bisitz 2850:
1.193 raeburn 2851: my (%alerts,%rulematch,%inst_results,%curr_rules);
1.334 raeburn 2852: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
1.361 raeburn 2853: my @usertools = ('aboutme','blog','webdav','portfolio');
1.384 raeburn 2854: my @requestcourses = ('official','unofficial','community','textbook');
1.362 raeburn 2855: my @requestauthor = ('requestauthor');
1.286 raeburn 2856: my ($othertitle,$usertypes,$types) =
2857: &Apache::loncommon::sorted_inst_types($env{'form.ccdomain'});
1.334 raeburn 2858: my %canmodify_status =
2859: &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},
2860: ['inststatus']);
1.101 albertel 2861: if ($env{'form.makeuser'}) {
1.164 albertel 2862: $r->print('<h3>'.&mt('Creating new account.').'</h3>');
1.27 matthew 2863: # Check for the authentication mode and password
2864: if (! $amode || ! $genpwd) {
1.193 raeburn 2865: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
1.27 matthew 2866: return;
1.18 albertel 2867: }
1.29 matthew 2868: # Determine desired host
1.101 albertel 2869: my $desiredhost = $env{'form.hserver'};
1.29 matthew 2870: if (lc($desiredhost) eq 'default') {
2871: $desiredhost = undef;
2872: } else {
1.147 albertel 2873: my %home_servers =
2874: &Apache::lonnet::get_servers($env{'form.ccdomain'},'library');
1.29 matthew 2875: if (! exists($home_servers{$desiredhost})) {
1.193 raeburn 2876: $r->print($error.&mt('Invalid home server specified').$end.$rtnlink);
2877: return;
2878: }
2879: }
2880: # Check ID format
2881: my %checkhash;
2882: my %checks = ('id' => 1);
2883: %{$checkhash{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}}} = (
1.219 raeburn 2884: 'newuser' => $newuser,
1.196 raeburn 2885: 'id' => $env{'form.cid'},
1.193 raeburn 2886: );
1.196 raeburn 2887: if ($env{'form.cid'} ne '') {
2888: &Apache::loncommon::user_rule_check(\%checkhash,\%checks,\%alerts,
2889: \%rulematch,\%inst_results,\%curr_rules);
2890: if (ref($alerts{'id'}) eq 'HASH') {
2891: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
2892: my $domdesc =
2893: &Apache::lonnet::domain($env{'form.ccdomain'},'description');
2894: if ($alerts{'id'}{$env{'form.ccdomain'}}{$env{'form.cid'}}) {
2895: my $userchkmsg;
2896: if (ref($curr_rules{$env{'form.ccdomain'}}) eq 'HASH') {
2897: $userchkmsg =
2898: &Apache::loncommon::instrule_disallow_msg('id',
2899: $domdesc,1).
2900: &Apache::loncommon::user_rule_formats($env{'form.ccdomain'},
2901: $domdesc,$curr_rules{$env{'form.ccdomain'}}{'id'},'id');
2902: }
2903: $r->print($error.&mt('Invalid ID format').$end.
2904: $userchkmsg.$rtnlink);
2905: return;
2906: }
2907: }
1.29 matthew 2908: }
2909: }
1.367 golterma 2910: &Apache::lonhtmlcommon::Increment_PrgWin($r, \%prog_state);
1.27 matthew 2911: # Call modifyuser
2912: my $result = &Apache::lonnet::modifyuser
1.193 raeburn 2913: ($env{'form.ccdomain'},$env{'form.ccuname'},$env{'form.cid'},
1.188 raeburn 2914: $amode,$genpwd,$env{'form.cfirstname'},
2915: $env{'form.cmiddlename'},$env{'form.clastname'},
2916: $env{'form.cgeneration'},undef,$desiredhost,
2917: $env{'form.cpermanentemail'});
1.77 www 2918: $r->print(&mt('Generating user').': '.$result);
1.219 raeburn 2919: $uhome = &Apache::lonnet::homeserver($env{'form.ccuname'},
1.101 albertel 2920: $env{'form.ccdomain'});
1.334 raeburn 2921: my (%changeHash,%newcustom,%changed,%changedinfo);
1.267 raeburn 2922: if ($uhome ne 'no_host') {
1.334 raeburn 2923: if ($context eq 'domain') {
1.378 raeburn 2924: foreach my $name ('portfolio','author') {
2925: if ($env{'form.custom_'.$name.'quota'} == 1) {
2926: if ($env{'form.'.$name.'quota'} eq '') {
2927: $newcustom{$name.'quota'} = 0;
2928: } else {
2929: $newcustom{$name.'quota'} = $env{'form.'.$name.'quota'};
2930: $newcustom{$name.'quota'} =~ s/[^\d\.]//g;
2931: }
2932: if ("a_admin($newcustom{$name.'quota'},\%changeHash,$name)) {
2933: $changed{$name.'quota'} = 1;
2934: }
1.334 raeburn 2935: }
2936: }
2937: foreach my $item (@usertools) {
2938: if ($env{'form.custom'.$item} == 1) {
2939: $newcustom{$item} = $env{'form.tools_'.$item};
2940: $changed{$item} = &tool_admin($item,$newcustom{$item},
2941: \%changeHash,'tools');
2942: }
1.267 raeburn 2943: }
1.334 raeburn 2944: foreach my $item (@requestcourses) {
1.341 raeburn 2945: if ($env{'form.custom'.$item} == 1) {
2946: $newcustom{$item} = $env{'form.crsreq_'.$item};
2947: if ($env{'form.crsreq_'.$item} eq 'autolimit') {
2948: $newcustom{$item} .= '=';
1.383 raeburn 2949: $env{'form.crsreq_'.$item.'_limit'} =~ s/\D+//g;
2950: if ($env{'form.crsreq_'.$item.'_limit'}) {
1.341 raeburn 2951: $newcustom{$item} .= $env{'form.crsreq_'.$item.'_limit'};
2952: }
1.334 raeburn 2953: }
1.341 raeburn 2954: $changed{$item} = &tool_admin($item,$newcustom{$item},
2955: \%changeHash,'requestcourses');
1.334 raeburn 2956: }
1.275 raeburn 2957: }
1.362 raeburn 2958: if ($env{'form.customrequestauthor'} == 1) {
2959: $newcustom{'requestauthor'} = $env{'form.requestauthor'};
2960: $changed{'requestauthor'} = &tool_admin('requestauthor',
2961: $newcustom{'requestauthor'},
2962: \%changeHash,'requestauthor');
2963: }
1.275 raeburn 2964: }
1.334 raeburn 2965: if ($canmodify_status{'inststatus'}) {
2966: if (exists($env{'form.inststatus'})) {
2967: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
2968: if (@inststatuses > 0) {
2969: $changeHash{'inststatus'} = join(',',@inststatuses);
2970: $changed{'inststatus'} = $changeHash{'inststatus'};
1.306 raeburn 2971: }
2972: }
1.232 raeburn 2973: }
1.334 raeburn 2974: if (keys(%changed)) {
2975: foreach my $item (@userinfo) {
2976: $changeHash{$item} = $env{'form.c'.$item};
1.286 raeburn 2977: }
1.267 raeburn 2978: my $chgresult =
2979: &Apache::lonnet::put('environment',\%changeHash,
2980: $env{'form.ccdomain'},$env{'form.ccuname'});
2981: }
1.232 raeburn 2982: }
1.406.2.19 raeburn 2983: $r->print('<br />'.&mt('Home Server').': '.$uhome.' '.
1.219 raeburn 2984: &Apache::lonnet::hostname($uhome));
1.101 albertel 2985: } elsif (($env{'form.login'} ne 'nochange') &&
2986: ($env{'form.login'} ne '' )) {
1.27 matthew 2987: # Modify user privileges
2988: if (! $amode || ! $genpwd) {
1.193 raeburn 2989: $r->print($error.'Invalid login mode or password'.$end.$rtnlink);
1.27 matthew 2990: return;
1.20 harris41 2991: }
1.395 bisitz 2992: # Only allow authentication modification if the person has authority
1.101 albertel 2993: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.20 harris41 2994: $r->print('Modifying authentication: '.
1.31 matthew 2995: &Apache::lonnet::modifyuserauth(
1.101 albertel 2996: $env{'form.ccdomain'},$env{'form.ccuname'},
1.21 harris41 2997: $amode,$genpwd));
1.406.2.19 raeburn 2998: $r->print('<br />'.&mt('Home Server').': '.&Apache::lonnet::homeserver
1.101 albertel 2999: ($env{'form.ccuname'},$env{'form.ccdomain'}));
1.4 www 3000: } else {
1.27 matthew 3001: # Okay, this is a non-fatal error.
1.406.2.17 raeburn 3002: $r->print($error.&mt('You do not have privileges to modify the authentication configuration for this user.').$end);
1.27 matthew 3003: }
1.406.2.17 raeburn 3004: } elsif (($env{'form.intarg'} ne '') &&
3005: (&Apache::lonnet::queryauthenticate($env{'form.ccuname'},$env{'form.ccdomain'}) =~ /^internal:/) &&
3006: (&Apache::lonuserutils::can_change_internalpass($env{'form.ccuname'},$env{'form.ccdomain'},$crstype,$permission))) {
3007: $r->print('Modifying authentication: '.
3008: &Apache::lonnet::modifyuserauth(
3009: $env{'form.ccdomain'},$env{'form.ccuname'},
3010: 'internal',$env{'form.intarg'}));
1.28 matthew 3011: }
1.344 bisitz 3012: $r->rflush(); # Finish display of header before time consuming actions start
1.367 golterma 3013: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state);
1.28 matthew 3014: ##
1.375 raeburn 3015: my (@userroles,%userupdate,$cnum,$cdom,$defaultcredits,%namechanged);
1.213 raeburn 3016: if ($context eq 'course') {
1.375 raeburn 3017: ($cnum,$cdom) =
3018: &Apache::lonuserutils::get_course_identity();
1.318 raeburn 3019: $crstype = &Apache::loncommon::course_type($cdom.'_'.$cnum);
1.375 raeburn 3020: if ($showcredits) {
3021: $defaultcredits = &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
3022: }
1.213 raeburn 3023: }
1.101 albertel 3024: if (! $env{'form.makeuser'} ) {
1.28 matthew 3025: # Check for need to change
3026: my %userenv = &Apache::lonnet::get
1.134 raeburn 3027: ('environment',['firstname','middlename','lastname','generation',
1.378 raeburn 3028: 'id','permanentemail','portfolioquota','authorquota','inststatus',
3029: 'tools.aboutme','tools.blog','tools.webdav','tools.portfolio',
1.361 raeburn 3030: 'requestcourses.official','requestcourses.unofficial',
1.384 raeburn 3031: 'requestcourses.community','requestcourses.textbook',
3032: 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
3033: 'reqcrsotherdom.community','reqcrsotherdom.textbook',
1.406.2.9 raeburn 3034: 'requestauthor'],
1.160 raeburn 3035: $env{'form.ccdomain'},$env{'form.ccuname'});
1.28 matthew 3036: my ($tmp) = keys(%userenv);
3037: if ($tmp =~ /^(con_lost|error)/i) {
3038: %userenv = ();
3039: }
1.206 raeburn 3040: my $no_forceid_alert;
3041: # Check to see if user information can be changed
3042: my %domconfig =
3043: &Apache::lonnet::get_dom('configuration',['usermodification'],
3044: $env{'form.ccdomain'});
1.213 raeburn 3045: my @statuses = ('active','future');
3046: my %roles = &Apache::lonnet::get_my_roles($env{'form.ccuname'},$env{'form.ccdomain'},'userroles',\@statuses,undef,$env{'request.role.domain'});
3047: my ($auname,$audom);
1.220 raeburn 3048: if ($context eq 'author') {
1.206 raeburn 3049: $auname = $env{'user.name'};
3050: $audom = $env{'user.domain'};
3051: }
3052: foreach my $item (keys(%roles)) {
1.220 raeburn 3053: my ($rolenum,$roledom,$role) = split(/:/,$item,-1);
1.206 raeburn 3054: if ($context eq 'course') {
3055: if ($cnum ne '' && $cdom ne '') {
3056: if ($rolenum eq $cnum && $roledom eq $cdom) {
3057: if (!grep(/^\Q$role\E$/,@userroles)) {
3058: push(@userroles,$role);
3059: }
3060: }
3061: }
3062: } elsif ($context eq 'author') {
3063: if ($rolenum eq $auname && $roledom eq $audom) {
3064: if (!grep(/^\Q$role\E$/,@userroles)) {
3065: push(@userroles,$role);
3066: }
3067: }
3068: }
3069: }
1.220 raeburn 3070: if ($env{'form.action'} eq 'singlestudent') {
3071: if (!grep(/^st$/,@userroles)) {
3072: push(@userroles,'st');
3073: }
3074: } else {
3075: # Check for course or co-author roles being activated or re-enabled
3076: if ($context eq 'author' || $context eq 'course') {
3077: foreach my $key (keys(%env)) {
3078: if ($context eq 'author') {
3079: if ($key=~/^form\.act_\Q$audom\E_\Q$auname\E_([^_]+)/) {
3080: if (!grep(/^\Q$1\E$/,@userroles)) {
3081: push(@userroles,$1);
3082: }
3083: } elsif ($key =~/^form\.ren\:\Q$audom\E\/\Q$auname\E_([^_]+)/) {
3084: if (!grep(/^\Q$1\E$/,@userroles)) {
3085: push(@userroles,$1);
3086: }
1.206 raeburn 3087: }
1.220 raeburn 3088: } elsif ($context eq 'course') {
3089: if ($key=~/^form\.act_\Q$cdom\E_\Q$cnum\E_([^_]+)/) {
3090: if (!grep(/^\Q$1\E$/,@userroles)) {
3091: push(@userroles,$1);
3092: }
3093: } elsif ($key =~/^form\.ren\:\Q$cdom\E\/\Q$cnum\E(\/?\w*)_([^_]+)/) {
3094: if (!grep(/^\Q$1\E$/,@userroles)) {
3095: push(@userroles,$1);
3096: }
1.206 raeburn 3097: }
3098: }
3099: }
3100: }
3101: }
3102: #Check to see if we can change personal data for the user
3103: my (@mod_disallowed,@longroles);
3104: foreach my $role (@userroles) {
3105: if ($role eq 'cr') {
3106: push(@longroles,'Custom');
3107: } else {
1.318 raeburn 3108: push(@longroles,&Apache::lonnet::plaintext($role,$crstype));
1.206 raeburn 3109: }
3110: }
1.219 raeburn 3111: my %canmodify = &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},\@userinfo,\@userroles);
3112: foreach my $item (@userinfo) {
1.28 matthew 3113: # Strip leading and trailing whitespace
1.203 raeburn 3114: $env{'form.c'.$item} =~ s/(\s+$|^\s+)//g;
1.219 raeburn 3115: if (!$canmodify{$item}) {
1.207 raeburn 3116: if (defined($env{'form.c'.$item})) {
3117: if ($env{'form.c'.$item} ne $userenv{$item}) {
3118: push(@mod_disallowed,$item);
3119: }
1.206 raeburn 3120: }
3121: $env{'form.c'.$item} = $userenv{$item};
3122: }
1.28 matthew 3123: }
1.259 bisitz 3124: # Check to see if we can change the Student/Employee ID
1.196 raeburn 3125: my $forceid = $env{'form.forceid'};
3126: my $recurseid = $env{'form.recurseid'};
3127: my (%alerts,%rulematch,%idinst_results,%curr_rules,%got_rules);
1.203 raeburn 3128: my %uidhash = &Apache::lonnet::idrget($env{'form.ccdomain'},
3129: $env{'form.ccuname'});
3130: if (($uidhash{$env{'form.ccuname'}}) &&
3131: ($uidhash{$env{'form.ccuname'}}!~/error\:/) &&
3132: (!$forceid)) {
3133: if ($env{'form.cid'} ne $uidhash{$env{'form.ccuname'}}) {
3134: $env{'form.cid'} = $userenv{'id'};
1.293 bisitz 3135: $no_forceid_alert = &mt('New student/employee ID does not match existing ID for this user.')
1.259 bisitz 3136: .'<br />'
3137: .&mt("Change is not permitted without checking the 'Force ID change' checkbox on the previous page.")
3138: .'<br />'."\n";
1.203 raeburn 3139: }
3140: }
3141: if ($env{'form.cid'} ne $userenv{'id'}) {
1.196 raeburn 3142: my $checkhash;
3143: my $checks = { 'id' => 1 };
3144: $checkhash->{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}} =
3145: { 'newuser' => $newuser,
3146: 'id' => $env{'form.cid'},
3147: };
3148: &Apache::loncommon::user_rule_check($checkhash,$checks,
3149: \%alerts,\%rulematch,\%idinst_results,\%curr_rules,\%got_rules);
3150: if (ref($alerts{'id'}) eq 'HASH') {
3151: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
1.203 raeburn 3152: $env{'form.cid'} = $userenv{'id'};
1.196 raeburn 3153: }
3154: }
3155: }
1.378 raeburn 3156: my (%quotachanged,%oldquota,%newquota,%olddefquota,%newdefquota,
3157: $oldinststatus,$newinststatus,%oldisdefault,%newisdefault,%oldsettings,
1.339 raeburn 3158: %oldsettingstext,%newsettings,%newsettingstext,@disporder,
1.378 raeburn 3159: %oldsettingstatus,%newsettingstatus);
1.334 raeburn 3160: @disporder = ('inststatus');
3161: if ($env{'request.role.domain'} eq $env{'form.ccdomain'}) {
1.362 raeburn 3162: push(@disporder,'requestcourses','requestauthor');
1.334 raeburn 3163: } else {
3164: push(@disporder,'reqcrsotherdom');
3165: }
3166: push(@disporder,('quota','tools'));
1.338 raeburn 3167: $oldinststatus = $userenv{'inststatus'};
1.378 raeburn 3168: foreach my $name ('portfolio','author') {
3169: ($olddefquota{$name},$oldsettingstatus{$name}) =
3170: &Apache::loncommon::default_quota($env{'form.ccdomain'},$oldinststatus,$name);
3171: ($newdefquota{$name},$newsettingstatus{$name}) = ($olddefquota{$name},$oldsettingstatus{$name});
3172: }
1.334 raeburn 3173: my %canshow;
1.220 raeburn 3174: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
1.334 raeburn 3175: $canshow{'quota'} = 1;
1.220 raeburn 3176: }
1.267 raeburn 3177: if (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
1.334 raeburn 3178: $canshow{'tools'} = 1;
1.267 raeburn 3179: }
1.275 raeburn 3180: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
1.334 raeburn 3181: $canshow{'requestcourses'} = 1;
1.300 raeburn 3182: } elsif (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.334 raeburn 3183: $canshow{'reqcrsotherdom'} = 1;
1.275 raeburn 3184: }
1.286 raeburn 3185: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.334 raeburn 3186: $canshow{'inststatus'} = 1;
1.286 raeburn 3187: }
1.362 raeburn 3188: if (&Apache::lonnet::allowed('cau',$env{'form.ccdomain'})) {
3189: $canshow{'requestauthor'} = 1;
3190: }
1.267 raeburn 3191: my (%changeHash,%changed);
1.286 raeburn 3192: if ($oldinststatus eq '') {
1.334 raeburn 3193: $oldsettings{'inststatus'} = $othertitle;
1.286 raeburn 3194: } else {
3195: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 3196: $oldsettings{'inststatus'} = join(', ',map{ $usertypes->{ &unescape($_) }; } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 3197: } else {
1.334 raeburn 3198: $oldsettings{'inststatus'} = join(', ',map{ &unescape($_); } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 3199: }
3200: }
3201: $changeHash{'inststatus'} = $userenv{'inststatus'};
1.334 raeburn 3202: if ($canmodify_status{'inststatus'}) {
3203: $canshow{'inststatus'} = 1;
1.286 raeburn 3204: if (exists($env{'form.inststatus'})) {
3205: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
3206: if (@inststatuses > 0) {
3207: $newinststatus = join(':',map { &escape($_); } @inststatuses);
3208: $changeHash{'inststatus'} = $newinststatus;
3209: if ($newinststatus ne $oldinststatus) {
3210: $changed{'inststatus'} = $newinststatus;
1.378 raeburn 3211: foreach my $name ('portfolio','author') {
3212: ($newdefquota{$name},$newsettingstatus{$name}) =
3213: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
3214: }
1.286 raeburn 3215: }
3216: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 3217: $newsettings{'inststatus'} = join(', ',map{ $usertypes->{$_}; } (@inststatuses));
1.286 raeburn 3218: } else {
1.337 raeburn 3219: $newsettings{'inststatus'} = join(', ',@inststatuses);
1.286 raeburn 3220: }
1.334 raeburn 3221: }
3222: } else {
3223: $newinststatus = '';
3224: $changeHash{'inststatus'} = $newinststatus;
3225: $newsettings{'inststatus'} = $othertitle;
3226: if ($newinststatus ne $oldinststatus) {
3227: $changed{'inststatus'} = $changeHash{'inststatus'};
1.378 raeburn 3228: foreach my $name ('portfolio','author') {
3229: ($newdefquota{$name},$newsettingstatus{$name}) =
3230: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
3231: }
1.286 raeburn 3232: }
3233: }
1.334 raeburn 3234: } elsif ($context ne 'selfcreate') {
3235: $canshow{'inststatus'} = 1;
1.337 raeburn 3236: $newsettings{'inststatus'} = $oldsettings{'inststatus'};
1.286 raeburn 3237: }
1.378 raeburn 3238: foreach my $name ('portfolio','author') {
3239: $changeHash{$name.'quota'} = $userenv{$name.'quota'};
3240: }
1.334 raeburn 3241: if ($context eq 'domain') {
1.378 raeburn 3242: foreach my $name ('portfolio','author') {
3243: if ($userenv{$name.'quota'} ne '') {
3244: $oldquota{$name} = $userenv{$name.'quota'};
3245: if ($env{'form.custom_'.$name.'quota'} == 1) {
3246: if ($env{'form.'.$name.'quota'} eq '') {
3247: $newquota{$name} = 0;
3248: } else {
3249: $newquota{$name} = $env{'form.'.$name.'quota'};
3250: $newquota{$name} =~ s/[^\d\.]//g;
3251: }
3252: if ($newquota{$name} != $oldquota{$name}) {
3253: if ("a_admin($newquota{$name},\%changeHash,$name)) {
3254: $changed{$name.'quota'} = 1;
3255: }
3256: }
1.334 raeburn 3257: } else {
1.378 raeburn 3258: if ("a_admin('',\%changeHash,$name)) {
3259: $changed{$name.'quota'} = 1;
3260: $newquota{$name} = $newdefquota{$name};
3261: $newisdefault{$name} = 1;
3262: }
1.334 raeburn 3263: }
1.149 raeburn 3264: } else {
1.378 raeburn 3265: $oldisdefault{$name} = 1;
3266: $oldquota{$name} = $olddefquota{$name};
3267: if ($env{'form.custom_'.$name.'quota'} == 1) {
3268: if ($env{'form.'.$name.'quota'} eq '') {
3269: $newquota{$name} = 0;
3270: } else {
3271: $newquota{$name} = $env{'form.'.$name.'quota'};
3272: $newquota{$name} =~ s/[^\d\.]//g;
3273: }
3274: if ("a_admin($newquota{$name},\%changeHash,$name)) {
3275: $changed{$name.'quota'} = 1;
3276: }
1.334 raeburn 3277: } else {
1.378 raeburn 3278: $newquota{$name} = $newdefquota{$name};
3279: $newisdefault{$name} = 1;
1.334 raeburn 3280: }
1.378 raeburn 3281: }
3282: if ($oldisdefault{$name}) {
3283: $oldsettingstext{'quota'}{$name} = &get_defaultquota_text($oldsettingstatus{$name});
1.383 raeburn 3284: } else {
3285: $oldsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$oldquota{$name});
1.378 raeburn 3286: }
3287: if ($newisdefault{$name}) {
3288: $newsettingstext{'quota'}{$name} = &get_defaultquota_text($newsettingstatus{$name});
1.383 raeburn 3289: } else {
3290: $newsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$newquota{$name});
1.134 raeburn 3291: }
3292: }
1.334 raeburn 3293: &tool_changes('tools',\@usertools,\%oldsettings,\%oldsettingstext,\%userenv,
3294: \%changeHash,\%changed,\%newsettings,\%newsettingstext);
3295: if ($env{'form.ccdomain'} eq $env{'request.role.domain'}) {
3296: &tool_changes('requestcourses',\@requestcourses,\%oldsettings,\%oldsettingstext,
3297: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.384 raeburn 3298: &tool_changes('requestauthor',\@requestauthor,\%oldsettings,\%oldsettingstext,
3299: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 3300: } else {
1.334 raeburn 3301: &tool_changes('reqcrsotherdom',\@requestcourses,\%oldsettings,\%oldsettingstext,
3302: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 3303: }
3304: }
1.334 raeburn 3305: foreach my $item (@userinfo) {
3306: if ($env{'form.c'.$item} ne $userenv{$item}) {
3307: $namechanged{$item} = 1;
3308: }
1.204 raeburn 3309: }
1.378 raeburn 3310: foreach my $name ('portfolio','author') {
1.390 bisitz 3311: $oldsettings{'quota'}{$name} = &mt('[_1] MB',$oldquota{$name});
3312: $newsettings{'quota'}{$name} = &mt('[_1] MB',$newquota{$name});
1.378 raeburn 3313: }
1.334 raeburn 3314: if ((keys(%namechanged) > 0) || (keys(%changed) > 0)) {
1.267 raeburn 3315: my ($chgresult,$namechgresult);
3316: if (keys(%changed) > 0) {
3317: $chgresult =
1.204 raeburn 3318: &Apache::lonnet::put('environment',\%changeHash,
3319: $env{'form.ccdomain'},$env{'form.ccuname'});
1.267 raeburn 3320: if ($chgresult eq 'ok') {
3321: if (($env{'user.name'} eq $env{'form.ccuname'}) &&
3322: ($env{'user.domain'} eq $env{'form.ccdomain'})) {
1.270 raeburn 3323: my %newenvhash;
3324: foreach my $key (keys(%changed)) {
1.299 raeburn 3325: if (($key eq 'official') || ($key eq 'unofficial')
1.403 raeburn 3326: || ($key eq 'community') || ($key eq 'textbook')) {
1.279 raeburn 3327: $newenvhash{'environment.requestcourses.'.$key} =
3328: $changeHash{'requestcourses.'.$key};
1.362 raeburn 3329: if ($changeHash{'requestcourses.'.$key}) {
1.332 raeburn 3330: $newenvhash{'environment.canrequest.'.$key} = 1;
1.279 raeburn 3331: } else {
3332: $newenvhash{'environment.canrequest.'.$key} =
3333: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3334: $key,'reload','requestcourses');
3335: }
1.362 raeburn 3336: } elsif ($key eq 'requestauthor') {
3337: $newenvhash{'environment.'.$key} = $changeHash{$key};
3338: if ($changeHash{$key}) {
3339: $newenvhash{'environment.canrequest.author'} = 1;
3340: } else {
3341: $newenvhash{'environment.canrequest.author'} =
3342: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3343: $key,'reload','requestauthor');
3344: }
1.275 raeburn 3345: } elsif ($key ne 'quota') {
1.270 raeburn 3346: $newenvhash{'environment.tools.'.$key} =
3347: $changeHash{'tools.'.$key};
1.279 raeburn 3348: if ($changeHash{'tools.'.$key} ne '') {
3349: $newenvhash{'environment.availabletools.'.$key} =
3350: $changeHash{'tools.'.$key};
3351: } else {
3352: $newenvhash{'environment.availabletools.'.$key} =
1.367 golterma 3353: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3354: $key,'reload','tools');
1.279 raeburn 3355: }
1.270 raeburn 3356: }
3357: }
1.271 raeburn 3358: if (keys(%newenvhash)) {
3359: &Apache::lonnet::appenv(\%newenvhash);
3360: }
1.267 raeburn 3361: }
3362: }
1.204 raeburn 3363: }
1.334 raeburn 3364: if (keys(%namechanged) > 0) {
1.337 raeburn 3365: foreach my $field (@userinfo) {
3366: $changeHash{$field} = $env{'form.c'.$field};
3367: }
3368: # Make the change
1.204 raeburn 3369: $namechgresult =
3370: &Apache::lonnet::modifyuser($env{'form.ccdomain'},
3371: $env{'form.ccuname'},$changeHash{'id'},undef,undef,
3372: $changeHash{'firstname'},$changeHash{'middlename'},
3373: $changeHash{'lastname'},$changeHash{'generation'},
1.337 raeburn 3374: $changeHash{'id'},undef,$changeHash{'permanentemail'},undef,\@userinfo);
1.220 raeburn 3375: %userupdate = (
3376: lastname => $env{'form.clastname'},
3377: middlename => $env{'form.cmiddlename'},
3378: firstname => $env{'form.cfirstname'},
3379: generation => $env{'form.cgeneration'},
3380: id => $env{'form.cid'},
3381: );
1.204 raeburn 3382: }
1.334 raeburn 3383: if (((keys(%namechanged) > 0) && $namechgresult eq 'ok') ||
1.267 raeburn 3384: ((keys(%changed) > 0) && $chgresult eq 'ok')) {
1.28 matthew 3385: # Tell the user we changed the name
1.334 raeburn 3386: &display_userinfo($r,1,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 3387: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,
1.334 raeburn 3388: \%oldsettings, \%oldsettingstext,\%newsettings,
3389: \%newsettingstext);
1.203 raeburn 3390: if ($env{'form.cid'} ne $userenv{'id'}) {
3391: &Apache::lonnet::idput($env{'form.ccdomain'},
1.406.2.5 raeburn 3392: {$env{'form.ccuname'} => $env{'form.cid'}});
1.203 raeburn 3393: if (($recurseid) &&
3394: (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}))) {
3395: my $idresult =
3396: &Apache::lonuserutils::propagate_id_change(
3397: $env{'form.ccuname'},$env{'form.ccdomain'},
3398: \%userupdate);
3399: $r->print('<br />'.$idresult.'<br />');
3400: }
1.196 raeburn 3401: }
1.149 raeburn 3402: if (($env{'form.ccdomain'} eq $env{'user.domain'}) &&
3403: ($env{'form.ccuname'} eq $env{'user.name'})) {
3404: my %newenvhash;
3405: foreach my $key (keys(%changeHash)) {
3406: $newenvhash{'environment.'.$key} = $changeHash{$key};
3407: }
1.238 raeburn 3408: &Apache::lonnet::appenv(\%newenvhash);
1.149 raeburn 3409: }
1.28 matthew 3410: } else { # error occurred
1.389 bisitz 3411: $r->print(
3412: '<p class="LC_error">'
3413: .&mt('Unable to successfully change environment for [_1] in domain [_2].',
3414: '"'.$env{'form.ccuname'}.'"',
3415: '"'.$env{'form.ccdomain'}.'"')
3416: .'</p>');
1.28 matthew 3417: }
1.334 raeburn 3418: } else { # End of if ($env ... ) logic
1.275 raeburn 3419: # They did not want to change the users name, quota, tool availability,
3420: # or ability to request creation of courses,
1.267 raeburn 3421: # but we can still tell them what the name and quota and availabilities are
1.334 raeburn 3422: &display_userinfo($r,undef,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 3423: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,\%oldsettings,
1.334 raeburn 3424: \%oldsettingstext,\%newsettings,\%newsettingstext);
1.28 matthew 3425: }
1.206 raeburn 3426: if (@mod_disallowed) {
3427: my ($rolestr,$contextname);
3428: if (@longroles > 0) {
3429: $rolestr = join(', ',@longroles);
3430: } else {
3431: $rolestr = &mt('No roles');
3432: }
3433: if ($context eq 'course') {
1.399 bisitz 3434: $contextname = 'course';
1.206 raeburn 3435: } elsif ($context eq 'author') {
1.399 bisitz 3436: $contextname = 'co-author';
1.206 raeburn 3437: }
3438: $r->print(&mt('The following fields were not updated: ').'<ul>');
3439: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
3440: foreach my $field (@mod_disallowed) {
3441: $r->print('<li>'.$fieldtitles{$field}.'</li>'."\n");
3442: }
1.207 raeburn 3443: $r->print('</ul>');
3444: if (@mod_disallowed == 1) {
1.399 bisitz 3445: $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 3446: } else {
1.399 bisitz 3447: $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 3448: }
1.292 bisitz 3449: my $helplink = 'javascript:helpMenu('."'display'".')';
3450: $r->print('<span class="LC_cusr_emph">'.$rolestr.'</span><br />'
3451: .&mt('Please contact your [_1]helpdesk[_2] for more information.'
3452: ,'<a href="'.$helplink.'">','</a>')
3453: .'<br />');
1.206 raeburn 3454: }
1.259 bisitz 3455: $r->print('<span class="LC_warning">'
3456: .$no_forceid_alert
3457: .&Apache::lonuserutils::print_namespacing_alerts($env{'form.ccdomain'},\%alerts,\%curr_rules)
3458: .'</span>');
1.4 www 3459: }
1.367 golterma 3460: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1.220 raeburn 3461: if ($env{'form.action'} eq 'singlestudent') {
1.375 raeburn 3462: &enroll_single_student($r,$uhome,$amode,$genpwd,$now,$newuser,$context,
3463: $crstype,$showcredits,$defaultcredits);
1.386 bisitz 3464: my $linktext = ($crstype eq 'Community' ?
3465: &mt('Enroll Another Member') : &mt('Enroll Another Student'));
3466: $r->print(
3467: &Apache::lonhtmlcommon::actionbox([
3468: '<a href="javascript:backPage(document.userupdate)">'
3469: .($crstype eq 'Community' ?
3470: &mt('Enroll Another Member') : &mt('Enroll Another Student'))
3471: .'</a>']));
1.220 raeburn 3472: } else {
1.375 raeburn 3473: my @rolechanges = &update_roles($r,$context,$showcredits);
1.334 raeburn 3474: if (keys(%namechanged) > 0) {
1.220 raeburn 3475: if ($context eq 'course') {
3476: if (@userroles > 0) {
1.225 raeburn 3477: if ((@rolechanges == 0) ||
3478: (!(grep(/^st$/,@rolechanges)))) {
3479: if (grep(/^st$/,@userroles)) {
3480: my $classlistupdated =
3481: &Apache::lonuserutils::update_classlist($cdom,
1.220 raeburn 3482: $cnum,$env{'form.ccdomain'},
3483: $env{'form.ccuname'},\%userupdate);
1.225 raeburn 3484: }
1.220 raeburn 3485: }
3486: }
3487: }
3488: }
1.226 raeburn 3489: my $userinfo = &Apache::loncommon::plainname($env{'form.ccuname'},
1.233 raeburn 3490: $env{'form.ccdomain'});
3491: if ($env{'form.popup'}) {
3492: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
3493: } else {
1.367 golterma 3494: $r->print('<br />'.&Apache::lonhtmlcommon::actionbox(['<a href="javascript:backPage(document.userupdate,'."'$env{'form.prevphase'}','modify'".')">'
3495: .&mt('Modify this user: [_1]','<span class="LC_cusr_emph">'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.' ('.$userinfo.')</span>').'</a>',
3496: '<a href="javascript:backPage(document.userupdate)">'.&mt('Create/Modify Another User').'</a>']));
1.233 raeburn 3497: }
1.220 raeburn 3498: }
3499: }
3500:
1.334 raeburn 3501: sub display_userinfo {
1.362 raeburn 3502: my ($r,$changed,$order,$canshow,$requestcourses,$usertools,$requestauthor,
3503: $userenv,$changedhash,$namechangedhash,$oldsetting,$oldsettingtext,
1.334 raeburn 3504: $newsetting,$newsettingtext) = @_;
3505: return unless (ref($order) eq 'ARRAY' &&
3506: ref($canshow) eq 'HASH' &&
3507: ref($requestcourses) eq 'ARRAY' &&
1.362 raeburn 3508: ref($requestauthor) eq 'ARRAY' &&
1.334 raeburn 3509: ref($usertools) eq 'ARRAY' &&
3510: ref($userenv) eq 'HASH' &&
3511: ref($changedhash) eq 'HASH' &&
3512: ref($oldsetting) eq 'HASH' &&
3513: ref($oldsettingtext) eq 'HASH' &&
3514: ref($newsetting) eq 'HASH' &&
3515: ref($newsettingtext) eq 'HASH');
3516: my %lt=&Apache::lonlocal::texthash(
1.372 raeburn 3517: 'ui' => 'User Information',
1.334 raeburn 3518: 'uic' => 'User Information Changed',
3519: 'firstname' => 'First Name',
3520: 'middlename' => 'Middle Name',
3521: 'lastname' => 'Last Name',
3522: 'generation' => 'Generation',
3523: 'id' => 'Student/Employee ID',
3524: 'permanentemail' => 'Permanent e-mail address',
1.378 raeburn 3525: 'portfolioquota' => 'Disk space allocated to portfolio files',
1.385 bisitz 3526: 'authorquota' => 'Disk space allocated to Authoring Space',
1.334 raeburn 3527: 'blog' => 'Blog Availability',
1.361 raeburn 3528: 'webdav' => 'WebDAV Availability',
1.334 raeburn 3529: 'aboutme' => 'Personal Information Page Availability',
3530: 'portfolio' => 'Portfolio Availability',
3531: 'official' => 'Can Request Official Courses',
3532: 'unofficial' => 'Can Request Unofficial Courses',
3533: 'community' => 'Can Request Communities',
1.384 raeburn 3534: 'textbook' => 'Can Request Textbook Courses',
1.362 raeburn 3535: 'requestauthor' => 'Can Request Author Role',
1.334 raeburn 3536: 'inststatus' => "Affiliation",
3537: 'prvs' => 'Previous Value:',
3538: 'chto' => 'Changed To:'
3539: );
3540: if ($changed) {
1.372 raeburn 3541: $r->print('<h3>'.$lt{'uic'}.'</h3>'.
1.367 golterma 3542: &Apache::loncommon::start_data_table().
3543: &Apache::loncommon::start_data_table_header_row());
1.334 raeburn 3544: $r->print("<th> </th>\n");
1.367 golterma 3545: $r->print('<th><b>'.$lt{'prvs'}.'</b></th>');
3546: $r->print('<th><span class="LC_nobreak"><b>'.$lt{'chto'}.'</b></span></th>');
3547: $r->print(&Apache::loncommon::end_data_table_header_row());
3548: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
3549:
1.334 raeburn 3550: foreach my $item (@userinfo) {
3551: my $value = $env{'form.c'.$item};
1.367 golterma 3552: #show changes only:
1.383 raeburn 3553: unless ($value eq $userenv->{$item}){
1.367 golterma 3554: $r->print(&Apache::loncommon::start_data_table_row());
3555: $r->print("<td>$lt{$item}</td>\n");
1.383 raeburn 3556: $r->print("<td>".$userenv->{$item}."</td>\n");
1.367 golterma 3557: $r->print("<td>$value </td>\n");
3558: $r->print(&Apache::loncommon::end_data_table_row());
1.334 raeburn 3559: }
3560: }
3561: foreach my $entry (@{$order}) {
1.383 raeburn 3562: if ($canshow->{$entry}) {
3563: if (($entry eq 'requestcourses') || ($entry eq 'reqcrsotherdom') || ($entry eq 'requestauthor')) {
3564: my @items;
3565: if ($entry eq 'requestauthor') {
3566: @items = ($entry);
3567: } else {
3568: @items = @{$requestcourses};
1.384 raeburn 3569: }
1.383 raeburn 3570: foreach my $item (@items) {
3571: if (($newsetting->{$item} ne $oldsetting->{$item}) ||
3572: ($newsettingtext->{$item} ne $oldsettingtext->{$item})) {
3573: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3574: $r->print("<td>$lt{$item}</td>\n");
3575: $r->print("<td>".$oldsetting->{$item});
3576: if ($oldsettingtext->{$item}) {
3577: if ($oldsetting->{$item}) {
3578: $r->print(' -- ');
3579: }
3580: $r->print($oldsettingtext->{$item});
3581: }
3582: $r->print("</td>\n");
3583: $r->print("<td>".$newsetting->{$item});
3584: if ($newsettingtext->{$item}) {
3585: if ($newsetting->{$item}) {
3586: $r->print(' -- ');
3587: }
3588: $r->print($newsettingtext->{$item});
3589: }
3590: $r->print("</td>\n");
3591: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3592: }
3593: }
3594: } elsif ($entry eq 'tools') {
3595: foreach my $item (@{$usertools}) {
1.383 raeburn 3596: if ($newsetting->{$item} ne $oldsetting->{$item}) {
3597: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3598: $r->print("<td>$lt{$item}</td>\n");
3599: $r->print("<td>".$oldsetting->{$item}.' '.$oldsettingtext->{$item}."</td>\n");
3600: $r->print("<td>".$newsetting->{$item}.' '.$newsettingtext->{$item}."</td>\n");
3601: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3602: }
3603: }
1.378 raeburn 3604: } elsif ($entry eq 'quota') {
3605: if ((ref($oldsetting->{$entry}) eq 'HASH') && (ref($oldsettingtext->{$entry}) eq 'HASH') &&
3606: (ref($newsetting->{$entry}) eq 'HASH') && (ref($newsettingtext->{$entry}) eq 'HASH')) {
3607: foreach my $name ('portfolio','author') {
1.383 raeburn 3608: if ($newsetting->{$entry}->{$name} ne $oldsetting->{$entry}->{$name}) {
3609: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3610: $r->print("<td>$lt{$name.$entry}</td>\n");
3611: $r->print("<td>".$oldsettingtext->{$entry}->{$name}."</td>\n");
3612: $r->print("<td>".$newsettingtext->{$entry}->{$name}."</td>\n");
3613: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.378 raeburn 3614: }
3615: }
3616: }
1.334 raeburn 3617: } else {
1.383 raeburn 3618: if ($newsetting->{$entry} ne $oldsetting->{$entry}) {
3619: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3620: $r->print("<td>$lt{$entry}</td>\n");
3621: $r->print("<td>".$oldsetting->{$entry}.' '.$oldsettingtext->{$entry}."</td>\n");
3622: $r->print("<td>".$newsetting->{$entry}.' '.$newsettingtext->{$entry}."</td>\n");
3623: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3624: }
3625: }
3626: }
3627: }
1.367 golterma 3628: $r->print(&Apache::loncommon::end_data_table().'<br />');
1.372 raeburn 3629: } else {
3630: $r->print('<h3>'.$lt{'ui'}.'</h3>'.
3631: '<p>'.&mt('No changes made to user information').'</p>');
1.334 raeburn 3632: }
3633: return;
3634: }
3635:
1.275 raeburn 3636: sub tool_changes {
3637: my ($context,$usertools,$oldaccess,$oldaccesstext,$userenv,$changeHash,
3638: $changed,$newaccess,$newaccesstext) = @_;
3639: if (!((ref($usertools) eq 'ARRAY') && (ref($oldaccess) eq 'HASH') &&
3640: (ref($oldaccesstext) eq 'HASH') && (ref($userenv) eq 'HASH') &&
3641: (ref($changeHash) eq 'HASH') && (ref($changed) eq 'HASH') &&
3642: (ref($newaccess) eq 'HASH') && (ref($newaccesstext) eq 'HASH'))) {
3643: return;
3644: }
1.383 raeburn 3645: my %reqdisplay = &requestchange_display();
1.300 raeburn 3646: if ($context eq 'reqcrsotherdom') {
1.309 raeburn 3647: my @options = ('approval','validate','autolimit');
1.306 raeburn 3648: my $optregex = join('|',@options);
1.300 raeburn 3649: my $cdom = $env{'request.role.domain'};
3650: foreach my $tool (@{$usertools}) {
1.383 raeburn 3651: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
1.314 raeburn 3652: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
1.300 raeburn 3653: $changeHash->{$context.'.'.$tool} = $userenv->{$context.'.'.$tool};
1.383 raeburn 3654: my ($newop,$limit);
1.314 raeburn 3655: if ($env{'form.'.$context.'_'.$tool}) {
3656: $newop = $env{'form.'.$context.'_'.$tool};
3657: if ($newop eq 'autolimit') {
1.383 raeburn 3658: $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
1.314 raeburn 3659: $limit =~ s/\D+//g;
3660: $newop .= '='.$limit;
3661: }
3662: }
1.300 raeburn 3663: if ($userenv->{$context.'.'.$tool} eq '') {
1.314 raeburn 3664: if ($newop) {
3665: $changed->{$tool}=&tool_admin($tool,$cdom.':'.$newop,
1.300 raeburn 3666: $changeHash,$context);
3667: if ($changed->{$tool}) {
1.383 raeburn 3668: if ($newop =~ /^autolimit/) {
3669: if ($limit) {
3670: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3671: } else {
3672: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3673: }
3674: } else {
3675: $newaccesstext->{$tool} = $reqdisplay{$newop};
3676: }
1.300 raeburn 3677: } else {
3678: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3679: }
3680: }
3681: } else {
3682: my @curr = split(',',$userenv->{$context.'.'.$tool});
3683: my @new;
3684: my $changedoms;
1.314 raeburn 3685: foreach my $req (@curr) {
3686: if ($req =~ /^\Q$cdom\E\:($optregex\=?\d*)$/) {
3687: my $oldop = $1;
1.383 raeburn 3688: if ($oldop =~ /^autolimit=(\d*)/) {
3689: my $limit = $1;
3690: if ($limit) {
3691: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3692: } else {
3693: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3694: }
3695: } else {
3696: $oldaccesstext->{$tool} = $reqdisplay{$oldop};
3697: }
1.314 raeburn 3698: if ($oldop ne $newop) {
3699: $changedoms = 1;
3700: foreach my $item (@curr) {
3701: my ($reqdom,$option) = split(':',$item);
3702: unless ($reqdom eq $cdom) {
3703: push(@new,$item);
3704: }
3705: }
3706: if ($newop) {
3707: push(@new,$cdom.':'.$newop);
1.300 raeburn 3708: }
1.314 raeburn 3709: @new = sort(@new);
1.300 raeburn 3710: }
1.314 raeburn 3711: last;
1.300 raeburn 3712: }
1.314 raeburn 3713: }
3714: if ((!$changedoms) && ($newop)) {
1.300 raeburn 3715: $changedoms = 1;
1.306 raeburn 3716: @new = sort(@curr,$cdom.':'.$newop);
1.300 raeburn 3717: }
3718: if ($changedoms) {
1.314 raeburn 3719: my $newdomstr;
1.300 raeburn 3720: if (@new) {
3721: $newdomstr = join(',',@new);
3722: }
3723: $changed->{$tool}=&tool_admin($tool,$newdomstr,$changeHash,
3724: $context);
3725: if ($changed->{$tool}) {
3726: if ($env{'form.'.$context.'_'.$tool}) {
1.306 raeburn 3727: if ($env{'form.'.$context.'_'.$tool} eq 'autolimit') {
1.314 raeburn 3728: my $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
3729: $limit =~ s/\D+//g;
3730: if ($limit) {
1.383 raeburn 3731: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
1.314 raeburn 3732: } else {
1.383 raeburn 3733: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
1.306 raeburn 3734: }
1.314 raeburn 3735: } else {
1.306 raeburn 3736: $newaccesstext->{$tool} = $reqdisplay{$env{'form.'.$context.'_'.$tool}};
3737: }
1.300 raeburn 3738: } else {
1.383 raeburn 3739: $newaccesstext->{$tool} = &mt("availability set to 'off'");
1.300 raeburn 3740: }
3741: }
3742: }
3743: }
3744: }
3745: return;
3746: }
1.275 raeburn 3747: foreach my $tool (@{$usertools}) {
1.383 raeburn 3748: my ($newval,$limit,$envkey);
1.362 raeburn 3749: $envkey = $context.'.'.$tool;
1.306 raeburn 3750: if ($context eq 'requestcourses') {
3751: $newval = $env{'form.crsreq_'.$tool};
3752: if ($newval eq 'autolimit') {
1.383 raeburn 3753: $limit = $env{'form.crsreq_'.$tool.'_limit'};
3754: $limit =~ s/\D+//g;
3755: $newval .= '='.$limit;
1.306 raeburn 3756: }
1.362 raeburn 3757: } elsif ($context eq 'requestauthor') {
3758: $newval = $env{'form.'.$context};
3759: $envkey = $context;
1.314 raeburn 3760: } else {
1.306 raeburn 3761: $newval = $env{'form.'.$context.'_'.$tool};
3762: }
1.362 raeburn 3763: if ($userenv->{$envkey} ne '') {
1.275 raeburn 3764: $oldaccess->{$tool} = &mt('custom');
1.383 raeburn 3765: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3766: if ($userenv->{$envkey} =~ /^autolimit=(\d*)$/) {
3767: my $currlimit = $1;
3768: if ($currlimit eq '') {
3769: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3770: } else {
3771: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$currlimit);
3772: }
3773: } elsif ($userenv->{$envkey}) {
3774: $oldaccesstext->{$tool} = $reqdisplay{$userenv->{$envkey}};
3775: } else {
3776: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
3777: }
1.275 raeburn 3778: } else {
1.383 raeburn 3779: if ($userenv->{$envkey}) {
3780: $oldaccesstext->{$tool} = &mt("availability set to 'on'");
3781: } else {
3782: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
3783: }
1.275 raeburn 3784: }
1.362 raeburn 3785: $changeHash->{$envkey} = $userenv->{$envkey};
1.275 raeburn 3786: if ($env{'form.custom'.$tool} == 1) {
1.362 raeburn 3787: if ($newval ne $userenv->{$envkey}) {
1.306 raeburn 3788: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
3789: $context);
1.275 raeburn 3790: if ($changed->{$tool}) {
3791: $newaccess->{$tool} = &mt('custom');
1.383 raeburn 3792: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3793: if ($newval =~ /^autolimit/) {
3794: if ($limit) {
3795: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3796: } else {
3797: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3798: }
3799: } elsif ($newval) {
3800: $newaccesstext->{$tool} = $reqdisplay{$newval};
3801: } else {
3802: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3803: }
1.275 raeburn 3804: } else {
1.383 raeburn 3805: if ($newval) {
3806: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3807: } else {
3808: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3809: }
1.275 raeburn 3810: }
3811: } else {
3812: $newaccess->{$tool} = $oldaccess->{$tool};
1.383 raeburn 3813: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3814: if ($newval =~ /^autolimit/) {
3815: if ($limit) {
3816: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3817: } else {
3818: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3819: }
3820: } elsif ($newval) {
3821: $newaccesstext->{$tool} = $reqdisplay{$newval};
3822: } else {
3823: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3824: }
1.275 raeburn 3825: } else {
1.383 raeburn 3826: if ($userenv->{$context.'.'.$tool}) {
3827: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3828: } else {
3829: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3830: }
1.275 raeburn 3831: }
3832: }
3833: } else {
3834: $newaccess->{$tool} = $oldaccess->{$tool};
3835: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3836: }
3837: } else {
3838: $changed->{$tool} = &tool_admin($tool,'',$changeHash,$context);
3839: if ($changed->{$tool}) {
3840: $newaccess->{$tool} = &mt('default');
3841: } else {
3842: $newaccess->{$tool} = $oldaccess->{$tool};
1.383 raeburn 3843: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3844: if ($newval =~ /^autolimit/) {
3845: if ($limit) {
3846: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3847: } else {
3848: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3849: }
3850: } elsif ($newval) {
3851: $newaccesstext->{$tool} = $reqdisplay{$newval};
3852: } else {
3853: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3854: }
1.275 raeburn 3855: } else {
1.383 raeburn 3856: if ($userenv->{$context.'.'.$tool}) {
3857: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3858: } else {
3859: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3860: }
1.275 raeburn 3861: }
3862: }
3863: }
3864: } else {
3865: $oldaccess->{$tool} = &mt('default');
3866: if ($env{'form.custom'.$tool} == 1) {
1.306 raeburn 3867: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
3868: $context);
1.275 raeburn 3869: if ($changed->{$tool}) {
3870: $newaccess->{$tool} = &mt('custom');
1.383 raeburn 3871: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3872: if ($newval =~ /^autolimit/) {
3873: if ($limit) {
3874: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3875: } else {
3876: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3877: }
3878: } elsif ($newval) {
3879: $newaccesstext->{$tool} = $reqdisplay{$newval};
3880: } else {
3881: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3882: }
1.275 raeburn 3883: } else {
1.383 raeburn 3884: if ($newval) {
3885: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3886: } else {
3887: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3888: }
1.275 raeburn 3889: }
3890: } else {
3891: $newaccess->{$tool} = $oldaccess->{$tool};
3892: }
3893: } else {
3894: $newaccess->{$tool} = $oldaccess->{$tool};
3895: }
3896: }
3897: }
3898: return;
3899: }
3900:
1.220 raeburn 3901: sub update_roles {
1.375 raeburn 3902: my ($r,$context,$showcredits) = @_;
1.4 www 3903: my $now=time;
1.225 raeburn 3904: my @rolechanges;
1.220 raeburn 3905: my %disallowed;
1.73 sakharuk 3906: $r->print('<h3>'.&mt('Modifying Roles').'</h3>');
1.404 raeburn 3907: foreach my $key (keys(%env)) {
1.135 raeburn 3908: next if (! $env{$key});
1.190 raeburn 3909: next if ($key eq 'form.action');
1.27 matthew 3910: # Revoke roles
1.135 raeburn 3911: if ($key=~/^form\.rev/) {
3912: if ($key=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) {
1.64 www 3913: # Revoke standard role
1.170 albertel 3914: my ($scope,$role) = ($1,$2);
3915: my $result =
3916: &Apache::lonnet::revokerole($env{'form.ccdomain'},
3917: $env{'form.ccuname'},
1.239 raeburn 3918: $scope,$role,'','',$context);
1.367 golterma 3919: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 3920: &mt('Revoking [_1] in [_2]',
3921: &Apache::lonnet::plaintext($role),
1.372 raeburn 3922: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 3923: $result ne "ok").'<br />');
3924: if ($result ne "ok") {
3925: $r->print(&mt('Error: [_1]',$result).'<br />');
3926: }
1.170 albertel 3927: if ($role eq 'st') {
1.202 raeburn 3928: my $result =
1.198 raeburn 3929: &Apache::lonuserutils::classlist_drop($scope,
3930: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 3931: $now);
1.367 golterma 3932: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.53 www 3933: }
1.225 raeburn 3934: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3935: push(@rolechanges,$role);
3936: }
1.196 raeburn 3937: }
1.195 raeburn 3938: if ($key=~m{^form\.rev\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}s) {
1.64 www 3939: # Revoke custom role
1.369 bisitz 3940: my $result = &Apache::lonnet::revokecustomrole(
3941: $env{'form.ccdomain'},$env{'form.ccuname'},$1,$2,$3,$4,'','',$context);
1.367 golterma 3942: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 3943: &mt('Revoking custom role [_1] by [_2] in [_3]',
1.372 raeburn 3944: $4,$3.':'.$2,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 3945: $result ne 'ok').'<br />');
3946: if ($result ne "ok") {
3947: $r->print(&mt('Error: [_1]',$result).'<br />');
3948: }
1.225 raeburn 3949: if (!grep(/^cr$/,@rolechanges)) {
3950: push(@rolechanges,'cr');
3951: }
1.64 www 3952: }
1.135 raeburn 3953: } elsif ($key=~/^form\.del/) {
3954: if ($key=~/^form\.del\:([^\_]+)\_([^\_\.]+)$/) {
1.116 raeburn 3955: # Delete standard role
1.170 albertel 3956: my ($scope,$role) = ($1,$2);
3957: my $result =
3958: &Apache::lonnet::assignrole($env{'form.ccdomain'},
3959: $env{'form.ccuname'},
1.239 raeburn 3960: $scope,$role,$now,0,1,'',
3961: $context);
1.367 golterma 3962: $r->print(&Apache::lonhtmlcommon::confirm_success(
3963: &mt('Deleting [_1] in [_2]',
1.369 bisitz 3964: &Apache::lonnet::plaintext($role),
1.372 raeburn 3965: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 3966: $result ne 'ok').'<br />');
3967: if ($result ne "ok") {
3968: $r->print(&mt('Error: [_1]',$result).'<br />');
3969: }
1.367 golterma 3970:
1.170 albertel 3971: if ($role eq 'st') {
1.202 raeburn 3972: my $result =
1.198 raeburn 3973: &Apache::lonuserutils::classlist_drop($scope,
3974: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 3975: $now);
1.369 bisitz 3976: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.81 albertel 3977: }
1.225 raeburn 3978: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3979: push(@rolechanges,$role);
3980: }
1.116 raeburn 3981: }
1.139 albertel 3982: if ($key=~m{^form\.del\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 3983: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
3984: # Delete custom role
1.369 bisitz 3985: my $result =
3986: &Apache::lonnet::assigncustomrole($env{'form.ccdomain'},
3987: $env{'form.ccuname'},$url,$rdom,$rnam,$rolename,$now,
3988: 0,1,$context);
3989: $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('Deleting custom role [_1] by [_2] in [_3]',
1.372 raeburn 3990: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 3991: $result ne "ok").'<br />');
3992: if ($result ne "ok") {
3993: $r->print(&mt('Error: [_1]',$result).'<br />');
3994: }
1.367 golterma 3995:
1.225 raeburn 3996: if (!grep(/^cr$/,@rolechanges)) {
3997: push(@rolechanges,'cr');
3998: }
1.116 raeburn 3999: }
1.135 raeburn 4000: } elsif ($key=~/^form\.ren/) {
1.101 albertel 4001: my $udom = $env{'form.ccdomain'};
4002: my $uname = $env{'form.ccuname'};
1.116 raeburn 4003: # Re-enable standard role
1.135 raeburn 4004: if ($key=~/^form\.ren\:([^\_]+)\_([^\_\.]+)$/) {
1.89 raeburn 4005: my $url = $1;
4006: my $role = $2;
4007: my $logmsg;
4008: my $output;
4009: if ($role eq 'st') {
1.141 albertel 4010: if ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
1.374 raeburn 4011: my ($cdom,$cnum,$csec) = ($1,$2,$3);
1.375 raeburn 4012: my $credits;
4013: if ($showcredits) {
4014: my $defaultcredits =
4015: &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
4016: $credits = &get_user_credits($defaultcredits,$cdom,$cnum);
4017: }
4018: my $result = &Apache::loncommon::commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$cdom,$cnum,$csec,$context,$credits);
1.220 raeburn 4019: if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course') || ($result eq 'refused')) {
1.223 raeburn 4020: if ($result eq 'refused' && $logmsg) {
4021: $output = $logmsg;
4022: } else {
1.369 bisitz 4023: $output = &mt('Error: [_1]',$result)."\n";
1.223 raeburn 4024: }
1.89 raeburn 4025: } else {
1.372 raeburn 4026: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Assigning [_1] in [_2] starting [_3]',
4027: &Apache::lonnet::plaintext($role),
4028: &Apache::loncommon::show_role_extent($url,$context,'st'),
4029: &Apache::lonlocal::locallocaltime($now))).'<br />'.$logmsg.'<br />';
1.89 raeburn 4030: }
4031: }
4032: } else {
1.101 albertel 4033: my $result=&Apache::lonnet::assignrole($env{'form.ccdomain'},
1.239 raeburn 4034: $env{'form.ccuname'},$url,$role,0,$now,'','',
4035: $context);
1.367 golterma 4036: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Re-enabling [_1] in [_2]',
1.372 raeburn 4037: &Apache::lonnet::plaintext($role),
4038: &Apache::loncommon::show_role_extent($url,$context,$role)),$result ne "ok").'<br />';
1.369 bisitz 4039: if ($result ne "ok") {
4040: $output .= &mt('Error: [_1]',$result).'<br />';
4041: }
4042: }
1.89 raeburn 4043: $r->print($output);
1.225 raeburn 4044: if (!grep(/^\Q$role\E$/,@rolechanges)) {
4045: push(@rolechanges,$role);
4046: }
1.113 raeburn 4047: }
1.116 raeburn 4048: # Re-enable custom role
1.139 albertel 4049: if ($key=~m{^form\.ren\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 4050: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
4051: my $result = &Apache::lonnet::assigncustomrole(
4052: $env{'form.ccdomain'}, $env{'form.ccuname'},
1.240 raeburn 4053: $url,$rdom,$rnam,$rolename,0,$now,undef,$context);
1.369 bisitz 4054: $r->print(&Apache::lonhtmlcommon::confirm_success(
4055: &mt('Re-enabling custom role [_1] by [_2] in [_3]',
1.372 raeburn 4056: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 4057: $result ne "ok").'<br />');
4058: if ($result ne "ok") {
4059: $r->print(&mt('Error: [_1]',$result).'<br />');
4060: }
1.225 raeburn 4061: if (!grep(/^cr$/,@rolechanges)) {
4062: push(@rolechanges,'cr');
4063: }
1.116 raeburn 4064: }
1.135 raeburn 4065: } elsif ($key=~/^form\.act/) {
1.101 albertel 4066: my $udom = $env{'form.ccdomain'};
4067: my $uname = $env{'form.ccuname'};
1.141 albertel 4068: if ($key=~/^form\.act\_($match_domain)\_($match_courseid)\_cr_cr_($match_domain)_($match_username)_([^\_]+)$/) {
1.65 www 4069: # Activate a custom role
1.83 albertel 4070: my ($one,$two,$three,$four,$five)=($1,$2,$3,$4,$5);
4071: my $url='/'.$one.'/'.$two;
4072: my $full=$one.'_'.$two.'_cr_cr_'.$three.'_'.$four.'_'.$five;
1.65 www 4073:
1.101 albertel 4074: my $start = ( $env{'form.start_'.$full} ?
4075: $env{'form.start_'.$full} :
1.88 raeburn 4076: $now );
1.101 albertel 4077: my $end = ( $env{'form.end_'.$full} ?
4078: $env{'form.end_'.$full} :
1.88 raeburn 4079: 0 );
4080:
4081: # split multiple sections
4082: my %sections = ();
1.101 albertel 4083: my $num_sections = &build_roles($env{'form.sec_'.$full},\%sections,$5);
1.88 raeburn 4084: if ($num_sections == 0) {
1.240 raeburn 4085: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end,$context));
1.88 raeburn 4086: } else {
1.114 albertel 4087: my %curr_groups =
1.117 raeburn 4088: &Apache::longroup::coursegroups($one,$two);
1.404 raeburn 4089: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.113 raeburn 4090: if (($sec eq 'none') || ($sec eq 'all') ||
4091: exists($curr_groups{$sec})) {
4092: $disallowed{$sec} = $url;
4093: next;
4094: }
4095: my $securl = $url.'/'.$sec;
1.240 raeburn 4096: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end,$context));
1.88 raeburn 4097: }
4098: }
1.225 raeburn 4099: if (!grep(/^cr$/,@rolechanges)) {
4100: push(@rolechanges,'cr');
4101: }
1.142 raeburn 4102: } elsif ($key=~/^form\.act\_($match_domain)\_($match_name)\_([^\_]+)$/) {
1.27 matthew 4103: # Activate roles for sections with 3 id numbers
4104: # set start, end times, and the url for the class
1.83 albertel 4105: my ($one,$two,$three)=($1,$2,$3);
1.101 albertel 4106: my $start = ( $env{'form.start_'.$one.'_'.$two.'_'.$three} ?
4107: $env{'form.start_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 4108: $now );
1.101 albertel 4109: my $end = ( $env{'form.end_'.$one.'_'.$two.'_'.$three} ?
4110: $env{'form.end_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 4111: 0 );
1.83 albertel 4112: my $url='/'.$one.'/'.$two;
1.88 raeburn 4113: my $type = 'three';
4114: # split multiple sections
4115: my %sections = ();
1.101 albertel 4116: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections,$three);
1.375 raeburn 4117: my $credits;
4118: if ($three eq 'st') {
4119: if ($showcredits) {
4120: my $defaultcredits =
4121: &Apache::lonuserutils::get_defaultcredits($one,$two);
4122: $credits = $env{'form.credits_'.$one.'_'.$two.'_'.$three};
4123: $credits =~ s/[^\d\.]//g;
4124: if ($credits eq $defaultcredits) {
4125: undef($credits);
4126: }
4127: }
4128: }
1.88 raeburn 4129: if ($num_sections == 0) {
1.375 raeburn 4130: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 4131: } else {
1.114 albertel 4132: my %curr_groups =
1.117 raeburn 4133: &Apache::longroup::coursegroups($one,$two);
1.88 raeburn 4134: my $emptysec = 0;
1.404 raeburn 4135: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.88 raeburn 4136: $sec =~ s/\W//g;
1.113 raeburn 4137: if ($sec ne '') {
4138: if (($sec eq 'none') || ($sec eq 'all') ||
4139: exists($curr_groups{$sec})) {
4140: $disallowed{$sec} = $url;
4141: next;
4142: }
1.88 raeburn 4143: my $securl = $url.'/'.$sec;
1.375 raeburn 4144: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec,$context,$credits));
1.88 raeburn 4145: } else {
4146: $emptysec = 1;
4147: }
4148: }
4149: if ($emptysec) {
1.375 raeburn 4150: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 4151: }
1.225 raeburn 4152: }
4153: if (!grep(/^\Q$three\E$/,@rolechanges)) {
4154: push(@rolechanges,$three);
4155: }
1.135 raeburn 4156: } elsif ($key=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
1.27 matthew 4157: # Activate roles for sections with two id numbers
4158: # set start, end times, and the url for the class
1.101 albertel 4159: my $start = ( $env{'form.start_'.$1.'_'.$2} ?
4160: $env{'form.start_'.$1.'_'.$2} :
1.27 matthew 4161: $now );
1.101 albertel 4162: my $end = ( $env{'form.end_'.$1.'_'.$2} ?
4163: $env{'form.end_'.$1.'_'.$2} :
1.27 matthew 4164: 0 );
1.225 raeburn 4165: my $one = $1;
4166: my $two = $2;
4167: my $url='/'.$one.'/';
1.88 raeburn 4168: # split multiple sections
4169: my %sections = ();
1.225 raeburn 4170: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two},\%sections,$two);
1.88 raeburn 4171: if ($num_sections == 0) {
1.240 raeburn 4172: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 4173: } else {
4174: my $emptysec = 0;
1.404 raeburn 4175: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.88 raeburn 4176: if ($sec ne '') {
4177: my $securl = $url.'/'.$sec;
1.240 raeburn 4178: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$two,$start,$end,$one,undef,$sec,$context));
1.88 raeburn 4179: } else {
4180: $emptysec = 1;
4181: }
4182: }
4183: if ($emptysec) {
1.240 raeburn 4184: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 4185: }
4186: }
1.225 raeburn 4187: if (!grep(/^\Q$two\E$/,@rolechanges)) {
4188: push(@rolechanges,$two);
4189: }
1.64 www 4190: } else {
1.190 raeburn 4191: $r->print('<p><span class="LC_error">'.&mt('ERROR').': '.&mt('Unknown command').' <tt>'.$key.'</tt></span></p><br />');
1.64 www 4192: }
1.113 raeburn 4193: foreach my $key (sort(keys(%disallowed))) {
1.274 bisitz 4194: $r->print('<p class="LC_warning">');
1.113 raeburn 4195: if (($key eq 'none') || ($key eq 'all')) {
1.274 bisitz 4196: $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 4197: } else {
1.274 bisitz 4198: $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 4199: }
1.274 bisitz 4200: $r->print('</p><p>'
4201: .&mt('Please [_1]go back[_2] and choose a different section name.'
4202: ,'<a href="javascript:history.go(-1)'
4203: ,'</a>')
4204: .'</p><br />'
4205: );
1.113 raeburn 4206: }
4207: }
1.101 albertel 4208: } # End of foreach (keys(%env))
1.75 www 4209: # Flush the course logs so reverse user roles immediately updated
1.349 raeburn 4210: $r->register_cleanup(\&Apache::lonnet::flushcourselogs);
1.225 raeburn 4211: if (@rolechanges == 0) {
1.372 raeburn 4212: $r->print('<p>'.&mt('No roles to modify').'</p>');
1.193 raeburn 4213: }
1.225 raeburn 4214: return @rolechanges;
1.220 raeburn 4215: }
4216:
1.375 raeburn 4217: sub get_user_credits {
4218: my ($uname,$udom,$defaultcredits,$cdom,$cnum) = @_;
4219: if ($cdom eq '' || $cnum eq '') {
4220: return unless ($env{'request.course.id'});
4221: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4222: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
4223: }
4224: my $credits;
4225: my %currhash =
4226: &Apache::lonnet::get('classlist',[$uname.':'.$udom],$cdom,$cnum);
4227: if (keys(%currhash) > 0) {
4228: my @items = split(/:/,$currhash{$uname.':'.$udom});
4229: my $crdidx = &Apache::loncoursedata::CL_CREDITS() - 3;
4230: $credits = $items[$crdidx];
4231: $credits =~ s/[^\d\.]//g;
4232: }
4233: if ($credits eq $defaultcredits) {
4234: undef($credits);
4235: }
4236: return $credits;
4237: }
4238:
1.220 raeburn 4239: sub enroll_single_student {
1.375 raeburn 4240: my ($r,$uhome,$amode,$genpwd,$now,$newuser,$context,$crstype,
4241: $showcredits,$defaultcredits) = @_;
1.318 raeburn 4242: $r->print('<h3>');
4243: if ($crstype eq 'Community') {
4244: $r->print(&mt('Enrolling Member'));
4245: } else {
4246: $r->print(&mt('Enrolling Student'));
4247: }
4248: $r->print('</h3>');
1.220 raeburn 4249:
4250: # Remove non alphanumeric values from section
4251: $env{'form.sections'}=~s/\W//g;
4252:
1.375 raeburn 4253: my $credits;
4254: if (($showcredits) && ($env{'form.credits'} ne '')) {
4255: $credits = $env{'form.credits'};
4256: $credits =~ s/[^\d\.]//g;
4257: if ($credits ne '') {
4258: if ($credits eq $defaultcredits) {
4259: undef($credits);
4260: }
4261: }
4262: }
4263:
1.220 raeburn 4264: # Clean out any old student roles the user has in this class.
4265: &Apache::lonuserutils::modifystudent($env{'form.ccdomain'},
4266: $env{'form.ccuname'},$env{'request.course.id'},undef,$uhome);
4267: my ($startdate,$enddate) = &Apache::lonuserutils::get_dates_from_form();
4268: my $enroll_result =
4269: &Apache::lonnet::modify_student_enrollment($env{'form.ccdomain'},
4270: $env{'form.ccuname'},$env{'form.cid'},$env{'form.cfirstname'},
4271: $env{'form.cmiddlename'},$env{'form.clastname'},
4272: $env{'form.generation'},$env{'form.sections'},$enddate,
1.375 raeburn 4273: $startdate,'manual',undef,$env{'request.course.id'},'',$context,
4274: $credits);
1.220 raeburn 4275: if ($enroll_result =~ /^ok/) {
1.381 bisitz 4276: $r->print(&mt('[_1] enrolled','<b>'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.'</b>'));
1.220 raeburn 4277: if ($env{'form.sections'} ne '') {
4278: $r->print(' '.&mt('in section [_1]',$env{'form.sections'}));
4279: }
4280: my ($showstart,$showend);
4281: if ($startdate <= $now) {
4282: $showstart = &mt('Access starts immediately');
4283: } else {
4284: $showstart = &mt('Access starts: ').&Apache::lonlocal::locallocaltime($startdate);
4285: }
4286: if ($enddate == 0) {
4287: $showend = &mt('ends: no ending date');
4288: } else {
4289: $showend = &mt('ends: ').&Apache::lonlocal::locallocaltime($enddate);
4290: }
4291: $r->print('.<br />'.$showstart.'; '.$showend);
4292: if ($startdate <= $now && !$newuser) {
1.386 bisitz 4293: $r->print('<p class="LC_info">');
1.318 raeburn 4294: if ($crstype eq 'Community') {
1.392 raeburn 4295: $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 4296: } else {
1.392 raeburn 4297: $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 4298: }
4299: $r->print('</p>');
1.220 raeburn 4300: }
4301: } else {
4302: $r->print(&mt('unable to enroll').": ".$enroll_result);
4303: }
4304: return;
1.188 raeburn 4305: }
4306:
1.204 raeburn 4307: sub get_defaultquota_text {
4308: my ($settingstatus) = @_;
4309: my $defquotatext;
4310: if ($settingstatus eq '') {
1.383 raeburn 4311: $defquotatext = &mt('default');
1.204 raeburn 4312: } else {
4313: my ($usertypes,$order) =
4314: &Apache::lonnet::retrieve_inst_usertypes($env{'form.ccdomain'});
4315: if ($usertypes->{$settingstatus} eq '') {
1.383 raeburn 4316: $defquotatext = &mt('default');
1.204 raeburn 4317: } else {
1.383 raeburn 4318: $defquotatext = &mt('default for [_1]',$usertypes->{$settingstatus});
1.204 raeburn 4319: }
4320: }
4321: return $defquotatext;
4322: }
4323:
1.188 raeburn 4324: sub update_result_form {
4325: my ($uhome) = @_;
4326: my $outcome =
1.367 golterma 4327: '<form name="userupdate" method="post" action="">'."\n";
1.160 raeburn 4328: foreach my $item ('srchby','srchin','srchtype','srchterm','srchdomain','ccuname','ccdomain') {
1.188 raeburn 4329: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 4330: }
1.207 raeburn 4331: if ($env{'form.origname'} ne '') {
4332: $outcome .= '<input type="hidden" name="origname" value="'.$env{'form.origname'}.'" />'."\n";
4333: }
1.160 raeburn 4334: foreach my $item ('sortby','seluname','seludom') {
4335: if (exists($env{'form.'.$item})) {
1.188 raeburn 4336: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 4337: }
4338: }
1.188 raeburn 4339: if ($uhome eq 'no_host') {
4340: $outcome .= '<input type="hidden" name="forcenewuser" value="1" />'."\n";
4341: }
4342: $outcome .= '<input type="hidden" name="phase" value="" />'."\n".
1.383 raeburn 4343: '<input type="hidden" name="currstate" value="" />'."\n".
4344: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
1.188 raeburn 4345: '</form>';
4346: return $outcome;
1.4 www 4347: }
4348:
1.149 raeburn 4349: sub quota_admin {
1.378 raeburn 4350: my ($setquota,$changeHash,$name) = @_;
1.149 raeburn 4351: my $quotachanged;
4352: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
4353: # Current user has quota modification privileges
1.267 raeburn 4354: if (ref($changeHash) eq 'HASH') {
4355: $quotachanged = 1;
1.378 raeburn 4356: $changeHash->{$name.'quota'} = $setquota;
1.267 raeburn 4357: }
1.149 raeburn 4358: }
4359: return $quotachanged;
4360: }
4361:
1.267 raeburn 4362: sub tool_admin {
1.275 raeburn 4363: my ($tool,$settool,$changeHash,$context) = @_;
4364: my $canchange = 0;
1.279 raeburn 4365: if ($context eq 'requestcourses') {
1.275 raeburn 4366: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
4367: $canchange = 1;
4368: }
1.300 raeburn 4369: } elsif ($context eq 'reqcrsotherdom') {
4370: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
4371: $canchange = 1;
4372: }
1.362 raeburn 4373: } elsif ($context eq 'requestauthor') {
4374: if (&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) {
4375: $canchange = 1;
4376: }
1.275 raeburn 4377: } elsif (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
4378: # Current user has quota modification privileges
4379: $canchange = 1;
4380: }
1.267 raeburn 4381: my $toolchanged;
1.275 raeburn 4382: if ($canchange) {
1.267 raeburn 4383: if (ref($changeHash) eq 'HASH') {
4384: $toolchanged = 1;
1.362 raeburn 4385: if ($tool eq 'requestauthor') {
4386: $changeHash->{$context} = $settool;
4387: } else {
4388: $changeHash->{$context.'.'.$tool} = $settool;
4389: }
1.267 raeburn 4390: }
4391: }
4392: return $toolchanged;
4393: }
4394:
1.88 raeburn 4395: sub build_roles {
1.89 raeburn 4396: my ($sectionstr,$sections,$role) = @_;
1.88 raeburn 4397: my $num_sections = 0;
4398: if ($sectionstr=~ /,/) {
4399: my @secnums = split/,/,$sectionstr;
1.89 raeburn 4400: if ($role eq 'st') {
4401: $secnums[0] =~ s/\W//g;
4402: $$sections{$secnums[0]} = 1;
4403: $num_sections = 1;
4404: } else {
4405: foreach my $sec (@secnums) {
4406: $sec =~ ~s/\W//g;
1.150 banghart 4407: if (!($sec eq "")) {
1.89 raeburn 4408: if (exists($$sections{$sec})) {
4409: $$sections{$sec} ++;
4410: } else {
4411: $$sections{$sec} = 1;
4412: $num_sections ++;
4413: }
1.88 raeburn 4414: }
4415: }
4416: }
4417: } else {
4418: $sectionstr=~s/\W//g;
4419: unless ($sectionstr eq '') {
4420: $$sections{$sectionstr} = 1;
4421: $num_sections ++;
4422: }
4423: }
1.129 albertel 4424:
1.88 raeburn 4425: return $num_sections;
4426: }
4427:
1.58 www 4428: # ========================================================== Custom Role Editor
4429:
4430: sub custom_role_editor {
1.406.2.14 raeburn 4431: my ($r,$context,$brcrum,$prefix,$permission) = @_;
1.324 raeburn 4432: my $action = $env{'form.customroleaction'};
1.406.2.14 raeburn 4433: my ($rolename,$helpitem);
1.324 raeburn 4434: if ($action eq 'new') {
4435: $rolename=$env{'form.newrolename'};
4436: } else {
4437: $rolename=$env{'form.rolename'};
1.59 www 4438: }
4439:
1.324 raeburn 4440: my ($crstype,$context);
4441: if ($env{'request.course.id'}) {
4442: $crstype = &Apache::loncommon::course_type();
4443: $context = 'course';
1.406.2.14 raeburn 4444: $helpitem = 'Course_Editing_Custom_Roles';
1.324 raeburn 4445: } else {
4446: $context = 'domain';
1.406.2.5 raeburn 4447: $crstype = 'course';
1.406.2.14 raeburn 4448: $helpitem = 'Domain_Editing_Custom_Roles';
1.324 raeburn 4449: }
1.351 raeburn 4450:
4451: $rolename=~s/[^A-Za-z0-9]//gs;
4452: if (!$rolename || $env{'form.phase'} eq 'pickrole') {
1.406.2.14 raeburn 4453: &print_username_entry_form($r,$context,undef,undef,undef,$crstype,$brcrum,
4454: $permission);
1.351 raeburn 4455: return;
4456: }
4457:
1.406.2.5 raeburn 4458: my $formname = 'form1';
4459: my %privs=();
4460: my $body_top = '<h2>';
4461: # ------------------------------------------------------- Does this role exist?
1.59 www 4462: my ($rdummy,$roledef)=
4463: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
4464: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.406.2.5 raeburn 4465: $body_top .= &mt('Existing Role').' "';
1.61 www 4466: # ------------------------------------------------- Get current role privileges
1.406.2.5 raeburn 4467: ($privs{'system'},$privs{'domain'},$privs{'course'})=split(/\_/,$roledef);
4468: if ($privs{'system'} =~ /bre\&S/) {
4469: if ($context eq 'domain') {
4470: $crstype = 'Course';
4471: } elsif ($crstype eq 'Community') {
4472: $privs{'system'} =~ s/bre\&S//;
4473: }
4474: } elsif ($context eq 'domain') {
4475: $crstype = 'Course';
1.324 raeburn 4476: }
1.59 www 4477: } else {
1.406.2.5 raeburn 4478: $body_top .= &mt('New Role').' "';
4479: $roledef='';
1.59 www 4480: }
1.153 banghart 4481: $body_top .= $rolename.'"</h2>';
1.406.2.5 raeburn 4482:
4483: # ------------------------------------------------------- What can be assigned?
4484: my %full=();
4485: my %levels=(
4486: course => {},
4487: domain => {},
4488: system => {},
4489: );
4490: my %levelscurrent=(
4491: course => {},
4492: domain => {},
4493: system => {},
4494: );
4495: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
1.160 raeburn 4496: my ($jsback,$elements) = &crumb_utilities();
1.406.2.5 raeburn 4497: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
4498: my $head_script =
4499: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,
4500: \%full,\@templateroles,$jsback);
1.351 raeburn 4501: push (@{$brcrum},
1.406.2.5 raeburn 4502: {href => "javascript:backPage(document.$formname,'pickrole','')",
1.351 raeburn 4503: text => "Pick custom role",
4504: faq => 282,bug=>'Instructor Interface',},
1.406.2.5 raeburn 4505: {href => "javascript:backPage(document.$formname,'','')",
1.351 raeburn 4506: text => "Edit custom role",
4507: faq => 282,
4508: bug => 'Instructor Interface',
1.406.2.14 raeburn 4509: help => $helpitem}
1.351 raeburn 4510: );
4511: my $args = { bread_crumbs => $brcrum,
4512: bread_crumbs_component => 'User Management'};
4513: $r->print(&Apache::loncommon::start_page('Custom Role Editor',
4514: $head_script,$args).
4515: $body_top);
1.406.2.5 raeburn 4516: $r->print('<form name="'.$formname.'" method="post" action="">'."\n".
4517: &Apache::lonuserutils::custom_role_header($context,$crstype,
4518: \@templateroles,$prefix));
1.264 bisitz 4519:
1.61 www 4520: $r->print(<<ENDCCF);
4521: <input type="hidden" name="phase" value="set_custom_roles" />
4522: <input type="hidden" name="rolename" value="$rolename" />
4523: ENDCCF
1.406.2.5 raeburn 4524: $r->print(&Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
4525: \%levelscurrent,$prefix));
1.135 raeburn 4526: $r->print(&Apache::loncommon::end_data_table().
1.190 raeburn 4527: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
1.160 raeburn 4528: '<input type="hidden" name="startrolename" value="'.$env{'form.rolename'}.
1.406.2.5 raeburn 4529: '" />'."\n".'<input type="hidden" name="currstate" value="" />'."\n".
1.160 raeburn 4530: '<input type="reset" value="'.&mt("Reset").'" />'."\n".
1.351 raeburn 4531: '<input type="submit" value="'.&mt('Save').'" /></form>');
1.61 www 4532: }
1.406.2.5 raeburn 4533:
1.61 www 4534: # ---------------------------------------------------------- Call to definerole
4535: sub set_custom_role {
1.406.2.14 raeburn 4536: my ($r,$context,$brcrum,$prefix,$permission) = @_;
1.101 albertel 4537: my $rolename=$env{'form.rolename'};
1.63 www 4538: $rolename=~s/[^A-Za-z0-9]//gs;
1.150 banghart 4539: if (!$rolename) {
1.406.2.14 raeburn 4540: &custom_role_editor($r,$context,$brcrum,$prefix,$permission);
1.61 www 4541: return;
4542: }
1.160 raeburn 4543: my ($jsback,$elements) = &crumb_utilities();
1.301 bisitz 4544: my $jscript = '<script type="text/javascript">'
4545: .'// <![CDATA['."\n"
4546: .$jsback."\n"
4547: .'// ]]>'."\n"
4548: .'</script>'."\n";
1.406.2.14 raeburn 4549: my $helpitem = 'Course_Editing_Custom_Roles';
4550: if ($context eq 'domain') {
4551: $helpitem = 'Domain_Editing_Custom_Roles';
4552: }
1.352 raeburn 4553: push(@{$brcrum},
4554: {href => "javascript:backPage(document.customresult,'pickrole','')",
4555: text => "Pick custom role",
4556: faq => 282,
4557: bug => 'Instructor Interface',},
4558: {href => "javascript:backPage(document.customresult,'selected_custom_edit','')",
4559: text => "Edit custom role",
4560: faq => 282,
4561: bug => 'Instructor Interface',},
4562: {href => "javascript:backPage(document.customresult,'set_custom_roles','')",
4563: text => "Result",
4564: faq => 282,
4565: bug => 'Instructor Interface',
1.406.2.14 raeburn 4566: help => $helpitem,}
1.352 raeburn 4567: );
4568: my $args = { bread_crumbs => $brcrum,
1.406.2.5 raeburn 4569: bread_crumbs_component => 'User Management'};
1.351 raeburn 4570: $r->print(&Apache::loncommon::start_page('Save Custom Role',$jscript,$args));
1.160 raeburn 4571:
1.393 raeburn 4572: my $newrole;
1.61 www 4573: my ($rdummy,$roledef)=
1.110 albertel 4574: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
4575:
1.61 www 4576: # ------------------------------------------------------- Does this role exist?
1.188 raeburn 4577: $r->print('<h3>');
1.61 www 4578: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.73 sakharuk 4579: $r->print(&mt('Existing Role').' "');
1.61 www 4580: } else {
1.73 sakharuk 4581: $r->print(&mt('New Role').' "');
1.61 www 4582: $roledef='';
1.393 raeburn 4583: $newrole = 1;
1.61 www 4584: }
1.188 raeburn 4585: $r->print($rolename.'"</h3>');
1.406.2.5 raeburn 4586: # ------------------------------------------------- Assign role and show result
1.61 www 4587:
1.387 bisitz 4588: my $errmsg;
1.406.2.5 raeburn 4589: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$prefix);
4590: # Assign role and return result
4591: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
4592: $newprivs{'c'});
1.387 bisitz 4593: if ($result ne 'ok') {
4594: $errmsg = ': '.$result;
4595: }
4596: my $message =
4597: &Apache::lonhtmlcommon::confirm_success(
4598: &mt('Defining Role').$errmsg, ($result eq 'ok' ? 0 : 1));
1.101 albertel 4599: if ($env{'request.course.id'}) {
4600: my $url='/'.$env{'request.course.id'};
1.63 www 4601: $url=~s/\_/\//g;
1.387 bisitz 4602: $result =
4603: &Apache::lonnet::assigncustomrole(
4604: $env{'user.domain'},$env{'user.name'},
4605: $url,
4606: $env{'user.domain'},$env{'user.name'},
4607: $rolename,undef,undef,undef,$context);
4608: if ($result ne 'ok') {
4609: $errmsg = ': '.$result;
4610: }
4611: $message .=
4612: '<br />'
4613: .&Apache::lonhtmlcommon::confirm_success(
4614: &mt('Assigning Role to Self').$errmsg, ($result eq 'ok' ? 0 : 1));
1.63 www 4615: }
1.380 bisitz 4616: $r->print(
1.387 bisitz 4617: &Apache::loncommon::confirmwrapper($message)
4618: .'<br />'
4619: .&Apache::lonhtmlcommon::actionbox([
4620: '<a href="javascript:backPage(document.customresult,'."'pickrole'".')">'
4621: .&mt('Create or edit another custom role')
4622: .'</a>'])
1.380 bisitz 4623: .'<form name="customresult" method="post" action="">'
1.387 bisitz 4624: .&Apache::lonhtmlcommon::echo_form_input([])
4625: .'</form>'
1.380 bisitz 4626: );
1.58 www 4627: }
4628:
1.2 www 4629: # ================================================================ Main Handler
4630: sub handler {
4631: my $r = shift;
4632: if ($r->header_only) {
1.68 www 4633: &Apache::loncommon::content_type($r,'text/html');
1.2 www 4634: $r->send_http_header;
4635: return OK;
4636: }
1.406.2.14 raeburn 4637: my ($context,$crstype,$cid,$cnum,$cdom,$allhelpitems);
4638:
1.190 raeburn 4639: if ($env{'request.course.id'}) {
4640: $context = 'course';
1.318 raeburn 4641: $crstype = &Apache::loncommon::course_type();
1.190 raeburn 4642: } elsif ($env{'request.role'} =~ /^au\./) {
1.206 raeburn 4643: $context = 'author';
1.190 raeburn 4644: } else {
4645: $context = 'domain';
4646: }
1.375 raeburn 4647:
1.406.2.14 raeburn 4648: my ($permission,$allowed) =
4649: &Apache::lonuserutils::get_permission($context,$crstype);
4650:
4651: if ($allowed) {
4652: my @allhelp;
4653: if ($context eq 'course') {
4654: $cid = $env{'request.course.id'};
4655: $cdom = $env{'course.'.$cid.'.domain'};
4656: $cnum = $env{'course.'.$cid.'.num'};
4657:
4658: if ($permission->{'cusr'}) {
4659: push(@allhelp,'Course_Create_Class_List');
4660: }
4661: if ($permission->{'view'} || $permission->{'cusr'}) {
4662: push(@allhelp,('Course_Change_Privileges','Course_View_Class_List'));
4663: }
4664: if ($permission->{'custom'}) {
4665: push(@allhelp,'Course_Editing_Custom_Roles');
4666: }
4667: if ($permission->{'cusr'}) {
4668: push(@allhelp,('Course_Add_Student','Course_Drop_Student'));
4669: }
4670: unless ($permission->{'cusr_section'}) {
4671: if (&Apache::lonnet::auto_run($cnum,$cdom) && (($permission->{'cusr'}) || ($permission->{'view'}))) {
4672: push(@allhelp,'Course_Automated_Enrollment');
4673: }
1.406.2.21 raeburn 4674: if (($permission->{'selfenrolladmin'}) || ($permission->{'selfenrollview'})) {
1.406.2.14 raeburn 4675: push(@allhelp,'Course_Approve_Selfenroll');
4676: }
4677: }
4678: if ($permission->{'grp_manage'}) {
4679: push(@allhelp,'Course_Manage_Group');
4680: }
4681: if ($permission->{'view'} || $permission->{'cusr'}) {
4682: push(@allhelp,'Course_User_Logs');
4683: }
4684: } elsif ($context eq 'author') {
4685: push(@allhelp,('Author_Change_Privileges','Author_Create_Coauthor_List',
4686: 'Author_View_Coauthor_List','Author_User_Logs'));
4687: } else {
4688: if ($permission->{'cusr'}) {
4689: push(@allhelp,'Domain_Change_Privileges');
4690: if ($permission->{'activity'}) {
4691: push(@allhelp,'Domain_User_Access_Logs');
4692: }
4693: push(@allhelp,('Domain_Create_Users','Domain_View_Users_List'));
4694: if ($permission->{'custom'}) {
4695: push(@allhelp,'Domain_Editing_Custom_Roles');
4696: }
4697: push(@allhelp,('Domain_Role_Approvals','Domain_Username_Approvals','Domain_Change_Logs'));
4698: } elsif ($permission->{'view'}) {
4699: push(@allhelp,'Domain_View_Privileges');
4700: if ($permission->{'activity'}) {
4701: push(@allhelp,'Domain_User_Access_Logs');
4702: }
4703: push(@allhelp,('Domain_View_Users_List','Domain_Change_Logs'));
4704: }
4705: }
4706: if (@allhelp) {
4707: $allhelpitems = join(',',@allhelp);
4708: }
4709: }
4710:
1.190 raeburn 4711: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.233 raeburn 4712: ['action','state','callingform','roletype','showrole','bulkaction','popup','phase',
1.391 raeburn 4713: 'username','domain','srchterm','srchdomain','srchin','srchby','srchtype','queue']);
1.190 raeburn 4714: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.351 raeburn 4715: my $args;
4716: my $brcrum = [];
4717: my $bread_crumbs_component = 'User Management';
1.391 raeburn 4718: if (($env{'form.action'} ne 'dateselect') && ($env{'form.action'} ne 'displayuserreq')) {
1.351 raeburn 4719: $brcrum = [{href=>"/adm/createuser",
4720: text=>"User Management",
1.406.2.14 raeburn 4721: help=>$allhelpitems}
1.351 raeburn 4722: ];
1.202 raeburn 4723: }
1.190 raeburn 4724: if (!$allowed) {
1.358 raeburn 4725: if ($context eq 'course') {
4726: $r->internal_redirect('/adm/viewclasslist');
4727: return OK;
4728: }
1.190 raeburn 4729: $env{'user.error.msg'}=
4730: "/adm/createuser:cst:0:0:Cannot create/modify user data ".
4731: "or view user status.";
4732: return HTTP_NOT_ACCEPTABLE;
4733: }
4734:
4735: &Apache::loncommon::content_type($r,'text/html');
4736: $r->send_http_header;
4737:
1.375 raeburn 4738: my $showcredits;
4739: if ((($context eq 'course') && ($crstype eq 'Course')) ||
4740: ($context eq 'domain')) {
4741: my %domdefaults =
4742: &Apache::lonnet::get_domain_defaults($env{'request.role.domain'});
4743: if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'}) {
4744: $showcredits = 1;
4745: }
4746: }
4747:
1.190 raeburn 4748: # Main switch on form.action and form.state, as appropriate
4749: if (! exists($env{'form.action'})) {
1.351 raeburn 4750: $args = {bread_crumbs => $brcrum,
4751: bread_crumbs_component => $bread_crumbs_component};
4752: $r->print(&header(undef,$args));
1.318 raeburn 4753: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 4754: } elsif ($env{'form.action'} eq 'upload' && $permission->{'cusr'}) {
1.406.2.14 raeburn 4755: my $helpitem = 'Course_Create_Class_List';
4756: if ($context eq 'author') {
4757: $helpitem = 'Author_Create_Coauthor_List';
4758: } elsif ($context eq 'domain') {
4759: $helpitem = 'Domain_Create_Users';
4760: }
1.351 raeburn 4761: push(@{$brcrum},
4762: { href => '/adm/createuser?action=upload&state=',
4763: text => 'Upload Users List',
1.406.2.14 raeburn 4764: help => $helpitem,
1.351 raeburn 4765: });
4766: $bread_crumbs_component = 'Upload Users List';
4767: $args = {bread_crumbs => $brcrum,
4768: bread_crumbs_component => $bread_crumbs_component};
4769: $r->print(&header(undef,$args));
1.190 raeburn 4770: $r->print('<form name="studentform" method="post" '.
4771: 'enctype="multipart/form-data" '.
4772: ' action="/adm/createuser">'."\n");
4773: if (! exists($env{'form.state'})) {
4774: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4775: } elsif ($env{'form.state'} eq 'got_file') {
1.406.2.15 raeburn 4776: my $result =
4777: &Apache::lonuserutils::print_upload_manager_form($r,$context,
4778: $permission,
4779: $crstype,$showcredits);
4780: if ($result eq 'missingdata') {
4781: delete($env{'form.state'});
4782: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4783: }
1.190 raeburn 4784: } elsif ($env{'form.state'} eq 'enrolling') {
4785: if ($env{'form.datatoken'}) {
1.406.2.15 raeburn 4786: my $result = &Apache::lonuserutils::upfile_drop_add($r,$context,
4787: $permission,
4788: $showcredits);
4789: if ($result eq 'missingdata') {
4790: delete($env{'form.state'});
4791: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4792: } elsif ($result eq 'invalidhome') {
4793: $env{'form.state'} = 'got_file';
4794: delete($env{'form.lcserver'});
4795: my $result =
4796: &Apache::lonuserutils::print_upload_manager_form($r,$context,$permission,
4797: $crstype,$showcredits);
4798: if ($result eq 'missingdata') {
4799: delete($env{'form.state'});
4800: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4801: }
4802: }
4803: } else {
4804: delete($env{'form.state'});
4805: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
1.190 raeburn 4806: }
4807: } else {
4808: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4809: }
1.406.2.15 raeburn 4810: $r->print('</form>');
1.406.2.5 raeburn 4811: } elsif (((($env{'form.action'} eq 'singleuser') || ($env{'form.action'}
4812: eq 'singlestudent')) && ($permission->{'cusr'})) ||
1.406.2.6 raeburn 4813: (($env{'form.action'} eq 'singleuser') && ($permission->{'view'})) ||
1.406.2.5 raeburn 4814: (($env{'form.action'} eq 'accesslogs') && ($permission->{'activity'}))) {
1.190 raeburn 4815: my $phase = $env{'form.phase'};
4816: my @search = ('srchterm','srchby','srchin','srchtype','srchdomain');
1.192 albertel 4817: &Apache::loncreateuser::restore_prev_selections();
4818: my $srch;
4819: foreach my $item (@search) {
4820: $srch->{$item} = $env{'form.'.$item};
4821: }
1.207 raeburn 4822: if (($phase eq 'get_user_info') || ($phase eq 'userpicked') ||
1.406.2.5 raeburn 4823: ($phase eq 'createnewuser') || ($phase eq 'activity')) {
1.207 raeburn 4824: if ($env{'form.phase'} eq 'createnewuser') {
4825: my $response;
4826: if ($env{'form.srchterm'} !~ /^$match_username$/) {
1.366 bisitz 4827: my $response =
4828: '<span class="LC_warning">'
4829: .&mt('You must specify a valid username. Only the following are allowed:'
4830: .' letters numbers - . @')
4831: .'</span>';
1.221 raeburn 4832: $env{'form.phase'} = '';
1.375 raeburn 4833: &print_username_entry_form($r,$context,$response,$srch,undef,
1.406.2.14 raeburn 4834: $crstype,$brcrum,$permission);
1.207 raeburn 4835: } else {
4836: my $ccuname =&LONCAPA::clean_username($srch->{'srchterm'});
4837: my $ccdomain=&LONCAPA::clean_domain($srch->{'srchdomain'});
4838: &print_user_modification_page($r,$ccuname,$ccdomain,
1.221 raeburn 4839: $srch,$response,$context,
1.375 raeburn 4840: $permission,$crstype,$brcrum,
4841: $showcredits);
1.207 raeburn 4842: }
4843: } elsif ($env{'form.phase'} eq 'get_user_info') {
1.190 raeburn 4844: my ($currstate,$response,$forcenewuser,$results) =
1.221 raeburn 4845: &user_search_result($context,$srch);
1.190 raeburn 4846: if ($env{'form.currstate'} eq 'modify') {
4847: $currstate = $env{'form.currstate'};
4848: }
4849: if ($currstate eq 'select') {
4850: &print_user_selection_page($r,$response,$srch,$results,
1.351 raeburn 4851: \@search,$context,undef,$crstype,
4852: $brcrum);
1.406.2.5 raeburn 4853: } elsif (($currstate eq 'modify') || ($env{'form.action'} eq 'accesslogs')) {
4854: my ($ccuname,$ccdomain,$uhome);
1.190 raeburn 4855: if (($srch->{'srchby'} eq 'uname') &&
4856: ($srch->{'srchtype'} eq 'exact')) {
4857: $ccuname = $srch->{'srchterm'};
4858: $ccdomain= $srch->{'srchdomain'};
4859: } else {
4860: my @matchedunames = keys(%{$results});
4861: ($ccuname,$ccdomain) = split(/:/,$matchedunames[0]);
4862: }
4863: $ccuname =&LONCAPA::clean_username($ccuname);
4864: $ccdomain=&LONCAPA::clean_domain($ccdomain);
1.406.2.5 raeburn 4865: if ($env{'form.action'} eq 'accesslogs') {
4866: my $uhome;
4867: if (($ccuname ne '') && ($ccdomain ne '')) {
4868: $uhome = &Apache::lonnet::homeserver($ccuname,$ccdomain);
4869: }
4870: if (($uhome eq '') || ($uhome eq 'no_host')) {
4871: $env{'form.phase'} = '';
4872: undef($forcenewuser);
4873: #if ($response) {
4874: # unless ($response =~ m{\Q<br /><br />\E$}) {
4875: # $response .= '<br /><br />';
4876: # }
4877: #}
4878: &print_username_entry_form($r,$context,$response,$srch,
1.406.2.14 raeburn 4879: $forcenewuser,$crstype,$brcrum,
4880: $permission);
1.406.2.5 raeburn 4881: } else {
4882: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
4883: }
4884: } else {
4885: if ($env{'form.forcenewuser'}) {
4886: $response = '';
4887: }
4888: &print_user_modification_page($r,$ccuname,$ccdomain,
4889: $srch,$response,$context,
4890: $permission,$crstype,$brcrum);
1.190 raeburn 4891: }
4892: } elsif ($currstate eq 'query') {
1.351 raeburn 4893: &print_user_query_page($r,'createuser',$brcrum);
1.190 raeburn 4894: } else {
1.229 raeburn 4895: $env{'form.phase'} = '';
1.207 raeburn 4896: &print_username_entry_form($r,$context,$response,$srch,
1.406.2.14 raeburn 4897: $forcenewuser,$crstype,$brcrum,
4898: $permission);
1.190 raeburn 4899: }
4900: } elsif ($env{'form.phase'} eq 'userpicked') {
4901: my $ccuname = &LONCAPA::clean_username($env{'form.seluname'});
4902: my $ccdomain = &LONCAPA::clean_domain($env{'form.seludom'});
1.406.2.5 raeburn 4903: if ($env{'form.action'} eq 'accesslogs') {
4904: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
4905: } else {
4906: &print_user_modification_page($r,$ccuname,$ccdomain,$srch,'',
4907: $context,$permission,$crstype,
4908: $brcrum);
4909: }
4910: } elsif ($env{'form.action'} eq 'accesslogs') {
4911: my $ccuname = &LONCAPA::clean_username($env{'form.accessuname'});
4912: my $ccdomain = &LONCAPA::clean_domain($env{'form.accessudom'});
4913: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
1.190 raeburn 4914: }
4915: } elsif ($env{'form.phase'} eq 'update_user_data') {
1.406.2.17 raeburn 4916: &update_user_data($r,$context,$crstype,$brcrum,$showcredits,$permission);
1.190 raeburn 4917: } else {
1.351 raeburn 4918: &print_username_entry_form($r,$context,undef,$srch,undef,$crstype,
1.406.2.14 raeburn 4919: $brcrum,$permission);
1.190 raeburn 4920: }
4921: } elsif ($env{'form.action'} eq 'custom' && $permission->{'custom'}) {
1.406.2.5 raeburn 4922: my $prefix;
1.190 raeburn 4923: if ($env{'form.phase'} eq 'set_custom_roles') {
1.406.2.14 raeburn 4924: &set_custom_role($r,$context,$brcrum,$prefix,$permission);
1.190 raeburn 4925: } else {
1.406.2.14 raeburn 4926: &custom_role_editor($r,$context,$brcrum,$prefix,$permission);
1.190 raeburn 4927: }
1.362 raeburn 4928: } elsif (($env{'form.action'} eq 'processauthorreq') &&
4929: ($permission->{'cusr'}) &&
4930: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
4931: push(@{$brcrum},
4932: {href => '/adm/createuser?action=processauthorreq',
1.385 bisitz 4933: text => 'Authoring Space requests',
1.362 raeburn 4934: help => 'Domain_Role_Approvals'});
4935: $bread_crumbs_component = 'Authoring requests';
4936: if ($env{'form.state'} eq 'done') {
4937: push(@{$brcrum},
4938: {href => '/adm/createuser?action=authorreqqueue',
4939: text => 'Result',
4940: help => 'Domain_Role_Approvals'});
4941: $bread_crumbs_component = 'Authoring request result';
4942: }
4943: $args = { bread_crumbs => $brcrum,
4944: bread_crumbs_component => $bread_crumbs_component};
1.391 raeburn 4945: my $js = &usernamerequest_javascript();
4946: $r->print(&header(&add_script($js),$args));
1.362 raeburn 4947: if (!exists($env{'form.state'})) {
4948: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestauthor',
4949: $env{'request.role.domain'}));
4950: } elsif ($env{'form.state'} eq 'done') {
4951: $r->print('<h3>'.&mt('Authoring request processing').'</h3>'."\n");
4952: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestauthor',
4953: $env{'request.role.domain'}));
4954: }
1.391 raeburn 4955: } elsif (($env{'form.action'} eq 'processusernamereq') &&
4956: ($permission->{'cusr'}) &&
4957: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
4958: push(@{$brcrum},
4959: {href => '/adm/createuser?action=processusernamereq',
4960: text => 'LON-CAPA account requests',
4961: help => 'Domain_Username_Approvals'});
4962: $bread_crumbs_component = 'Account requests';
4963: if ($env{'form.state'} eq 'done') {
4964: push(@{$brcrum},
4965: {href => '/adm/createuser?action=usernamereqqueue',
4966: text => 'Result',
4967: help => 'Domain_Username_Approvals'});
4968: $bread_crumbs_component = 'LON-CAPA account request result';
4969: }
4970: $args = { bread_crumbs => $brcrum,
4971: bread_crumbs_component => $bread_crumbs_component};
4972: my $js = &usernamerequest_javascript();
4973: $r->print(&header(&add_script($js),$args));
4974: if (!exists($env{'form.state'})) {
4975: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestusername',
4976: $env{'request.role.domain'}));
4977: } elsif ($env{'form.state'} eq 'done') {
4978: $r->print('<h3>'.&mt('LON-CAPA account request processing').'</h3>'."\n");
4979: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestusername',
4980: $env{'request.role.domain'}));
4981: }
4982: } elsif (($env{'form.action'} eq 'displayuserreq') &&
4983: ($permission->{'cusr'})) {
4984: my $dom = $env{'form.domain'};
4985: my $uname = $env{'form.username'};
4986: my $warning;
4987: if (($dom =~ /^$match_domain$/) && (&Apache::lonnet::domain($dom) ne '')) {
4988: if (($dom eq $env{'request.role.domain'}) && (&Apache::lonnet::allowed('ccc',$dom))) {
4989: if (($uname =~ /^$match_username$/) && ($env{'form.queue'} eq 'approval')) {
4990: my $uhome = &Apache::lonnet::homeserver($uname,$dom);
4991: if ($uhome eq 'no_host') {
4992: my $queue = $env{'form.queue'};
4993: my $reqkey = &escape($uname).'_'.$queue;
4994: my $namespace = 'usernamequeue';
4995: my $domconfig = &Apache::lonnet::get_domainconfiguser($dom);
4996: my %queued =
4997: &Apache::lonnet::get($namespace,[$reqkey],$dom,$domconfig);
4998: unless ($queued{$reqkey}) {
4999: $warning = &mt('No information was found for this LON-CAPA account request.');
5000: }
5001: } else {
5002: $warning = &mt('A LON-CAPA account already exists for the requested username and domain.');
5003: }
5004: } else {
5005: $warning = &mt('LON-CAPA account request status check is for an invalid username.');
5006: }
5007: } else {
5008: $warning = &mt('You do not have rights to view LON-CAPA account requests in the domain specified.');
5009: }
5010: } else {
5011: $warning = &mt('LON-CAPA account request status check is for an invalid domain.');
5012: }
5013: my $args = { only_body => 1 };
5014: $r->print(&header(undef,$args).
5015: '<h3>'.&mt('LON-CAPA Account Request Details').'</h3>');
5016: if ($warning ne '') {
5017: $r->print('<div class="LC_warning">'.$warning.'</div>');
5018: } else {
5019: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
5020: my $domconfiguser = &Apache::lonnet::get_domainconfiguser($dom);
5021: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
5022: if (ref($domconfig{'usercreation'}) eq 'HASH') {
5023: if (ref($domconfig{'usercreation'}{'cancreate'}) eq 'HASH') {
5024: if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}) eq 'HASH') {
5025: my %info =
5026: &Apache::lonnet::get('nohist_requestedusernames',[$uname],$dom,$domconfiguser);
5027: if (ref($info{$uname}) eq 'HASH') {
1.396 raeburn 5028: my $usertype = $info{$uname}{'inststatus'};
5029: unless ($usertype) {
5030: $usertype = 'default';
5031: }
1.406.2.16 raeburn 5032: my ($showstatus,$showemail,$pickstart);
5033: my $numextras = 0;
5034: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5035: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
5036: if (ref($usertypes) eq 'HASH') {
5037: if ($usertypes->{$usertype}) {
5038: $showstatus = $usertypes->{$usertype};
5039: } else {
5040: $showstatus = $othertitle;
5041: }
5042: if ($showstatus) {
5043: $numextras ++;
5044: }
5045: }
5046: }
5047: if (($info{$uname}{'email'} ne '') && ($info{$uname}{'email'} ne $uname)) {
5048: $showemail = $info{$uname}{'email'};
5049: $numextras ++;
5050: }
1.396 raeburn 5051: if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}) eq 'HASH') {
5052: if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
1.406.2.16 raeburn 5053: $pickstart = 1;
1.396 raeburn 5054: $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box());
1.406.2.16 raeburn 5055: my ($num,$count);
1.396 raeburn 5056: $count = scalar(keys(%{$domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}}));
1.406.2.16 raeburn 5057: $count += $numextras;
1.396 raeburn 5058: foreach my $field (@{$infofields}) {
5059: next unless ($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}{$field});
5060: next unless ($infotitles->{$field});
5061: $r->print(&Apache::lonhtmlcommon::row_title($infotitles->{$field}).
5062: $info{$uname}{$field});
5063: $num ++;
1.406.2.16 raeburn 5064: unless ($count == $num) {
1.396 raeburn 5065: $r->print(&Apache::lonhtmlcommon::row_closure());
5066: }
5067: }
1.406.2.16 raeburn 5068: }
5069: }
5070: if ($numextras) {
5071: unless ($pickstart) {
5072: $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box());
5073: $pickstart = 1;
5074: }
5075: if ($showemail) {
5076: my $closure = '';
5077: unless ($showstatus) {
5078: $closure = 1;
1.391 raeburn 5079: }
1.406.2.16 raeburn 5080: $r->print(&Apache::lonhtmlcommon::row_title(&mt('E-mail address')).
5081: $showemail.
5082: &Apache::lonhtmlcommon::row_closure($closure));
5083: }
5084: if ($showstatus) {
5085: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Status type[_1](self-reported)','<br />')).
5086: $showstatus.
5087: &Apache::lonhtmlcommon::row_closure(1));
1.391 raeburn 5088: }
5089: }
1.406.2.16 raeburn 5090: if ($pickstart) {
5091: $r->print(&Apache::lonhtmlcommon::end_pick_box().'</div>');
5092: } else {
5093: $r->print('<div>'.&mt('No information to display for this account request.').'</div>');
5094: }
5095: } else {
5096: $r->print('<div>'.&mt('No information available for this account request.').'</div>');
1.391 raeburn 5097: }
5098: }
5099: }
5100: }
5101: }
1.406.2.16 raeburn 5102: $r->print(&close_popup_form());
1.207 raeburn 5103: } elsif (($env{'form.action'} eq 'listusers') &&
5104: ($permission->{'view'} || $permission->{'cusr'})) {
1.406.2.14 raeburn 5105: my $helpitem = 'Course_View_Class_List';
5106: if ($context eq 'author') {
5107: $helpitem = 'Author_View_Coauthor_List';
5108: } elsif ($context eq 'domain') {
5109: $helpitem = 'Domain_View_Users_List';
5110: }
1.202 raeburn 5111: if ($env{'form.phase'} eq 'bulkchange') {
1.351 raeburn 5112: push(@{$brcrum},
5113: {href => '/adm/createuser?action=listusers',
5114: text => "List Users"},
5115: {href => "/adm/createuser",
5116: text => "Result",
1.406.2.14 raeburn 5117: help => $helpitem});
1.351 raeburn 5118: $bread_crumbs_component = 'Update Users';
5119: $args = {bread_crumbs => $brcrum,
5120: bread_crumbs_component => $bread_crumbs_component};
5121: $r->print(&header(undef,$args));
1.202 raeburn 5122: my $setting = $env{'form.roletype'};
5123: my $choice = $env{'form.bulkaction'};
5124: if ($permission->{'cusr'}) {
1.336 raeburn 5125: &Apache::lonuserutils::update_user_list($r,$context,$setting,$choice,$crstype);
1.221 raeburn 5126: } else {
5127: $r->print(&mt('You are not authorized to make bulk changes to user roles'));
1.223 raeburn 5128: $r->print('<p><a href="/adm/createuser?action=listusers">'.&mt('Display User Lists').'</a>');
1.202 raeburn 5129: }
5130: } else {
1.351 raeburn 5131: push(@{$brcrum},
5132: {href => '/adm/createuser?action=listusers',
5133: text => "List Users",
1.406.2.14 raeburn 5134: help => $helpitem});
1.351 raeburn 5135: $bread_crumbs_component = 'List Users';
5136: $args = {bread_crumbs => $brcrum,
5137: bread_crumbs_component => $bread_crumbs_component};
1.202 raeburn 5138: my ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles);
5139: my $formname = 'studentform';
1.364 raeburn 5140: my $hidecall = "hide_searching();";
1.321 raeburn 5141: if (($context eq 'domain') && (($env{'form.roletype'} eq 'course') ||
5142: ($env{'form.roletype'} eq 'community'))) {
5143: if ($env{'form.roletype'} eq 'course') {
5144: ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles) =
5145: &Apache::lonuserutils::courses_selector($env{'request.role.domain'},
5146: $formname);
5147: } elsif ($env{'form.roletype'} eq 'community') {
5148: $cb_jscript =
5149: &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
5150: my %elements = (
5151: coursepick => 'radio',
5152: coursetotal => 'text',
5153: courselist => 'text',
5154: );
5155: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements);
5156: }
1.364 raeburn 5157: $jscript .= &verify_user_display($context)."\n".
5158: &Apache::loncommon::check_uncheck_jscript();
1.202 raeburn 5159: my $js = &add_script($jscript).$cb_jscript;
5160: my $loadcode =
5161: &Apache::lonuserutils::course_selector_loadcode($formname);
5162: if ($loadcode ne '') {
1.364 raeburn 5163: $args->{add_entries} = {onload => "$loadcode;$hidecall"};
5164: } else {
5165: $args->{add_entries} = {onload => $hidecall};
1.202 raeburn 5166: }
1.351 raeburn 5167: $r->print(&header($js,$args));
1.191 raeburn 5168: } else {
1.364 raeburn 5169: $args->{add_entries} = {onload => $hidecall};
5170: $jscript = &verify_user_display($context).
5171: &Apache::loncommon::check_uncheck_jscript();
5172: $r->print(&header(&add_script($jscript),$args));
1.191 raeburn 5173: }
1.202 raeburn 5174: &Apache::lonuserutils::print_userlist($r,undef,$permission,$context,
1.375 raeburn 5175: $formname,$totcodes,$codetitles,$idlist,$idlist_titles,
5176: $showcredits);
1.191 raeburn 5177: }
1.213 raeburn 5178: } elsif ($env{'form.action'} eq 'drop' && $permission->{'cusr'}) {
1.318 raeburn 5179: my $brtext;
5180: if ($crstype eq 'Community') {
5181: $brtext = 'Drop Members';
5182: } else {
5183: $brtext = 'Drop Students';
5184: }
1.351 raeburn 5185: push(@{$brcrum},
5186: {href => '/adm/createuser?action=drop',
5187: text => $brtext,
5188: help => 'Course_Drop_Student'});
5189: if ($env{'form.state'} eq 'done') {
5190: push(@{$brcrum},
5191: {href=>'/adm/createuser?action=drop',
5192: text=>"Result"});
5193: }
5194: $bread_crumbs_component = $brtext;
5195: $args = {bread_crumbs => $brcrum,
5196: bread_crumbs_component => $bread_crumbs_component};
5197: $r->print(&header(undef,$args));
1.213 raeburn 5198: if (!exists($env{'form.state'})) {
1.318 raeburn 5199: &Apache::lonuserutils::print_drop_menu($r,$context,$permission,$crstype);
1.213 raeburn 5200: } elsif ($env{'form.state'} eq 'done') {
5201: &Apache::lonuserutils::update_user_list($r,$context,undef,
5202: $env{'form.action'});
5203: }
1.202 raeburn 5204: } elsif ($env{'form.action'} eq 'dateselect') {
5205: if ($permission->{'cusr'}) {
1.351 raeburn 5206: $r->print(&header(undef,{'no_nav_bar' => 1}).
1.375 raeburn 5207: &Apache::lonuserutils::date_section_selector($context,$permission,
5208: $crstype,$showcredits));
1.202 raeburn 5209: } else {
1.351 raeburn 5210: $r->print(&header(undef,{'no_nav_bar' => 1}).
5211: '<span class="LC_error">'.&mt('You do not have permission to modify dates or sections for users').'</span>');
1.202 raeburn 5212: }
1.237 raeburn 5213: } elsif ($env{'form.action'} eq 'selfenroll') {
1.406.2.21 raeburn 5214: my %currsettings;
5215: if ($permission->{selfenrolladmin} || $permission->{selfenrollview}) {
5216: %currsettings = (
1.398 raeburn 5217: selfenroll_types => $env{'course.'.$cid.'.internal.selfenroll_types'},
5218: selfenroll_registered => $env{'course.'.$cid.'.internal.selfenroll_registered'},
5219: selfenroll_section => $env{'course.'.$cid.'.internal.selfenroll_section'},
5220: selfenroll_notifylist => $env{'course.'.$cid.'.internal.selfenroll_notifylist'},
5221: selfenroll_approval => $env{'course.'.$cid.'.internal.selfenroll_approval'},
5222: selfenroll_limit => $env{'course.'.$cid.'.internal.selfenroll_limit'},
5223: selfenroll_cap => $env{'course.'.$cid.'.internal.selfenroll_cap'},
5224: selfenroll_start_date => $env{'course.'.$cid.'.internal.selfenroll_start_date'},
5225: selfenroll_end_date => $env{'course.'.$cid.'.internal.selfenroll_end_date'},
5226: selfenroll_start_access => $env{'course.'.$cid.'.internal.selfenroll_start_access'},
5227: selfenroll_end_access => $env{'course.'.$cid.'.internal.selfenroll_end_access'},
5228: default_enrollment_start_date => $env{'course.'.$cid.'.default_enrollment_start_date'},
5229: default_enrollment_end_date => $env{'course.'.$cid.'.default_enrollment_end_date'},
1.400 raeburn 5230: uniquecode => $env{'course.'.$cid.'.internal.uniquecode'},
1.398 raeburn 5231: );
1.406.2.21 raeburn 5232: }
5233: if ($permission->{selfenrolladmin}) {
1.398 raeburn 5234: push(@{$brcrum},
5235: {href => '/adm/createuser?action=selfenroll',
5236: text => "Configure Self-enrollment",
5237: help => 'Course_Self_Enrollment'});
5238: if (!exists($env{'form.state'})) {
5239: $args = { bread_crumbs => $brcrum,
5240: bread_crumbs_component => 'Configure Self-enrollment'};
5241: $r->print(&header(undef,$args));
5242: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
5243: &print_selfenroll_menu($r,'course',$cid,$cdom,$cnum,\%currsettings);
5244: } elsif ($env{'form.state'} eq 'done') {
5245: push (@{$brcrum},
5246: {href=>'/adm/createuser?action=selfenroll',
5247: text=>"Result"});
5248: $args = { bread_crumbs => $brcrum,
5249: bread_crumbs_component => 'Self-enrollment result'};
5250: $r->print(&header(undef,$args));
5251: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
1.400 raeburn 5252: &update_selfenroll_config($r,$cid,$cdom,$cnum,$context,$crstype,\%currsettings);
1.398 raeburn 5253: }
1.406.2.21 raeburn 5254: } elsif ($permission->{selfenrollview}) {
5255: push(@{$brcrum},
5256: {href => '/adm/createuser?action=selfenroll',
5257: text => "View Self-enrollment configuration",
5258: help => 'Course_Self_Enrollment'});
5259: $args = { bread_crumbs => $brcrum,
5260: bread_crumbs_component => 'Self-enrollment Settings'};
5261: $r->print(&header(undef,$args));
5262: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
5263: &print_selfenroll_menu($r,'course',$cid,$cdom,$cnum,\%currsettings,'',1);
1.398 raeburn 5264: } else {
5265: $r->print(&header(undef,{'no_nav_bar' => 1}).
5266: '<span class="LC_error">'.&mt('You do not have permission to configure self-enrollment').'</span>');
1.237 raeburn 5267: }
1.277 raeburn 5268: } elsif ($env{'form.action'} eq 'selfenrollqueue') {
1.406.2.6 raeburn 5269: if ($permission->{selfenrolladmin}) {
1.351 raeburn 5270: push(@{$brcrum},
5271: {href => '/adm/createuser?action=selfenrollqueue',
1.406.2.6 raeburn 5272: text => 'Enrollment requests',
1.406.2.14 raeburn 5273: help => 'Course_Approve_Selfenroll'});
1.406.2.6 raeburn 5274: $bread_crumbs_component = 'Enrollment requests';
5275: if ($env{'form.state'} eq 'done') {
5276: push(@{$brcrum},
5277: {href => '/adm/createuser?action=selfenrollqueue',
5278: text => 'Result',
1.406.2.14 raeburn 5279: help => 'Course_Approve_Selfenroll'});
1.406.2.6 raeburn 5280: $bread_crumbs_component = 'Enrollment result';
5281: }
5282: $args = { bread_crumbs => $brcrum,
5283: bread_crumbs_component => $bread_crumbs_component};
5284: $r->print(&header(undef,$args));
5285: my $coursedesc = $env{'course.'.$cid.'.description'};
5286: if (!exists($env{'form.state'})) {
5287: $r->print('<h3>'.&mt('Pending enrollment requests').'</h3>'."\n");
5288: $r->print(&Apache::loncoursequeueadmin::display_queued_requests($context,
5289: $cdom,$cnum));
5290: } elsif ($env{'form.state'} eq 'done') {
5291: $r->print('<h3>'.&mt('Enrollment request processing').'</h3>'."\n");
5292: $r->print(&Apache::loncoursequeueadmin::update_request_queue($context,
5293: $cdom,$cnum,$coursedesc));
5294: }
5295: } else {
5296: $r->print(&header(undef,{'no_nav_bar' => 1}).
5297: '<span class="LC_error">'.&mt('You do not have permission to manage self-enrollment').'</span>');
1.277 raeburn 5298: }
1.239 raeburn 5299: } elsif ($env{'form.action'} eq 'changelogs') {
1.406.2.6 raeburn 5300: if ($permission->{cusr} || $permission->{view}) {
5301: &print_userchangelogs_display($r,$context,$permission,$brcrum);
5302: } else {
5303: $r->print(&header(undef,{'no_nav_bar' => 1}).
5304: '<span class="LC_error">'.&mt('You do not have permission to view change logs').'</span>');
5305: }
1.406.2.10 raeburn 5306: } elsif ($env{'form.action'} eq 'helpdesk') {
5307: if (($permission->{'owner'}) || ($permission->{'co-owner'})) {
5308: if ($env{'form.state'} eq 'process') {
5309: if ($permission->{'owner'}) {
5310: &update_helpdeskaccess($r,$permission,$brcrum);
5311: } else {
5312: &print_helpdeskaccess_display($r,$permission,$brcrum);
5313: }
5314: } else {
5315: &print_helpdeskaccess_display($r,$permission,$brcrum);
5316: }
5317: } else {
5318: $r->print(&header(undef,{'no_nav_bar' => 1}).
5319: '<span class="LC_error">'.&mt('You do not have permission to view helpdesk access').'</span>');
5320: }
1.190 raeburn 5321: } else {
1.351 raeburn 5322: $bread_crumbs_component = 'User Management';
5323: $args = { bread_crumbs => $brcrum,
5324: bread_crumbs_component => $bread_crumbs_component};
5325: $r->print(&header(undef,$args));
1.318 raeburn 5326: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 5327: }
1.351 raeburn 5328: $r->print(&Apache::loncommon::end_page());
1.190 raeburn 5329: return OK;
5330: }
5331:
5332: sub header {
1.351 raeburn 5333: my ($jscript,$args) = @_;
1.190 raeburn 5334: my $start_page;
1.351 raeburn 5335: if (ref($args) eq 'HASH') {
5336: $start_page=&Apache::loncommon::start_page('User Management',$jscript,$args);
1.190 raeburn 5337: } else {
1.351 raeburn 5338: $start_page=&Apache::loncommon::start_page('User Management',$jscript);
1.190 raeburn 5339: }
5340: return $start_page;
5341: }
1.2 www 5342:
1.191 raeburn 5343: sub add_script {
5344: my ($js) = @_;
1.301 bisitz 5345: return '<script type="text/javascript">'."\n"
5346: .'// <![CDATA['."\n"
5347: .$js."\n"
5348: .'// ]]>'."\n"
5349: .'</script>'."\n";
1.191 raeburn 5350: }
5351:
1.391 raeburn 5352: sub usernamerequest_javascript {
5353: my $js = <<ENDJS;
5354:
5355: function openusernamereqdisplay(dom,uname,queue) {
5356: var url = '/adm/createuser?action=displayuserreq';
5357: url += '&domain='+dom+'&username='+uname+'&queue='+queue;
5358: var title = 'Account_Request_Browser';
5359: var options = 'scrollbars=1,resizable=1,menubar=0';
5360: options += ',width=700,height=600';
5361: var stdeditbrowser = open(url,title,options,'1');
5362: stdeditbrowser.focus();
5363: return;
5364: }
5365:
5366: ENDJS
5367: }
5368:
5369: sub close_popup_form {
5370: my $close= &mt('Close Window');
5371: return << "END";
5372: <p><form name="displayreq" action="" method="post">
5373: <input type="button" name="closeme" value="$close" onclick="javascript:self.close();" />
5374: </form></p>
5375: END
5376: }
5377:
1.202 raeburn 5378: sub verify_user_display {
1.364 raeburn 5379: my ($context) = @_;
1.374 raeburn 5380: my %lt = &Apache::lonlocal::texthash (
5381: course => 'course(s): description, section(s), status',
5382: community => 'community(s): description, section(s), status',
5383: author => 'author',
5384: );
1.364 raeburn 5385: my $photos;
5386: if (($context eq 'course') && $env{'request.course.id'}) {
5387: $photos = $env{'course.'.$env{'request.course.id'}.'.internal.showphoto'};
5388: }
1.202 raeburn 5389: my $output = <<"END";
5390:
1.364 raeburn 5391: function hide_searching() {
5392: if (document.getElementById('searching')) {
5393: document.getElementById('searching').style.display = 'none';
5394: }
5395: return;
5396: }
5397:
1.202 raeburn 5398: function display_update() {
5399: document.studentform.action.value = 'listusers';
5400: document.studentform.phase.value = 'display';
5401: document.studentform.submit();
5402: }
5403:
1.364 raeburn 5404: function updateCols(caller) {
5405: var context = '$context';
5406: var photos = '$photos';
5407: if (caller == 'Status') {
1.374 raeburn 5408: if ((context == 'domain') &&
5409: ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
5410: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community'))) {
1.364 raeburn 5411: document.getElementById('showcolstatus').checked = false;
5412: document.getElementById('showcolstatus').disabled = 'disabled';
5413: document.getElementById('showcolstart').checked = false;
5414: document.getElementById('showcolend').checked = false;
1.374 raeburn 5415: } else {
5416: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
5417: document.getElementById('showcolstatus').checked = true;
5418: document.getElementById('showcolstatus').disabled = '';
5419: document.getElementById('showcolstart').checked = true;
5420: document.getElementById('showcolend').checked = true;
5421: } else {
5422: document.getElementById('showcolstatus').checked = false;
5423: document.getElementById('showcolstatus').disabled = 'disabled';
5424: document.getElementById('showcolstart').checked = false;
5425: document.getElementById('showcolend').checked = false;
5426: }
1.364 raeburn 5427: }
5428: }
5429: if (caller == 'output') {
5430: if (photos == 1) {
5431: if (document.getElementById('showcolphoto')) {
5432: var photoitem = document.getElementById('showcolphoto');
5433: if (document.studentform.output.options[document.studentform.output.selectedIndex].value == 'html') {
5434: photoitem.checked = true;
5435: photoitem.disabled = '';
5436: } else {
5437: photoitem.checked = false;
5438: photoitem.disabled = 'disabled';
5439: }
5440: }
5441: }
5442: }
5443: if (caller == 'showrole') {
1.371 raeburn 5444: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any') ||
5445: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'cr')) {
1.364 raeburn 5446: document.getElementById('showcolrole').checked = true;
5447: document.getElementById('showcolrole').disabled = '';
5448: } else {
5449: document.getElementById('showcolrole').checked = false;
5450: document.getElementById('showcolrole').disabled = 'disabled';
5451: }
1.374 raeburn 5452: if (context == 'domain') {
1.382 raeburn 5453: var quotausageshow = 0;
1.374 raeburn 5454: if ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
5455: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community')) {
5456: document.getElementById('showcolstatus').checked = false;
5457: document.getElementById('showcolstatus').disabled = 'disabled';
5458: document.getElementById('showcolstart').checked = false;
5459: document.getElementById('showcolend').checked = false;
5460: } else {
5461: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
5462: document.getElementById('showcolstatus').checked = true;
5463: document.getElementById('showcolstatus').disabled = '';
5464: document.getElementById('showcolstart').checked = true;
5465: document.getElementById('showcolend').checked = true;
5466: }
5467: }
5468: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'domain') {
5469: document.getElementById('showcolextent').disabled = 'disabled';
5470: document.getElementById('showcolextent').checked = 'false';
5471: document.getElementById('showextent').style.display='none';
5472: document.getElementById('showcoltextextent').innerHTML = '';
1.382 raeburn 5473: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'au') ||
5474: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any')) {
5475: if (document.getElementById('showcolauthorusage')) {
5476: document.getElementById('showcolauthorusage').disabled = '';
5477: }
5478: if (document.getElementById('showcolauthorquota')) {
5479: document.getElementById('showcolauthorquota').disabled = '';
5480: }
5481: quotausageshow = 1;
5482: }
1.374 raeburn 5483: } else {
5484: document.getElementById('showextent').style.display='block';
5485: document.getElementById('showextent').style.textAlign='left';
5486: document.getElementById('showextent').style.textFace='normal';
5487: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'author') {
5488: document.getElementById('showcolextent').disabled = '';
5489: document.getElementById('showcolextent').checked = 'true';
5490: document.getElementById('showcoltextextent').innerHTML="$lt{'author'}";
5491: } else {
5492: document.getElementById('showcolextent').disabled = '';
5493: document.getElementById('showcolextent').checked = 'true';
5494: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community') {
5495: document.getElementById('showcoltextextent').innerHTML="$lt{'community'}";
5496: } else {
5497: document.getElementById('showcoltextextent').innerHTML="$lt{'course'}";
5498: }
5499: }
5500: }
1.382 raeburn 5501: if (quotausageshow == 0) {
5502: if (document.getElementById('showcolauthorusage')) {
5503: document.getElementById('showcolauthorusage').checked = false;
5504: document.getElementById('showcolauthorusage').disabled = 'disabled';
5505: }
5506: if (document.getElementById('showcolauthorquota')) {
5507: document.getElementById('showcolauthorquota').checked = false;
5508: document.getElementById('showcolauthorquota').disabled = 'disabled';
5509: }
5510: }
1.374 raeburn 5511: }
1.364 raeburn 5512: }
5513: return;
5514: }
5515:
1.202 raeburn 5516: END
5517: return $output;
5518:
5519: }
5520:
1.190 raeburn 5521: ###############################################################
5522: ###############################################################
5523: # Menu Phase One
5524: sub print_main_menu {
1.318 raeburn 5525: my ($permission,$context,$crstype) = @_;
5526: my $linkcontext = $context;
5527: my $stuterm = lc(&Apache::lonnet::plaintext('st',$crstype));
5528: if (($context eq 'course') && ($crstype eq 'Community')) {
5529: $linkcontext = lc($crstype);
5530: $stuterm = 'Members';
5531: }
1.208 raeburn 5532: my %links = (
1.298 droeschl 5533: domain => {
5534: upload => 'Upload a File of Users',
5535: singleuser => 'Add/Modify a User',
5536: listusers => 'Manage Users',
5537: },
5538: author => {
5539: upload => 'Upload a File of Co-authors',
5540: singleuser => 'Add/Modify a Co-author',
5541: listusers => 'Manage Co-authors',
5542: },
5543: course => {
5544: upload => 'Upload a File of Course Users',
5545: singleuser => 'Add/Modify a Course User',
1.354 www 5546: listusers => 'List and Modify Multiple Course Users',
1.298 droeschl 5547: },
1.318 raeburn 5548: community => {
5549: upload => 'Upload a File of Community Users',
5550: singleuser => 'Add/Modify a Community User',
1.354 www 5551: listusers => 'List and Modify Multiple Community Users',
1.318 raeburn 5552: },
5553: );
5554: my %linktitles = (
5555: domain => {
5556: singleuser => 'Add a user to the domain, and/or a course or community in the domain.',
5557: listusers => 'Show and manage users in this domain.',
5558: },
5559: author => {
5560: singleuser => 'Add a user with a co- or assistant author role.',
5561: listusers => 'Show and manage co- or assistant authors.',
5562: },
5563: course => {
5564: singleuser => 'Add a user with a certain role to this course.',
5565: listusers => 'Show and manage users in this course.',
5566: },
5567: community => {
5568: singleuser => 'Add a user with a certain role to this community.',
5569: listusers => 'Show and manage users in this community.',
5570: },
1.298 droeschl 5571: );
1.406.2.6 raeburn 5572: if ($linkcontext eq 'domain') {
5573: unless ($permission->{'cusr'}) {
5574: $links{'domain'}{'singleuser'} = 'View a User';
5575: $linktitles{'domain'}{'singleuser'} = 'View information about a user in the domain';
5576: }
5577: } elsif ($linkcontext eq 'course') {
5578: unless ($permission->{'cusr'}) {
5579: $links{'course'}{'singleuser'} = 'View a Course User';
5580: $linktitles{'course'}{'singleuser'} = 'View information about a user in this course';
5581: $links{'course'}{'listusers'} = 'List Course Users';
5582: $linktitles{'course'}{'listusers'} = 'Show information about users in this course';
5583: }
5584: } elsif ($linkcontext eq 'community') {
5585: unless ($permission->{'cusr'}) {
5586: $links{'community'}{'singleuser'} = 'View a Community User';
5587: $linktitles{'community'}{'singleuser'} = 'View information about a user in this community';
5588: $links{'community'}{'listusers'} = 'List Community Users';
5589: $linktitles{'community'}{'listusers'} = 'Show information about users in this community';
5590: }
5591: }
1.298 droeschl 5592: my @menu = ( {categorytitle => 'Single Users',
5593: items =>
5594: [
5595: {
1.318 raeburn 5596: linktext => $links{$linkcontext}{'singleuser'},
1.298 droeschl 5597: icon => 'edit-redo.png',
5598: #help => 'Course_Change_Privileges',
5599: url => '/adm/createuser?action=singleuser',
1.406.2.6 raeburn 5600: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.318 raeburn 5601: linktitle => $linktitles{$linkcontext}{'singleuser'},
1.298 droeschl 5602: },
5603: ]},
5604:
5605: {categorytitle => 'Multiple Users',
5606: items =>
5607: [
5608: {
1.318 raeburn 5609: linktext => $links{$linkcontext}{'upload'},
1.340 wenzelju 5610: icon => 'uplusr.png',
1.298 droeschl 5611: #help => 'Course_Create_Class_List',
5612: url => '/adm/createuser?action=upload',
5613: permission => $permission->{'cusr'},
5614: linktitle => 'Upload a CSV or a text file containing users.',
5615: },
5616: {
1.318 raeburn 5617: linktext => $links{$linkcontext}{'listusers'},
1.340 wenzelju 5618: icon => 'mngcu.png',
1.298 droeschl 5619: #help => 'Course_View_Class_List',
5620: url => '/adm/createuser?action=listusers',
5621: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.318 raeburn 5622: linktitle => $linktitles{$linkcontext}{'listusers'},
1.298 droeschl 5623: },
5624:
5625: ]},
5626:
5627: {categorytitle => 'Administration',
5628: items => [ ]},
5629: );
1.406.2.5 raeburn 5630:
1.265 mielkec 5631: if ($context eq 'domain'){
1.406.2.5 raeburn 5632: push(@{ $menu[0]->{items} }, # Single Users
5633: {
5634: linktext => 'User Access Log',
5635: icon => 'document-properties.png',
1.406.2.8 raeburn 5636: #help => 'Domain_User_Access_Logs',
1.406.2.5 raeburn 5637: url => '/adm/createuser?action=accesslogs',
5638: permission => $permission->{'activity'},
5639: linktitle => 'View user access log.',
5640: }
5641: );
1.298 droeschl 5642:
5643: push(@{ $menu[2]->{items} }, #Category: Administration
5644: {
5645: linktext => 'Custom Roles',
5646: icon => 'emblem-photos.png',
5647: #help => 'Course_Editing_Custom_Roles',
5648: url => '/adm/createuser?action=custom',
5649: permission => $permission->{'custom'},
5650: linktitle => 'Configure a custom role.',
5651: },
1.362 raeburn 5652: {
5653: linktext => 'Authoring Space Requests',
5654: icon => 'selfenrl-queue.png',
5655: #help => 'Domain_Role_Approvals',
5656: url => '/adm/createuser?action=processauthorreq',
5657: permission => $permission->{'cusr'},
5658: linktitle => 'Approve or reject author role requests',
5659: },
1.363 raeburn 5660: {
1.391 raeburn 5661: linktext => 'LON-CAPA Account Requests',
5662: icon => 'list-add.png',
5663: #help => 'Domain_Username_Approvals',
5664: url => '/adm/createuser?action=processusernamereq',
5665: permission => $permission->{'cusr'},
5666: linktitle => 'Approve or reject LON-CAPA account requests',
5667: },
5668: {
1.363 raeburn 5669: linktext => 'Change Log',
5670: icon => 'document-properties.png',
5671: #help => 'Course_User_Logs',
5672: url => '/adm/createuser?action=changelogs',
1.406.2.6 raeburn 5673: permission => ($permission->{'cusr'} || $permission->{'view'}),
1.363 raeburn 5674: linktitle => 'View change log.',
5675: },
1.298 droeschl 5676: );
5677:
1.265 mielkec 5678: }elsif ($context eq 'course'){
1.298 droeschl 5679: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity();
1.318 raeburn 5680:
5681: my %linktext = (
5682: 'Course' => {
5683: single => 'Add/Modify a Student',
5684: drop => 'Drop Students',
5685: groups => 'Course Groups',
5686: },
5687: 'Community' => {
5688: single => 'Add/Modify a Member',
5689: drop => 'Drop Members',
5690: groups => 'Community Groups',
5691: },
5692: );
5693:
5694: my %linktitle = (
5695: 'Course' => {
5696: single => 'Add a user with the role of student to this course',
5697: drop => 'Remove a student from this course.',
5698: groups => 'Manage course groups',
5699: },
5700: 'Community' => {
5701: single => 'Add a user with the role of member to this community',
5702: drop => 'Remove a member from this community.',
5703: groups => 'Manage community groups',
5704: },
5705: );
5706:
1.298 droeschl 5707: push(@{ $menu[0]->{items} }, #Category: Single Users
5708: {
1.318 raeburn 5709: linktext => $linktext{$crstype}{'single'},
1.298 droeschl 5710: #help => 'Course_Add_Student',
5711: icon => 'list-add.png',
5712: url => '/adm/createuser?action=singlestudent',
5713: permission => $permission->{'cusr'},
1.318 raeburn 5714: linktitle => $linktitle{$crstype}{'single'},
1.298 droeschl 5715: },
5716: );
5717:
5718: push(@{ $menu[1]->{items} }, #Category: Multiple Users
5719: {
1.318 raeburn 5720: linktext => $linktext{$crstype}{'drop'},
1.298 droeschl 5721: icon => 'edit-undo.png',
5722: #help => 'Course_Drop_Student',
5723: url => '/adm/createuser?action=drop',
5724: permission => $permission->{'cusr'},
1.318 raeburn 5725: linktitle => $linktitle{$crstype}{'drop'},
1.298 droeschl 5726: },
5727: );
5728: push(@{ $menu[2]->{items} }, #Category: Administration
1.406.2.11 raeburn 5729: {
5730: linktext => 'Helpdesk Access',
5731: icon => 'helpdesk-access.png',
5732: #help => 'Course_Helpdesk_Access',
5733: url => '/adm/createuser?action=helpdesk',
5734: permission => ($permission->{'owner'} || $permission->{'co-owner'}),
5735: linktitle => 'Helpdesk access options',
5736: },
5737: {
1.298 droeschl 5738: linktext => 'Custom Roles',
5739: icon => 'emblem-photos.png',
5740: #help => 'Course_Editing_Custom_Roles',
5741: url => '/adm/createuser?action=custom',
5742: permission => $permission->{'custom'},
5743: linktitle => 'Configure a custom role.',
5744: },
5745: {
1.318 raeburn 5746: linktext => $linktext{$crstype}{'groups'},
1.333 wenzelju 5747: icon => 'grps.png',
1.298 droeschl 5748: #help => 'Course_Manage_Group',
5749: url => '/adm/coursegroups?refpage=cusr',
5750: permission => $permission->{'grp_manage'},
1.318 raeburn 5751: linktitle => $linktitle{$crstype}{'groups'},
1.298 droeschl 5752: },
5753: {
1.328 wenzelju 5754: linktext => 'Change Log',
1.298 droeschl 5755: icon => 'document-properties.png',
5756: #help => 'Course_User_Logs',
5757: url => '/adm/createuser?action=changelogs',
1.406.2.6 raeburn 5758: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.298 droeschl 5759: linktitle => 'View change log.',
5760: },
5761: );
1.277 raeburn 5762: if ($env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'}) {
1.298 droeschl 5763: push(@{ $menu[2]->{items} },
1.398 raeburn 5764: {
1.298 droeschl 5765: linktext => 'Enrollment Requests',
5766: icon => 'selfenrl-queue.png',
5767: #help => 'Course_Approve_Selfenroll',
5768: url => '/adm/createuser?action=selfenrollqueue',
1.406.2.21 raeburn 5769: permission => $permission->{'selfenrolladmin'} || $permission->{'selfenrollview'},
1.298 droeschl 5770: linktitle =>'Approve or reject enrollment requests.',
5771: },
5772: );
1.277 raeburn 5773: }
1.298 droeschl 5774:
1.265 mielkec 5775: if (!exists($permission->{'cusr_section'})){
1.320 raeburn 5776: if ($crstype ne 'Community') {
5777: push(@{ $menu[2]->{items} },
5778: {
5779: linktext => 'Automated Enrollment',
5780: icon => 'roles.png',
5781: #help => 'Course_Automated_Enrollment',
5782: permission => (&Apache::lonnet::auto_run($cnum,$cdom)
1.406.2.6 raeburn 5783: && (($permission->{'cusr'}) ||
5784: ($permission->{'view'}))),
1.320 raeburn 5785: url => '/adm/populate',
5786: linktitle => 'Automated enrollment manager.',
5787: }
5788: );
5789: }
5790: push(@{ $menu[2]->{items} },
1.298 droeschl 5791: {
5792: linktext => 'User Self-Enrollment',
1.342 wenzelju 5793: icon => 'self_enroll.png',
1.298 droeschl 5794: #help => 'Course_Self_Enrollment',
5795: url => '/adm/createuser?action=selfenroll',
1.406.2.21 raeburn 5796: permission => $permission->{'selfenrolladmin'} || $permission->{'selfenrollview'},
1.317 bisitz 5797: linktitle => 'Configure user self-enrollment.',
1.298 droeschl 5798: },
5799: );
5800: }
1.363 raeburn 5801: } elsif ($context eq 'author') {
1.370 raeburn 5802: push(@{ $menu[2]->{items} }, #Category: Administration
1.363 raeburn 5803: {
5804: linktext => 'Change Log',
5805: icon => 'document-properties.png',
5806: #help => 'Course_User_Logs',
5807: url => '/adm/createuser?action=changelogs',
5808: permission => $permission->{'cusr'},
5809: linktitle => 'View change log.',
5810: },
1.370 raeburn 5811: );
1.363 raeburn 5812: }
5813: return Apache::lonhtmlcommon::generate_menu(@menu);
1.250 raeburn 5814: # { text => 'View Log-in History',
5815: # help => 'Course_User_Logins',
5816: # action => 'logins',
5817: # permission => $permission->{'cusr'},
5818: # });
1.190 raeburn 5819: }
5820:
1.189 albertel 5821: sub restore_prev_selections {
5822: my %saveable_parameters = ('srchby' => 'scalar',
5823: 'srchin' => 'scalar',
5824: 'srchtype' => 'scalar',
5825: );
5826: &Apache::loncommon::store_settings('user','user_picker',
5827: \%saveable_parameters);
5828: &Apache::loncommon::restore_settings('user','user_picker',
5829: \%saveable_parameters);
5830: }
5831:
1.237 raeburn 5832: sub print_selfenroll_menu {
1.406.2.6 raeburn 5833: my ($r,$context,$cid,$cdom,$cnum,$currsettings,$additional,$readonly) = @_;
1.322 raeburn 5834: my $crstype = &Apache::loncommon::course_type();
1.398 raeburn 5835: my $formname = 'selfenroll';
1.237 raeburn 5836: my $nolink = 1;
1.398 raeburn 5837: my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles();
1.237 raeburn 5838: my $groupslist = &Apache::lonuserutils::get_groupslist();
5839: my $setsec_js =
5840: &Apache::lonuserutils::setsections_javascript($formname,$groupslist);
1.249 raeburn 5841: my %alerts = &Apache::lonlocal::texthash(
5842: acto => 'Activation of self-enrollment was selected for the following domain(s)',
5843: butn => 'but no user types have been checked.',
5844: wilf => "Please uncheck 'activate' or check at least one type.",
5845: );
1.406.2.6 raeburn 5846: my $disabled;
5847: if ($readonly) {
5848: $disabled = ' disabled="disabled"';
5849: }
1.405 damieng 5850: &js_escape(\%alerts);
1.249 raeburn 5851: my $selfenroll_js = <<"ENDSCRIPT";
5852: function update_types(caller,num) {
5853: var delidx = getIndexByName('selfenroll_delete');
5854: var actidx = getIndexByName('selfenroll_activate');
5855: if (caller == 'selfenroll_all') {
5856: var selall;
5857: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5858: if (document.$formname.selfenroll_all[i].checked) {
5859: selall = document.$formname.selfenroll_all[i].value;
5860: }
5861: }
5862: if (selall == 1) {
5863: if (delidx != -1) {
5864: if (document.$formname.selfenroll_delete.length) {
5865: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
5866: document.$formname.selfenroll_delete[j].checked = true;
5867: }
5868: } else {
5869: document.$formname.elements[delidx].checked = true;
5870: }
5871: }
5872: if (actidx != -1) {
5873: if (document.$formname.selfenroll_activate.length) {
5874: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5875: document.$formname.selfenroll_activate[j].checked = false;
5876: }
5877: } else {
5878: document.$formname.elements[actidx].checked = false;
5879: }
5880: }
5881: document.$formname.selfenroll_newdom.selectedIndex = 0;
5882: }
5883: }
5884: if (caller == 'selfenroll_activate') {
5885: if (document.$formname.selfenroll_activate.length) {
5886: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5887: if (document.$formname.selfenroll_activate[j].value == num) {
5888: if (document.$formname.selfenroll_activate[j].checked) {
5889: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5890: if (document.$formname.selfenroll_all[i].value == '1') {
5891: document.$formname.selfenroll_all[i].checked = false;
5892: }
5893: if (document.$formname.selfenroll_all[i].value == '0') {
5894: document.$formname.selfenroll_all[i].checked = true;
5895: }
5896: }
5897: }
5898: }
5899: }
5900: } else {
5901: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5902: if (document.$formname.selfenroll_all[i].value == '1') {
5903: document.$formname.selfenroll_all[i].checked = false;
5904: }
5905: if (document.$formname.selfenroll_all[i].value == '0') {
5906: document.$formname.selfenroll_all[i].checked = true;
5907: }
5908: }
5909: }
5910: }
5911: if (caller == 'selfenroll_delete') {
5912: if (document.$formname.selfenroll_delete.length) {
5913: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
5914: if (document.$formname.selfenroll_delete[j].value == num) {
5915: if (document.$formname.selfenroll_delete[j].checked) {
5916: var delindex = getIndexByName('selfenroll_types_'+num);
5917: if (delindex != -1) {
5918: if (document.$formname.elements[delindex].length) {
5919: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
5920: document.$formname.elements[delindex][k].checked = false;
5921: }
5922: } else {
5923: document.$formname.elements[delindex].checked = false;
5924: }
5925: }
5926: }
5927: }
5928: }
5929: } else {
5930: if (document.$formname.selfenroll_delete.checked) {
5931: var delindex = getIndexByName('selfenroll_types_'+num);
5932: if (delindex != -1) {
5933: if (document.$formname.elements[delindex].length) {
5934: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
5935: document.$formname.elements[delindex][k].checked = false;
5936: }
5937: } else {
5938: document.$formname.elements[delindex].checked = false;
5939: }
5940: }
5941: }
5942: }
5943: }
5944: return;
5945: }
5946:
5947: function validate_types(form) {
5948: var needaction = new Array();
5949: var countfail = 0;
5950: var actidx = getIndexByName('selfenroll_activate');
5951: if (actidx != -1) {
5952: if (document.$formname.selfenroll_activate.length) {
5953: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5954: var num = document.$formname.selfenroll_activate[j].value;
5955: if (document.$formname.selfenroll_activate[j].checked) {
5956: countfail = check_types(num,countfail,needaction)
5957: }
5958: }
5959: } else {
5960: if (document.$formname.selfenroll_activate.checked) {
1.398 raeburn 5961: var num = document.$formname.selfenroll_activate.value;
1.249 raeburn 5962: countfail = check_types(num,countfail,needaction)
5963: }
5964: }
5965: }
5966: if (countfail > 0) {
5967: var msg = "$alerts{'acto'}\\n";
5968: var loopend = needaction.length -1;
5969: if (loopend > 0) {
5970: for (var m=0; m<loopend; m++) {
5971: msg += needaction[m]+", ";
5972: }
5973: }
5974: msg += needaction[loopend]+"\\n$alerts{'butn'}\\n$alerts{'wilf'}";
5975: alert(msg);
5976: return;
5977: }
5978: setSections(form);
5979: }
5980:
5981: function check_types(num,countfail,needaction) {
1.406.2.15 raeburn 5982: var boxname = 'selfenroll_types_'+num;
5983: var typeidx = getIndexByName(boxname);
1.249 raeburn 5984: var count = 0;
5985: if (typeidx != -1) {
1.406.2.15 raeburn 5986: if (document.$formname.elements[boxname].length) {
5987: for (var k=0; k<document.$formname.elements[boxname].length; k++) {
5988: if (document.$formname.elements[boxname][k].checked) {
1.249 raeburn 5989: count ++;
5990: }
5991: }
5992: } else {
5993: if (document.$formname.elements[typeidx].checked) {
5994: count ++;
5995: }
5996: }
5997: if (count == 0) {
5998: var domidx = getIndexByName('selfenroll_dom_'+num);
5999: if (domidx != -1) {
6000: var domname = document.$formname.elements[domidx].value;
6001: needaction[countfail] = domname;
6002: countfail ++;
6003: }
6004: }
6005: }
6006: return countfail;
6007: }
6008:
1.398 raeburn 6009: function toggleNotify() {
6010: var selfenrollApproval = 0;
6011: if (document.$formname.selfenroll_approval.length) {
6012: for (var i=0; i<document.$formname.selfenroll_approval.length; i++) {
6013: if (document.$formname.selfenroll_approval[i].checked) {
6014: selfenrollApproval = document.$formname.selfenroll_approval[i].value;
6015: break;
6016: }
6017: }
6018: }
6019: if (document.getElementById('notified')) {
6020: if (selfenrollApproval == 0) {
6021: document.getElementById('notified').style.display='none';
6022: } else {
6023: document.getElementById('notified').style.display='block';
6024: }
6025: }
6026: return;
6027: }
6028:
1.249 raeburn 6029: function getIndexByName(item) {
6030: for (var i=0;i<document.$formname.elements.length;i++) {
6031: if (document.$formname.elements[i].name == item) {
6032: return i;
6033: }
6034: }
6035: return -1;
6036: }
6037: ENDSCRIPT
1.256 raeburn 6038:
1.237 raeburn 6039: my $output = '<script type="text/javascript">'."\n".
1.301 bisitz 6040: '// <![CDATA['."\n".
1.249 raeburn 6041: $setsec_js."\n".$selfenroll_js."\n".
1.301 bisitz 6042: '// ]]>'."\n".
1.237 raeburn 6043: '</script>'."\n".
1.256 raeburn 6044: '<h3>'.$lt->{'selfenroll'}.'</h3>'."\n";
1.406.2.21 raeburn 6045: my $visactions = &cat_visibility($cdom);
1.400 raeburn 6046: my ($cathash,%cattype);
6047: my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
6048: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
6049: $cathash = $domconfig{'coursecategories'}{'cats'};
6050: $cattype{'auth'} = $domconfig{'coursecategories'}{'auth'};
6051: $cattype{'unauth'} = $domconfig{'coursecategories'}{'unauth'};
1.406 raeburn 6052: if ($cattype{'auth'} eq '') {
6053: $cattype{'auth'} = 'std';
6054: }
6055: if ($cattype{'unauth'} eq '') {
6056: $cattype{'unauth'} = 'std';
6057: }
1.400 raeburn 6058: } else {
6059: $cathash = {};
6060: $cattype{'auth'} = 'std';
6061: $cattype{'unauth'} = 'std';
6062: }
6063: if (($cattype{'auth'} eq 'none') && ($cattype{'unauth'} eq 'none')) {
6064: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
6065: '<br />'.
6066: '<br />'.$visactions->{'take'}.'<ul>'.
6067: '<li>'.$visactions->{'dc_chgconf'}.'</li>'.
6068: '</ul>');
6069: } elsif (($cattype{'auth'} !~ /^(std|domonly)$/) && ($cattype{'unauth'} !~ /^(std|domonly)$/)) {
6070: if ($currsettings->{'uniquecode'}) {
6071: $r->print('<span class="LC_info">'.$visactions->{'vis'}.'</span>');
6072: } else {
6073: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
6074: '<br />'.
6075: '<br />'.$visactions->{'take'}.'<ul>'.
6076: '<li>'.$visactions->{'dc_setcode'}.'</li>'.
6077: '</ul><br />');
6078: }
6079: } else {
6080: my ($visible,$cansetvis,$vismsgs) = &visible_in_stdcat($cdom,$cnum,\%domconfig);
6081: if (ref($visactions) eq 'HASH') {
6082: if ($visible) {
6083: $output .= '<p class="LC_info">'.$visactions->{'vis'}.'</p>';
6084: } else {
6085: $output .= '<p class="LC_warning">'.$visactions->{'miss'}.'</p>'
6086: .$visactions->{'yous'}.
6087: '<p>'.$visactions->{'gen'}.'<br />'.$visactions->{'coca'};
6088: if (ref($vismsgs) eq 'ARRAY') {
6089: $output .= '<br />'.$visactions->{'make'}.'<ul>';
6090: foreach my $item (@{$vismsgs}) {
6091: $output .= '<li>'.$visactions->{$item}.'</li>';
6092: }
6093: $output .= '</ul>';
1.256 raeburn 6094: }
1.400 raeburn 6095: $output .= '</p>';
1.256 raeburn 6096: }
6097: }
6098: }
1.398 raeburn 6099: my $actionhref = '/adm/createuser';
6100: if ($context eq 'domain') {
6101: $actionhref = '/adm/modifycourse';
6102: }
1.400 raeburn 6103:
6104: my %noedit;
6105: unless ($context eq 'domain') {
6106: %noedit = &get_noedit_fields($cdom,$cnum,$crstype,$row);
6107: }
1.398 raeburn 6108: $output .= '<form name="'.$formname.'" method="post" action="'.$actionhref.'">'."\n".
1.256 raeburn 6109: &Apache::lonhtmlcommon::start_pick_box();
1.237 raeburn 6110: if (ref($row) eq 'ARRAY') {
6111: foreach my $item (@{$row}) {
6112: my $title = $item;
6113: if (ref($lt) eq 'HASH') {
6114: $title = $lt->{$item};
6115: }
1.297 bisitz 6116: $output .= &Apache::lonhtmlcommon::row_title($title);
1.237 raeburn 6117: if ($item eq 'types') {
1.398 raeburn 6118: my $curr_types;
6119: if (ref($currsettings) eq 'HASH') {
6120: $curr_types = $currsettings->{'selfenroll_types'};
6121: }
1.400 raeburn 6122: if ($noedit{$item}) {
6123: if ($curr_types eq '*') {
6124: $output .= &mt('Any user in any domain');
6125: } else {
6126: my @entries = split(/;/,$curr_types);
6127: if (@entries > 0) {
6128: $output .= '<ul>';
6129: foreach my $entry (@entries) {
6130: my ($currdom,$typestr) = split(/:/,$entry);
6131: next if ($typestr eq '');
6132: my $domdesc = &Apache::lonnet::domain($currdom);
6133: my @currinsttypes = split(',',$typestr);
6134: my ($othertitle,$usertypes,$types) =
6135: &Apache::loncommon::sorted_inst_types($currdom);
6136: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
6137: $usertypes->{'any'} = &mt('any user');
6138: if (keys(%{$usertypes}) > 0) {
6139: $usertypes->{'other'} = &mt('other users');
6140: }
6141: my @longinsttypes = map { $usertypes->{$_}; } @currinsttypes;
6142: $output .= '<li>'.$domdesc.':'.join(', ',@longinsttypes).'</li>';
6143: }
6144: }
6145: $output .= '</ul>';
6146: } else {
6147: $output .= &mt('None');
6148: }
6149: }
6150: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6151: next;
6152: }
1.241 raeburn 6153: my $showdomdesc = 1;
6154: my $includeempty = 1;
6155: my $num = 0;
6156: $output .= &Apache::loncommon::start_data_table().
6157: &Apache::loncommon::start_data_table_row()
6158: .'<td colspan="2"><span class="LC_nobreak"><label>'
6159: .&mt('Any user in any domain:')
6160: .' <input type="radio" name="selfenroll_all" value="1" ';
6161: if ($curr_types eq '*') {
6162: $output .= ' checked="checked" ';
6163: }
1.249 raeburn 6164: $output .= 'onchange="javascript:update_types('.
1.406.2.6 raeburn 6165: "'selfenroll_all'".');"'.$disabled.' />'.&mt('Yes').'</label>'.
1.249 raeburn 6166: ' <input type="radio" name="selfenroll_all" value="0" ';
1.241 raeburn 6167: if ($curr_types ne '*') {
6168: $output .= ' checked="checked" ';
6169: }
1.249 raeburn 6170: $output .= ' onchange="javascript:update_types('.
1.406.2.6 raeburn 6171: "'selfenroll_all'".');"'.$disabled.' />'.&mt('No').'</label></td>'.
1.249 raeburn 6172: &Apache::loncommon::end_data_table_row().
6173: &Apache::loncommon::end_data_table().
6174: &mt('Or').'<br />'.
6175: &Apache::loncommon::start_data_table();
1.241 raeburn 6176: my %currdoms;
1.249 raeburn 6177: if ($curr_types eq '') {
1.241 raeburn 6178: $output .= &new_selfenroll_dom_row($cdom,'0');
6179: } elsif ($curr_types ne '*') {
6180: my @entries = split(/;/,$curr_types);
6181: if (@entries > 0) {
6182: foreach my $entry (@entries) {
6183: my ($currdom,$typestr) = split(/:/,$entry);
6184: $currdoms{$currdom} = 1;
6185: my $domdesc = &Apache::lonnet::domain($currdom);
1.249 raeburn 6186: my @currinsttypes = split(',',$typestr);
1.241 raeburn 6187: $output .= &Apache::loncommon::start_data_table_row()
6188: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').'<b>'
6189: .' '.$domdesc.' ('.$currdom.')'
6190: .'</b><input type="hidden" name="selfenroll_dom_'.$num
6191: .'" value="'.$currdom.'" /></span><br />'
6192: .'<span class="LC_nobreak"><label><input type="checkbox" '
1.406.2.6 raeburn 6193: .'name="selfenroll_delete" value="'.$num.'" onchange="javascript:update_types('."'selfenroll_delete','$num'".');"'.$disabled.' />'
1.241 raeburn 6194: .&mt('Delete').'</label></span></td>';
1.249 raeburn 6195: $output .= '<td valign="top"> '.&mt('User types:').'<br />'
1.406.2.6 raeburn 6196: .&selfenroll_inst_types($num,$currdom,\@currinsttypes,$readonly).'</td>'
1.241 raeburn 6197: .&Apache::loncommon::end_data_table_row();
6198: $num ++;
6199: }
6200: }
6201: }
1.249 raeburn 6202: my $add_domtitle = &mt('Users in additional domain:');
1.241 raeburn 6203: if ($curr_types eq '*') {
1.249 raeburn 6204: $add_domtitle = &mt('Users in specific domain:');
1.241 raeburn 6205: } elsif ($curr_types eq '') {
1.249 raeburn 6206: $add_domtitle = &mt('Users in other domain:');
1.241 raeburn 6207: }
6208: $output .= &Apache::loncommon::start_data_table_row()
6209: .'<td colspan="2"><span class="LC_nobreak">'.$add_domtitle.'</span><br />'
6210: .&Apache::loncommon::select_dom_form('','selfenroll_newdom',
1.406.2.6 raeburn 6211: $includeempty,$showdomdesc,'','','',$readonly)
1.241 raeburn 6212: .'<input type="hidden" name="selfenroll_types_total" value="'.$num.'" />'
6213: .'</td>'.&Apache::loncommon::end_data_table_row()
6214: .&Apache::loncommon::end_data_table();
1.237 raeburn 6215: } elsif ($item eq 'registered') {
6216: my ($regon,$regoff);
1.398 raeburn 6217: my $registered;
6218: if (ref($currsettings) eq 'HASH') {
6219: $registered = $currsettings->{'selfenroll_registered'};
6220: }
1.400 raeburn 6221: if ($noedit{$item}) {
6222: if ($registered) {
6223: $output .= &mt('Must be registered in course');
6224: } else {
6225: $output .= &mt('No requirement');
6226: }
6227: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6228: next;
6229: }
1.398 raeburn 6230: if ($registered) {
1.237 raeburn 6231: $regon = ' checked="checked" ';
1.406.2.6 raeburn 6232: $regoff = '';
1.237 raeburn 6233: } else {
1.406.2.6 raeburn 6234: $regon = '';
1.237 raeburn 6235: $regoff = ' checked="checked" ';
6236: }
6237: $output .= '<label>'.
1.406.2.6 raeburn 6238: '<input type="radio" name="selfenroll_registered" value="1"'.$regon.$disabled.' />'.
1.244 bisitz 6239: &mt('Yes').'</label> <label>'.
1.406.2.6 raeburn 6240: '<input type="radio" name="selfenroll_registered" value="0"'.$regoff.$disabled.' />'.
1.244 bisitz 6241: &mt('No').'</label>';
1.237 raeburn 6242: } elsif ($item eq 'enroll_dates') {
1.398 raeburn 6243: my ($starttime,$endtime);
6244: if (ref($currsettings) eq 'HASH') {
6245: $starttime = $currsettings->{'selfenroll_start_date'};
6246: $endtime = $currsettings->{'selfenroll_end_date'};
6247: if ($starttime eq '') {
6248: $starttime = $currsettings->{'default_enrollment_start_date'};
6249: }
6250: if ($endtime eq '') {
6251: $endtime = $currsettings->{'default_enrollment_end_date'};
6252: }
1.237 raeburn 6253: }
1.400 raeburn 6254: if ($noedit{$item}) {
6255: $output .= &mt('From: [_1], to: [_2]',&Apache::lonlocal::locallocaltime($starttime),
6256: &Apache::lonlocal::locallocaltime($endtime));
6257: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6258: next;
6259: }
1.237 raeburn 6260: my $startform =
6261: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_date',$starttime,
1.406.2.6 raeburn 6262: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6263: my $endform =
6264: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_date',$endtime,
1.406.2.6 raeburn 6265: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6266: $output .= &selfenroll_date_forms($startform,$endform);
6267: } elsif ($item eq 'access_dates') {
1.398 raeburn 6268: my ($starttime,$endtime);
6269: if (ref($currsettings) eq 'HASH') {
6270: $starttime = $currsettings->{'selfenroll_start_access'};
6271: $endtime = $currsettings->{'selfenroll_end_access'};
6272: if ($starttime eq '') {
6273: $starttime = $currsettings->{'default_enrollment_start_date'};
6274: }
6275: if ($endtime eq '') {
6276: $endtime = $currsettings->{'default_enrollment_end_date'};
6277: }
1.237 raeburn 6278: }
1.400 raeburn 6279: if ($noedit{$item}) {
6280: $output .= &mt('From: [_1], to: [_2]',&Apache::lonlocal::locallocaltime($starttime),
6281: &Apache::lonlocal::locallocaltime($endtime));
6282: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6283: next;
6284: }
1.237 raeburn 6285: my $startform =
6286: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_access',$starttime,
1.406.2.6 raeburn 6287: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6288: my $endform =
6289: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_access',$endtime,
1.406.2.6 raeburn 6290: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6291: $output .= &selfenroll_date_forms($startform,$endform);
6292: } elsif ($item eq 'section') {
1.398 raeburn 6293: my $currsec;
6294: if (ref($currsettings) eq 'HASH') {
6295: $currsec = $currsettings->{'selfenroll_section'};
6296: }
1.237 raeburn 6297: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
6298: my $newsecval;
6299: if ($currsec ne 'none' && $currsec ne '') {
6300: if (!defined($sections_count{$currsec})) {
6301: $newsecval = $currsec;
6302: }
6303: }
1.400 raeburn 6304: if ($noedit{$item}) {
6305: if ($currsec ne '') {
6306: $output .= $currsec;
6307: } else {
6308: $output .= &mt('No specific section');
6309: }
6310: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6311: next;
6312: }
1.237 raeburn 6313: my $sections_select =
1.406.2.6 raeburn 6314: &Apache::lonuserutils::course_sections(\%sections_count,'st',$currsec,$disabled);
1.237 raeburn 6315: $output .= '<table class="LC_createuser">'."\n".
6316: '<tr class="LC_section_row">'."\n".
6317: '<td align="center">'.&mt('Existing sections')."\n".
6318: '<br />'.$sections_select.'</td><td align="center">'.
6319: &mt('New section').'<br />'."\n".
1.406.2.6 raeburn 6320: '<input type="text" name="newsec" size="15" value="'.$newsecval.'"'.$disabled.' />'."\n".
1.237 raeburn 6321: '<input type="hidden" name="sections" value="" />'."\n".
6322: '</td></tr></table>'."\n";
1.276 raeburn 6323: } elsif ($item eq 'approval') {
1.398 raeburn 6324: my ($currnotified,$currapproval,%appchecked);
6325: my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs();
1.406.2.6 raeburn 6326: if (ref($currsettings) eq 'HASH') {
1.398 raeburn 6327: $currnotified = $currsettings->{'selfenroll_notifylist'};
6328: $currapproval = $currsettings->{'selfenroll_approval'};
6329: }
6330: if ($currapproval !~ /^[012]$/) {
6331: $currapproval = 0;
6332: }
1.400 raeburn 6333: if ($noedit{$item}) {
6334: $output .= $selfdescs{'approval'}{$currapproval}.
6335: '<br />'.&mt('(Set by Domain Coordinator)');
6336: next;
6337: }
1.398 raeburn 6338: $appchecked{$currapproval} = ' checked="checked"';
6339: for my $i (0..2) {
6340: $output .= '<label>'.
6341: '<input type="radio" name="selfenroll_approval" value="'.$i.'"'.
1.406.2.6 raeburn 6342: $appchecked{$i}.' onclick="toggleNotify();"'.$disabled.' />'.
6343: $selfdescs{'approval'}{$i}.'</label>'.(' 'x2);
1.276 raeburn 6344: }
6345: my %advhash = &Apache::lonnet::get_course_adv_roles($cid,1);
6346: my (@ccs,%notified);
1.322 raeburn 6347: my $ccrole = 'cc';
6348: if ($crstype eq 'Community') {
6349: $ccrole = 'co';
6350: }
6351: if ($advhash{$ccrole}) {
6352: @ccs = split(/,/,$advhash{$ccrole});
1.276 raeburn 6353: }
6354: if ($currnotified) {
6355: foreach my $current (split(/,/,$currnotified)) {
6356: $notified{$current} = 1;
6357: if (!grep(/^\Q$current\E$/,@ccs)) {
6358: push(@ccs,$current);
6359: }
6360: }
6361: }
6362: if (@ccs) {
1.398 raeburn 6363: my $style;
6364: unless ($currapproval) {
6365: $style = ' style="display: none;"';
6366: }
6367: $output .= '<br /><div id="notified"'.$style.'>'.
6368: &mt('Personnel to be notified when an enrollment request needs approval, or has been approved:').' '.
6369: &Apache::loncommon::start_data_table().
1.276 raeburn 6370: &Apache::loncommon::start_data_table_row();
6371: my $count = 0;
6372: my $numcols = 4;
6373: foreach my $cc (sort(@ccs)) {
6374: my $notifyon;
6375: my ($ccuname,$ccudom) = split(/:/,$cc);
6376: if ($notified{$cc}) {
6377: $notifyon = ' checked="checked" ';
6378: }
6379: if ($count && !$count%$numcols) {
6380: $output .= &Apache::loncommon::end_data_table_row().
6381: &Apache::loncommon::start_data_table_row()
6382: }
6383: $output .= '<td><span class="LC_nobreak"><label>'.
1.406.2.6 raeburn 6384: '<input type="checkbox" name="selfenroll_notify"'.$notifyon.' value="'.$cc.'"'.$disabled.' />'.
1.276 raeburn 6385: &Apache::loncommon::plainname($ccuname,$ccudom).
6386: '</label></span></td>';
1.343 raeburn 6387: $count ++;
1.276 raeburn 6388: }
6389: my $rem = $count%$numcols;
6390: if ($rem) {
6391: my $emptycols = $numcols - $rem;
6392: for (my $i=0; $i<$emptycols; $i++) {
6393: $output .= '<td> </td>';
6394: }
6395: }
6396: $output .= &Apache::loncommon::end_data_table_row().
1.398 raeburn 6397: &Apache::loncommon::end_data_table().
6398: '</div>';
1.276 raeburn 6399: }
6400: } elsif ($item eq 'limit') {
1.398 raeburn 6401: my ($crslimit,$selflimit,$nolimit,$currlim,$currcap);
6402: if (ref($currsettings) eq 'HASH') {
6403: $currlim = $currsettings->{'selfenroll_limit'};
6404: $currcap = $currsettings->{'selfenroll_cap'};
6405: }
1.400 raeburn 6406: if ($noedit{$item}) {
6407: if (($currlim eq 'allstudents') || ($currlim eq 'selfenrolled')) {
6408: if ($currlim eq 'allstudents') {
6409: $output .= &mt('Limit by total students');
6410: } elsif ($currlim eq 'selfenrolled') {
6411: $output .= &mt('Limit by total self-enrolled students');
6412: }
6413: $output .= ' '.&mt('Maximum: [_1]',$currcap).
6414: '<br />'.&mt('(Set by Domain Coordinator)');
6415: } else {
6416: $output .= &mt('No limit').'<br />'.&mt('(Set by Domain Coordinator)');
6417: }
6418: next;
6419: }
1.276 raeburn 6420: if ($currlim eq 'allstudents') {
6421: $crslimit = ' checked="checked" ';
6422: $selflimit = ' ';
6423: $nolimit = ' ';
6424: } elsif ($currlim eq 'selfenrolled') {
6425: $crslimit = ' ';
6426: $selflimit = ' checked="checked" ';
6427: $nolimit = ' ';
6428: } else {
6429: $crslimit = ' ';
6430: $selflimit = ' ';
1.398 raeburn 6431: $nolimit = ' checked="checked" ';
1.276 raeburn 6432: }
6433: $output .= '<table><tr><td><label>'.
1.406.2.6 raeburn 6434: '<input type="radio" name="selfenroll_limit" value="none"'.$nolimit.$disabled.'/>'.
1.276 raeburn 6435: &mt('No limit').'</label></td><td><label>'.
1.406.2.6 raeburn 6436: '<input type="radio" name="selfenroll_limit" value="allstudents"'.$crslimit.$disabled.'/>'.
1.276 raeburn 6437: &mt('Limit by total students').'</label></td><td><label>'.
1.406.2.6 raeburn 6438: '<input type="radio" name="selfenroll_limit" value="selfenrolled"'.$selflimit.$disabled.'/>'.
1.276 raeburn 6439: &mt('Limit by total self-enrolled students').
6440: '</td></tr><tr>'.
6441: '<td> </td><td colspan="2"><span class="LC_nobreak">'.
6442: (' 'x3).&mt('Maximum number allowed: ').
1.406.2.6 raeburn 6443: '<input type="text" name="selfenroll_cap" size = "5" value="'.$currcap.'"'.$disabled.' /></td></tr></table>';
1.237 raeburn 6444: }
6445: $output .= &Apache::lonhtmlcommon::row_closure(1);
6446: }
6447: }
1.406.2.6 raeburn 6448: $output .= &Apache::lonhtmlcommon::end_pick_box().'<br />';
6449: unless ($readonly) {
6450: $output .= '<input type="button" name="selfenrollconf" value="'
6451: .&mt('Save').'" onclick="validate_types(this.form);" />';
6452: }
6453: $output .= '<input type="hidden" name="action" value="selfenroll" />'
1.406.2.11 raeburn 6454: .'<input type="hidden" name="state" value="done" />'."\n"
6455: .$additional.'</form>';
1.237 raeburn 6456: $r->print($output);
6457: return;
6458: }
6459:
1.400 raeburn 6460: sub get_noedit_fields {
6461: my ($cdom,$cnum,$crstype,$row) = @_;
6462: my %noedit;
6463: if (ref($row) eq 'ARRAY') {
6464: my %settings = &Apache::lonnet::get('environment',['internal.coursecode','internal.textbook',
6465: 'internal.selfenrollmgrdc',
6466: 'internal.selfenrollmgrcc'],$cdom,$cnum);
6467: my $type = &Apache::lonuserutils::get_extended_type($cdom,$cnum,$crstype,\%settings);
6468: my (%specific_managebydc,%specific_managebycc,%default_managebydc);
6469: map { $specific_managebydc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrdc'}));
6470: map { $specific_managebycc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrcc'}));
6471: my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
6472: map { $default_managebydc{$_} = 1; } (split(/,/,$domdefaults{$type.'selfenrolladmdc'}));
6473:
6474: foreach my $item (@{$row}) {
6475: next if ($specific_managebycc{$item});
6476: if (($specific_managebydc{$item}) || ($default_managebydc{$item})) {
6477: $noedit{$item} = 1;
6478: }
6479: }
6480: }
6481: return %noedit;
6482: }
6483:
6484: sub visible_in_stdcat {
6485: my ($cdom,$cnum,$domconf) = @_;
6486: my ($cathash,%settable,@vismsgs,$cansetvis,$visible);
6487: unless (ref($domconf) eq 'HASH') {
6488: return ($visible,$cansetvis,\@vismsgs);
6489: }
6490: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6491: if ($domconf->{'coursecategories'}{'togglecats'} eq 'crs') {
1.256 raeburn 6492: $settable{'togglecats'} = 1;
6493: }
1.400 raeburn 6494: if ($domconf->{'coursecategories'}{'categorize'} eq 'crs') {
1.256 raeburn 6495: $settable{'categorize'} = 1;
6496: }
1.400 raeburn 6497: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6498: }
1.260 raeburn 6499: if ($settable{'togglecats'} && $settable{'categorize'}) {
1.256 raeburn 6500: $cansetvis = &mt('You are able to both assign a course category and choose to exclude this course from the catalog.');
6501: } elsif ($settable{'togglecats'}) {
6502: $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 6503: } elsif ($settable{'categorize'}) {
1.256 raeburn 6504: $cansetvis = &mt('You may assign a course category, but only a Domain Coordinator may choose to exclude this course from the catalog.');
6505: } else {
6506: $cansetvis = &mt('Only a Domain Coordinator may assign a course category or choose to exclude this course from the catalog.');
6507: }
6508:
6509: my %currsettings =
6510: &Apache::lonnet::get('environment',['hidefromcat','categories','internal.coursecode'],
6511: $cdom,$cnum);
1.400 raeburn 6512: $visible = 0;
1.256 raeburn 6513: if ($currsettings{'internal.coursecode'} ne '') {
1.400 raeburn 6514: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6515: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6516: if (ref($cathash) eq 'HASH') {
6517: if ($cathash->{'instcode::0'} eq '') {
6518: push(@vismsgs,'dc_addinst');
6519: } else {
6520: $visible = 1;
6521: }
6522: } else {
6523: $visible = 1;
6524: }
6525: } else {
6526: $visible = 1;
6527: }
6528: } else {
6529: if (ref($cathash) eq 'HASH') {
6530: if ($cathash->{'instcode::0'} ne '') {
6531: push(@vismsgs,'dc_instcode');
6532: }
6533: } else {
6534: push(@vismsgs,'dc_instcode');
6535: }
6536: }
6537: if ($currsettings{'categories'} ne '') {
6538: my $cathash;
1.400 raeburn 6539: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6540: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6541: if (ref($cathash) eq 'HASH') {
6542: if (keys(%{$cathash}) == 0) {
6543: push(@vismsgs,'dc_catalog');
6544: } elsif ((keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} ne '')) {
6545: push(@vismsgs,'dc_categories');
6546: } else {
6547: my @currcategories = split('&',$currsettings{'categories'});
6548: my $matched = 0;
6549: foreach my $cat (@currcategories) {
6550: if ($cathash->{$cat} ne '') {
6551: $visible = 1;
6552: $matched = 1;
6553: last;
6554: }
6555: }
6556: if (!$matched) {
1.260 raeburn 6557: if ($settable{'categorize'}) {
1.256 raeburn 6558: push(@vismsgs,'chgcat');
6559: } else {
6560: push(@vismsgs,'dc_chgcat');
6561: }
6562: }
6563: }
6564: }
6565: }
6566: } else {
6567: if (ref($cathash) eq 'HASH') {
6568: if ((keys(%{$cathash}) > 1) ||
6569: (keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} eq '')) {
1.260 raeburn 6570: if ($settable{'categorize'}) {
1.256 raeburn 6571: push(@vismsgs,'addcat');
6572: } else {
6573: push(@vismsgs,'dc_addcat');
6574: }
6575: }
6576: }
6577: }
6578: if ($currsettings{'hidefromcat'} eq 'yes') {
6579: $visible = 0;
6580: if ($settable{'togglecats'}) {
6581: unshift(@vismsgs,'unhide');
6582: } else {
6583: unshift(@vismsgs,'dc_unhide')
6584: }
6585: }
1.400 raeburn 6586: return ($visible,$cansetvis,\@vismsgs);
6587: }
6588:
6589: sub cat_visibility {
1.406.2.21 raeburn 6590: my ($cdom) = @_;
1.400 raeburn 6591: my %visactions = &Apache::lonlocal::texthash(
6592: vis => 'This course/community currently appears in the Course/Community Catalog for this domain.',
6593: 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.',
6594: miss => 'This course/community does not currently appear in the Course/Community Catalog for this domain.',
6595: none => 'Display of a course catalog is disabled for this domain.',
6596: yous => 'You should remedy this if you plan to allow self-enrollment, otherwise students will have difficulty finding this course.',
6597: 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.',
6598: make => 'Make any changes to self-enrollment settings below, click "Save", then take action to include the course in the Catalog:',
6599: take => 'Take the following action to ensure the course appears in the Catalog:',
6600: dc_chgconf => 'Ask a domain coordinator to change the Catalog type for this domain.',
6601: dc_setcode => 'Ask a domain coordinator to assign a six character code to the course',
6602: dc_unhide => 'Ask a domain coordinator to change the "Exclude from course catalog" setting.',
1.406.2.21 raeburn 6603: dc_addinst => 'Ask a domain coordinator to enable catalog display of "Official courses (with institutional codes)".',
1.400 raeburn 6604: dc_instcode => 'Ask a domain coordinator to assign an institutional code (if this is an official course).',
6605: dc_catalog => 'Ask a domain coordinator to enable or create at least one course category in the domain.',
6606: dc_categories => 'Ask a domain coordinator to create a hierarchy of categories and sub categories for courses in the domain.',
6607: 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',
6608: dc_addcat => 'Ask a domain coordinator to assign a category to the course.',
6609: );
1.406.2.21 raeburn 6610: if ($env{'request.role'} eq "dc./$cdom/") {
6611: $visactions{'dc_chgconf'} = &mt('Use: "Main menu" [_1] "Set domain configuration" [_1] "Cataloging of courses/communities" to change the Catalog type for this domain.','»');
6612: $visactions{'dc_setcode'} = &mt('Use: "Main menu" [_1] "Set domain configuration" [_1] "Cataloging of courses/communities" to assign a six character code to the course.','»');
6613: $visactions{'dc_unhide'} = &mt('Use: "Main menu" [_1] "Set domain configuration" [_1] "Cataloging of courses/communities" to change the "Exclude from course catalog" setting.','»');
6614: $visactions{'dc_addinst'} = &mt('Use: "Main menu" [_1] "Set domain configuration" [_1] "Cataloging of courses/communities" to enable catalog display of "Official courses (with institutional codes)".','»');
6615: $visactions{'dc_instcode'} = &mt('Use: "Main menu" [_1] "View or modify a course or community" [_1] "View/Modify course owner, institutional code ... " to assign an institutional code (if this is an official course).','»');
6616: $visactions{'dc_catalog'} = &mt('Use: "Main menu" [_1] "Set domain configuration" [_1] "Cataloging of courses/communities" to enable or create at least one course category in the domain.','»');
6617: $visactions{'dc_categories'} = &mt('Use: "Main menu" [_1] "Set domain configuration" [_1] "Cataloging of courses/communities" to create a hierarchy of categories and sub categories for courses in the domain.','»');
6618: $visactions{'dc_chgcat'} = &mt('Use: "Main menu" [_1] "View or modify a course or community" [_1] "View/Modify catalog settings for course" to change the category assigned to the course, as the one currently assigned is no longer used in the domain.','»');
6619: $visactions{'dc_addcat'} = &mt('Use: "Main menu" [_1] "View or modify a course or community" [_1] "View/Modify catalog settings for course" to assign a category to the course.','»');
6620: }
1.400 raeburn 6621: $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>"');
6622: $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>"');
6623: $visactions{'addcat'} = &mt('Use [_1]Categorize course[_2] to assign a category to the course.','"<a href="/adm/courseprefs?phase=display&actions=courseinfo">','</a>"');
6624: return \%visactions;
1.256 raeburn 6625: }
6626:
1.241 raeburn 6627: sub new_selfenroll_dom_row {
6628: my ($newdom,$num) = @_;
6629: my $domdesc = &Apache::lonnet::domain($newdom);
6630: my $output;
6631: if ($domdesc ne '') {
6632: $output .= &Apache::loncommon::start_data_table_row()
6633: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').' <b>'.$domdesc
6634: .' ('.$newdom.')</b><input type="hidden" name="selfenroll_dom_'.$num
1.249 raeburn 6635: .'" value="'.$newdom.'" /></span><br />'
6636: .'<span class="LC_nobreak"><label><input type="checkbox" '
6637: .'name="selfenroll_activate" value="'.$num.'" '
6638: .'onchange="javascript:update_types('
6639: ."'selfenroll_activate','$num'".');" />'
6640: .&mt('Activate').'</label></span></td>';
1.241 raeburn 6641: my @currinsttypes;
6642: $output .= '<td>'.&mt('User types:').'<br />'
6643: .&selfenroll_inst_types($num,$newdom,\@currinsttypes).'</td>'
6644: .&Apache::loncommon::end_data_table_row();
6645: }
6646: return $output;
6647: }
6648:
6649: sub selfenroll_inst_types {
1.406.2.6 raeburn 6650: my ($num,$currdom,$currinsttypes,$readonly) = @_;
1.241 raeburn 6651: my $output;
6652: my $numinrow = 4;
6653: my $count = 0;
6654: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($currdom);
1.247 raeburn 6655: my $othervalue = 'any';
1.406.2.6 raeburn 6656: my $disabled;
6657: if ($readonly) {
6658: $disabled = ' disabled="disabled"';
6659: }
1.241 raeburn 6660: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
1.251 raeburn 6661: if (keys(%{$usertypes}) > 0) {
1.247 raeburn 6662: $othervalue = 'other';
6663: }
1.241 raeburn 6664: $output .= '<table><tr>';
6665: foreach my $type (@{$types}) {
6666: if (($count > 0) && ($count%$numinrow == 0)) {
6667: $output .= '</tr><tr>';
6668: }
6669: if (defined($usertypes->{$type})) {
1.257 raeburn 6670: my $esc_type = &escape($type);
1.241 raeburn 6671: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.
1.257 raeburn 6672: $esc_type.'" ';
1.241 raeburn 6673: if (ref($currinsttypes) eq 'ARRAY') {
6674: if (@{$currinsttypes} > 0) {
1.249 raeburn 6675: if (grep(/^any$/,@{$currinsttypes})) {
6676: $output .= 'checked="checked"';
1.257 raeburn 6677: } elsif (grep(/^\Q$esc_type\E$/,@{$currinsttypes})) {
1.241 raeburn 6678: $output .= 'checked="checked"';
6679: }
1.249 raeburn 6680: } else {
6681: $output .= 'checked="checked"';
1.241 raeburn 6682: }
6683: }
1.406.2.6 raeburn 6684: $output .= ' name="selfenroll_types_'.$num.'"'.$disabled.' />'.$usertypes->{$type}.'</label></span></td>';
1.241 raeburn 6685: }
6686: $count ++;
6687: }
6688: if (($count > 0) && ($count%$numinrow == 0)) {
6689: $output .= '</tr><tr>';
6690: }
1.249 raeburn 6691: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.$othervalue.'"';
1.241 raeburn 6692: if (ref($currinsttypes) eq 'ARRAY') {
6693: if (@{$currinsttypes} > 0) {
1.249 raeburn 6694: if (grep(/^any$/,@{$currinsttypes})) {
6695: $output .= ' checked="checked"';
6696: } elsif ($othervalue eq 'other') {
6697: if (grep(/^\Q$othervalue\E$/,@{$currinsttypes})) {
6698: $output .= ' checked="checked"';
6699: }
1.241 raeburn 6700: }
1.249 raeburn 6701: } else {
6702: $output .= ' checked="checked"';
1.241 raeburn 6703: }
1.249 raeburn 6704: } else {
6705: $output .= ' checked="checked"';
1.241 raeburn 6706: }
1.406.2.6 raeburn 6707: $output .= ' name="selfenroll_types_'.$num.'"'.$disabled.' />'.$othertitle.'</label></span></td></tr></table>';
1.241 raeburn 6708: }
6709: return $output;
6710: }
6711:
1.237 raeburn 6712: sub selfenroll_date_forms {
6713: my ($startform,$endform) = @_;
6714: my $output .= &Apache::lonhtmlcommon::start_pick_box()."\n".
1.244 bisitz 6715: &Apache::lonhtmlcommon::row_title(&mt('Start date'),
1.237 raeburn 6716: 'LC_oddrow_value')."\n".
6717: $startform."\n".
6718: &Apache::lonhtmlcommon::row_closure(1).
1.244 bisitz 6719: &Apache::lonhtmlcommon::row_title(&mt('End date'),
1.237 raeburn 6720: 'LC_oddrow_value')."\n".
6721: $endform."\n".
6722: &Apache::lonhtmlcommon::row_closure(1).
6723: &Apache::lonhtmlcommon::end_pick_box();
6724: return $output;
6725: }
6726:
1.239 raeburn 6727: sub print_userchangelogs_display {
1.406.2.5 raeburn 6728: my ($r,$context,$permission,$brcrum) = @_;
1.363 raeburn 6729: my $formname = 'rolelog';
1.406.2.6 raeburn 6730: my ($username,$domain,$crstype,$viewablesec,%roleslog);
1.363 raeburn 6731: if ($context eq 'domain') {
6732: $domain = $env{'request.role.domain'};
6733: %roleslog=&Apache::lonnet::dump_dom('nohist_rolelog',$domain);
6734: } else {
6735: if ($context eq 'course') {
6736: $domain = $env{'course.'.$env{'request.course.id'}.'.domain'};
6737: $username = $env{'course.'.$env{'request.course.id'}.'.num'};
6738: $crstype = &Apache::loncommon::course_type();
1.406.2.6 raeburn 6739: $viewablesec = &Apache::lonuserutils::viewable_section($permission);
1.363 raeburn 6740: my %saveable_parameters = ('show' => 'scalar',);
6741: &Apache::loncommon::store_course_settings('roles_log',
6742: \%saveable_parameters);
6743: &Apache::loncommon::restore_course_settings('roles_log',
6744: \%saveable_parameters);
6745: } elsif ($context eq 'author') {
6746: $domain = $env{'user.domain'};
6747: if ($env{'request.role'} =~ m{^au\./\Q$domain\E/$}) {
6748: $username = $env{'user.name'};
6749: } else {
6750: undef($domain);
6751: }
6752: }
6753: if ($domain ne '' && $username ne '') {
6754: %roleslog=&Apache::lonnet::dump('nohist_rolelog',$domain,$username);
6755: }
6756: }
1.239 raeburn 6757: if ((keys(%roleslog))[0]=~/^error\:/) { undef(%roleslog); }
6758:
1.406.2.5 raeburn 6759: my $helpitem;
6760: if ($context eq 'course') {
6761: $helpitem = 'Course_User_Logs';
1.406.2.14 raeburn 6762: } elsif ($context eq 'domain') {
6763: $helpitem = 'Domain_Role_Logs';
6764: } elsif ($context eq 'author') {
6765: $helpitem = 'Author_User_Logs';
1.406.2.5 raeburn 6766: }
6767: push (@{$brcrum},
6768: {href => '/adm/createuser?action=changelogs',
6769: text => 'User Management Logs',
6770: help => $helpitem});
6771: my $bread_crumbs_component = 'User Changes';
6772: my $args = { bread_crumbs => $brcrum,
6773: bread_crumbs_component => $bread_crumbs_component};
6774:
6775: # Create navigation javascript
6776: my $jsnav = &userlogdisplay_js($formname);
6777:
6778: my $jscript = (<<ENDSCRIPT);
6779: <script type="text/javascript">
6780: // <![CDATA[
6781: $jsnav
6782: // ]]>
6783: </script>
6784: ENDSCRIPT
6785:
6786: # print page header
6787: $r->print(&header($jscript,$args));
6788:
1.239 raeburn 6789: # set defaults
6790: my $now = time();
6791: my $defstart = $now - (7*24*3600); #7 days ago
6792: my %defaults = (
6793: page => '1',
6794: show => '10',
6795: role => 'any',
6796: chgcontext => 'any',
6797: rolelog_start_date => $defstart,
6798: rolelog_end_date => $now,
6799: );
6800: my $more_records = 0;
6801:
6802: # set current
6803: my %curr;
6804: foreach my $item ('show','page','role','chgcontext') {
6805: $curr{$item} = $env{'form.'.$item};
6806: }
6807: my ($startdate,$enddate) =
6808: &Apache::lonuserutils::get_dates_from_form('rolelog_start_date','rolelog_end_date');
6809: $curr{'rolelog_start_date'} = $startdate;
6810: $curr{'rolelog_end_date'} = $enddate;
6811: foreach my $key (keys(%defaults)) {
6812: if ($curr{$key} eq '') {
6813: $curr{$key} = $defaults{$key};
6814: }
6815: }
1.248 raeburn 6816: my (%whodunit,%changed,$version);
6817: ($version) = ($r->dir_config('lonVersion') =~ /^([\d\.]+)\-/);
1.239 raeburn 6818: my ($minshown,$maxshown);
1.255 raeburn 6819: $minshown = 1;
1.239 raeburn 6820: my $count = 0;
1.406.2.5 raeburn 6821: if ($curr{'show'} =~ /\D/) {
6822: $curr{'page'} = 1;
6823: } else {
1.239 raeburn 6824: $maxshown = $curr{'page'} * $curr{'show'};
6825: if ($curr{'page'} > 1) {
6826: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
6827: }
6828: }
1.301 bisitz 6829:
1.327 raeburn 6830: # Form Header
6831: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
1.363 raeburn 6832: &role_display_filter($context,$formname,$domain,$username,\%curr,
6833: $version,$crstype));
1.327 raeburn 6834:
6835: my $showntableheader = 0;
6836:
6837: # Table Header
6838: my $tableheader =
6839: &Apache::loncommon::start_data_table_header_row()
6840: .'<th> </th>'
6841: .'<th>'.&mt('When').'</th>'
6842: .'<th>'.&mt('Who made the change').'</th>'
6843: .'<th>'.&mt('Changed User').'</th>'
1.363 raeburn 6844: .'<th>'.&mt('Role').'</th>';
6845:
6846: if ($context eq 'course') {
6847: $tableheader .= '<th>'.&mt('Section').'</th>';
6848: }
6849: $tableheader .=
6850: '<th>'.&mt('Context').'</th>'
1.327 raeburn 6851: .'<th>'.&mt('Start').'</th>'
6852: .'<th>'.&mt('End').'</th>'
6853: .&Apache::loncommon::end_data_table_header_row();
6854:
6855: # Display user change log data
1.239 raeburn 6856: foreach my $id (sort { $roleslog{$b}{'exe_time'}<=>$roleslog{$a}{'exe_time'} } (keys(%roleslog))) {
6857: next if (($roleslog{$id}{'exe_time'} < $curr{'rolelog_start_date'}) ||
6858: ($roleslog{$id}{'exe_time'} > $curr{'rolelog_end_date'}));
1.406.2.5 raeburn 6859: if ($curr{'show'} !~ /\D/) {
1.239 raeburn 6860: if ($count >= $curr{'page'} * $curr{'show'}) {
6861: $more_records = 1;
6862: last;
6863: }
6864: }
6865: if ($curr{'role'} ne 'any') {
6866: next if ($roleslog{$id}{'logentry'}{'role'} ne $curr{'role'});
6867: }
6868: if ($curr{'chgcontext'} ne 'any') {
6869: if ($curr{'chgcontext'} eq 'selfenroll') {
6870: next if (!$roleslog{$id}{'logentry'}{'selfenroll'});
6871: } else {
6872: next if ($roleslog{$id}{'logentry'}{'context'} ne $curr{'chgcontext'});
6873: }
6874: }
1.406.2.6 raeburn 6875: if (($context eq 'course') && ($viewablesec ne '')) {
6876: next if ($roleslog{$id}{'logentry'}{'section'} ne $viewablesec);
6877: }
1.239 raeburn 6878: $count ++;
6879: next if ($count < $minshown);
1.327 raeburn 6880: unless ($showntableheader) {
1.406.2.5 raeburn 6881: $r->print(&Apache::loncommon::start_data_table()
1.327 raeburn 6882: .$tableheader);
6883: $r->rflush();
6884: $showntableheader = 1;
6885: }
1.239 raeburn 6886: if ($whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} eq '') {
6887: $whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} =
6888: &Apache::loncommon::plainname($roleslog{$id}{'exe_uname'},$roleslog{$id}{'exe_udom'});
6889: }
6890: if ($changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} eq '') {
6891: $changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} =
6892: &Apache::loncommon::plainname($roleslog{$id}{'uname'},$roleslog{$id}{'udom'});
6893: }
6894: my $sec = $roleslog{$id}{'logentry'}{'section'};
6895: if ($sec eq '') {
6896: $sec = &mt('None');
6897: }
6898: my ($rolestart,$roleend);
6899: if ($roleslog{$id}{'delflag'}) {
6900: $rolestart = &mt('deleted');
6901: $roleend = &mt('deleted');
6902: } else {
6903: $rolestart = $roleslog{$id}{'logentry'}{'start'};
6904: $roleend = $roleslog{$id}{'logentry'}{'end'};
6905: if ($rolestart eq '' || $rolestart == 0) {
6906: $rolestart = &mt('No start date');
6907: } else {
6908: $rolestart = &Apache::lonlocal::locallocaltime($rolestart);
6909: }
6910: if ($roleend eq '' || $roleend == 0) {
6911: $roleend = &mt('No end date');
6912: } else {
6913: $roleend = &Apache::lonlocal::locallocaltime($roleend);
6914: }
6915: }
6916: my $chgcontext = $roleslog{$id}{'logentry'}{'context'};
6917: if ($roleslog{$id}{'logentry'}{'selfenroll'}) {
6918: $chgcontext = 'selfenroll';
6919: }
1.363 raeburn 6920: my %lt = &rolechg_contexts($context,$crstype);
1.239 raeburn 6921: if ($chgcontext ne '' && $lt{$chgcontext} ne '') {
6922: $chgcontext = $lt{$chgcontext};
6923: }
1.327 raeburn 6924: $r->print(
1.301 bisitz 6925: &Apache::loncommon::start_data_table_row()
6926: .'<td>'.$count.'</td>'
6927: .'<td>'.&Apache::lonlocal::locallocaltime($roleslog{$id}{'exe_time'}).'</td>'
6928: .'<td>'.$whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}}.'</td>'
6929: .'<td>'.$changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}}.'</td>'
1.363 raeburn 6930: .'<td>'.&Apache::lonnet::plaintext($roleslog{$id}{'logentry'}{'role'},$crstype).'</td>');
6931: if ($context eq 'course') {
6932: $r->print('<td>'.$sec.'</td>');
6933: }
6934: $r->print(
6935: '<td>'.$chgcontext.'</td>'
1.301 bisitz 6936: .'<td>'.$rolestart.'</td>'
6937: .'<td>'.$roleend.'</td>'
1.327 raeburn 6938: .&Apache::loncommon::end_data_table_row()."\n");
1.301 bisitz 6939: }
6940:
1.327 raeburn 6941: if ($showntableheader) { # Table footer, if content displayed above
1.406.2.5 raeburn 6942: $r->print(&Apache::loncommon::end_data_table().
6943: &userlogdisplay_navlinks(\%curr,$more_records));
1.327 raeburn 6944: } else { # No content displayed above
1.301 bisitz 6945: $r->print('<p class="LC_info">'
6946: .&mt('There are no records to display.')
6947: .'</p>'
6948: );
1.239 raeburn 6949: }
1.301 bisitz 6950:
1.327 raeburn 6951: # Form Footer
6952: $r->print(
6953: '<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
6954: .'<input type="hidden" name="action" value="changelogs" />'
6955: .'</form>');
6956: return;
6957: }
1.301 bisitz 6958:
1.406.2.5 raeburn 6959: sub print_useraccesslogs_display {
6960: my ($r,$uname,$udom,$permission,$brcrum) = @_;
6961: my $formname = 'accesslog';
6962: my $form = 'document.accesslog';
6963:
6964: # set breadcrumbs
1.406.2.7 raeburn 6965: my %breadcrumb_text = &singleuser_breadcrumb('','domain',$udom);
1.406.2.12 raeburn 6966: my $prevphasestr;
6967: if ($env{'form.popup'}) {
6968: $brcrum = [];
6969: } else {
6970: push (@{$brcrum},
6971: {href => "javascript:backPage($form)",
6972: text => $breadcrumb_text{'search'}});
6973: my @prevphases;
6974: if ($env{'form.prevphases'}) {
6975: @prevphases = split(/,/,$env{'form.prevphases'});
6976: $prevphasestr = $env{'form.prevphases'};
6977: }
6978: if (($env{'form.phase'} eq 'userpicked') || (grep(/^userpicked$/,@prevphases))) {
6979: push(@{$brcrum},
6980: {href => "javascript:backPage($form,'get_user_info','select')",
6981: text => $breadcrumb_text{'userpicked'}});
6982: if ($env{'form.phase'} eq 'userpicked') {
6983: $prevphasestr = 'userpicked';
6984: }
1.406.2.5 raeburn 6985: }
6986: }
6987: push(@{$brcrum},
6988: {href => '/adm/createuser?action=accesslogs',
6989: text => 'User access logs',
1.406.2.8 raeburn 6990: help => 'Domain_User_Access_Logs'});
1.406.2.5 raeburn 6991: my $bread_crumbs_component = 'User Access Logs';
6992: my $args = { bread_crumbs => $brcrum,
6993: bread_crumbs_component => 'User Management'};
1.406.2.8 raeburn 6994: if ($env{'form.popup'}) {
6995: $args->{'no_nav_bar'} = 1;
1.406.2.12 raeburn 6996: $args->{'bread_crumbs_nomenu'} = 1;
1.406.2.8 raeburn 6997: }
1.406.2.5 raeburn 6998:
6999: # set javascript
7000: my ($jsback,$elements) = &crumb_utilities();
7001: my $jsnav = &userlogdisplay_js($formname);
7002:
7003: my $jscript = (<<ENDSCRIPT);
1.239 raeburn 7004: <script type="text/javascript">
1.301 bisitz 7005: // <![CDATA[
1.406.2.5 raeburn 7006:
7007: $jsback
7008: $jsnav
7009:
7010: // ]]>
7011: </script>
7012:
7013: ENDSCRIPT
7014:
7015: # print page header
7016: $r->print(&header($jscript,$args));
7017:
7018: # early out unless log data can be displayed.
7019: unless ($permission->{'activity'}) {
7020: $r->print('<p class="LC_warning">'
7021: .&mt('You do not have rights to display user access logs.')
1.406.2.12 raeburn 7022: .'</p>');
7023: if ($env{'form.popup'}) {
7024: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
7025: } else {
7026: $r->print(&earlyout_accesslog_form($formname,$prevphasestr,$udom));
7027: }
1.406.2.5 raeburn 7028: return;
7029: }
7030:
7031: unless ($udom eq $env{'request.role.domain'}) {
7032: $r->print('<p class="LC_warning">'
7033: .&mt("User's domain must match role's domain")
7034: .'</p>'
7035: .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
7036: return;
7037: }
7038:
7039: if (($uname eq '') || ($udom eq '')) {
7040: $r->print('<p class="LC_warning">'
7041: .&mt('Invalid username or domain')
7042: .'</p>'
7043: .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
7044: return;
7045: }
7046:
1.406.2.13 raeburn 7047: if (&Apache::lonnet::privileged($uname,$udom,
7048: [$env{'request.role.domain'}],['dc','su'])) {
7049: unless (&Apache::lonnet::privileged($env{'user.name'},$env{'user.domain'},
7050: [$env{'request.role.domain'}],['dc','su'])) {
7051: $r->print('<p class="LC_warning">'
7052: .&mt('You need to be a privileged user to display user access logs for [_1]',
7053: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),
7054: $uname,$udom))
7055: .'</p>');
7056: if ($env{'form.popup'}) {
7057: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
7058: } else {
7059: $r->print(&earlyout_accesslog_form($formname,$prevphasestr,$udom));
7060: }
7061: return;
7062: }
7063: }
7064:
1.406.2.5 raeburn 7065: # set defaults
7066: my $now = time();
7067: my $defstart = $now - (7*24*3600);
7068: my %defaults = (
7069: page => '1',
7070: show => '10',
7071: activity => 'any',
7072: accesslog_start_date => $defstart,
7073: accesslog_end_date => $now,
7074: );
7075: my $more_records = 0;
7076:
7077: # set current
7078: my %curr;
7079: foreach my $item ('show','page','activity') {
7080: $curr{$item} = $env{'form.'.$item};
7081: }
7082: my ($startdate,$enddate) =
7083: &Apache::lonuserutils::get_dates_from_form('accesslog_start_date','accesslog_end_date');
7084: $curr{'accesslog_start_date'} = $startdate;
7085: $curr{'accesslog_end_date'} = $enddate;
7086: foreach my $key (keys(%defaults)) {
7087: if ($curr{$key} eq '') {
7088: $curr{$key} = $defaults{$key};
7089: }
7090: }
7091: my ($minshown,$maxshown);
7092: $minshown = 1;
7093: my $count = 0;
7094: if ($curr{'show'} =~ /\D/) {
7095: $curr{'page'} = 1;
7096: } else {
7097: $maxshown = $curr{'page'} * $curr{'show'};
7098: if ($curr{'page'} > 1) {
7099: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
7100: }
7101: }
7102:
7103: # form header
7104: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
7105: &activity_display_filter($formname,\%curr));
7106:
7107: my $showntableheader = 0;
7108: my ($nav_script,$nav_links);
7109:
7110: # table header
1.406.2.18 raeburn 7111: my $heading = '<h3>'.
1.406.2.12 raeburn 7112: &mt('User access logs for: [_1]',
1.406.2.18 raeburn 7113: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom)).'</h3>';
7114: my $tableheader = $heading
1.406.2.12 raeburn 7115: .&Apache::loncommon::start_data_table_header_row()
1.406.2.5 raeburn 7116: .'<th> </th>'
7117: .'<th>'.&mt('When').'</th>'
7118: .'<th>'.&mt('HostID').'</th>'
7119: .'<th>'.&mt('Event').'</th>'
7120: .'<th>'.&mt('Other data').'</th>'
7121: .&Apache::loncommon::end_data_table_header_row();
7122:
7123: my %filters=(
7124: start => $curr{'accesslog_start_date'},
7125: end => $curr{'accesslog_end_date'},
7126: action => $curr{'activity'},
7127: );
7128:
7129: my $reply = &Apache::lonnet::userlog_query($uname,$udom,%filters);
7130: unless ( ($reply =~/^timeout/) || ($reply =~/^error/) ) {
7131: my (%courses,%missing);
7132: my @results = split(/\&/,$reply);
7133: foreach my $item (reverse(@results)) {
7134: my ($timestamp,$host,$event) = split(/:/,$item);
7135: next unless ($event =~ /^(Log|Role)/);
7136: if ($curr{'show'} !~ /\D/) {
7137: if ($count >= $curr{'page'} * $curr{'show'}) {
7138: $more_records = 1;
7139: last;
7140: }
7141: }
7142: $count ++;
7143: next if ($count < $minshown);
7144: unless ($showntableheader) {
7145: $r->print($nav_script
7146: .&Apache::loncommon::start_data_table()
7147: .$tableheader);
7148: $r->rflush();
7149: $showntableheader = 1;
7150: }
1.406.2.6 raeburn 7151: my ($shown,$extra);
1.406.2.13 raeburn 7152: my ($event,$data) = split(/\s+/,&unescape($event),2);
1.406.2.5 raeburn 7153: if ($event eq 'Role') {
7154: my ($rolecode,$extent) = split(/\./,$data,2);
7155: next if ($extent eq '');
7156: my ($crstype,$desc,$info);
1.406.2.6 raeburn 7157: if ($extent =~ m{^/($match_domain)/($match_courseid)(?:/(\w+)|)$}) {
7158: my ($cdom,$cnum,$sec) = ($1,$2,$3);
1.406.2.5 raeburn 7159: my $cid = $cdom.'_'.$cnum;
7160: if (exists($courses{$cid})) {
7161: $crstype = $courses{$cid}{'type'};
7162: $desc = $courses{$cid}{'description'};
7163: } elsif ($missing{$cid}) {
7164: $crstype = 'Course';
7165: $desc = 'Course/Community';
7166: } else {
7167: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',$cnum,undef,undef,'.');
7168: if (ref($crsinfo{$cdom.'_'.$cnum}) eq 'HASH') {
7169: $courses{$cid} = $crsinfo{$cid};
7170: $crstype = $crsinfo{$cid}{'type'};
7171: $desc = $crsinfo{$cid}{'description'};
7172: } else {
7173: $missing{$cid} = 1;
7174: }
7175: }
7176: $extra = &mt($crstype).': <a href="/public/'.$cdom.'/'.$cnum.'/syllabus">'.$desc.'</a>';
1.406.2.6 raeburn 7177: if ($sec ne '') {
7178: $extra .= ' ('.&mt('Section: [_1]',$sec).')';
7179: }
1.406.2.5 raeburn 7180: } elsif ($extent =~ m{^/($match_domain)/($match_username|$)}) {
7181: my ($dom,$name) = ($1,$2);
7182: if ($rolecode eq 'au') {
7183: $extra = '';
7184: } elsif ($rolecode =~ /^(ca|aa)$/) {
7185: $extra = &mt('Authoring Space: [_1]',$name.':'.$dom);
7186: } elsif ($rolecode =~ /^(li|dg|dh|dc|sc)$/) {
7187: $extra = &mt('Domain: [_1]',$dom);
7188: }
7189: }
7190: my $rolename;
7191: if ($rolecode =~ m{^cr/($match_domain)/($match_username)/(\w+)}) {
7192: my $role = $3;
7193: my $owner = "($2:$1)";
7194: if ($2 eq $1.'-domainconfig') {
7195: $owner = '(ad hoc)';
7196: }
7197: $rolename = &mt('Custom role: [_1]',$role.' '.$owner);
7198: } else {
7199: $rolename = &Apache::lonnet::plaintext($rolecode,$crstype);
7200: }
7201: $shown = &mt('Role selection: [_1]',$rolename);
7202: } else {
7203: $shown = &mt($event);
1.406.2.13 raeburn 7204: if ($data =~ /^webdav/) {
7205: my ($path,$clientip) = split(/\s+/,$data,2);
7206: $path =~ s/^webdav//;
7207: if ($clientip ne '') {
7208: $extra = &mt('Client IP address: [_1]',$clientip);
7209: }
7210: if ($path ne '') {
7211: $shown .= ' '.&mt('(WebDAV access to [_1])',$path);
7212: }
7213: } elsif ($data ne '') {
7214: $extra = &mt('Client IP address: [_1]',$data);
1.406.2.5 raeburn 7215: }
7216: }
7217: $r->print(
7218: &Apache::loncommon::start_data_table_row()
7219: .'<td>'.$count.'</td>'
7220: .'<td>'.&Apache::lonlocal::locallocaltime($timestamp).'</td>'
7221: .'<td>'.$host.'</td>'
7222: .'<td>'.$shown.'</td>'
7223: .'<td>'.$extra.'</td>'
7224: .&Apache::loncommon::end_data_table_row()."\n");
7225: }
7226: }
7227:
7228: if ($showntableheader) { # Table footer, if content displayed above
7229: $r->print(&Apache::loncommon::end_data_table().
7230: &userlogdisplay_navlinks(\%curr,$more_records));
7231: } else { # No content displayed above
1.406.2.18 raeburn 7232: $r->print($heading.'<p class="LC_info">'
1.406.2.5 raeburn 7233: .&mt('There are no records to display.')
7234: .'</p>');
7235: }
7236:
1.406.2.8 raeburn 7237: if ($env{'form.popup'} == 1) {
7238: $r->print('<input type="hidden" name="popup" value="1" />'."\n");
7239: }
7240:
1.406.2.5 raeburn 7241: # Form Footer
7242: $r->print(
7243: '<input type="hidden" name="currstate" value="" />'
7244: .'<input type="hidden" name="accessuname" value="'.$uname.'" />'
7245: .'<input type="hidden" name="accessudom" value="'.$udom.'" />'
7246: .'<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
7247: .'<input type="hidden" name="prevphases" value="'.$prevphasestr.'" />'
7248: .'<input type="hidden" name="phase" value="activity" />'
7249: .'<input type="hidden" name="action" value="accesslogs" />'
7250: .'<input type="hidden" name="srchdomain" value="'.$udom.'" />'
7251: .'<input type="hidden" name="srchby" value="'.$env{'form.srchby'}.'" />'
7252: .'<input type="hidden" name="srchtype" value="'.$env{'form.srchtype'}.'" />'
7253: .'<input type="hidden" name="srchterm" value="'.&HTML::Entities::encode($env{'form.srchterm'},'<>"&').'" />'
7254: .'<input type="hidden" name="srchin" value="'.$env{'form.srchin'}.'" />'
7255: .'</form>');
7256: return;
7257: }
7258:
7259: sub earlyout_accesslog_form {
7260: my ($formname,$prevphasestr,$udom) = @_;
7261: my $srchterm = &HTML::Entities::encode($env{'form.srchterm'},'<>"&');
7262: return <<"END";
7263: <form action="/adm/createuser" method="post" name="$formname">
7264: <input type="hidden" name="currstate" value="" />
7265: <input type="hidden" name="prevphases" value="$prevphasestr" />
7266: <input type="hidden" name="phase" value="activity" />
7267: <input type="hidden" name="action" value="accesslogs" />
7268: <input type="hidden" name="srchdomain" value="$udom" />
7269: <input type="hidden" name="srchby" value="$env{'form.srchby'}" />
7270: <input type="hidden" name="srchtype" value="$env{'form.srchtype'}" />
7271: <input type="hidden" name="srchterm" value="$srchterm" />
7272: <input type="hidden" name="srchin" value="$env{'form.srchin'}" />
7273: </form>
7274: END
7275: }
7276:
7277: sub activity_display_filter {
7278: my ($formname,$curr) = @_;
7279: my $nolink = 1;
7280: my $output = '<table><tr><td valign="top">'.
7281: '<span class="LC_nobreak"><b>'.&mt('Actions/page:').'</b></span><br />'.
7282: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
7283: (&mt('all'),5,10,20,50,100,1000,10000)).
7284: '</td><td> </td>';
7285: my $startform =
7286: &Apache::lonhtmlcommon::date_setter($formname,'accesslog_start_date',
7287: $curr->{'accesslog_start_date'},undef,
7288: undef,undef,undef,undef,undef,undef,$nolink);
7289: my $endform =
7290: &Apache::lonhtmlcommon::date_setter($formname,'accesslog_end_date',
7291: $curr->{'accesslog_end_date'},undef,
7292: undef,undef,undef,undef,undef,undef,$nolink);
7293: my %lt = &Apache::lonlocal::texthash (
7294: activity => 'Activity',
7295: Role => 'Role selection',
7296: log => 'Log-in or Logout',
7297: );
7298: $output .= '<td valign="top"><b>'.&mt('Window during which actions occurred:').'</b><br />'.
7299: '<table><tr><td>'.&mt('After:').
7300: '</td><td>'.$startform.'</td></tr>'.
7301: '<tr><td>'.&mt('Before:').'</td>'.
7302: '<td>'.$endform.'</td></tr></table>'.
7303: '</td>'.
7304: '<td> </td>'.
7305: '<td valign="top"><b>'.&mt('Activities').'</b><br />'.
7306: '<select name="activity"><option value="any"';
7307: if ($curr->{'activity'} eq 'any') {
7308: $output .= ' selected="selected"';
7309: }
7310: $output .= '>'.&mt('Any').'</option>'."\n";
7311: foreach my $activity ('Role','log') {
7312: my $selstr = '';
7313: if ($activity eq $curr->{'activity'}) {
7314: $selstr = ' selected="selected"';
7315: }
7316: $output .= '<option value="'.$activity.'"'.$selstr.'>'.$lt{$activity}.'</option>';
7317: }
7318: $output .= '</select></td>'.
7319: '</tr></table>';
7320: # Update Display button
7321: $output .= '<p>'
7322: .'<input type="submit" value="'.&mt('Update Display').'" />'
1.406.2.12 raeburn 7323: .'</p><hr />';
1.406.2.5 raeburn 7324: return $output;
7325: }
7326:
7327: sub userlogdisplay_js {
7328: my ($formname) = @_;
7329: return <<"ENDSCRIPT";
7330:
1.239 raeburn 7331: function chgPage(caller) {
7332: if (caller == 'previous') {
7333: document.$formname.page.value --;
7334: }
7335: if (caller == 'next') {
7336: document.$formname.page.value ++;
7337: }
1.327 raeburn 7338: document.$formname.submit();
1.239 raeburn 7339: return;
7340: }
7341: ENDSCRIPT
1.406.2.5 raeburn 7342: }
7343:
7344: sub userlogdisplay_navlinks {
7345: my ($curr,$more_records) = @_;
7346: return unless(ref($curr) eq 'HASH');
7347: # Navigation Buttons
7348: my $nav_links = '<p>';
7349: if (($curr->{'page'} > 1) || ($more_records)) {
7350: if (($curr->{'page'} > 1) && ($curr->{'show'} !~ /\D/)) {
7351: $nav_links .= '<input type="button"'
7352: .' onclick="javascript:chgPage('."'previous'".');"'
7353: .' value="'.&mt('Previous [_1] changes',$curr->{'show'})
7354: .'" /> ';
7355: }
7356: if ($more_records) {
7357: $nav_links .= '<input type="button"'
7358: .' onclick="javascript:chgPage('."'next'".');"'
7359: .' value="'.&mt('Next [_1] changes',$curr->{'show'})
7360: .'" />';
1.301 bisitz 7361: }
7362: }
1.406.2.5 raeburn 7363: $nav_links .= '</p>';
7364: return $nav_links;
1.239 raeburn 7365: }
7366:
7367: sub role_display_filter {
1.363 raeburn 7368: my ($context,$formname,$cdom,$cnum,$curr,$version,$crstype) = @_;
7369: my $lctype;
7370: if ($context eq 'course') {
7371: $lctype = lc($crstype);
7372: }
1.239 raeburn 7373: my $nolink = 1;
7374: my $output = '<table><tr><td valign="top">'.
1.301 bisitz 7375: '<span class="LC_nobreak"><b>'.&mt('Changes/page:').'</b></span><br />'.
1.239 raeburn 7376: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
7377: (&mt('all'),5,10,20,50,100,1000,10000)).
7378: '</td><td> </td>';
7379: my $startform =
7380: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_start_date',
7381: $curr->{'rolelog_start_date'},undef,
7382: undef,undef,undef,undef,undef,undef,$nolink);
7383: my $endform =
7384: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_end_date',
7385: $curr->{'rolelog_end_date'},undef,
7386: undef,undef,undef,undef,undef,undef,$nolink);
1.363 raeburn 7387: my %lt = &rolechg_contexts($context,$crstype);
1.301 bisitz 7388: $output .= '<td valign="top"><b>'.&mt('Window during which changes occurred:').'</b><br />'.
7389: '<table><tr><td>'.&mt('After:').
7390: '</td><td>'.$startform.'</td></tr>'.
7391: '<tr><td>'.&mt('Before:').'</td>'.
7392: '<td>'.$endform.'</td></tr></table>'.
7393: '</td>'.
7394: '<td> </td>'.
1.239 raeburn 7395: '<td valign="top"><b>'.&mt('Role:').'</b><br />'.
7396: '<select name="role"><option value="any"';
7397: if ($curr->{'role'} eq 'any') {
7398: $output .= ' selected="selected"';
7399: }
7400: $output .= '>'.&mt('Any').'</option>'."\n";
1.363 raeburn 7401: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
1.239 raeburn 7402: foreach my $role (@roles) {
7403: my $plrole;
7404: if ($role eq 'cr') {
7405: $plrole = &mt('Custom Role');
7406: } else {
1.318 raeburn 7407: $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.239 raeburn 7408: }
7409: my $selstr = '';
7410: if ($role eq $curr->{'role'}) {
7411: $selstr = ' selected="selected"';
7412: }
7413: $output .= ' <option value="'.$role.'"'.$selstr.'>'.$plrole.'</option>';
7414: }
1.301 bisitz 7415: $output .= '</select></td>'.
7416: '<td> </td>'.
7417: '<td valign="top"><b>'.
1.239 raeburn 7418: &mt('Context:').'</b><br /><select name="chgcontext">';
1.363 raeburn 7419: my @posscontexts;
7420: if ($context eq 'course') {
1.406.2.20 raeburn 7421: @posscontexts = ('any','automated','updatenow','createcourse','course','domain','selfenroll','requestcourses','chgtype');
1.363 raeburn 7422: } elsif ($context eq 'domain') {
7423: @posscontexts = ('any','domain','requestauthor','domconfig','server');
7424: } else {
7425: @posscontexts = ('any','author','domain');
1.406.2.20 raeburn 7426: }
1.363 raeburn 7427: foreach my $chgtype (@posscontexts) {
1.239 raeburn 7428: my $selstr = '';
7429: if ($curr->{'chgcontext'} eq $chgtype) {
1.301 bisitz 7430: $selstr = ' selected="selected"';
1.239 raeburn 7431: }
1.363 raeburn 7432: if ($context eq 'course') {
1.376 raeburn 7433: if (($chgtype eq 'automated') || ($chgtype eq 'updatenow')) {
1.363 raeburn 7434: next if (!&Apache::lonnet::auto_run($cnum,$cdom));
7435: }
1.239 raeburn 7436: }
7437: $output .= '<option value="'.$chgtype.'"'.$selstr.'>'.$lt{$chgtype}.'</option>'."\n";
1.248 raeburn 7438: }
1.303 bisitz 7439: $output .= '</select></td>'
7440: .'</tr></table>';
7441:
7442: # Update Display button
7443: $output .= '<p>'
7444: .'<input type="submit" value="'.&mt('Update Display').'" />'
7445: .'</p>';
7446:
7447: # Server version info
1.363 raeburn 7448: my $needsrev = '2.11.0';
7449: if ($context eq 'course') {
7450: $needsrev = '2.7.0';
7451: }
7452:
1.303 bisitz 7453: $output .= '<p class="LC_info">'
7454: .&mt('Only changes made from servers running LON-CAPA [_1] or later are displayed.'
1.363 raeburn 7455: ,$needsrev);
1.248 raeburn 7456: if ($version) {
1.303 bisitz 7457: $output .= ' '.&mt('This LON-CAPA server is version [_1]',$version);
7458: }
7459: $output .= '</p><hr />';
1.239 raeburn 7460: return $output;
7461: }
7462:
7463: sub rolechg_contexts {
1.363 raeburn 7464: my ($context,$crstype) = @_;
7465: my %lt;
7466: if ($context eq 'course') {
7467: %lt = &Apache::lonlocal::texthash (
1.239 raeburn 7468: any => 'Any',
1.376 raeburn 7469: automated => 'Automated Enrollment',
1.406.2.20 raeburn 7470: chgtype => 'Enrollment Type/Lock Change',
1.239 raeburn 7471: updatenow => 'Roster Update',
7472: createcourse => 'Course Creation',
7473: course => 'User Management in course',
7474: domain => 'User Management in domain',
1.313 raeburn 7475: selfenroll => 'Self-enrolled',
1.318 raeburn 7476: requestcourses => 'Course Request',
1.239 raeburn 7477: );
1.363 raeburn 7478: if ($crstype eq 'Community') {
7479: $lt{'createcourse'} = &mt('Community Creation');
7480: $lt{'course'} = &mt('User Management in community');
7481: $lt{'requestcourses'} = &mt('Community Request');
7482: }
7483: } elsif ($context eq 'domain') {
7484: %lt = &Apache::lonlocal::texthash (
7485: any => 'Any',
7486: domain => 'User Management in domain',
7487: requestauthor => 'Authoring Request',
7488: server => 'Command line script (DC role)',
7489: domconfig => 'Self-enrolled',
7490: );
7491: } else {
7492: %lt = &Apache::lonlocal::texthash (
7493: any => 'Any',
7494: domain => 'User Management in domain',
7495: author => 'User Management by author',
7496: );
7497: }
1.239 raeburn 7498: return %lt;
7499: }
7500:
1.406.2.10 raeburn 7501: sub print_helpdeskaccess_display {
7502: my ($r,$permission,$brcrum) = @_;
7503: my $formname = 'helpdeskaccess';
7504: my $helpitem = 'Course_Helpdesk_Access';
7505: push (@{$brcrum},
7506: {href => '/adm/createuser?action=helpdesk',
7507: text => 'Helpdesk Access',
7508: help => $helpitem});
7509: my $bread_crumbs_component = 'Helpdesk Staff Access';
7510: my $args = { bread_crumbs => $brcrum,
7511: bread_crumbs_component => $bread_crumbs_component};
7512:
7513: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
7514: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
7515: my $confname = $cdom.'-domainconfig';
7516: my $crstype = &Apache::loncommon::course_type();
7517:
1.406.2.12 raeburn 7518: my @accesstypes = ('all','dh','da','none');
1.406.2.10 raeburn 7519: my ($numstatustypes,@jsarray);
7520: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($cdom);
7521: if (ref($types) eq 'ARRAY') {
7522: if (@{$types} > 0) {
7523: $numstatustypes = scalar(@{$types});
7524: push(@accesstypes,'status');
7525: @jsarray = ('bystatus');
7526: }
7527: }
7528: my %customroles = &get_domain_customroles($cdom,$confname);
1.406.2.12 raeburn 7529: my %domhelpdesk = &Apache::lonnet::get_active_domroles($cdom,['dh','da']);
1.406.2.10 raeburn 7530: if (keys(%domhelpdesk)) {
7531: push(@accesstypes,('inc','exc'));
7532: push(@jsarray,('notinc','notexc'));
7533: }
7534: push(@jsarray,'privs');
7535: my $hiddenstr = join("','",@jsarray);
7536: my $rolestr = join("','",sort(keys(%customroles)));
7537:
7538: my $jscript;
7539: my (%settings,%overridden);
7540: if (keys(%customroles)) {
7541: &get_adhocrole_settings($env{'request.course.id'},\@accesstypes,
7542: $types,\%customroles,\%settings,\%overridden);
7543: my %jsfull=();
7544: my %jslevels= (
7545: course => {},
7546: domain => {},
7547: system => {},
7548: );
7549: my %jslevelscurrent=(
7550: course => {},
7551: domain => {},
7552: system => {},
7553: );
7554: my (%privs,%jsprivs);
7555: &Apache::lonuserutils::custom_role_privs(\%privs,\%jsfull,\%jslevels,\%jslevelscurrent);
7556: foreach my $priv (keys(%jsfull)) {
7557: if ($jslevels{'course'}{$priv}) {
7558: $jsprivs{$priv} = 1;
7559: }
7560: }
7561: my (%elements,%stored);
7562: foreach my $role (keys(%customroles)) {
7563: $elements{$role.'_access'} = 'radio';
7564: $elements{$role.'_incrs'} = 'radio';
7565: if ($numstatustypes) {
7566: $elements{$role.'_status'} = 'checkbox';
7567: }
7568: if (keys(%domhelpdesk) > 0) {
7569: $elements{$role.'_staff_inc'} = 'checkbox';
7570: $elements{$role.'_staff_exc'} = 'checkbox';
7571: }
7572: $elements{$role.'_override'} = 'checkbox';
7573: if (ref($settings{$role}) eq 'HASH') {
7574: if ($settings{$role}{'access'} ne '') {
7575: my $curraccess = $settings{$role}{'access'};
7576: $stored{$role.'_access'} = $curraccess;
7577: $stored{$role.'_incrs'} = 1;
7578: if ($curraccess eq 'status') {
7579: if (ref($settings{$role}{'status'}) eq 'ARRAY') {
7580: $stored{$role.'_status'} = $settings{$role}{'status'};
7581: }
7582: } elsif (($curraccess eq 'exc') || ($curraccess eq 'inc')) {
7583: if (ref($settings{$role}{$curraccess}) eq 'ARRAY') {
7584: $stored{$role.'_staff_'.$curraccess} = $settings{$role}{$curraccess};
7585: }
7586: }
7587: } else {
7588: $stored{$role.'_incrs'} = 0;
7589: }
7590: $stored{$role.'_override'} = [];
7591: if ($env{'course.'.$env{'request.course.id'}.'.internal.adhocpriv.'.$role}) {
7592: if (ref($settings{$role}{'off'}) eq 'ARRAY') {
7593: foreach my $priv (@{$settings{$role}{'off'}}) {
7594: push(@{$stored{$role.'_override'}},$priv);
7595: }
7596: }
7597: if (ref($settings{$role}{'on'}) eq 'ARRAY') {
7598: foreach my $priv (@{$settings{$role}{'on'}}) {
7599: unless (grep(/^$priv$/,@{$stored{$role.'_override'}})) {
7600: push(@{$stored{$role.'_override'}},$priv);
7601: }
7602: }
7603: }
7604: }
7605: } else {
7606: $stored{$role.'_incrs'} = 0;
7607: }
7608: }
7609: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements,\%stored);
7610: }
7611:
7612: my $js = <<"ENDJS";
7613: <script type="text/javascript">
7614: // <![CDATA[
7615: $jscript;
7616:
7617: function switchRoleTab(caller,role) {
7618: if (document.getElementById(role+'_maindiv')) {
7619: if (caller.id != 'LC_current_minitab') {
7620: if (document.getElementById('LC_current_minitab')) {
7621: document.getElementById('LC_current_minitab').id=null;
7622: }
7623: var roledivs = Array('$rolestr');
7624: if (roledivs.length > 0) {
7625: for (var i=0; i<roledivs.length; i++) {
7626: if (document.getElementById(roledivs[i]+'_maindiv')) {
7627: document.getElementById(roledivs[i]+'_maindiv').style.display='none';
7628: }
7629: }
7630: }
7631: caller.id = 'LC_current_minitab';
7632: document.getElementById(role+'_maindiv').style.display='block';
7633: }
7634: }
7635: return false;
7636: }
7637:
7638: function helpdeskAccess(role) {
7639: var curraccess = null;
7640: if (document.$formname.elements[role+'_access'].length) {
7641: for (var i=0; i<document.$formname.elements[role+'_access'].length; i++) {
7642: if (document.$formname.elements[role+'_access'][i].checked) {
7643: curraccess = document.$formname.elements[role+'_access'][i].value;
7644: }
7645: }
7646: }
7647: var shown = Array();
7648: var hidden = Array();
7649: if (curraccess == 'none') {
7650: hidden = Array ('$hiddenstr');
7651: } else {
7652: if (curraccess == 'status') {
7653: shown = Array ('bystatus','privs');
7654: hidden = Array ('notinc','notexc');
7655: } else {
7656: if (curraccess == 'exc') {
7657: shown = Array ('notexc','privs');
7658: hidden = Array ('notinc','bystatus');
7659: }
7660: if (curraccess == 'inc') {
7661: shown = Array ('notinc','privs');
7662: hidden = Array ('notexc','bystatus');
7663: }
7664: if (curraccess == 'all') {
7665: shown = Array ('privs');
7666: hidden = Array ('notinc','notexc','bystatus');
7667: }
7668: }
7669: }
7670: if (hidden.length > 0) {
7671: for (var i=0; i<hidden.length; i++) {
7672: if (document.getElementById(role+'_'+hidden[i])) {
7673: document.getElementById(role+'_'+hidden[i]).style.display = 'none';
7674: }
7675: }
7676: }
7677: if (shown.length > 0) {
7678: for (var i=0; i<shown.length; i++) {
7679: if (document.getElementById(role+'_'+shown[i])) {
7680: if (shown[i] == 'privs') {
7681: document.getElementById(role+'_'+shown[i]).style.display = 'block';
7682: } else {
7683: document.getElementById(role+'_'+shown[i]).style.display = 'inline';
7684: }
7685: }
7686: }
7687: }
7688: return;
7689: }
7690:
7691: function toggleAccess(role) {
7692: if ((document.getElementById(role+'_setincrs')) &&
7693: (document.getElementById(role+'_setindom'))) {
7694: for (var i=0; i<document.$formname.elements[role+'_incrs'].length; i++) {
7695: if (document.$formname.elements[role+'_incrs'][i].checked) {
7696: if (document.$formname.elements[role+'_incrs'][i].value == 1) {
7697: document.getElementById(role+'_setindom').style.display = 'none';
7698: document.getElementById(role+'_setincrs').style.display = 'block';
7699: } else {
7700: document.getElementById(role+'_setincrs').style.display = 'none';
7701: document.getElementById(role+'_setindom').style.display = 'block';
7702: }
7703: break;
7704: }
7705: }
7706: }
7707: return;
7708: }
7709:
7710: // ]]>
7711: </script>
7712: ENDJS
7713:
7714: $args->{add_entries} = {onload => "javascript:setFormElements(document.$formname)"};
7715:
7716: # print page header
7717: $r->print(&header($js,$args));
7718: # print form header
7719: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">');
7720:
7721: if (keys(%customroles)) {
7722: my %lt = &Apache::lonlocal::texthash(
7723: 'aco' => 'As course owner you may override the defaults set in the domain for role usage and/or privileges.',
7724: 'rou' => 'Role usage',
7725: 'whi' => 'Which helpdesk personnel may use this role?',
7726: 'udd' => 'Use domain default',
1.406.2.12 raeburn 7727: 'all' => 'All with domain helpdesk or helpdesk assistant role',
7728: 'dh' => 'All with domain helpdesk role',
7729: 'da' => 'All with domain helpdesk assistant role',
1.406.2.10 raeburn 7730: 'none' => 'None',
7731: 'status' => 'Determined based on institutional status',
7732: 'inc' => 'Include all, but exclude specific personnel',
7733: 'exc' => 'Exclude all, but include specific personnel',
7734: 'hel' => 'Helpdesk',
7735: 'rpr' => 'Role privileges',
7736: );
7737: $lt{'tfh'} = &mt("Custom [_1]ad hoc[_2] course roles available for use by the domain's helpdesk are as follows",'<i>','</i>');
7738: my %domconfig = &Apache::lonnet::get_dom('configuration',['helpsettings'],$cdom);
7739: my (%domcurrent,%ordered,%description,%domusage,$disabled);
7740: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
7741: if (ref($domconfig{'helpsettings'}{'adhoc'}) eq 'HASH') {
7742: %domcurrent = %{$domconfig{'helpsettings'}{'adhoc'}};
7743: }
7744: }
7745: my $count = 0;
7746: foreach my $role (sort(keys(%customroles))) {
7747: my ($order,$desc,$access_in_dom);
7748: if (ref($domcurrent{$role}) eq 'HASH') {
7749: $order = $domcurrent{$role}{'order'};
7750: $desc = $domcurrent{$role}{'desc'};
7751: $access_in_dom = $domcurrent{$role}{'access'};
7752: }
7753: if ($order eq '') {
7754: $order = $count;
7755: }
7756: $ordered{$order} = $role;
7757: if ($desc ne '') {
7758: $description{$role} = $desc;
7759: } else {
7760: $description{$role}= $role;
7761: }
7762: $count++;
7763: }
7764: %domusage = &domain_adhoc_access(\%customroles,\%domcurrent,\@accesstypes,$usertypes,$othertitle);
7765: my @roles_by_num = ();
7766: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
7767: push(@roles_by_num,$ordered{$item});
7768: }
7769: $r->print('<p>'.$lt{'tfh'}.': <i>'.join('</i>, <i>',map { $description{$_}; } @roles_by_num).'</i>.');
7770: if ($permission->{'owner'}) {
7771: $r->print('<br />'.$lt{'aco'}.'</p><p>');
7772: $r->print('<input type="hidden" name="state" value="process" />'.
7773: '<input type="submit" value="'.&mt('Save changes').'" />');
7774: } else {
7775: if ($env{'course.'.$env{'request.course.id'}.'.internal.courseowner'}) {
7776: my ($ownername,$ownerdom) = split(/:/,$env{'course.'.$env{'request.course.id'}.'.internal.courseowner'});
7777: $r->print('<br />'.&mt('The course owner -- [_1] -- can override the default access and/or privileges for these ad hoc roles.',
7778: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($ownername,$ownerdom),$ownername,$ownerdom)));
7779: }
7780: $disabled = ' disabled="disabled"';
7781: }
7782: $r->print('</p>');
7783:
7784: $r->print('<div id="LC_minitab_header"><ul>');
7785: my $count = 0;
7786: my %visibility;
7787: foreach my $role (@roles_by_num) {
7788: my $id;
7789: if ($count == 0) {
7790: $id=' id="LC_current_minitab"';
7791: $visibility{$role} = ' style="display:block"';
7792: } else {
7793: $visibility{$role} = ' style="display:none"';
7794: }
7795: $count ++;
7796: $r->print('<li'.$id.'><a href="#" onclick="javascript:switchRoleTab(this.parentNode,'."'$role'".');">'.$description{$role}.'</a></li>');
7797: }
7798: $r->print('</ul></div>');
7799:
7800: foreach my $role (@roles_by_num) {
7801: my %usecheck = (
7802: all => ' checked="checked"',
7803: );
7804: my %displaydiv = (
7805: status => 'none',
7806: inc => 'none',
7807: exc => 'none',
7808: priv => 'block',
7809: );
7810: my (%selected,$overridden,$incrscheck,$indomcheck,$indomvis,$incrsvis);
7811: if (ref($settings{$role}) eq 'HASH') {
7812: if ($settings{$role}{'access'} ne '') {
7813: $indomvis = ' style="display:none"';
7814: $incrsvis = ' style="display:block"';
7815: $incrscheck = ' checked="checked"';
7816: if ($settings{$role}{'access'} ne 'all') {
7817: $usecheck{$settings{$role}{'access'}} = $usecheck{'all'};
7818: delete($usecheck{'all'});
7819: if ($settings{$role}{'access'} eq 'status') {
7820: my $access = 'status';
7821: $displaydiv{$access} = 'inline';
7822: if (ref($settings{$role}{$access}) eq 'ARRAY') {
7823: $selected{$access} = $settings{$role}{$access};
7824: }
7825: } elsif ($settings{$role}{'access'} =~ /^(inc|exc)$/) {
7826: my $access = $1;
7827: $displaydiv{$access} = 'inline';
7828: if (ref($settings{$role}{$access}) eq 'ARRAY') {
7829: $selected{$access} = $settings{$role}{$access};
7830: }
7831: } elsif ($settings{$role}{'access'} eq 'none') {
7832: $displaydiv{'priv'} = 'none';
7833: }
7834: }
7835: } else {
7836: $indomcheck = ' checked="checked"';
7837: $indomvis = ' style="display:block"';
7838: $incrsvis = ' style="display:none"';
7839: }
7840: } else {
7841: $indomcheck = ' checked="checked"';
7842: $indomvis = ' style="display:block"';
7843: $incrsvis = ' style="display:none"';
7844: }
7845: $r->print('<div class="LC_left_float" id="'.$role.'_maindiv"'.$visibility{$role}.'>'.
7846: '<fieldset><legend>'.$lt{'rou'}.'</legend>'.
7847: '<p>'.$lt{'whi'}.' <span class="LC_nobreak">'.
7848: '<label><input type="radio" name="'.$role.'_incrs" value="1"'.$incrscheck.' onclick="toggleAccess('."'$role'".');"'.$disabled.'>'.
7849: &mt('Set here in [_1]',lc($crstype)).'</label>'.
7850: '<span>'.(' 'x2).
7851: '<label><input type="radio" name="'.$role.'_incrs" value="0"'.$indomcheck.' onclick="toggleAccess('."'$role'".');"'.$disabled.'>'.
7852: $lt{'udd'}.'</label><span></p>'.
7853: '<div id="'.$role.'_setindom"'.$indomvis.'>'.
7854: '<span class="LC_cusr_emph">'.$domusage{$role}.'</span></div>'.
7855: '<div id="'.$role.'_setincrs"'.$incrsvis.'>');
7856: foreach my $access (@accesstypes) {
7857: $r->print('<p><label><input type="radio" name="'.$role.'_access" value="'.$access.'" '.$usecheck{$access}.
7858: ' onclick="helpdeskAccess('."'$role'".');"'.$disabled.' />'.$lt{$access}.'</label>');
7859: if ($access eq 'status') {
7860: $r->print('<div id="'.$role.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
7861: &Apache::lonuserutils::adhoc_status_types($cdom,undef,$role,$selected{$access},
7862: $othertitle,$usertypes,$types,$disabled).
7863: '</div>');
7864: } elsif (($access eq 'inc') && (keys(%domhelpdesk) > 0)) {
7865: $r->print('<div id="'.$role.'_notinc" style="display:'.$displaydiv{$access}.'">'.
7866: &Apache::lonuserutils::adhoc_staff($access,undef,$role,$selected{$access},
7867: \%domhelpdesk,$disabled).
7868: '</div>');
7869: } elsif (($access eq 'exc') && (keys(%domhelpdesk) > 0)) {
7870: $r->print('<div id="'.$role.'_notexc" style="display:'.$displaydiv{$access}.'">'.
7871: &Apache::lonuserutils::adhoc_staff($access,undef,$role,$selected{$access},
7872: \%domhelpdesk,$disabled).
7873: '</div>');
7874: }
7875: $r->print('</p>');
7876: }
7877: $r->print('</div></fieldset>');
7878: my %full=();
7879: my %levels= (
7880: course => {},
7881: domain => {},
7882: system => {},
7883: );
7884: my %levelscurrent=(
7885: course => {},
7886: domain => {},
7887: system => {},
7888: );
7889: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
7890: $r->print('<fieldset id="'.$role.'_privs" style="display:'.$displaydiv{'priv'}.'">'.
7891: '<legend>'.$lt{'rpr'}.'</legend>'.
7892: &role_priv_table($role,$permission,$crstype,\%full,\%levels,\%levelscurrent,$overridden{$role}).
7893: '</fieldset></div><div style="padding:0;clear:both;margin:0;border:0"></div>');
7894: }
7895: if ($permission->{'owner'}) {
7896: $r->print('<p><input type="submit" value="'.&mt('Save changes').'" /></p>');
7897: }
7898: } else {
7899: $r->print(&mt('Helpdesk roles have not yet been created in this domain.'));
7900: }
7901: # Form Footer
7902: $r->print('<input type="hidden" name="action" value="helpdesk" />'
7903: .'</form>');
7904: return;
7905: }
7906:
7907: sub domain_adhoc_access {
7908: my ($roles,$domcurrent,$accesstypes,$usertypes,$othertitle) = @_;
7909: my %domusage;
7910: return unless ((ref($roles) eq 'HASH') && (ref($domcurrent) eq 'HASH') && (ref($accesstypes) eq 'ARRAY'));
7911: foreach my $role (keys(%{$roles})) {
7912: if (ref($domcurrent->{$role}) eq 'HASH') {
7913: my $access = $domcurrent->{$role}{'access'};
7914: if (($access eq '') || (!grep(/^\Q$access\E$/,@{$accesstypes}))) {
7915: $access = 'all';
1.406.2.12 raeburn 7916: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',&Apache::lonnet::plaintext('dh'),
7917: &Apache::lonnet::plaintext('da'));
1.406.2.10 raeburn 7918: } elsif ($access eq 'status') {
7919: if (ref($domcurrent->{$role}{$access}) eq 'ARRAY') {
7920: my @shown;
7921: foreach my $type (@{$domcurrent->{$role}{$access}}) {
7922: unless ($type eq 'default') {
7923: if ($usertypes->{$type}) {
7924: push(@shown,$usertypes->{$type});
7925: }
7926: }
7927: }
7928: if (grep(/^default$/,@{$domcurrent->{$role}{$access}})) {
7929: push(@shown,$othertitle);
7930: }
7931: if (@shown) {
7932: my $shownstatus = join(' '.&mt('or').' ',@shown);
1.406.2.12 raeburn 7933: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role, and institutional status: [_3]',
7934: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$shownstatus);
1.406.2.10 raeburn 7935: } else {
7936: $domusage{$role} = &mt('No one in the domain');
7937: }
7938: }
7939: } elsif ($access eq 'inc') {
7940: my @dominc = ();
7941: if (ref($domcurrent->{$role}{'inc'}) eq 'ARRAY') {
7942: foreach my $user (@{$domcurrent->{$role}{'inc'}}) {
7943: my ($uname,$udom) = split(/:/,$user);
7944: push(@dominc,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom));
7945: }
7946: my $showninc = join(', ',@dominc);
7947: if ($showninc ne '') {
1.406.2.12 raeburn 7948: $domusage{$role} = &mt('Include any user in domain with active [_1] or [_2] role, except: [_3]',
7949: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$showninc);
1.406.2.10 raeburn 7950: } else {
1.406.2.12 raeburn 7951: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
7952: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.406.2.10 raeburn 7953: }
7954: }
7955: } elsif ($access eq 'exc') {
7956: my @domexc = ();
7957: if (ref($domcurrent->{$role}{'exc'}) eq 'ARRAY') {
7958: foreach my $user (@{$domcurrent->{$role}{'exc'}}) {
7959: my ($uname,$udom) = split(/:/,$user);
7960: push(@domexc,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom));
7961: }
7962: }
7963: my $shownexc = join(', ',@domexc);
7964: if ($shownexc ne '') {
1.406.2.12 raeburn 7965: $domusage{$role} = &mt('Only the following in the domain with active [_1] or [_2] role: [_3]',
7966: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$shownexc);
1.406.2.10 raeburn 7967: } else {
7968: $domusage{$role} = &mt('No one in the domain');
7969: }
7970: } elsif ($access eq 'none') {
7971: $domusage{$role} = &mt('No one in the domain');
1.406.2.12 raeburn 7972: } elsif ($access eq 'dh') {
1.406.2.10 raeburn 7973: $domusage{$role} = &mt('Any user in domain with active [_1] role',&Apache::lonnet::plaintext('dh'));
1.406.2.12 raeburn 7974: } elsif ($access eq 'da') {
7975: $domusage{$role} = &mt('Any user in domain with active [_1] role',&Apache::lonnet::plaintext('da'));
7976: } elsif ($access eq 'all') {
7977: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
7978: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.406.2.10 raeburn 7979: }
7980: } else {
1.406.2.12 raeburn 7981: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
7982: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.406.2.10 raeburn 7983: }
7984: }
7985: return %domusage;
7986: }
7987:
7988: sub get_domain_customroles {
7989: my ($cdom,$confname) = @_;
7990: my %existing=&Apache::lonnet::dump('roles',$cdom,$confname,'rolesdef_');
7991: my %customroles;
7992: foreach my $key (keys(%existing)) {
7993: if ($key=~/^rolesdef\_(\w+)$/) {
7994: my $rolename = $1;
7995: my %privs;
7996: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
7997: $customroles{$rolename} = \%privs;
7998: }
7999: }
8000: return %customroles;
8001: }
8002:
8003: sub role_priv_table {
8004: my ($role,$permission,$crstype,$full,$levels,$levelscurrent,$overridden) = @_;
8005: return unless ((ref($full) eq 'HASH') && (ref($levels) eq 'HASH') &&
8006: (ref($levelscurrent) eq 'HASH'));
8007: my %lt=&Apache::lonlocal::texthash (
8008: 'crl' => 'Course Level Privilege',
8009: 'def' => 'Domain Defaults',
8010: 'ove' => 'Override in Course',
8011: 'ine' => 'In effect',
8012: 'dis' => 'Disabled',
8013: 'ena' => 'Enabled',
8014: );
8015: if ($crstype eq 'Community') {
8016: $lt{'ove'} = 'Override in Community',
8017: }
8018: my @status = ('Disabled','Enabled');
8019: my (%on,%off);
8020: if (ref($overridden) eq 'HASH') {
8021: if (ref($overridden->{'on'}) eq 'ARRAY') {
8022: map { $on{$_} = 1; } (@{$overridden->{'on'}});
8023: }
8024: if (ref($overridden->{'off'}) eq 'ARRAY') {
8025: map { $off{$_} = 1; } (@{$overridden->{'off'}});
8026: }
8027: }
8028: my $output=&Apache::loncommon::start_data_table().
8029: &Apache::loncommon::start_data_table_header_row().
8030: '<th>'.$lt{'crl'}.'</th><th>'.$lt{'def'}.'</th><th>'.$lt{'ove'}.
8031: '</th><th>'.$lt{'ine'}.'</th>'.
8032: &Apache::loncommon::end_data_table_header_row();
8033: foreach my $priv (sort(keys(%{$full}))) {
8034: next unless ($levels->{'course'}{$priv});
8035: my $privtext = &Apache::lonnet::plaintext($priv,$crstype);
8036: my ($default,$ineffect);
8037: if ($levelscurrent->{'course'}{$priv}) {
8038: $default = '<img src="/adm/lonIcons/navmap.correct.gif" alt="'.$lt{'ena'}.'" />';
8039: $ineffect = $default;
8040: }
8041: my ($customstatus,$checked);
8042: $output .= &Apache::loncommon::start_data_table_row().
8043: '<td>'.$privtext.'</td>'.
8044: '<td>'.$default.'</td><td>';
8045: if (($levelscurrent->{'course'}{$priv}) && ($off{$priv})) {
8046: if ($permission->{'owner'}) {
8047: $checked = ' checked="checked"';
8048: }
8049: $customstatus = '<img src="/adm/lonIcons/navmap.wrong.gif" alt="'.$lt{'dis'}.'" />';
8050: $ineffect = $customstatus;
8051: } elsif ((!$levelscurrent->{'course'}{$priv}) && ($on{$priv})) {
8052: if ($permission->{'owner'}) {
8053: $checked = ' checked="checked"';
8054: }
8055: $customstatus = '<img src="/adm/lonIcons/navmap.correct.gif" alt="'.$lt{'ena'}.'" />';
8056: $ineffect = $customstatus;
8057: }
8058: if ($permission->{'owner'}) {
8059: $output .= '<input type="checkbox" name="'.$role.'_override" value="'.$priv.'"'.$checked.' />';
8060: } else {
8061: $output .= $customstatus;
8062: }
8063: $output .= '</td><td>'.$ineffect.'</td>'.
8064: &Apache::loncommon::end_data_table_row();
8065: }
8066: $output .= &Apache::loncommon::end_data_table();
8067: return $output;
8068: }
8069:
8070: sub get_adhocrole_settings {
8071: my ($cid,$accesstypes,$types,$customroles,$settings,$overridden) = @_;
8072: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($customroles) eq 'HASH') &&
8073: (ref($settings) eq 'HASH') && (ref($overridden) eq 'HASH'));
8074: foreach my $role (split(/,/,$env{'course.'.$cid.'.internal.adhocaccess'})) {
8075: my ($curraccess,$rest) = split(/=/,$env{'course.'.$cid.'.internal.adhoc.'.$role});
8076: if (($curraccess ne '') && (grep(/^\Q$curraccess\E$/,@{$accesstypes}))) {
8077: $settings->{$role}{'access'} = $curraccess;
8078: if (($curraccess eq 'status') && (ref($types) eq 'ARRAY')) {
8079: my @status = split(/,/,$rest);
8080: my @currstatus;
8081: foreach my $type (@status) {
8082: if ($type eq 'default') {
8083: push(@currstatus,$type);
8084: } elsif (grep(/^\Q$type\E$/,@{$types})) {
8085: push(@currstatus,$type);
8086: }
8087: }
8088: if (@currstatus) {
8089: $settings->{$role}{$curraccess} = \@currstatus;
8090: } elsif (($curraccess eq 'exc') || ($curraccess eq 'inc')) {
8091: my @personnel = split(/,/,$rest);
8092: $settings->{$role}{$curraccess} = \@personnel;
8093: }
8094: }
8095: }
8096: }
8097: foreach my $role (keys(%{$customroles})) {
8098: if ($env{'course.'.$cid.'.internal.adhocpriv.'.$role}) {
8099: my %currentprivs;
8100: if (ref($customroles->{$role}) eq 'HASH') {
8101: if (exists($customroles->{$role}{'course'})) {
8102: my %full=();
8103: my %levels= (
8104: course => {},
8105: domain => {},
8106: system => {},
8107: );
8108: my %levelscurrent=(
8109: course => {},
8110: domain => {},
8111: system => {},
8112: );
8113: &Apache::lonuserutils::custom_role_privs($customroles->{$role},\%full,\%levels,\%levelscurrent);
8114: %currentprivs = %{$levelscurrent{'course'}};
8115: }
8116: }
8117: foreach my $item (split(/,/,$env{'course.'.$cid.'.internal.adhocpriv.'.$role})) {
8118: next if ($item eq '');
8119: my ($rule,$rest) = split(/=/,$item);
8120: next unless (($rule eq 'off') || ($rule eq 'on'));
8121: foreach my $priv (split(/:/,$rest)) {
8122: if ($priv ne '') {
8123: if ($rule eq 'off') {
8124: push(@{$overridden->{$role}{'off'}},$priv);
8125: if ($currentprivs{$priv}) {
8126: push(@{$settings->{$role}{'off'}},$priv);
8127: }
8128: } else {
8129: push(@{$overridden->{$role}{'on'}},$priv);
8130: unless ($currentprivs{$priv}) {
8131: push(@{$settings->{$role}{'on'}},$priv);
8132: }
8133: }
8134: }
8135: }
8136: }
8137: }
8138: }
8139: return;
8140: }
8141:
8142: sub update_helpdeskaccess {
8143: my ($r,$permission,$brcrum) = @_;
8144: my $helpitem = 'Course_Helpdesk_Access';
8145: push (@{$brcrum},
8146: {href => '/adm/createuser?action=helpdesk',
8147: text => 'Helpdesk Access',
8148: help => $helpitem},
8149: {href => '/adm/createuser?action=helpdesk',
8150: text => 'Result',
8151: help => $helpitem}
8152: );
8153: my $bread_crumbs_component = 'Helpdesk Staff Access';
8154: my $args = { bread_crumbs => $brcrum,
8155: bread_crumbs_component => $bread_crumbs_component};
8156:
8157: # print page header
8158: $r->print(&header('',$args));
8159: unless ((ref($permission) eq 'HASH') && ($permission->{'owner'})) {
8160: $r->print('<p class="LC_error">'.&mt('You do not have permission to change helpdesk access.').'</p>');
8161: return;
8162: }
1.406.2.12 raeburn 8163: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.406.2.10 raeburn 8164: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8165: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
8166: my $confname = $cdom.'-domainconfig';
8167: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($cdom);
8168: my $crstype = &Apache::loncommon::course_type();
8169: my %customroles = &get_domain_customroles($cdom,$confname);
8170: my (%settings,%overridden);
8171: &get_adhocrole_settings($env{'request.course.id'},\@accesstypes,
8172: $types,\%customroles,\%settings,\%overridden);
1.406.2.12 raeburn 8173: my %domhelpdesk = &Apache::lonnet::get_active_domroles($cdom,['dh','da']);
1.406.2.10 raeburn 8174: my (%changed,%storehash,@todelete);
8175:
8176: if (keys(%customroles)) {
8177: my (%newsettings,@incrs);
8178: foreach my $role (keys(%customroles)) {
8179: $newsettings{$role} = {
8180: access => '',
8181: status => '',
8182: exc => '',
8183: inc => '',
8184: on => '',
8185: off => '',
8186: };
8187: my %current;
8188: if (ref($settings{$role}) eq 'HASH') {
8189: %current = %{$settings{$role}};
8190: }
8191: if (ref($overridden{$role}) eq 'HASH') {
8192: $current{'overridden'} = $overridden{$role};
8193: }
8194: if ($env{'form.'.$role.'_incrs'}) {
8195: my $access = $env{'form.'.$role.'_access'};
8196: if (grep(/^\Q$access\E$/,@accesstypes)) {
8197: push(@incrs,$role);
8198: unless ($current{'access'} eq $access) {
8199: $changed{$role}{'access'} = 1;
8200: $storehash{'internal.adhoc.'.$role} = $access;
8201: }
8202: if ($access eq 'status') {
8203: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$role.'_status');
8204: my @stored;
8205: my @shownstatus;
8206: if (ref($types) eq 'ARRAY') {
8207: foreach my $type (sort(@statuses)) {
8208: if ($type eq 'default') {
8209: push(@stored,$type);
8210: } elsif (grep(/^\Q$type\E$/,@{$types})) {
8211: push(@stored,$type);
8212: push(@shownstatus,$usertypes->{$type});
8213: }
8214: }
8215: if (grep(/^default$/,@statuses)) {
8216: push(@shownstatus,$othertitle);
8217: }
8218: $storehash{'internal.adhoc.'.$role} .= '='.join(',',@stored);
8219: }
8220: $newsettings{$role}{'status'} = join(' '.&mt('or').' ',@shownstatus);
8221: if (ref($current{'status'}) eq 'ARRAY') {
8222: my @diffs = &Apache::loncommon::compare_arrays(\@stored,$current{'status'});
8223: if (@diffs) {
8224: $changed{$role}{'status'} = 1;
8225: }
8226: } elsif (@stored) {
8227: $changed{$role}{'status'} = 1;
8228: }
8229: } elsif (($access eq 'inc') || ($access eq 'exc')) {
8230: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$role.'_staff_'.$access);
8231: my @newspecstaff;
8232: my @stored;
8233: my @currstaff;
8234: foreach my $person (sort(@personnel)) {
8235: if ($domhelpdesk{$person}) {
8236: push(@stored,$person);
8237: }
8238: }
8239: if (ref($current{$access}) eq 'ARRAY') {
8240: my @diffs = &Apache::loncommon::compare_arrays(\@stored,$current{$access});
8241: if (@diffs) {
8242: $changed{$role}{$access} = 1;
8243: }
8244: } elsif (@stored) {
8245: $changed{$role}{$access} = 1;
8246: }
8247: $storehash{'internal.adhoc.'.$role} .= '='.join(',',@stored);
8248: foreach my $person (@stored) {
8249: my ($uname,$udom) = split(/:/,$person);
8250: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
8251: }
8252: $newsettings{$role}{$access} = join(', ',sort(@newspecstaff));
8253: }
8254: $newsettings{$role}{'access'} = $access;
8255: }
8256: } else {
8257: if (($current{'access'} ne '') && (grep(/^\Q$current{'access'}\E$/,@accesstypes))) {
8258: $changed{$role}{'access'} = 1;
8259: $newsettings{$role} = {};
8260: push(@todelete,'internal.adhoc.'.$role);
8261: }
8262: }
8263: if (($env{'form.'.$role.'_incrs'}) && ($env{'form.'.$role.'_access'} eq 'none')) {
8264: if (ref($current{'overridden'}) eq 'HASH') {
8265: push(@todelete,'internal.adhocpriv.'.$role);
8266: }
8267: } else {
8268: my %full=();
8269: my %levels= (
8270: course => {},
8271: domain => {},
8272: system => {},
8273: );
8274: my %levelscurrent=(
8275: course => {},
8276: domain => {},
8277: system => {},
8278: );
8279: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
8280: my (@updatedon,@updatedoff,@override);
8281: @override = &Apache::loncommon::get_env_multiple('form.'.$role.'_override');
8282: if (@override) {
8283: foreach my $priv (sort(keys(%full))) {
8284: next unless ($levels{'course'}{$priv});
8285: if (grep(/^\Q$priv\E$/,@override)) {
8286: if ($levelscurrent{'course'}{$priv}) {
8287: push(@updatedoff,$priv);
8288: } else {
8289: push(@updatedon,$priv);
8290: }
8291: }
8292: }
8293: }
8294: if (@updatedon) {
8295: $newsettings{$role}{'on'} = join('</li><li>', map { &Apache::lonnet::plaintext($_,$crstype) } (@updatedon));
8296: }
8297: if (@updatedoff) {
8298: $newsettings{$role}{'off'} = join('</li><li>', map { &Apache::lonnet::plaintext($_,$crstype) } (@updatedoff));
8299: }
8300: if (ref($current{'overridden'}) eq 'HASH') {
8301: if (ref($current{'overridden'}{'on'}) eq 'ARRAY') {
8302: if (@updatedon) {
8303: my @diffs = &Apache::loncommon::compare_arrays(\@updatedon,$current{'overridden'}{'on'});
8304: if (@diffs) {
8305: $changed{$role}{'on'} = 1;
8306: }
8307: } else {
8308: $changed{$role}{'on'} = 1;
8309: }
8310: } elsif (@updatedon) {
8311: $changed{$role}{'on'} = 1;
8312: }
8313: if (ref($current{'overridden'}{'off'}) eq 'ARRAY') {
8314: if (@updatedoff) {
8315: my @diffs = &Apache::loncommon::compare_arrays(\@updatedoff,$current{'overridden'}{'off'});
8316: if (@diffs) {
8317: $changed{$role}{'off'} = 1;
8318: }
8319: } else {
8320: $changed{$role}{'off'} = 1;
8321: }
8322: } elsif (@updatedoff) {
8323: $changed{$role}{'off'} = 1;
8324: }
8325: } else {
8326: if (@updatedon) {
8327: $changed{$role}{'on'} = 1;
8328: }
8329: if (@updatedoff) {
8330: $changed{$role}{'off'} = 1;
8331: }
8332: }
8333: if (ref($changed{$role}) eq 'HASH') {
8334: if (($changed{$role}{'on'} || $changed{$role}{'off'})) {
8335: my $newpriv;
8336: if (@updatedon) {
8337: $newpriv = 'on='.join(':',@updatedon);
8338: }
8339: if (@updatedoff) {
8340: $newpriv .= ($newpriv ? ',' : '' ).'off='.join(':',@updatedoff);
8341: }
8342: if ($newpriv eq '') {
8343: push(@todelete,'internal.adhocpriv.'.$role);
8344: } else {
8345: $storehash{'internal.adhocpriv.'.$role} = $newpriv;
8346: }
8347: }
8348: }
8349: }
8350: }
8351: if (@incrs) {
8352: $storehash{'internal.adhocaccess'} = join(',',@incrs);
8353: } elsif (@todelete) {
8354: push(@todelete,'internal.adhocaccess');
8355: }
8356: if (keys(%changed)) {
8357: my ($putres,$delres);
8358: if (keys(%storehash)) {
8359: $putres = &Apache::lonnet::put('environment',\%storehash,$cdom,$cnum);
8360: my %newenvhash;
8361: foreach my $key (keys(%storehash)) {
8362: $newenvhash{'course.'.$env{'request.course.id'}.'.'.$key} = $storehash{$key};
8363: }
8364: &Apache::lonnet::appenv(\%newenvhash);
8365: }
8366: if (@todelete) {
8367: $delres = &Apache::lonnet::del('environment',\@todelete,$cdom,$cnum);
8368: foreach my $key (@todelete) {
8369: &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.'.$key);
8370: }
8371: }
8372: if (($putres eq 'ok') || ($delres eq 'ok')) {
8373: my %domconfig = &Apache::lonnet::get_dom('configuration',['helpsettings'],$cdom);
8374: my (%domcurrent,%ordered,%description,%domusage);
8375: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
8376: if (ref($domconfig{'helpsettings'}{'adhoc'}) eq 'HASH') {
8377: %domcurrent = %{$domconfig{'helpsettings'}{'adhoc'}};
8378: }
8379: }
8380: my $count = 0;
8381: foreach my $role (sort(keys(%customroles))) {
8382: my ($order,$desc);
8383: if (ref($domcurrent{$role}) eq 'HASH') {
8384: $order = $domcurrent{$role}{'order'};
8385: $desc = $domcurrent{$role}{'desc'};
8386: }
8387: if ($order eq '') {
8388: $order = $count;
8389: }
8390: $ordered{$order} = $role;
8391: if ($desc ne '') {
8392: $description{$role} = $desc;
8393: } else {
8394: $description{$role}= $role;
8395: }
8396: $count++;
8397: }
8398: my @roles_by_num = ();
8399: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
8400: push(@roles_by_num,$ordered{$item});
8401: }
8402: %domusage = &domain_adhoc_access(\%changed,\%domcurrent,\@accesstypes,$usertypes,$othertitle);
8403: $r->print(&mt('Helpdesk access settings have been changed as follows').'<br />');
8404: $r->print('<ul>');
8405: foreach my $role (@roles_by_num) {
8406: next unless (ref($changed{$role}) eq 'HASH');
8407: $r->print('<li>'.&mt('Ad hoc role').': <b>'.$description{$role}.'</b>'.
8408: '<ul>');
8409: if ($changed{$role}{'access'} || $changed{$role}{'status'} || $changed{$role}{'inc'} || $changed{$role}{'exc'}) {
8410: $r->print('<li>');
8411: if ($env{'form.'.$role.'_incrs'}) {
8412: if ($newsettings{$role}{'access'} eq 'all') {
8413: $r->print(&mt('All helpdesk staff can access '.lc($crstype).' with this role.'));
1.406.2.12 raeburn 8414: } elsif ($newsettings{$role}{'access'} eq 'dh') {
8415: $r->print(&mt('Helpdesk staff can use this role if they have an active [_1] role',
8416: &Apache::lonnet::plaintext('dh')));
8417: } elsif ($newsettings{$role}{'access'} eq 'da') {
8418: $r->print(&mt('Helpdesk staff can use this role if they have an active [_1] role',
8419: &Apache::lonnet::plaintext('da')));
1.406.2.10 raeburn 8420: } elsif ($newsettings{$role}{'access'} eq 'none') {
8421: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
8422: } elsif ($newsettings{$role}{'access'} eq 'status') {
8423: if ($newsettings{$role}{'status'}) {
8424: my ($access,$rest) = split(/=/,$storehash{'internal.adhoc.'.$role});
8425: if (split(/,/,$rest) > 1) {
8426: $r->print(&mt('Helpdesk staff can use this role if their institutional type is one of: [_1].',
8427: $newsettings{$role}{'status'}));
8428: } else {
8429: $r->print(&mt('Helpdesk staff can use this role if their institutional type is: [_1].',
8430: $newsettings{$role}{'status'}));
8431: }
8432: } else {
8433: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
8434: }
8435: } elsif ($newsettings{$role}{'access'} eq 'exc') {
8436: if ($newsettings{$role}{'exc'}) {
8437: $r->print(&mt('Helpdesk staff who can use this role are as follows:').' '.$newsettings{$role}{'exc'}.'.');
8438: } else {
8439: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
8440: }
8441: } elsif ($newsettings{$role}{'access'} eq 'inc') {
8442: if ($newsettings{$role}{'inc'}) {
8443: $r->print(&mt('All helpdesk staff may use this role except the following:').' '.$newsettings{$role}{'inc'}.'.');
8444: } else {
8445: $r->print(&mt('All helpdesk staff may use this role.'));
8446: }
8447: }
8448: } else {
8449: $r->print(&mt('Default access set in the domain now applies.').'<br />'.
8450: '<span class="LC_cusr_emph">'.$domusage{$role}.'</span>');
8451: }
8452: $r->print('</li>');
8453: }
8454: unless ($newsettings{$role}{'access'} eq 'none') {
8455: if ($changed{$role}{'off'}) {
8456: if ($newsettings{$role}{'off'}) {
8457: $r->print('<li>'.&mt('Privileges which are available by default for this ad hoc role, but are disabled for this specific '.lc($crstype).':').
8458: '<ul><li>'.$newsettings{$role}{'off'}.'</li></ul></li>');
8459: } else {
8460: $r->print('<li>'.&mt('All privileges available by default for this ad hoc role are enabled.').'</li>');
8461: }
8462: }
8463: if ($changed{$role}{'on'}) {
8464: if ($newsettings{$role}{'on'}) {
8465: $r->print('<li>'.&mt('Privileges which are not available by default for this ad hoc role, but are enabled for this specific '.lc($crstype).':').
8466: '<ul><li>'.$newsettings{$role}{'on'}.'</li></ul></li>');
8467: } else {
8468: $r->print('<li>'.&mt('None of the privileges unavailable by default for this ad hoc role are enabled.').'</li>');
8469: }
8470: }
8471: }
8472: $r->print('</ul></li>');
8473: }
8474: $r->print('</ul>');
8475: }
8476: } else {
8477: $r->print(&mt('No changes made to helpdesk access settings.'));
8478: }
8479: }
8480: return;
8481: }
8482:
1.27 matthew 8483: #-------------------------------------------------- functions for &phase_two
1.160 raeburn 8484: sub user_search_result {
1.221 raeburn 8485: my ($context,$srch) = @_;
1.160 raeburn 8486: my %allhomes;
8487: my %inst_matches;
8488: my %srch_results;
1.181 raeburn 8489: my ($response,$currstate,$forcenewuser,$dirsrchres);
1.183 raeburn 8490: $srch->{'srchterm'} =~ s/\s+/ /g;
1.176 raeburn 8491: if ($srch->{'srchby'} !~ /^(uname|lastname|lastfirst)$/) {
1.160 raeburn 8492: $response = &mt('Invalid search.');
8493: }
8494: if ($srch->{'srchin'} !~ /^(crs|dom|alc|instd)$/) {
8495: $response = &mt('Invalid search.');
8496: }
1.177 raeburn 8497: if ($srch->{'srchtype'} !~ /^(exact|contains|begins)$/) {
1.160 raeburn 8498: $response = &mt('Invalid search.');
8499: }
8500: if ($srch->{'srchterm'} eq '') {
8501: $response = &mt('You must enter a search term.');
8502: }
1.183 raeburn 8503: if ($srch->{'srchterm'} =~ /^\s+$/) {
8504: $response = &mt('Your search term must contain more than just spaces.');
8505: }
1.160 raeburn 8506: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'instd')) {
8507: if (($srch->{'srchdomain'} eq '') ||
1.163 albertel 8508: ! (&Apache::lonnet::domain($srch->{'srchdomain'}))) {
1.160 raeburn 8509: $response = &mt('You must specify a valid domain when searching in a domain or institutional directory.')
8510: }
8511: }
8512: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs') ||
8513: ($srch->{'srchin'} eq 'alc')) {
1.176 raeburn 8514: if ($srch->{'srchby'} eq 'uname') {
1.243 raeburn 8515: my $unamecheck = $srch->{'srchterm'};
8516: if ($srch->{'srchtype'} eq 'contains') {
8517: if ($unamecheck !~ /^\w/) {
8518: $unamecheck = 'a'.$unamecheck;
8519: }
8520: }
8521: if ($unamecheck !~ /^$match_username$/) {
1.176 raeburn 8522: $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
8523: }
1.160 raeburn 8524: }
8525: }
1.180 raeburn 8526: if ($response ne '') {
1.406.2.4 raeburn 8527: $response = '<span class="LC_warning">'.$response.'</span><br />';
1.180 raeburn 8528: }
1.160 raeburn 8529: if ($srch->{'srchin'} eq 'instd') {
1.406.2.3 raeburn 8530: my $instd_chk = &instdirectorysrch_check($srch);
1.160 raeburn 8531: if ($instd_chk ne 'ok') {
1.406.2.3 raeburn 8532: my $domd_chk = &domdirectorysrch_check($srch);
1.406.2.4 raeburn 8533: $response .= '<span class="LC_warning">'.$instd_chk.'</span><br />';
1.406.2.3 raeburn 8534: if ($domd_chk eq 'ok') {
1.406.2.4 raeburn 8535: $response .= &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.');
1.406.2.3 raeburn 8536: }
1.406.2.5 raeburn 8537: $response .= '<br />';
1.406.2.3 raeburn 8538: }
8539: } else {
8540: unless (($context eq 'requestcrs') && ($srch->{'srchtype'} eq 'exact')) {
8541: my $domd_chk = &domdirectorysrch_check($srch);
1.406.2.14 raeburn 8542: if (($domd_chk ne 'ok') && ($env{'form.action'} ne 'accesslogs')) {
1.406.2.3 raeburn 8543: my $instd_chk = &instdirectorysrch_check($srch);
1.406.2.4 raeburn 8544: $response .= '<span class="LC_warning">'.$domd_chk.'</span><br />';
1.406.2.3 raeburn 8545: if ($instd_chk eq 'ok') {
1.406.2.4 raeburn 8546: $response .= &mt('You may want to search in the institutional directory instead of the LON-CAPA domain.');
1.406.2.3 raeburn 8547: }
1.406.2.5 raeburn 8548: $response .= '<br />';
1.406.2.3 raeburn 8549: }
1.160 raeburn 8550: }
8551: }
8552: if ($response ne '') {
1.180 raeburn 8553: return ($currstate,$response);
1.160 raeburn 8554: }
8555: if ($srch->{'srchby'} eq 'uname') {
8556: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs')) {
8557: if ($env{'form.forcenew'}) {
8558: if ($srch->{'srchdomain'} ne $env{'request.role.domain'}) {
8559: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
8560: if ($uhome eq 'no_host') {
8561: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
1.180 raeburn 8562: my $showdom = &display_domain_info($env{'request.role.domain'});
8563: $response = &mt('New users can only be created in the domain to which your current role belongs - [_1].',$showdom);
1.160 raeburn 8564: } else {
1.179 raeburn 8565: $currstate = 'modify';
1.160 raeburn 8566: }
8567: } else {
1.179 raeburn 8568: $currstate = 'modify';
1.160 raeburn 8569: }
8570: } else {
8571: if ($srch->{'srchin'} eq 'dom') {
1.162 raeburn 8572: if ($srch->{'srchtype'} eq 'exact') {
8573: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
8574: if ($uhome eq 'no_host') {
1.179 raeburn 8575: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8576: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 8577: } else {
1.179 raeburn 8578: $currstate = 'modify';
1.406.2.5 raeburn 8579: if ($env{'form.action'} eq 'accesslogs') {
8580: $currstate = 'activity';
8581: }
1.310 raeburn 8582: my $uname = $srch->{'srchterm'};
8583: my $udom = $srch->{'srchdomain'};
8584: $srch_results{$uname.':'.$udom} =
8585: { &Apache::lonnet::get('environment',
8586: ['firstname',
8587: 'lastname',
8588: 'permanentemail'],
8589: $udom,$uname)
8590: };
1.162 raeburn 8591: }
8592: } else {
8593: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 8594: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8595: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8596: }
8597: } else {
1.167 albertel 8598: my $courseusers = &get_courseusers();
1.162 raeburn 8599: if ($srch->{'srchtype'} eq 'exact') {
1.167 albertel 8600: if (exists($courseusers->{$srch->{'srchterm'}.':'.$srch->{'srchdomain'}})) {
1.179 raeburn 8601: $currstate = 'modify';
1.162 raeburn 8602: } else {
1.179 raeburn 8603: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8604: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 8605: }
1.160 raeburn 8606: } else {
1.167 albertel 8607: foreach my $user (keys(%$courseusers)) {
1.162 raeburn 8608: my ($cuname,$cudomain) = split(/:/,$user);
8609: if ($cudomain eq $srch->{'srchdomain'}) {
1.177 raeburn 8610: my $matched = 0;
8611: if ($srch->{'srchtype'} eq 'begins') {
8612: if ($cuname =~ /^\Q$srch->{'srchterm'}\E/i) {
8613: $matched = 1;
8614: }
8615: } else {
8616: if ($cuname =~ /\Q$srch->{'srchterm'}\E/i) {
8617: $matched = 1;
8618: }
8619: }
8620: if ($matched) {
1.167 albertel 8621: $srch_results{$user} =
8622: {&Apache::lonnet::get('environment',
8623: ['firstname',
8624: 'lastname',
1.194 albertel 8625: 'permanentemail'],
8626: $cudomain,$cuname)};
1.162 raeburn 8627: }
8628: }
8629: }
1.179 raeburn 8630: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8631: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8632: }
8633: }
8634: }
8635: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 8636: $currstate = 'query';
1.160 raeburn 8637: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 8638: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
8639: if ($dirsrchres eq 'ok') {
8640: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8641: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 8642: } else {
8643: my $showdom = &display_domain_info($srch->{'srchdomain'});
8644: $response = '<span class="LC_warning">'.
8645: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
8646: '</span><br />'.
8647: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
1.406.2.5 raeburn 8648: '<br />';
1.181 raeburn 8649: }
1.160 raeburn 8650: }
8651: } else {
8652: if ($srch->{'srchin'} eq 'dom') {
8653: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 8654: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8655: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8656: } elsif ($srch->{'srchin'} eq 'crs') {
1.167 albertel 8657: my $courseusers = &get_courseusers();
8658: foreach my $user (keys(%$courseusers)) {
1.160 raeburn 8659: my ($uname,$udom) = split(/:/,$user);
8660: my %names = &Apache::loncommon::getnames($uname,$udom);
8661: my %emails = &Apache::loncommon::getemails($uname,$udom);
8662: if ($srch->{'srchby'} eq 'lastname') {
8663: if ((($srch->{'srchtype'} eq 'exact') &&
8664: ($names{'lastname'} eq $srch->{'srchterm'})) ||
1.177 raeburn 8665: (($srch->{'srchtype'} eq 'begins') &&
8666: ($names{'lastname'} =~ /^\Q$srch->{'srchterm'}\E/i)) ||
1.160 raeburn 8667: (($srch->{'srchtype'} eq 'contains') &&
8668: ($names{'lastname'} =~ /\Q$srch->{'srchterm'}\E/i))) {
8669: $srch_results{$user} = {firstname => $names{'firstname'},
8670: lastname => $names{'lastname'},
8671: permanentemail => $emails{'permanentemail'},
8672: };
8673: }
8674: } elsif ($srch->{'srchby'} eq 'lastfirst') {
8675: my ($srchlast,$srchfirst) = split(/,/,$srch->{'srchterm'});
1.177 raeburn 8676: $srchlast =~ s/\s+$//;
8677: $srchfirst =~ s/^\s+//;
1.160 raeburn 8678: if ($srch->{'srchtype'} eq 'exact') {
8679: if (($names{'lastname'} eq $srchlast) &&
8680: ($names{'firstname'} eq $srchfirst)) {
8681: $srch_results{$user} = {firstname => $names{'firstname'},
8682: lastname => $names{'lastname'},
8683: permanentemail => $emails{'permanentemail'},
8684:
8685: };
8686: }
1.177 raeburn 8687: } elsif ($srch->{'srchtype'} eq 'begins') {
8688: if (($names{'lastname'} =~ /^\Q$srchlast\E/i) &&
8689: ($names{'firstname'} =~ /^\Q$srchfirst\E/i)) {
8690: $srch_results{$user} = {firstname => $names{'firstname'},
8691: lastname => $names{'lastname'},
8692: permanentemail => $emails{'permanentemail'},
8693: };
8694: }
8695: } else {
1.160 raeburn 8696: if (($names{'lastname'} =~ /\Q$srchlast\E/i) &&
8697: ($names{'firstname'} =~ /\Q$srchfirst\E/i)) {
8698: $srch_results{$user} = {firstname => $names{'firstname'},
8699: lastname => $names{'lastname'},
8700: permanentemail => $emails{'permanentemail'},
8701: };
8702: }
8703: }
8704: }
8705: }
1.179 raeburn 8706: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8707: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8708: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 8709: $currstate = 'query';
1.160 raeburn 8710: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 8711: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
8712: if ($dirsrchres eq 'ok') {
8713: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8714: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 8715: } else {
1.406.2.5 raeburn 8716: my $showdom = &display_domain_info($srch->{'srchdomain'});
8717: $response = '<span class="LC_warning">'.
1.181 raeburn 8718: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
8719: '</span><br />'.
8720: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
1.406.2.5 raeburn 8721: '<br />';
1.181 raeburn 8722: }
1.160 raeburn 8723: }
8724: }
1.179 raeburn 8725: return ($currstate,$response,$forcenewuser,\%srch_results);
1.160 raeburn 8726: }
8727:
1.406.2.3 raeburn 8728: sub domdirectorysrch_check {
8729: my ($srch) = @_;
8730: my $response;
8731: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
8732: ['directorysrch'],$srch->{'srchdomain'});
8733: my $showdom = &display_domain_info($srch->{'srchdomain'});
8734: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
8735: if ($dom_inst_srch{'directorysrch'}{'lcavailable'} eq '0') {
8736: return &mt('LON-CAPA directory search is not available in domain: [_1]',$showdom);
8737: }
8738: if ($dom_inst_srch{'directorysrch'}{'lclocalonly'}) {
8739: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
8740: return &mt('LON-CAPA directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
8741: }
8742: }
8743: }
8744: return 'ok';
8745: }
8746:
8747: sub instdirectorysrch_check {
1.160 raeburn 8748: my ($srch) = @_;
8749: my $can_search = 0;
8750: my $response;
8751: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
8752: ['directorysrch'],$srch->{'srchdomain'});
1.180 raeburn 8753: my $showdom = &display_domain_info($srch->{'srchdomain'});
1.160 raeburn 8754: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
8755: if (!$dom_inst_srch{'directorysrch'}{'available'}) {
1.180 raeburn 8756: return &mt('Institutional directory search is not available in domain: [_1]',$showdom);
1.160 raeburn 8757: }
8758: if ($dom_inst_srch{'directorysrch'}{'localonly'}) {
8759: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
1.180 raeburn 8760: return &mt('Institutional directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
1.160 raeburn 8761: }
8762: my @usertypes = split(/:/,$env{'environment.inststatus'});
8763: if (!@usertypes) {
8764: push(@usertypes,'default');
8765: }
8766: if (ref($dom_inst_srch{'directorysrch'}{'cansearch'}) eq 'ARRAY') {
8767: foreach my $type (@usertypes) {
8768: if (grep(/^\Q$type\E$/,@{$dom_inst_srch{'directorysrch'}{'cansearch'}})) {
8769: $can_search = 1;
8770: last;
8771: }
8772: }
8773: }
8774: if (!$can_search) {
8775: my ($insttypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($srch->{'srchdomain'});
8776: my @longtypes;
8777: foreach my $item (@usertypes) {
1.229 raeburn 8778: if (defined($insttypes->{$item})) {
8779: push (@longtypes,$insttypes->{$item});
8780: } elsif ($item eq 'default') {
8781: push (@longtypes,&mt('other'));
8782: }
1.160 raeburn 8783: }
8784: my $insttype_str = join(', ',@longtypes);
1.180 raeburn 8785: return &mt('Institutional directory search in domain: [_1] is not available to your user type: ',$showdom).$insttype_str;
1.229 raeburn 8786: }
1.160 raeburn 8787: } else {
8788: $can_search = 1;
8789: }
8790: } else {
1.180 raeburn 8791: return &mt('Institutional directory search has not been configured for domain: [_1]',$showdom);
1.160 raeburn 8792: }
8793: my %longtext = &Apache::lonlocal::texthash (
1.167 albertel 8794: uname => 'username',
1.160 raeburn 8795: lastfirst => 'last name, first name',
1.167 albertel 8796: lastname => 'last name',
1.172 raeburn 8797: contains => 'contains',
1.178 raeburn 8798: exact => 'as exact match to',
8799: begins => 'begins with',
1.160 raeburn 8800: );
8801: if ($can_search) {
8802: if (ref($dom_inst_srch{'directorysrch'}{'searchby'}) eq 'ARRAY') {
8803: if (!grep(/^\Q$srch->{'srchby'}\E$/,@{$dom_inst_srch{'directorysrch'}{'searchby'}})) {
1.180 raeburn 8804: return &mt('Institutional directory search in domain: [_1] is not available for searching by "[_2]"',$showdom,$longtext{$srch->{'srchby'}});
1.160 raeburn 8805: }
8806: } else {
1.180 raeburn 8807: return &mt('Institutional directory search in domain: [_1] is not available.', $showdom);
1.160 raeburn 8808: }
8809: }
8810: if ($can_search) {
1.178 raeburn 8811: if (ref($dom_inst_srch{'directorysrch'}{'searchtypes'}) eq 'ARRAY') {
8812: if (grep(/^\Q$srch->{'srchtype'}\E/,@{$dom_inst_srch{'directorysrch'}{'searchtypes'}})) {
8813: return 'ok';
8814: } else {
1.180 raeburn 8815: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 8816: }
8817: } else {
8818: if ((($dom_inst_srch{'directorysrch'}{'searchtypes'} eq 'specify') &&
8819: ($srch->{'srchtype'} eq 'exact' || $srch->{'srchtype'} eq 'contains')) ||
8820: ($dom_inst_srch{'directorysrch'}{'searchtypes'} eq $srch->{'srchtype'})) {
8821: return 'ok';
8822: } else {
1.180 raeburn 8823: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 8824: }
1.160 raeburn 8825: }
8826: }
8827: }
8828:
8829: sub get_courseusers {
8830: my %advhash;
1.167 albertel 8831: my $classlist = &Apache::loncoursedata::get_classlist();
1.160 raeburn 8832: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles();
8833: foreach my $role (sort(keys(%coursepersonnel))) {
8834: foreach my $user (split(/\,/,$coursepersonnel{$role})) {
1.167 albertel 8835: if (!exists($classlist->{$user})) {
8836: $classlist->{$user} = [];
8837: }
1.160 raeburn 8838: }
8839: }
1.167 albertel 8840: return $classlist;
1.160 raeburn 8841: }
8842:
8843: sub build_search_response {
1.221 raeburn 8844: my ($context,$srch,%srch_results) = @_;
1.179 raeburn 8845: my ($currstate,$response,$forcenewuser);
1.160 raeburn 8846: my %names = (
1.330 bisitz 8847: 'uname' => 'username',
8848: 'lastname' => 'last name',
1.160 raeburn 8849: 'lastfirst' => 'last name, first name',
1.330 bisitz 8850: 'crs' => 'this course',
8851: 'dom' => 'LON-CAPA domain',
8852: 'instd' => 'the institutional directory for domain',
1.160 raeburn 8853: );
8854:
8855: my %single = (
1.180 raeburn 8856: begins => 'A match',
1.160 raeburn 8857: contains => 'A match',
1.180 raeburn 8858: exact => 'An exact match',
1.160 raeburn 8859: );
8860: my %nomatch = (
1.180 raeburn 8861: begins => 'No match',
1.160 raeburn 8862: contains => 'No match',
1.180 raeburn 8863: exact => 'No exact match',
1.160 raeburn 8864: );
8865: if (keys(%srch_results) > 1) {
1.179 raeburn 8866: $currstate = 'select';
1.160 raeburn 8867: } else {
8868: if (keys(%srch_results) == 1) {
1.406.2.5 raeburn 8869: if ($env{'form.action'} eq 'accesslogs') {
8870: $currstate = 'activity';
8871: } else {
8872: $currstate = 'modify';
8873: }
1.180 raeburn 8874: $response = &mt("$single{$srch->{'srchtype'}} was found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}.",$srch->{'srchterm'});
8875: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 8876: $response .= ': '.&display_domain_info($srch->{'srchdomain'});
1.180 raeburn 8877: }
1.330 bisitz 8878: } else { # Search has nothing found. Prepare message to user.
8879: $response = '<span class="LC_warning">';
1.180 raeburn 8880: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 8881: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}: [_2]",
8882: '<b>'.$srch->{'srchterm'}.'</b>',
8883: &display_domain_info($srch->{'srchdomain'}));
8884: } else {
8885: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}.",
8886: '<b>'.$srch->{'srchterm'}.'</b>');
1.180 raeburn 8887: }
8888: $response .= '</span>';
1.330 bisitz 8889:
1.160 raeburn 8890: if ($srch->{'srchin'} ne 'alc') {
8891: $forcenewuser = 1;
8892: my $cansrchinst = 0;
1.406.2.14 raeburn 8893: if (($srch->{'srchdomain'}) && ($env{'form.action'} ne 'accesslogs')) {
1.160 raeburn 8894: my %domconfig = &Apache::lonnet::get_dom('configuration',['directorysrch'],$srch->{'srchdomain'});
8895: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
8896: if ($domconfig{'directorysrch'}{'available'}) {
8897: $cansrchinst = 1;
8898: }
8899: }
8900: }
1.180 raeburn 8901: if ((($srch->{'srchby'} eq 'lastfirst') ||
8902: ($srch->{'srchby'} eq 'lastname')) &&
8903: ($srch->{'srchin'} eq 'dom')) {
8904: if ($cansrchinst) {
8905: $response .= '<br />'.&mt('You may want to broaden your search to a search of the institutional directory for the domain.');
1.160 raeburn 8906: }
8907: }
1.180 raeburn 8908: if ($srch->{'srchin'} eq 'crs') {
8909: $response .= '<br />'.&mt('You may want to broaden your search to the selected LON-CAPA domain.');
8910: }
8911: }
1.305 raeburn 8912: my $createdom = $env{'request.role.domain'};
8913: if ($context eq 'requestcrs') {
8914: if ($env{'form.coursedom'} ne '') {
8915: $createdom = $env{'form.coursedom'};
8916: }
8917: }
1.406.2.5 raeburn 8918: unless (($env{'form.action'} eq 'accesslogs') || (($srch->{'srchby'} eq 'uname') && ($srch->{'srchin'} eq 'dom') &&
8919: ($srch->{'srchtype'} eq 'exact') && ($srch->{'srchdomain'} eq $createdom))) {
1.221 raeburn 8920: my $cancreate =
1.305 raeburn 8921: &Apache::lonuserutils::can_create_user($createdom,$context);
8922: my $targetdom = '<span class="LC_cusr_emph">'.$createdom.'</span>';
1.221 raeburn 8923: if ($cancreate) {
1.305 raeburn 8924: my $showdom = &display_domain_info($createdom);
1.266 bisitz 8925: $response .= '<br /><br />'
8926: .'<b>'.&mt('To add a new user:').'</b>'
1.305 raeburn 8927: .'<br />';
8928: if ($context eq 'requestcrs') {
8929: $response .= &mt("(You can only define new users in the new course's domain - [_1])",$targetdom);
8930: } else {
8931: $response .= &mt("(You can only create new users in your current role's domain - [_1])",$targetdom);
8932: }
8933: $response .='<ul><li>'
1.266 bisitz 8934: .&mt("Set 'Domain/institution to search' to: [_1]",'<span class="LC_cusr_emph">'.$showdom.'</span>')
8935: .'</li><li>'
8936: .&mt("Set 'Search criteria' to: [_1]username is ..... in selected LON-CAPA domain[_2]",'<span class="LC_cusr_emph">','</span>')
8937: .'</li><li>'
8938: .&mt('Provide the proposed username')
8939: .'</li><li>'
8940: .&mt("Click 'Search'")
8941: .'</li></ul><br />';
1.221 raeburn 8942: } else {
1.406.2.7 raeburn 8943: unless (($context eq 'domain') && ($env{'form.action'} eq 'singleuser')) {
8944: my $helplink = ' href="javascript:helpMenu('."'display'".')"';
8945: $response .= '<br /><br />';
8946: if ($context eq 'requestcrs') {
8947: $response .= &mt("You are not authorized to define new users in the new course's domain - [_1].",$targetdom);
8948: } else {
8949: $response .= &mt("You are not authorized to create new users in your current role's domain - [_1].",$targetdom);
8950: }
8951: $response .= '<br />'
8952: .&mt('Please contact the [_1]helpdesk[_2] if you need to create a new user.'
8953: ,' <a'.$helplink.'>'
8954: ,'</a>')
8955: .'<br />';
1.305 raeburn 8956: }
1.221 raeburn 8957: }
1.160 raeburn 8958: }
8959: }
8960: }
1.179 raeburn 8961: return ($currstate,$response,$forcenewuser);
1.160 raeburn 8962: }
8963:
1.180 raeburn 8964: sub display_domain_info {
8965: my ($dom) = @_;
8966: my $output = $dom;
8967: if ($dom ne '') {
8968: my $domdesc = &Apache::lonnet::domain($dom,'description');
8969: if ($domdesc ne '') {
8970: $output .= ' <span class="LC_cusr_emph">('.$domdesc.')</span>';
8971: }
8972: }
8973: return $output;
8974: }
8975:
1.160 raeburn 8976: sub crumb_utilities {
8977: my %elements = (
8978: crtuser => {
8979: srchterm => 'text',
1.172 raeburn 8980: srchin => 'selectbox',
1.160 raeburn 8981: srchby => 'selectbox',
8982: srchtype => 'selectbox',
8983: srchdomain => 'selectbox',
8984: },
1.207 raeburn 8985: crtusername => {
8986: srchterm => 'text',
8987: srchdomain => 'selectbox',
8988: },
1.160 raeburn 8989: docustom => {
8990: rolename => 'selectbox',
8991: newrolename => 'textbox',
8992: },
1.179 raeburn 8993: studentform => {
8994: srchterm => 'text',
8995: srchin => 'selectbox',
8996: srchby => 'selectbox',
8997: srchtype => 'selectbox',
8998: srchdomain => 'selectbox',
8999: },
1.160 raeburn 9000: );
9001:
9002: my $jsback .= qq|
9003: function backPage(formname,prevphase,prevstate) {
1.211 raeburn 9004: if (typeof prevphase == 'undefined') {
9005: formname.phase.value = '';
9006: }
9007: else {
9008: formname.phase.value = prevphase;
9009: }
9010: if (typeof prevstate == 'undefined') {
9011: formname.currstate.value = '';
9012: }
9013: else {
9014: formname.currstate.value = prevstate;
9015: }
1.160 raeburn 9016: formname.submit();
9017: }
9018: |;
9019: return ($jsback,\%elements);
9020: }
9021:
1.26 matthew 9022: sub course_level_table {
1.375 raeburn 9023: my ($inccourses,$showcredits,$defaultcredits) = @_;
9024: return unless (ref($inccourses) eq 'HASH');
1.26 matthew 9025: my $table = '';
1.62 www 9026: # Custom Roles?
9027:
1.190 raeburn 9028: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.89 raeburn 9029: my %lt=&Apache::lonlocal::texthash(
9030: 'exs' => "Existing sections",
9031: 'new' => "Define new section",
9032: 'ssd' => "Set Start Date",
9033: 'sed' => "Set End Date",
1.131 raeburn 9034: 'crl' => "Course Level",
1.89 raeburn 9035: 'act' => "Activate",
9036: 'rol' => "Role",
9037: 'ext' => "Extent",
1.113 raeburn 9038: 'grs' => "Section",
1.375 raeburn 9039: 'crd' => "Credits",
1.89 raeburn 9040: 'sta' => "Start",
9041: 'end' => "End"
9042: );
1.62 www 9043:
1.375 raeburn 9044: foreach my $protectedcourse (sort(keys(%{$inccourses}))) {
1.135 raeburn 9045: my $thiscourse=$protectedcourse;
1.26 matthew 9046: $thiscourse=~s:_:/:g;
9047: my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
1.365 raeburn 9048: my $isowner = &Apache::lonuserutils::is_courseowner($protectedcourse,$coursedata{'internal.courseowner'});
1.26 matthew 9049: my $area=$coursedata{'description'};
1.321 raeburn 9050: my $crstype=$coursedata{'type'};
1.135 raeburn 9051: if (!defined($area)) { $area=&mt('Unavailable course').': '.$protectedcourse; }
1.89 raeburn 9052: my ($domain,$cnum)=split(/\//,$thiscourse);
1.115 albertel 9053: my %sections_count;
1.101 albertel 9054: if (defined($env{'request.course.id'})) {
9055: if ($env{'request.course.id'} eq $domain.'_'.$cnum) {
1.115 albertel 9056: %sections_count =
9057: &Apache::loncommon::get_sections($domain,$cnum);
1.92 raeburn 9058: }
9059: }
1.321 raeburn 9060: my @roles = &Apache::lonuserutils::roles_by_context('course','',$crstype);
1.213 raeburn 9061: foreach my $role (@roles) {
1.321 raeburn 9062: my $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.329 raeburn 9063: if ((&Apache::lonnet::allowed('c'.$role,$thiscourse)) ||
9064: ((($role eq 'cc') || ($role eq 'co')) && ($isowner))) {
1.221 raeburn 9065: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 9066: $plrole,\%sections_count,\%lt,
1.402 raeburn 9067: $showcredits,$defaultcredits,$crstype);
1.221 raeburn 9068: } elsif ($env{'request.course.sec'} ne '') {
9069: if (&Apache::lonnet::allowed('c'.$role,$thiscourse.'/'.
9070: $env{'request.course.sec'})) {
9071: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 9072: $plrole,\%sections_count,\%lt,
1.402 raeburn 9073: $showcredits,$defaultcredits,$crstype);
1.26 matthew 9074: }
9075: }
9076: }
1.221 raeburn 9077: if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
1.324 raeburn 9078: foreach my $cust (sort(keys(%customroles))) {
9079: next if ($crstype eq 'Community' && $customroles{$cust} =~ /bre\&S/);
1.221 raeburn 9080: my $role = 'cr_cr_'.$env{'user.domain'}.'_'.$env{'user.name'}.'_'.$cust;
9081: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.402 raeburn 9082: $cust,\%sections_count,\%lt,
9083: $showcredits,$defaultcredits,$crstype);
1.221 raeburn 9084: }
1.62 www 9085: }
1.26 matthew 9086: }
9087: return '' if ($table eq ''); # return nothing if there is nothing
9088: # in the table
1.188 raeburn 9089: my $result;
9090: if (!$env{'request.course.id'}) {
9091: $result = '<h4>'.$lt{'crl'}.'</h4>'."\n";
9092: }
9093: $result .=
1.136 raeburn 9094: &Apache::loncommon::start_data_table().
9095: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 9096: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
1.402 raeburn 9097: '<th>'.$lt{'ext'}.'</th><th>'."\n";
9098: if ($showcredits) {
9099: $result .= $lt{'crd'}.'</th>';
9100: }
9101: $result .=
1.375 raeburn 9102: '<th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th>'."\n".
9103: '<th>'.$lt{'end'}.'</th>'.
1.136 raeburn 9104: &Apache::loncommon::end_data_table_header_row().
9105: $table.
9106: &Apache::loncommon::end_data_table();
1.26 matthew 9107: return $result;
9108: }
1.88 raeburn 9109:
1.221 raeburn 9110: sub course_level_row {
1.375 raeburn 9111: my ($protectedcourse,$role,$area,$domain,$plrole,$sections_count,
1.402 raeburn 9112: $lt,$showcredits,$defaultcredits,$crstype) = @_;
1.375 raeburn 9113: my $creditem;
1.222 raeburn 9114: my $row = &Apache::loncommon::start_data_table_row().
9115: ' <td><input type="checkbox" name="act_'.
9116: $protectedcourse.'_'.$role.'" /></td>'."\n".
9117: ' <td>'.$plrole.'</td>'."\n".
9118: ' <td>'.$area.'<br />Domain: '.$domain.'</td>'."\n";
1.402 raeburn 9119: if (($showcredits) && ($role eq 'st') && ($crstype eq 'Course')) {
1.375 raeburn 9120: $row .=
9121: '<td><input type="text" name="credits_'.$protectedcourse.'_'.
9122: $role.'" size="3" value="'.$defaultcredits.'" /></td>';
9123: } else {
9124: $row .= '<td> </td>';
9125: }
1.322 raeburn 9126: if (($role eq 'cc') || ($role eq 'co')) {
1.222 raeburn 9127: $row .= '<td> </td>';
1.221 raeburn 9128: } elsif ($env{'request.course.sec'} ne '') {
1.222 raeburn 9129: $row .= ' <td><input type="hidden" value="'.
9130: $env{'request.course.sec'}.'" '.
9131: 'name="sec_'.$protectedcourse.'_'.$role.'" />'.
9132: $env{'request.course.sec'}.'</td>';
1.221 raeburn 9133: } else {
9134: if (ref($sections_count) eq 'HASH') {
9135: my $currsec =
9136: &Apache::lonuserutils::course_sections($sections_count,
9137: $protectedcourse.'_'.$role);
1.222 raeburn 9138: $row .= '<td><table class="LC_createuser">'."\n".
9139: '<tr class="LC_section_row">'."\n".
9140: ' <td valign="top">'.$lt->{'exs'}.'<br />'.
9141: $currsec.'</td>'."\n".
9142: ' <td> </td>'."\n".
9143: ' <td valign="top"> '.$lt->{'new'}.'<br />'.
1.221 raeburn 9144: '<input type="text" name="newsec_'.$protectedcourse.'_'.$role.
9145: '" value="" />'.
9146: '<input type="hidden" '.
9147: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n".
1.222 raeburn 9148: '</tr></table></td>'."\n";
1.221 raeburn 9149: } else {
1.222 raeburn 9150: $row .= '<td><input type="text" size="10" '.
1.375 raeburn 9151: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n";
1.221 raeburn 9152: }
9153: }
1.222 raeburn 9154: $row .= <<ENDTIMEENTRY;
9155: <td><input type="hidden" name="start_$protectedcourse\_$role" value="" />
1.221 raeburn 9156: <a href=
9157: "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 9158: <td><input type="hidden" name="end_$protectedcourse\_$role" value="" />
1.221 raeburn 9159: <a href=
9160: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$role.value,'end_$protectedcourse\_$role','cu.pres','dateset')">$lt->{'sed'}</a></td>
9161: ENDTIMEENTRY
1.222 raeburn 9162: $row .= &Apache::loncommon::end_data_table_row();
9163: return $row;
1.221 raeburn 9164: }
9165:
1.88 raeburn 9166: sub course_level_dc {
1.375 raeburn 9167: my ($dcdom,$showcredits) = @_;
1.190 raeburn 9168: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.213 raeburn 9169: my @roles = &Apache::lonuserutils::roles_by_context('course');
1.88 raeburn 9170: my $hiddenitems = '<input type="hidden" name="dcdomain" value="'.$dcdom.'" />'.
9171: '<input type="hidden" name="origdom" value="'.$dcdom.'" />'.
1.133 raeburn 9172: '<input type="hidden" name="dccourse" value="" />';
1.355 www 9173: my $courseform=&Apache::loncommon::selectcourse_link
1.356 raeburn 9174: ('cu','dccourse','dcdomain','coursedesc',undef,undef,'Select','crstype');
1.375 raeburn 9175: my $credit_elem;
9176: if ($showcredits) {
9177: $credit_elem = 'credits';
9178: }
9179: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,'currsec','cu','role','Course/Community Browser',$credit_elem);
1.88 raeburn 9180: my %lt=&Apache::lonlocal::texthash(
9181: 'rol' => "Role",
1.113 raeburn 9182: 'grs' => "Section",
1.88 raeburn 9183: 'exs' => "Existing sections",
9184: 'new' => "Define new section",
9185: 'sta' => "Start",
9186: 'end' => "End",
9187: 'ssd' => "Set Start Date",
1.355 www 9188: 'sed' => "Set End Date",
1.375 raeburn 9189: 'scc' => "Course/Community",
9190: 'crd' => "Credits",
1.88 raeburn 9191: );
1.323 raeburn 9192: my $header = '<h4>'.&mt('Course/Community Level').'</h4>'.
1.136 raeburn 9193: &Apache::loncommon::start_data_table().
9194: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 9195: '<th>'.$lt{'scc'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
1.397 bisitz 9196: '<th>'.$lt{'grs'}.'</th>'."\n";
9197: $header .= '<th>'.$lt{'crd'}.'</th>'."\n" if ($showcredits);
9198: $header .= '<th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'."\n".
1.136 raeburn 9199: &Apache::loncommon::end_data_table_header_row();
1.143 raeburn 9200: my $otheritems = &Apache::loncommon::start_data_table_row()."\n".
1.356 raeburn 9201: '<td><br /><span class="LC_nobreak"><input type="text" name="coursedesc" value="" onfocus="this.blur();opencrsbrowser('."'cu','dccourse','dcdomain','coursedesc','','','','crstype'".')" />'.
9202: $courseform.(' ' x4).'</span></td>'."\n".
1.389 bisitz 9203: '<td valign="top"><br /><select name="role">'."\n";
1.213 raeburn 9204: foreach my $role (@roles) {
1.135 raeburn 9205: my $plrole=&Apache::lonnet::plaintext($role);
1.389 bisitz 9206: $otheritems .= ' <option value="'.$role.'">'.$plrole.'</option>';
1.88 raeburn 9207: }
1.404 raeburn 9208: if ( keys(%customroles) > 0) {
9209: foreach my $cust (sort(keys(%customroles))) {
1.101 albertel 9210: my $custrole='cr_cr_'.$env{'user.domain'}.
1.135 raeburn 9211: '_'.$env{'user.name'}.'_'.$cust;
1.389 bisitz 9212: $otheritems .= ' <option value="'.$custrole.'">'.$cust.'</option>';
1.88 raeburn 9213: }
9214: }
9215: $otheritems .= '</select></td><td>'.
9216: '<table border="0" cellspacing="0" cellpadding="0">'.
9217: '<tr><td valign="top"><b>'.$lt{'exs'}.'</b><br /><select name="currsec">'.
1.389 bisitz 9218: ' <option value=""><--'.&mt('Pick course first').'</option></select></td>'.
1.88 raeburn 9219: '<td> </td>'.
9220: '<td valign="top"> <b>'.$lt{'new'}.'</b><br />'.
1.113 raeburn 9221: '<input type="text" name="newsec" value="" />'.
1.237 raeburn 9222: '<input type="hidden" name="section" value="" />'.
1.323 raeburn 9223: '<input type="hidden" name="groups" value="" />'.
9224: '<input type="hidden" name="crstype" value="" /></td>'.
1.375 raeburn 9225: '</tr></table></td>'."\n";
9226: if ($showcredits) {
9227: $otheritems .= '<td><br />'."\n".
1.397 bisitz 9228: '<input type="text" size="3" name="credits" value="" /></td>'."\n";
1.375 raeburn 9229: }
1.88 raeburn 9230: $otheritems .= <<ENDTIMEENTRY;
1.323 raeburn 9231: <td><br /><input type="hidden" name="start" value='' />
1.88 raeburn 9232: <a href=
9233: "javascript:pjump('date_start','Start Date',document.cu.start.value,'start','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.323 raeburn 9234: <td><br /><input type="hidden" name="end" value='' />
1.88 raeburn 9235: <a href=
9236: "javascript:pjump('date_end','End Date',document.cu.end.value,'end','cu.pres','dateset')">$lt{'sed'}</a></td>
9237: ENDTIMEENTRY
1.136 raeburn 9238: $otheritems .= &Apache::loncommon::end_data_table_row().
9239: &Apache::loncommon::end_data_table()."\n";
1.88 raeburn 9240: return $cb_jscript.$header.$hiddenitems.$otheritems;
9241: }
9242:
1.237 raeburn 9243: sub update_selfenroll_config {
1.400 raeburn 9244: my ($r,$cid,$cdom,$cnum,$context,$crstype,$currsettings) = @_;
1.398 raeburn 9245: return unless (ref($currsettings) eq 'HASH');
9246: my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles();
9247: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
1.237 raeburn 9248: my (%changes,%warning);
1.241 raeburn 9249: my $curr_types;
1.400 raeburn 9250: my %noedit;
9251: unless ($context eq 'domain') {
9252: %noedit = &get_noedit_fields($cdom,$cnum,$crstype,$row);
9253: }
1.237 raeburn 9254: if (ref($row) eq 'ARRAY') {
9255: foreach my $item (@{$row}) {
1.400 raeburn 9256: next if ($noedit{$item});
1.237 raeburn 9257: if ($item eq 'enroll_dates') {
9258: my (%currenrolldate,%newenrolldate);
9259: foreach my $type ('start','end') {
1.398 raeburn 9260: $currenrolldate{$type} = $currsettings->{'selfenroll_'.$type.'_date'};
1.237 raeburn 9261: $newenrolldate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_date');
9262: if ($newenrolldate{$type} ne $currenrolldate{$type}) {
9263: $changes{'internal.selfenroll_'.$type.'_date'} = $newenrolldate{$type};
9264: }
9265: }
9266: } elsif ($item eq 'access_dates') {
9267: my (%currdate,%newdate);
9268: foreach my $type ('start','end') {
1.398 raeburn 9269: $currdate{$type} = $currsettings->{'selfenroll_'.$type.'_access'};
1.237 raeburn 9270: $newdate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_access');
9271: if ($newdate{$type} ne $currdate{$type}) {
9272: $changes{'internal.selfenroll_'.$type.'_access'} = $newdate{$type};
9273: }
9274: }
1.241 raeburn 9275: } elsif ($item eq 'types') {
1.398 raeburn 9276: $curr_types = $currsettings->{'selfenroll_'.$item};
1.241 raeburn 9277: if ($env{'form.selfenroll_all'}) {
9278: if ($curr_types ne '*') {
9279: $changes{'internal.selfenroll_types'} = '*';
9280: } else {
9281: next;
9282: }
9283: } else {
1.249 raeburn 9284: my %currdoms;
1.241 raeburn 9285: my @entries = split(/;/,$curr_types);
9286: my @deletedoms = &Apache::loncommon::get_env_multiple('form.selfenroll_delete');
1.249 raeburn 9287: my @activations = &Apache::loncommon::get_env_multiple('form.selfenroll_activate');
1.241 raeburn 9288: my $newnum = 0;
1.249 raeburn 9289: my @latesttypes;
9290: foreach my $num (@activations) {
9291: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$num);
9292: if (@types > 0) {
1.241 raeburn 9293: @types = sort(@types);
9294: my $typestr = join(',',@types);
1.249 raeburn 9295: my $typedom = $env{'form.selfenroll_dom_'.$num};
9296: $latesttypes[$newnum] = $typedom.':'.$typestr;
9297: $currdoms{$typedom} = 1;
1.241 raeburn 9298: $newnum ++;
9299: }
9300: }
1.338 raeburn 9301: for (my $j=0; $j<$env{'form.selfenroll_types_total'}; $j++) {
9302: if ((!grep(/^$j$/,@deletedoms)) && (!grep(/^$j$/,@activations))) {
1.249 raeburn 9303: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$j);
9304: if (@types > 0) {
9305: @types = sort(@types);
9306: my $typestr = join(',',@types);
9307: my $typedom = $env{'form.selfenroll_dom_'.$j};
9308: $latesttypes[$newnum] = $typedom.':'.$typestr;
9309: $currdoms{$typedom} = 1;
9310: $newnum ++;
9311: }
9312: }
9313: }
9314: if ($env{'form.selfenroll_newdom'} ne '') {
9315: my $typedom = $env{'form.selfenroll_newdom'};
9316: if ((!defined($currdoms{$typedom})) &&
9317: (&Apache::lonnet::domain($typedom) ne '')) {
9318: my $typestr;
9319: my ($othertitle,$usertypes,$types) =
9320: &Apache::loncommon::sorted_inst_types($typedom);
9321: my $othervalue = 'any';
9322: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
9323: if (@{$types} > 0) {
1.257 raeburn 9324: my @esc_types = map { &escape($_); } @{$types};
1.249 raeburn 9325: $othervalue = 'other';
1.258 raeburn 9326: $typestr = join(',',(@esc_types,$othervalue));
1.249 raeburn 9327: }
9328: $typestr = $othervalue;
9329: } else {
9330: $typestr = $othervalue;
9331: }
9332: $latesttypes[$newnum] = $typedom.':'.$typestr;
9333: $newnum ++ ;
9334: }
9335: }
1.241 raeburn 9336: my $selfenroll_types = join(';',@latesttypes);
9337: if ($selfenroll_types ne $curr_types) {
9338: $changes{'internal.selfenroll_types'} = $selfenroll_types;
9339: }
9340: }
1.276 raeburn 9341: } elsif ($item eq 'limit') {
9342: my $newlimit = $env{'form.selfenroll_limit'};
9343: my $newcap = $env{'form.selfenroll_cap'};
9344: $newcap =~s/\s+//g;
1.398 raeburn 9345: my $currlimit = $currsettings->{'selfenroll_limit'};
1.276 raeburn 9346: $currlimit = 'none' if ($currlimit eq '');
1.398 raeburn 9347: my $currcap = $currsettings->{'selfenroll_cap'};
1.276 raeburn 9348: if ($newlimit ne $currlimit) {
9349: if ($newlimit ne 'none') {
9350: if ($newcap =~ /^\d+$/) {
9351: if ($newcap ne $currcap) {
9352: $changes{'internal.selfenroll_cap'} = $newcap;
9353: }
9354: $changes{'internal.selfenroll_limit'} = $newlimit;
9355: } else {
1.398 raeburn 9356: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.
9357: &mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
1.276 raeburn 9358: }
9359: } elsif ($currcap ne '') {
9360: $changes{'internal.selfenroll_cap'} = '';
9361: $changes{'internal.selfenroll_limit'} = $newlimit;
9362: }
9363: } elsif ($currlimit ne 'none') {
9364: if ($newcap =~ /^\d+$/) {
9365: if ($newcap ne $currcap) {
9366: $changes{'internal.selfenroll_cap'} = $newcap;
9367: }
9368: } else {
1.398 raeburn 9369: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.
9370: &mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
1.276 raeburn 9371: }
9372: }
9373: } elsif ($item eq 'approval') {
9374: my (@currnotified,@newnotified);
1.398 raeburn 9375: my $currapproval = $currsettings->{'selfenroll_approval'};
9376: my $currnotifylist = $currsettings->{'selfenroll_notifylist'};
1.276 raeburn 9377: if ($currnotifylist ne '') {
9378: @currnotified = split(/,/,$currnotifylist);
9379: @currnotified = sort(@currnotified);
9380: }
9381: my $newapproval = $env{'form.selfenroll_approval'};
9382: @newnotified = &Apache::loncommon::get_env_multiple('form.selfenroll_notify');
9383: @newnotified = sort(@newnotified);
9384: if ($newapproval ne $currapproval) {
9385: $changes{'internal.selfenroll_approval'} = $newapproval;
9386: if (!$newapproval) {
9387: if ($currnotifylist ne '') {
9388: $changes{'internal.selfenroll_notifylist'} = '';
9389: }
9390: } else {
9391: my @differences =
1.295 raeburn 9392: &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 9393: if (@differences > 0) {
9394: if (@newnotified > 0) {
9395: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
9396: } else {
9397: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
9398: }
9399: }
9400: }
9401: } else {
1.295 raeburn 9402: my @differences = &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 9403: if (@differences > 0) {
9404: if (@newnotified > 0) {
9405: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
9406: } else {
9407: $changes{'internal.selfenroll_notifylist'} = '';
9408: }
9409: }
9410: }
1.237 raeburn 9411: } else {
1.398 raeburn 9412: my $curr_val = $currsettings->{'selfenroll_'.$item};
1.237 raeburn 9413: my $newval = $env{'form.selfenroll_'.$item};
9414: if ($item eq 'section') {
9415: $newval = $env{'form.sections'};
1.241 raeburn 9416: if (defined($curr_groups{$newval})) {
1.237 raeburn 9417: $newval = $curr_val;
1.398 raeburn 9418: $warning{$item} = &mt('Section for self-enrolled users unchanged as the proposed section is a group').'<br />'.
9419: &mt('Group names and section names must be distinct');
1.237 raeburn 9420: } elsif ($newval eq 'all') {
9421: $newval = $curr_val;
1.274 bisitz 9422: $warning{$item} = &mt('Section for self-enrolled users unchanged, as "all" is a reserved section name.');
1.237 raeburn 9423: }
9424: if ($newval eq '') {
9425: $newval = 'none';
9426: }
9427: }
9428: if ($newval ne $curr_val) {
9429: $changes{'internal.selfenroll_'.$item} = $newval;
9430: }
1.241 raeburn 9431: }
1.237 raeburn 9432: }
9433: if (keys(%warning) > 0) {
9434: foreach my $item (@{$row}) {
9435: if (exists($warning{$item})) {
9436: $r->print($warning{$item}.'<br />');
9437: }
9438: }
9439: }
9440: if (keys(%changes) > 0) {
9441: my $putresult = &Apache::lonnet::put('environment',\%changes,$cdom,$cnum);
9442: if ($putresult eq 'ok') {
9443: if ((exists($changes{'internal.selfenroll_types'})) ||
9444: (exists($changes{'internal.selfenroll_start_date'})) ||
9445: (exists($changes{'internal.selfenroll_end_date'}))) {
9446: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',
9447: $cnum,undef,undef,'Course');
9448: my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
1.398 raeburn 9449: if (ref($crsinfo{$cid}) eq 'HASH') {
1.237 raeburn 9450: foreach my $item ('selfenroll_types','selfenroll_start_date','selfenroll_end_date') {
9451: if (exists($changes{'internal.'.$item})) {
1.398 raeburn 9452: $crsinfo{$cid}{$item} = $changes{'internal.'.$item};
1.237 raeburn 9453: }
9454: }
9455: my $crsputresult =
9456: &Apache::lonnet::courseidput($cdom,\%crsinfo,
9457: $chome,'notime');
9458: }
9459: }
9460: $r->print(&mt('The following changes were made to self-enrollment settings:').'<ul>');
9461: foreach my $item (@{$row}) {
9462: my $title = $item;
9463: if (ref($lt) eq 'HASH') {
9464: $title = $lt->{$item};
9465: }
9466: if ($item eq 'enroll_dates') {
9467: foreach my $type ('start','end') {
9468: if (exists($changes{'internal.selfenroll_'.$type.'_date'})) {
9469: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_date'});
1.244 bisitz 9470: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 9471: $title,$type,$newdate).'</li>');
9472: }
9473: }
9474: } elsif ($item eq 'access_dates') {
9475: foreach my $type ('start','end') {
9476: if (exists($changes{'internal.selfenroll_'.$type.'_access'})) {
9477: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_access'});
1.244 bisitz 9478: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 9479: $title,$type,$newdate).'</li>');
9480: }
9481: }
1.276 raeburn 9482: } elsif ($item eq 'limit') {
9483: if ((exists($changes{'internal.selfenroll_limit'})) ||
9484: (exists($changes{'internal.selfenroll_cap'}))) {
9485: my ($newval,$newcap);
9486: if ($changes{'internal.selfenroll_cap'} ne '') {
9487: $newcap = $changes{'internal.selfenroll_cap'}
9488: } else {
1.398 raeburn 9489: $newcap = $currsettings->{'selfenroll_cap'};
1.276 raeburn 9490: }
9491: if ($changes{'internal.selfenroll_limit'} eq 'none') {
9492: $newval = &mt('No limit');
9493: } elsif ($changes{'internal.selfenroll_limit'} eq
9494: 'allstudents') {
9495: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
9496: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
9497: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
9498: } else {
1.398 raeburn 9499: my $currlimit = $currsettings->{'selfenroll_limit'};
1.276 raeburn 9500: if ($currlimit eq 'allstudents') {
9501: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
9502: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
1.308 raeburn 9503: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
1.276 raeburn 9504: }
9505: }
9506: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
9507: }
9508: } elsif ($item eq 'approval') {
9509: if ((exists($changes{'internal.selfenroll_approval'})) ||
9510: (exists($changes{'internal.selfenroll_notifylist'}))) {
1.398 raeburn 9511: my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs();
1.276 raeburn 9512: my ($newval,$newnotify);
9513: if (exists($changes{'internal.selfenroll_notifylist'})) {
9514: $newnotify = $changes{'internal.selfenroll_notifylist'};
9515: } else {
1.398 raeburn 9516: $newnotify = $currsettings->{'selfenroll_notifylist'};
1.276 raeburn 9517: }
1.398 raeburn 9518: if (exists($changes{'internal.selfenroll_approval'})) {
9519: if ($changes{'internal.selfenroll_approval'} !~ /^[012]$/) {
9520: $changes{'internal.selfenroll_approval'} = '0';
9521: }
9522: $newval = $selfdescs{'approval'}{$changes{'internal.selfenroll_approval'}};
1.276 raeburn 9523: } else {
1.398 raeburn 9524: my $currapproval = $currsettings->{'selfenroll_approval'};
9525: if ($currapproval !~ /^[012]$/) {
9526: $currapproval = 0;
1.276 raeburn 9527: }
1.398 raeburn 9528: $newval = $selfdescs{'approval'}{$currapproval};
1.276 raeburn 9529: }
9530: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval));
9531: if ($newnotify) {
1.277 raeburn 9532: $r->print('<br />'.&mt('The following will be notified when an enrollment request needs approval, or has been approved: [_1].',$newnotify));
1.276 raeburn 9533: } else {
1.277 raeburn 9534: $r->print('<br />'.&mt('No notifications sent when an enrollment request needs approval, or has been approved.'));
1.276 raeburn 9535: }
9536: $r->print('</li>'."\n");
9537: }
1.237 raeburn 9538: } else {
9539: if (exists($changes{'internal.selfenroll_'.$item})) {
1.241 raeburn 9540: my $newval = $changes{'internal.selfenroll_'.$item};
9541: if ($item eq 'types') {
9542: if ($newval eq '') {
9543: $newval = &mt('None');
9544: } elsif ($newval eq '*') {
9545: $newval = &mt('Any user in any domain');
9546: }
1.245 raeburn 9547: } elsif ($item eq 'registered') {
9548: if ($newval eq '1') {
9549: $newval = &mt('Yes');
9550: } elsif ($newval eq '0') {
9551: $newval = &mt('No');
9552: }
1.241 raeburn 9553: }
1.244 bisitz 9554: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
1.237 raeburn 9555: }
9556: }
9557: }
9558: $r->print('</ul>');
1.398 raeburn 9559: if ($env{'course.'.$cid.'.description'} ne '') {
9560: my %newenvhash;
9561: foreach my $key (keys(%changes)) {
9562: $newenvhash{'course.'.$cid.'.'.$key} = $changes{$key};
9563: }
9564: &Apache::lonnet::appenv(\%newenvhash);
1.237 raeburn 9565: }
9566: } else {
1.398 raeburn 9567: $r->print(&mt('An error occurred when saving changes to self-enrollment settings in this course.').'<br />'.
9568: &mt('The error was: [_1].',$putresult));
1.237 raeburn 9569: }
9570: } else {
1.249 raeburn 9571: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.237 raeburn 9572: }
9573: } else {
1.249 raeburn 9574: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.241 raeburn 9575: }
1.406.2.21 raeburn 9576: my $visactions = &cat_visibility($cdom);
1.400 raeburn 9577: my ($cathash,%cattype);
9578: my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
9579: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
9580: $cathash = $domconfig{'coursecategories'}{'cats'};
9581: $cattype{'auth'} = $domconfig{'coursecategories'}{'auth'};
9582: $cattype{'unauth'} = $domconfig{'coursecategories'}{'unauth'};
9583: } else {
9584: $cathash = {};
9585: $cattype{'auth'} = 'std';
9586: $cattype{'unauth'} = 'std';
9587: }
9588: if (($cattype{'auth'} eq 'none') && ($cattype{'unauth'} eq 'none')) {
9589: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
9590: '<br />'.
9591: '<br />'.$visactions->{'take'}.'<ul>'.
9592: '<li>'.$visactions->{'dc_chgconf'}.'</li>'.
9593: '</ul>');
9594: } elsif (($cattype{'auth'} !~ /^(std|domonly)$/) && ($cattype{'unauth'} !~ /^(std|domonly)$/)) {
9595: if ($currsettings->{'uniquecode'}) {
9596: $r->print('<span class="LC_info">'.$visactions->{'vis'}.'</span>');
9597: } else {
1.366 bisitz 9598: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
1.400 raeburn 9599: '<br />'.
9600: '<br />'.$visactions->{'take'}.'<ul>'.
9601: '<li>'.$visactions->{'dc_setcode'}.'</li>'.
9602: '</ul><br />');
9603: }
9604: } else {
9605: my ($visible,$cansetvis,$vismsgs) = &visible_in_stdcat($cdom,$cnum,\%domconfig);
9606: if (ref($visactions) eq 'HASH') {
9607: if (!$visible) {
9608: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
9609: '<br />');
9610: if (ref($vismsgs) eq 'ARRAY') {
9611: $r->print('<br />'.$visactions->{'take'}.'<ul>');
9612: foreach my $item (@{$vismsgs}) {
9613: $r->print('<li>'.$visactions->{$item}.'</li>');
9614: }
9615: $r->print('</ul>');
1.256 raeburn 9616: }
1.400 raeburn 9617: $r->print($cansetvis);
1.256 raeburn 9618: }
9619: }
9620: }
1.237 raeburn 9621: return;
9622: }
9623:
1.27 matthew 9624: #---------------------------------------------- end functions for &phase_two
1.29 matthew 9625:
9626: #--------------------------------- functions for &phase_two and &phase_three
9627:
9628: #--------------------------end of functions for &phase_two and &phase_three
1.372 raeburn 9629:
1.1 www 9630: 1;
9631: __END__
1.2 www 9632:
9633:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>