Annotation of loncom/interface/loncreateuser.pm, revision 1.406.2.21
1.20 harris41 1: # The LearningOnline Network with CAPA
1.1 www 2: # Create a user
3: #
1.406.2.21! raeburn 4: # $Id: loncreateuser.pm,v 1.406.2.20 2021/12/13 20:53:06 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;
1279: }
1280: my $start_page =
1281: &Apache::loncommon::start_page('User Management',$js,$args);
1.3 www 1282:
1.25 matthew 1283: my $forminfo =<<"ENDFORMINFO";
1.216 raeburn 1284: <form action="/adm/createuser" method="post" name="$formname">
1.190 raeburn 1285: <input type="hidden" name="phase" value="update_user_data" />
1.188 raeburn 1286: <input type="hidden" name="ccuname" value="$ccuname" />
1287: <input type="hidden" name="ccdomain" value="$ccdomain" />
1.157 albertel 1288: <input type="hidden" name="pres_value" value="" />
1289: <input type="hidden" name="pres_type" value="" />
1290: <input type="hidden" name="pres_marker" value="" />
1.25 matthew 1291: ENDFORMINFO
1.375 raeburn 1292: my (%inccourses,$roledom,$defaultcredits);
1.329 raeburn 1293: if ($context eq 'course') {
1294: $inccourses{$env{'request.course.id'}}=1;
1295: $roledom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1.375 raeburn 1296: if ($showcredits) {
1297: $defaultcredits = &Apache::lonuserutils::get_defaultcredits();
1298: }
1.329 raeburn 1299: } elsif ($context eq 'author') {
1300: $roledom = $env{'request.role.domain'};
1301: } elsif ($context eq 'domain') {
1302: foreach my $key (keys(%env)) {
1303: $roledom = $env{'request.role.domain'};
1304: if ($key=~/^user\.priv\.cm\.\/($roledom)\/($match_username)/) {
1305: $inccourses{$1.'_'.$2}=1;
1306: }
1307: }
1308: } else {
1309: foreach my $key (keys(%env)) {
1310: if ($key=~/^user\.priv\.cm\.\/($match_domain)\/($match_username)/) {
1311: $inccourses{$1.'_'.$2}=1;
1312: }
1.2 www 1313: }
1.24 matthew 1314: }
1.389 bisitz 1315: my $title = '';
1.216 raeburn 1316: if ($newuser) {
1.406.2.9 raeburn 1317: my ($portfolioform,$domroleform);
1.267 raeburn 1318: if ((&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) ||
1319: (&Apache::lonnet::allowed('mut',$env{'request.role.domain'}))) {
1320: # Current user has quota or user tools modification privileges
1.378 raeburn 1321: $portfolioform = '<br />'.&user_quotas($ccuname,$ccdomain);
1.134 raeburn 1322: }
1.383 raeburn 1323: if ((&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) &&
1324: ($ccdomain eq $env{'request.role.domain'})) {
1.362 raeburn 1325: $domroleform = '<br />'.&domainrole_req($ccuname,$ccdomain);
1326: }
1.227 raeburn 1327: &initialize_authen_forms($ccdomain,$formname);
1.188 raeburn 1328: my %lt=&Apache::lonlocal::texthash(
1329: 'lg' => 'Login Data',
1.190 raeburn 1330: 'hs' => "Home Server",
1.188 raeburn 1331: );
1.185 raeburn 1332: $r->print(<<ENDTITLE);
1.110 albertel 1333: $start_page
1.160 raeburn 1334: $response
1.25 matthew 1335: $forminfo
1.31 matthew 1336: <script type="text/javascript" language="Javascript">
1.301 bisitz 1337: // <![CDATA[
1.20 harris41 1338: $loginscript
1.301 bisitz 1339: // ]]>
1.31 matthew 1340: </script>
1.20 harris41 1341: <input type='hidden' name='makeuser' value='1' />
1.185 raeburn 1342: ENDTITLE
1.213 raeburn 1343: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1344: if ($crstype eq 'Community') {
1.389 bisitz 1345: $title = &mt('Create New User [_1] in domain [_2] as a member',
1346: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1347: } else {
1.389 bisitz 1348: $title = &mt('Create New User [_1] in domain [_2] as a student',
1349: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1350: }
1.389 bisitz 1351: } else {
1352: $title = &mt('Create New User [_1] in domain [_2]',
1353: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.213 raeburn 1354: }
1.389 bisitz 1355: $r->print('<h2>'.$title.'</h2>'."\n");
1356: $r->print('<div class="LC_left_float">');
1.393 raeburn 1357: $r->print(&personal_data_display($ccuname,$ccdomain,$newuser,$context,
1358: $inst_results{$ccuname.':'.$ccdomain}));
1359: # Option to disable student/employee ID conflict checking not offerred for new users.
1.187 raeburn 1360: my ($home_server_pick,$numlib) =
1361: &Apache::loncommon::home_server_form_item($ccdomain,'hserver',
1362: 'default','hide');
1363: if ($numlib > 1) {
1364: $r->print("
1.185 raeburn 1365: <br />
1.187 raeburn 1366: $lt{'hs'}: $home_server_pick
1367: <br />");
1368: } else {
1369: $r->print($home_server_pick);
1370: }
1.304 raeburn 1371: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.362 raeburn 1372: $r->print('<br /><h3>'.
1373: &mt('User Can Request Creation of Courses/Communities in this Domain?').'</h3>'.
1.304 raeburn 1374: &Apache::loncommon::start_data_table().
1375: &build_tools_display($ccuname,$ccdomain,
1376: 'requestcourses').
1377: &Apache::loncommon::end_data_table());
1378: }
1.188 raeburn 1379: $r->print('</div>'."\n".'<div class="LC_left_float"><h3>'.
1380: $lt{'lg'}.'</h3>');
1.185 raeburn 1381: my ($fixedauth,$varauth,$authmsg);
1.193 raeburn 1382: if (ref($rulematch{$ccuname.':'.$ccdomain}) eq 'HASH') {
1383: my $matchedrule = $rulematch{$ccuname.':'.$ccdomain}{'username'};
1384: my ($rules,$ruleorder) =
1385: &Apache::lonnet::inst_userrules($ccdomain,'username');
1.185 raeburn 1386: if (ref($rules) eq 'HASH') {
1.193 raeburn 1387: if (ref($rules->{$matchedrule}) eq 'HASH') {
1388: my $authtype = $rules->{$matchedrule}{'authtype'};
1.185 raeburn 1389: if ($authtype !~ /^(krb4|krb5|int|fsys|loc)$/) {
1.190 raeburn 1390: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.275 raeburn 1391: } else {
1.193 raeburn 1392: my $authparm = $rules->{$matchedrule}{'authparm'};
1.273 raeburn 1393: $authmsg = $rules->{$matchedrule}{'authmsg'};
1.185 raeburn 1394: if ($authtype =~ /^krb(4|5)$/) {
1395: my $ver = $1;
1396: if ($authparm ne '') {
1397: $fixedauth = <<"KERB";
1398: <input type="hidden" name="login" value="krb" />
1399: <input type="hidden" name="krbver" value="$ver" />
1400: <input type="hidden" name="krbarg" value="$authparm" />
1401: KERB
1402: }
1403: } else {
1404: $fixedauth =
1405: '<input type="hidden" name="login" value="'.$authtype.'" />'."\n";
1.193 raeburn 1406: if ($rules->{$matchedrule}{'authparmfixed'}) {
1.185 raeburn 1407: $fixedauth .=
1408: '<input type="hidden" name="'.$authtype.'arg" value="'.$authparm.'" />'."\n";
1409: } else {
1.273 raeburn 1410: if ($authtype eq 'int') {
1411: $varauth = '<br />'.
1.301 bisitz 1412: &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 1413: } elsif ($authtype eq 'loc') {
1414: $varauth = '<br />'.
1415: &mt('[_1] Local Authentication with argument [_2]','','<input type="text" name="'.$authtype.'arg" value="" />')."\n";
1416: } else {
1417: $varauth =
1.185 raeburn 1418: '<input type="text" name="'.$authtype.'arg" value="" />'."\n";
1.273 raeburn 1419: }
1.185 raeburn 1420: }
1421: }
1422: }
1423: } else {
1.190 raeburn 1424: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.185 raeburn 1425: }
1426: }
1427: if ($authmsg) {
1428: $r->print(<<ENDAUTH);
1429: $fixedauth
1430: $authmsg
1431: $varauth
1432: ENDAUTH
1433: }
1434: } else {
1.190 raeburn 1435: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.187 raeburn 1436: }
1.406.2.9 raeburn 1437: $r->print($portfolioform.$domroleform);
1.215 raeburn 1438: if ($env{'form.action'} eq 'singlestudent') {
1439: $r->print(&date_sections_select($context,$newuser,$formname,
1.375 raeburn 1440: $permission,$crstype,$ccuname,
1441: $ccdomain,$showcredits));
1.215 raeburn 1442: }
1443: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.216 raeburn 1444: } else { # user already exists
1.389 bisitz 1445: $r->print($start_page.$forminfo);
1.213 raeburn 1446: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1447: if ($crstype eq 'Community') {
1.389 bisitz 1448: $title = &mt('Enroll one member: [_1] in domain [_2]',
1449: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1450: } else {
1.389 bisitz 1451: $title = &mt('Enroll one student: [_1] in domain [_2]',
1452: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1453: }
1.213 raeburn 1454: } else {
1.406.2.6 raeburn 1455: if ($permission->{'cusr'}) {
1456: $title = &mt('Modify existing user: [_1] in domain [_2]',
1457: '"'.$ccuname.'"','"'.$ccdomain.'"');
1458: } else {
1459: $title = &mt('Existing user: [_1] in domain [_2]',
1.389 bisitz 1460: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.406.2.6 raeburn 1461: }
1.213 raeburn 1462: }
1.389 bisitz 1463: $r->print('<h2>'.$title.'</h2>'."\n");
1464: $r->print('<div class="LC_left_float">');
1.393 raeburn 1465: $r->print(&personal_data_display($ccuname,$ccdomain,$newuser,$context,
1466: $inst_results{$ccuname.':'.$ccdomain}));
1.406.2.6 raeburn 1467: if ((&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) ||
1468: (&Apache::lonnet::allowed('udp',$env{'request.role.domain'}))) {
1.362 raeburn 1469: $r->print('<br /><h3>'.&mt('User Can Request Creation of Courses/Communities in this Domain?').'</h3>'.
1.300 raeburn 1470: &Apache::loncommon::start_data_table());
1.314 raeburn 1471: if ($env{'request.role.domain'} eq $ccdomain) {
1.300 raeburn 1472: $r->print(&build_tools_display($ccuname,$ccdomain,'requestcourses'));
1473: } else {
1474: $r->print(&coursereq_externaluser($ccuname,$ccdomain,
1475: $env{'request.role.domain'}));
1476: }
1477: $r->print(&Apache::loncommon::end_data_table());
1.275 raeburn 1478: }
1.199 raeburn 1479: $r->print('</div>');
1.406.2.9 raeburn 1480: my @order = ('auth','quota','tools','requestauthor');
1.362 raeburn 1481: my %user_text;
1482: my ($isadv,$isauthor) =
1.406.2.6 raeburn 1483: &Apache::lonnet::is_advanced_user($ccdomain,$ccuname);
1.362 raeburn 1484: if ((!$isauthor) &&
1.406.2.6 raeburn 1485: ((&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) ||
1486: (&Apache::lonnet::allowed('udp',$env{'request.role.domain'}))) &&
1487: ($env{'request.role.domain'} eq $ccdomain)) {
1.362 raeburn 1488: $user_text{'requestauthor'} = &domainrole_req($ccuname,$ccdomain);
1489: }
1.406.2.17 raeburn 1490: $user_text{'auth'} = &user_authentication($ccuname,$ccdomain,$formname,$crstype,$permission);
1.267 raeburn 1491: if ((&Apache::lonnet::allowed('mpq',$ccdomain)) ||
1.406.2.6 raeburn 1492: (&Apache::lonnet::allowed('mut',$ccdomain)) ||
1493: (&Apache::lonnet::allowed('udp',$ccdomain))) {
1.188 raeburn 1494: # Current user has quota modification privileges
1.378 raeburn 1495: $user_text{'quota'} = &user_quotas($ccuname,$ccdomain);
1.267 raeburn 1496: }
1497: if (!&Apache::lonnet::allowed('mpq',$ccdomain)) {
1498: if (&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) {
1499: my %lt=&Apache::lonlocal::texthash(
1.385 bisitz 1500: 'dska' => "Disk quotas for user's portfolio and Authoring Space",
1501: 'youd' => "You do not have privileges to modify the portfolio and/or Authoring Space quotas for this user.",
1.267 raeburn 1502: 'ichr' => "If a change is required, contact a domain coordinator for the domain",
1503: );
1.362 raeburn 1504: $user_text{'quota'} = <<ENDNOPORTPRIV;
1.188 raeburn 1505: <h3>$lt{'dska'}</h3>
1506: $lt{'youd'} $lt{'ichr'}: $ccdomain
1507: ENDNOPORTPRIV
1.267 raeburn 1508: }
1509: }
1510: if (!&Apache::lonnet::allowed('mut',$ccdomain)) {
1511: if (&Apache::lonnet::allowed('mut',$env{'request.role.domain'})) {
1512: my %lt=&Apache::lonlocal::texthash(
1513: 'utav' => "User Tools Availability",
1.361 raeburn 1514: 'yodo' => "You do not have privileges to modify Portfolio, Blog, WebDAV, or Personal Information Page settings for this user.",
1.267 raeburn 1515: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
1516: );
1.362 raeburn 1517: $user_text{'tools'} = <<ENDNOTOOLSPRIV;
1.267 raeburn 1518: <h3>$lt{'utav'}</h3>
1519: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1520: ENDNOTOOLSPRIV
1521: }
1.188 raeburn 1522: }
1.362 raeburn 1523: my $gotdiv = 0;
1524: foreach my $item (@order) {
1525: if ($user_text{$item} ne '') {
1526: unless ($gotdiv) {
1527: $r->print('<div class="LC_left_float">');
1528: $gotdiv = 1;
1529: }
1530: $r->print('<br />'.$user_text{$item});
1531: }
1532: }
1533: if ($env{'form.action'} eq 'singlestudent') {
1534: unless ($gotdiv) {
1535: $r->print('<div class="LC_left_float">');
1.213 raeburn 1536: }
1.375 raeburn 1537: my $credits;
1538: if ($showcredits) {
1539: $credits = &get_user_credits($ccuname,$ccdomain,$defaultcredits);
1540: if ($credits eq '') {
1541: $credits = $defaultcredits;
1542: }
1543: }
1.374 raeburn 1544: $r->print(&date_sections_select($context,$newuser,$formname,
1.375 raeburn 1545: $permission,$crstype,$ccuname,
1546: $ccdomain,$showcredits));
1.374 raeburn 1547: }
1.362 raeburn 1548: if ($gotdiv) {
1549: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.188 raeburn 1550: }
1.406.2.6 raeburn 1551: my $statuses;
1552: if (($context eq 'domain') && (&Apache::lonnet::allowed('udp',$ccdomain)) &&
1553: (!&Apache::lonnet::allowed('mau',$ccdomain))) {
1554: $statuses = ['active'];
1555: } elsif (($context eq 'course') && ((&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) ||
1556: ($env{'request.course.sec'} &&
1557: &Apache::lonnet::allowed('vcl',$env{'request.course.id'}.'/'.$env{'request.course.sec'})))) {
1558: $statuses = ['active'];
1559: }
1.217 raeburn 1560: if ($env{'form.action'} ne 'singlestudent') {
1.329 raeburn 1561: &display_existing_roles($r,$ccuname,$ccdomain,\%inccourses,$context,
1.406.2.6 raeburn 1562: $roledom,$crstype,$showcredits,$statuses);
1.217 raeburn 1563: }
1.25 matthew 1564: } ## End of new user/old user logic
1.218 raeburn 1565: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1566: my $btntxt;
1567: if ($crstype eq 'Community') {
1568: $btntxt = &mt('Enroll Member');
1569: } else {
1570: $btntxt = &mt('Enroll Student');
1571: }
1572: $r->print('<br /><input type="button" value="'.$btntxt.'" onclick="setSections(this.form)" />'."\n");
1.406.2.6 raeburn 1573: } elsif ($permission->{'cusr'}) {
1.393 raeburn 1574: $r->print('<div class="LC_left_float">'.
1575: '<fieldset><legend>'.&mt('Add Roles').'</legend>');
1.218 raeburn 1576: my $addrolesdisplay = 0;
1577: if ($context eq 'domain' || $context eq 'author') {
1578: $addrolesdisplay = &new_coauthor_roles($r,$ccuname,$ccdomain);
1579: }
1580: if ($context eq 'domain') {
1.357 raeburn 1581: my $add_domainroles = &new_domain_roles($r,$ccdomain);
1.218 raeburn 1582: if (!$addrolesdisplay) {
1583: $addrolesdisplay = $add_domainroles;
1.2 www 1584: }
1.375 raeburn 1585: $r->print(&course_level_dc($env{'request.role.domain'},$showcredits));
1.393 raeburn 1586: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1587: '<br /><input type="button" value="'.&mt('Save').'" onclick="setCourse()" />'."\n");
1.218 raeburn 1588: } elsif ($context eq 'author') {
1589: if ($addrolesdisplay) {
1.393 raeburn 1590: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1591: '<br /><input type="button" value="'.&mt('Save').'"');
1.218 raeburn 1592: if ($newuser) {
1.301 bisitz 1593: $r->print(' onclick="auth_check()" \>'."\n");
1.218 raeburn 1594: } else {
1.301 bisitz 1595: $r->print('onclick="this.form.submit()" \>'."\n");
1.218 raeburn 1596: }
1.188 raeburn 1597: } else {
1.393 raeburn 1598: $r->print('</fieldset></div>'.
1599: '<div class="LC_clear_float_footer"></div>'.
1600: '<br /><a href="javascript:backPage(document.cu)">'.
1.218 raeburn 1601: &mt('Back to previous page').'</a>');
1.188 raeburn 1602: }
1603: } else {
1.375 raeburn 1604: $r->print(&course_level_table(\%inccourses,$showcredits,$defaultcredits));
1.393 raeburn 1605: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1606: '<br /><input type="button" value="'.&mt('Save').'" onclick="setSections(this.form)" />'."\n");
1.188 raeburn 1607: }
1.88 raeburn 1608: }
1.188 raeburn 1609: $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','userrole','ccdomain','prevphase','currstate','ccuname','ccdomain']));
1.179 raeburn 1610: $r->print('<input type="hidden" name="currstate" value="" />');
1.393 raeburn 1611: $r->print('<input type="hidden" name="prevphase" value="'.$env{'form.phase'}.'" /></form><br /><br />');
1.218 raeburn 1612: return;
1.2 www 1613: }
1.1 www 1614:
1.213 raeburn 1615: sub singleuser_breadcrumb {
1.406.2.7 raeburn 1616: my ($crstype,$context,$domain) = @_;
1.213 raeburn 1617: my %breadcrumb_text;
1618: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1619: if ($crstype eq 'Community') {
1620: $breadcrumb_text{'search'} = 'Enroll a member';
1621: } else {
1622: $breadcrumb_text{'search'} = 'Enroll a student';
1623: }
1.406.2.7 raeburn 1624: $breadcrumb_text{'userpicked'} = 'Select a user';
1625: $breadcrumb_text{'modify'} = 'Set section/dates';
1.406.2.5 raeburn 1626: } elsif ($env{'form.action'} eq 'accesslogs') {
1627: $breadcrumb_text{'search'} = 'View access logs for a user';
1.406.2.7 raeburn 1628: $breadcrumb_text{'userpicked'} = 'Select a user';
1629: $breadcrumb_text{'activity'} = 'Activity';
1630: } elsif (($env{'form.action'} eq 'singleuser') && ($context eq 'domain') &&
1631: (!&Apache::lonnet::allowed('mau',$domain))) {
1632: $breadcrumb_text{'search'} = "View user's roles";
1633: $breadcrumb_text{'userpicked'} = 'Select a user';
1634: $breadcrumb_text{'modify'} = 'User roles';
1.213 raeburn 1635: } else {
1.229 raeburn 1636: $breadcrumb_text{'search'} = 'Create/modify a user';
1.406.2.7 raeburn 1637: $breadcrumb_text{'userpicked'} = 'Select a user';
1638: $breadcrumb_text{'modify'} = 'Set user role';
1.213 raeburn 1639: }
1640: return %breadcrumb_text;
1641: }
1642:
1643: sub date_sections_select {
1.375 raeburn 1644: my ($context,$newuser,$formname,$permission,$crstype,$ccuname,$ccdomain,
1645: $showcredits) = @_;
1646: my $credits;
1647: if ($showcredits) {
1648: my $defaultcredits = &Apache::lonuserutils::get_defaultcredits();
1649: $credits = &get_user_credits($ccuname,$ccdomain,$defaultcredits);
1650: if ($credits eq '') {
1651: $credits = $defaultcredits;
1652: }
1653: }
1.213 raeburn 1654: my $cid = $env{'request.course.id'};
1655: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity($cid);
1656: my $date_table = '<h3>'.&mt('Starting and Ending Dates').'</h3>'."\n".
1657: &Apache::lonuserutils::date_setting_table(undef,undef,$context,
1658: undef,$formname,$permission);
1659: my $rowtitle = 'Section';
1.375 raeburn 1660: my $secbox = '<h3>'.&mt('Section and Credits').'</h3>'."\n".
1.213 raeburn 1661: &Apache::lonuserutils::section_picker($cdom,$cnum,'st',$rowtitle,
1.375 raeburn 1662: $permission,$context,'',$crstype,
1663: $showcredits,$credits);
1.213 raeburn 1664: my $output = $date_table.$secbox;
1665: return $output;
1666: }
1667:
1.216 raeburn 1668: sub validation_javascript {
1.375 raeburn 1669: my ($context,$ccdomain,$pjump_def,$crstype,$groupslist,$newuser,$formname,
1.216 raeburn 1670: $loaditem) = @_;
1671: my $dc_setcourse_code = '';
1672: my $nondc_setsection_code = '';
1673: if ($context eq 'domain') {
1674: my $dcdom = $env{'request.role.domain'};
1675: $loaditem->{'onload'} = "document.cu.coursedesc.value='';";
1.227 raeburn 1676: $dc_setcourse_code =
1677: &Apache::lonuserutils::dc_setcourse_js('cu','singleuser',$context);
1.216 raeburn 1678: } else {
1.227 raeburn 1679: my $checkauth;
1680: if (($newuser) || (&Apache::lonnet::allowed('mau',$ccdomain))) {
1681: $checkauth = 1;
1682: }
1683: if ($context eq 'course') {
1684: $nondc_setsection_code =
1685: &Apache::lonuserutils::setsections_javascript($formname,$groupslist,
1.375 raeburn 1686: undef,$checkauth,
1687: $crstype);
1.227 raeburn 1688: }
1689: if ($checkauth) {
1690: $nondc_setsection_code .=
1691: &Apache::lonuserutils::verify_authen($formname,$context);
1692: }
1.216 raeburn 1693: }
1694: my $js = &user_modification_js($pjump_def,$dc_setcourse_code,
1695: $nondc_setsection_code,$groupslist);
1696: my ($jsback,$elements) = &crumb_utilities();
1697: $js .= "\n".
1.301 bisitz 1698: '<script type="text/javascript">'."\n".
1699: '// <![CDATA['."\n".
1700: $jsback."\n".
1701: '// ]]>'."\n".
1702: '</script>'."\n";
1.216 raeburn 1703: return $js;
1704: }
1705:
1.217 raeburn 1706: sub display_existing_roles {
1.375 raeburn 1707: my ($r,$ccuname,$ccdomain,$inccourses,$context,$roledom,$crstype,
1.406.2.6 raeburn 1708: $showcredits,$statuses) = @_;
1.329 raeburn 1709: my $now=time;
1.406.2.6 raeburn 1710: my $showall = 1;
1711: my ($showexpired,$showactive);
1712: if ((ref($statuses) eq 'ARRAY') && (@{$statuses} > 0)) {
1713: $showall = 0;
1714: if (grep(/^expired$/,@{$statuses})) {
1715: $showexpired = 1;
1716: }
1717: if (grep(/^active$/,@{$statuses})) {
1718: $showactive = 1;
1719: }
1720: if ($showexpired && $showactive) {
1721: $showall = 1;
1722: }
1723: }
1.329 raeburn 1724: my %lt=&Apache::lonlocal::texthash(
1.217 raeburn 1725: 'rer' => "Existing Roles",
1726: 'rev' => "Revoke",
1727: 'del' => "Delete",
1728: 'ren' => "Re-Enable",
1729: 'rol' => "Role",
1730: 'ext' => "Extent",
1.375 raeburn 1731: 'crd' => "Credits",
1.217 raeburn 1732: 'sta' => "Start",
1733: 'end' => "End",
1734: );
1.329 raeburn 1735: my (%rolesdump,%roletext,%sortrole,%roleclass,%rolepriv);
1736: if ($context eq 'course' || $context eq 'author') {
1737: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
1738: my %roleshash =
1739: &Apache::lonnet::get_my_roles($ccuname,$ccdomain,'userroles',
1740: ['active','previous','future'],\@roles,$roledom,1);
1741: foreach my $key (keys(%roleshash)) {
1742: my ($start,$end) = split(':',$roleshash{$key});
1743: next if ($start eq '-1' || $end eq '-1');
1744: my ($rnum,$rdom,$role,$sec) = split(':',$key);
1745: if ($context eq 'course') {
1746: next unless (($rnum eq $env{'course.'.$env{'request.course.id'}.'.num'})
1747: && ($rdom eq $env{'course.'.$env{'request.course.id'}.'.domain'}));
1748: } elsif ($context eq 'author') {
1749: next unless (($rnum eq $env{'user.name'}) && ($rdom eq $env{'request.role.domain'}));
1750: }
1751: my ($newkey,$newvalue,$newrole);
1752: $newkey = '/'.$rdom.'/'.$rnum;
1753: if ($sec ne '') {
1754: $newkey .= '/'.$sec;
1755: }
1756: $newvalue = $role;
1757: if ($role =~ /^cr/) {
1758: $newrole = 'cr';
1759: } else {
1760: $newrole = $role;
1761: }
1762: $newkey .= '_'.$newrole;
1763: if ($start ne '' && $end ne '') {
1764: $newvalue .= '_'.$end.'_'.$start;
1.335 raeburn 1765: } elsif ($end ne '') {
1766: $newvalue .= '_'.$end;
1.329 raeburn 1767: }
1768: $rolesdump{$newkey} = $newvalue;
1769: }
1770: } else {
1.360 raeburn 1771: %rolesdump=&Apache::lonnet::dump('roles',$ccdomain,$ccuname);
1.329 raeburn 1772: }
1773: # Build up table of user roles to allow revocation and re-enabling of roles.
1774: my ($tmp) = keys(%rolesdump);
1775: return if ($tmp =~ /^(con_lost|error)/i);
1776: foreach my $area (sort { my $a1=join('_',(split('_',$a))[1,0]);
1777: my $b1=join('_',(split('_',$b))[1,0]);
1778: return $a1 cmp $b1;
1779: } keys(%rolesdump)) {
1780: next if ($area =~ /^rolesdef/);
1781: my $envkey=$area;
1782: my $role = $rolesdump{$area};
1783: my $thisrole=$area;
1784: $area =~ s/\_\w\w$//;
1785: my ($role_code,$role_end_time,$role_start_time) =
1786: split(/_/,$role);
1.406.2.6 raeburn 1787: my $active=1;
1788: $active=0 if (($role_end_time) && ($now>$role_end_time));
1789: if ($active) {
1790: next unless($showall || $showactive);
1791: } else {
1792: next unless($showall || $showexpired);
1793: }
1.217 raeburn 1794: # Is this a custom role? Get role owner and title.
1.329 raeburn 1795: my ($croleudom,$croleuname,$croletitle)=
1796: ($role_code=~m{^cr/($match_domain)/($match_username)/(\w+)$});
1797: my $allowed=0;
1798: my $delallowed=0;
1799: my $sortkey=$role_code;
1800: my $class='Unknown';
1.375 raeburn 1801: my $credits='';
1.406.2.6 raeburn 1802: my $csec;
1.406.2.7 raeburn 1803: if ($area =~ m{^/($match_domain)/($match_courseid)}) {
1.329 raeburn 1804: $class='Course';
1805: my ($coursedom,$coursedir) = ($1,$2);
1806: my $cid = $1.'_'.$2;
1807: # $1.'_'.$2 is the course id (eg. 103_12345abcef103l3).
1.406.2.7 raeburn 1808: next if ($envkey =~ m{^/$match_domain/$match_courseid/[A-Za-z0-9]+_gr$});
1.329 raeburn 1809: my %coursedata=
1810: &Apache::lonnet::coursedescription($cid);
1811: if ($coursedir =~ /^$match_community$/) {
1812: $class='Community';
1813: }
1814: $sortkey.="\0$coursedom";
1815: my $carea;
1816: if (defined($coursedata{'description'})) {
1817: $carea=$coursedata{'description'}.
1818: '<br />'.&mt('Domain').': '.$coursedom.(' 'x8).
1819: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$coursedir,$coursedom);
1820: $sortkey.="\0".$coursedata{'description'};
1821: } else {
1822: if ($class eq 'Community') {
1823: $carea=&mt('Unavailable community').': '.$area;
1824: $sortkey.="\0".&mt('Unavailable community').': '.$area;
1.217 raeburn 1825: } else {
1826: $carea=&mt('Unavailable course').': '.$area;
1827: $sortkey.="\0".&mt('Unavailable course').': '.$area;
1828: }
1.329 raeburn 1829: }
1830: $sortkey.="\0$coursedir";
1831: $inccourses->{$cid}=1;
1.375 raeburn 1832: if (($showcredits) && ($class eq 'Course') && ($role_code eq 'st')) {
1833: my $defaultcredits = $coursedata{'internal.defaultcredits'};
1834: $credits =
1835: &get_user_credits($ccuname,$ccdomain,$defaultcredits,
1836: $coursedom,$coursedir);
1837: if ($credits eq '') {
1838: $credits = $defaultcredits;
1839: }
1840: }
1.329 raeburn 1841: if ((&Apache::lonnet::allowed('c'.$role_code,$coursedom.'/'.$coursedir)) ||
1842: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
1843: $allowed=1;
1844: }
1845: unless ($allowed) {
1.365 raeburn 1846: my $isowner = &Apache::lonuserutils::is_courseowner($cid,$coursedata{'internal.courseowner'});
1.329 raeburn 1847: if ($isowner) {
1848: if (($role_code eq 'co') && ($class eq 'Community')) {
1849: $allowed = 1;
1850: } elsif (($role_code eq 'cc') && ($class eq 'Course')) {
1851: $allowed = 1;
1852: }
1.217 raeburn 1853: }
1.329 raeburn 1854: }
1855: if ((&Apache::lonnet::allowed('dro',$coursedom)) ||
1856: (&Apache::lonnet::allowed('dro',$ccdomain))) {
1857: $delallowed=1;
1858: }
1.217 raeburn 1859: # - custom role. Needs more info, too
1.329 raeburn 1860: if ($croletitle) {
1861: if (&Apache::lonnet::allowed('ccr',$coursedom.'/'.$coursedir)) {
1862: $allowed=1;
1863: $thisrole.='.'.$role_code;
1.217 raeburn 1864: }
1.329 raeburn 1865: }
1.406.2.6 raeburn 1866: if ($area=~m{^/($match_domain/$match_courseid/(\w+))}) {
1867: $csec = $2;
1868: $carea.='<br />'.&mt('Section: [_1]',$csec);
1869: $sortkey.="\0$csec";
1.329 raeburn 1870: if (!$allowed) {
1.406.2.6 raeburn 1871: if ($env{'request.course.sec'} eq $csec) {
1872: if (&Apache::lonnet::allowed('c'.$role_code,$1)) {
1.329 raeburn 1873: $allowed = 1;
1.217 raeburn 1874: }
1875: }
1876: }
1.329 raeburn 1877: }
1878: $area=$carea;
1879: } else {
1880: $sortkey.="\0".$area;
1881: # Determine if current user is able to revoke privileges
1882: if ($area=~m{^/($match_domain)/}) {
1883: if ((&Apache::lonnet::allowed('c'.$role_code,$1)) ||
1884: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
1885: $allowed=1;
1.217 raeburn 1886: }
1.329 raeburn 1887: if (((&Apache::lonnet::allowed('dro',$1)) ||
1888: (&Apache::lonnet::allowed('dro',$ccdomain))) &&
1889: ($role_code ne 'dc')) {
1890: $delallowed=1;
1.217 raeburn 1891: }
1.329 raeburn 1892: } else {
1893: if (&Apache::lonnet::allowed('c'.$role_code,'/')) {
1.217 raeburn 1894: $allowed=1;
1895: }
1896: }
1.363 raeburn 1897: if ($role_code eq 'ca' || $role_code eq 'au' || $role_code eq 'aa') {
1.377 raeburn 1898: $class='Authoring Space';
1.329 raeburn 1899: } elsif ($role_code eq 'su') {
1900: $class='System';
1.217 raeburn 1901: } else {
1.329 raeburn 1902: $class='Domain';
1.217 raeburn 1903: }
1.329 raeburn 1904: }
1905: if (($role_code eq 'ca') || ($role_code eq 'aa')) {
1906: $area=~m{/($match_domain)/($match_username)};
1907: if (&Apache::lonuserutils::authorpriv($2,$1)) {
1908: $allowed=1;
1.217 raeburn 1909: } else {
1.329 raeburn 1910: $allowed=0;
1.217 raeburn 1911: }
1.329 raeburn 1912: }
1913: my $row = '';
1.406.2.6 raeburn 1914: if ($showall) {
1915: $row.= '<td>';
1916: if (($active) && ($allowed)) {
1917: $row.= '<input type="checkbox" name="rev:'.$thisrole.'" />';
1.217 raeburn 1918: } else {
1.406.2.6 raeburn 1919: if ($active) {
1920: $row.=' ';
1921: } else {
1922: $row.=&mt('expired or revoked');
1923: }
1.217 raeburn 1924: }
1.406.2.6 raeburn 1925: $row.='</td><td>';
1926: if ($allowed && !$active) {
1927: $row.= '<input type="checkbox" name="ren:'.$thisrole.'" />';
1928: } else {
1929: $row.=' ';
1930: }
1931: $row.='</td><td>';
1932: if ($delallowed) {
1933: $row.= '<input type="checkbox" name="del:'.$thisrole.'" />';
1934: } else {
1935: $row.=' ';
1936: }
1937: $row.= '</td>';
1.329 raeburn 1938: }
1939: my $plaintext='';
1940: if (!$croletitle) {
1.375 raeburn 1941: $plaintext=&Apache::lonnet::plaintext($role_code,$class);
1942: if (($showcredits) && ($credits ne '')) {
1943: $plaintext .= '<br/ ><span class="LC_nobreak">'.
1944: '<span class="LC_fontsize_small">'.
1945: &mt('Credits: [_1]',$credits).
1946: '</span></span>';
1947: }
1.329 raeburn 1948: } else {
1949: $plaintext=
1.395 bisitz 1950: &mt('Custom role [_1][_2]defined by [_3]',
1.346 bisitz 1951: '"'.$croletitle.'"',
1952: '<br />',
1953: $croleuname.':'.$croleudom);
1.329 raeburn 1954: }
1.406.2.6 raeburn 1955: $row.= '<td>'.$plaintext.'</td>'.
1956: '<td>'.$area.'</td>'.
1957: '<td>'.($role_start_time?&Apache::lonlocal::locallocaltime($role_start_time)
1958: : ' ' ).'</td>'.
1959: '<td>'.($role_end_time ?&Apache::lonlocal::locallocaltime($role_end_time)
1960: : ' ' ).'</td>';
1.329 raeburn 1961: $sortrole{$sortkey}=$envkey;
1962: $roletext{$envkey}=$row;
1963: $roleclass{$envkey}=$class;
1.406.2.6 raeburn 1964: if ($allowed) {
1965: $rolepriv{$envkey}='edit';
1966: } else {
1967: if ($context eq 'domain') {
1.406.2.7 raeburn 1968: if ((&Apache::lonnet::allowed('vur',$ccdomain)) &&
1969: ($envkey=~m{^/$ccdomain/})) {
1.406.2.6 raeburn 1970: $rolepriv{$envkey}='view';
1971: }
1972: } elsif ($context eq 'course') {
1973: if ((&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) ||
1974: ($env{'request.course.sec'} && ($env{'request.course.sec'} eq $csec) &&
1975: &Apache::lonnet::allowed('vcl',$env{'request.course.id'}.'/'.$env{'request.course.sec'}))) {
1976: $rolepriv{$envkey}='view';
1977: }
1978: }
1979: }
1.329 raeburn 1980: } # end of foreach (table building loop)
1981:
1982: my $rolesdisplay = 0;
1983: my %output = ();
1.377 raeburn 1984: foreach my $type ('Authoring Space','Course','Community','Domain','System','Unknown') {
1.329 raeburn 1985: $output{$type} = '';
1986: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
1987: if ( ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/ ) && ($rolepriv{$sortrole{$which}}) ) {
1988: $output{$type}.=
1989: &Apache::loncommon::start_data_table_row().
1990: $roletext{$sortrole{$which}}.
1991: &Apache::loncommon::end_data_table_row();
1.217 raeburn 1992: }
1.329 raeburn 1993: }
1994: unless($output{$type} eq '') {
1995: $output{$type} = '<tr class="LC_info_row">'.
1996: "<td align='center' colspan='7'>".&mt($type)."</td></tr>".
1997: $output{$type};
1998: $rolesdisplay = 1;
1999: }
2000: }
2001: if ($rolesdisplay == 1) {
2002: my $contextrole='';
2003: if ($env{'request.course.id'}) {
2004: if (&Apache::loncommon::course_type() eq 'Community') {
2005: $contextrole = &mt('Existing Roles in this Community');
1.290 bisitz 2006: } else {
1.329 raeburn 2007: $contextrole = &mt('Existing Roles in this Course');
1.290 bisitz 2008: }
1.329 raeburn 2009: } elsif ($env{'request.role'} =~ /^au\./) {
1.377 raeburn 2010: $contextrole = &mt('Existing Co-Author Roles in your Authoring Space');
1.329 raeburn 2011: } else {
1.406.2.6 raeburn 2012: if ($showall) {
2013: $contextrole = &mt('Existing Roles in this Domain');
2014: } elsif ($showactive) {
2015: $contextrole = &mt('Unexpired Roles in this Domain');
2016: } elsif ($showexpired) {
2017: $contextrole = &mt('Expired or Revoked Roles in this Domain');
2018: }
1.329 raeburn 2019: }
1.393 raeburn 2020: $r->print('<div class="LC_left_float">'.
1.375 raeburn 2021: '<fieldset><legend>'.$contextrole.'</legend>'.
1.217 raeburn 2022: &Apache::loncommon::start_data_table("LC_createuser").
1.406.2.6 raeburn 2023: &Apache::loncommon::start_data_table_header_row());
2024: if ($showall) {
2025: $r->print(
2026: '<th>'.$lt{'rev'}.'</th><th>'.$lt{'ren'}.'</th><th>'.$lt{'del'}.'</th>'
2027: );
2028: } elsif ($showexpired) {
2029: $r->print('<th>'.$lt{'rev'}.'</th>');
2030: }
2031: $r->print(
2032: '<th>'.$lt{'rol'}.'</th><th>'.$lt{'ext'}.'</th>'.
2033: '<th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
1.217 raeburn 2034: &Apache::loncommon::end_data_table_header_row());
1.377 raeburn 2035: foreach my $type ('Authoring Space','Course','Community','Domain','System','Unknown') {
1.329 raeburn 2036: if ($output{$type}) {
2037: $r->print($output{$type}."\n");
1.217 raeburn 2038: }
2039: }
1.375 raeburn 2040: $r->print(&Apache::loncommon::end_data_table().
2041: '</fieldset></div>');
1.329 raeburn 2042: }
1.217 raeburn 2043: return;
2044: }
2045:
1.218 raeburn 2046: sub new_coauthor_roles {
2047: my ($r,$ccuname,$ccdomain) = @_;
2048: my $addrolesdisplay = 0;
2049: #
2050: # Co-Author
2051: #
2052: if (&Apache::lonuserutils::authorpriv($env{'user.name'},
2053: $env{'request.role.domain'}) &&
2054: ($env{'user.name'} ne $ccuname || $env{'user.domain'} ne $ccdomain)) {
2055: # No sense in assigning co-author role to yourself
2056: $addrolesdisplay = 1;
2057: my $cuname=$env{'user.name'};
2058: my $cudom=$env{'request.role.domain'};
2059: my %lt=&Apache::lonlocal::texthash(
1.377 raeburn 2060: 'cs' => "Authoring Space",
1.218 raeburn 2061: 'act' => "Activate",
2062: 'rol' => "Role",
2063: 'ext' => "Extent",
2064: 'sta' => "Start",
2065: 'end' => "End",
2066: 'cau' => "Co-Author",
2067: 'caa' => "Assistant Co-Author",
2068: 'ssd' => "Set Start Date",
2069: 'sed' => "Set End Date"
2070: );
2071: $r->print('<h4>'.$lt{'cs'}.'</h4>'."\n".
2072: &Apache::loncommon::start_data_table()."\n".
2073: &Apache::loncommon::start_data_table_header_row()."\n".
2074: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'.
2075: '<th>'.$lt{'ext'}.'</th><th>'.$lt{'sta'}.'</th>'.
2076: '<th>'.$lt{'end'}.'</th>'."\n".
2077: &Apache::loncommon::end_data_table_header_row()."\n".
2078: &Apache::loncommon::start_data_table_row().'
2079: <td>
1.291 bisitz 2080: <input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_ca" />
1.218 raeburn 2081: </td>
2082: <td>'.$lt{'cau'}.'</td>
2083: <td>'.$cudom.'_'.$cuname.'</td>
2084: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_ca" value="" />
2085: <a href=
2086: "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>
2087: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_ca" value="" />
2088: <a href=
2089: "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".
2090: &Apache::loncommon::end_data_table_row()."\n".
2091: &Apache::loncommon::start_data_table_row()."\n".
1.291 bisitz 2092: '<td><input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_aa" /></td>
1.218 raeburn 2093: <td>'.$lt{'caa'}.'</td>
2094: <td>'.$cudom.'_'.$cuname.'</td>
2095: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_aa" value="" />
2096: <a href=
2097: "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>
2098: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_aa" value="" />
2099: <a href=
2100: "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".
2101: &Apache::loncommon::end_data_table_row()."\n".
2102: &Apache::loncommon::end_data_table());
2103: } elsif ($env{'request.role'} =~ /^au\./) {
2104: if (!(&Apache::lonuserutils::authorpriv($env{'user.name'},
2105: $env{'request.role.domain'}))) {
2106: $r->print('<span class="LC_error">'.
2107: &mt('You do not have privileges to assign co-author roles.').
2108: '</span>');
2109: } elsif (($env{'user.name'} eq $ccuname) &&
2110: ($env{'user.domain'} eq $ccdomain)) {
1.377 raeburn 2111: $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 2112: }
2113: }
2114: return $addrolesdisplay;;
2115: }
2116:
2117: sub new_domain_roles {
1.357 raeburn 2118: my ($r,$ccdomain) = @_;
1.218 raeburn 2119: my $addrolesdisplay = 0;
2120: #
2121: # Domain level
2122: #
2123: my $num_domain_level = 0;
2124: my $domaintext =
2125: '<h4>'.&mt('Domain Level').'</h4>'.
2126: &Apache::loncommon::start_data_table().
2127: &Apache::loncommon::start_data_table_header_row().
2128: '<th>'.&mt('Activate').'</th><th>'.&mt('Role').'</th><th>'.
2129: &mt('Extent').'</th>'.
2130: '<th>'.&mt('Start').'</th><th>'.&mt('End').'</th>'.
2131: &Apache::loncommon::end_data_table_header_row();
1.312 raeburn 2132: my @allroles = &Apache::lonuserutils::roles_by_context('domain');
1.218 raeburn 2133: foreach my $thisdomain (sort(&Apache::lonnet::all_domains())) {
1.312 raeburn 2134: foreach my $role (@allroles) {
2135: next if ($role eq 'ad');
1.357 raeburn 2136: next if (($role eq 'au') && ($ccdomain ne $thisdomain));
1.218 raeburn 2137: if (&Apache::lonnet::allowed('c'.$role,$thisdomain)) {
2138: my $plrole=&Apache::lonnet::plaintext($role);
2139: my %lt=&Apache::lonlocal::texthash(
2140: 'ssd' => "Set Start Date",
2141: 'sed' => "Set End Date"
2142: );
2143: $num_domain_level ++;
2144: $domaintext .=
2145: &Apache::loncommon::start_data_table_row().
1.291 bisitz 2146: '<td><input type="checkbox" name="act_'.$thisdomain.'_'.$role.'" /></td>
1.218 raeburn 2147: <td>'.$plrole.'</td>
2148: <td>'.$thisdomain.'</td>
2149: <td><input type="hidden" name="start_'.$thisdomain.'_'.$role.'" value="" />
2150: <a href=
2151: "javascript:pjump('."'date_start','Start Date $plrole',document.cu.start_$thisdomain\_$role.value,'start_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'ssd'}.'</a></td>
2152: <td><input type="hidden" name="end_'.$thisdomain.'_'.$role.'" value="" />
2153: <a href=
2154: "javascript:pjump('."'date_end','End Date $plrole',document.cu.end_$thisdomain\_$role.value,'end_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'sed'}.'</a></td>'.
2155: &Apache::loncommon::end_data_table_row();
2156: }
2157: }
2158: }
2159: $domaintext.= &Apache::loncommon::end_data_table();
2160: if ($num_domain_level > 0) {
2161: $r->print($domaintext);
2162: $addrolesdisplay = 1;
2163: }
2164: return $addrolesdisplay;
2165: }
2166:
1.188 raeburn 2167: sub user_authentication {
1.406.2.17 raeburn 2168: my ($ccuname,$ccdomain,$formname,$crstype,$permission) = @_;
1.188 raeburn 2169: my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
1.227 raeburn 2170: my $outcome;
1.406.2.6 raeburn 2171: my %lt=&Apache::lonlocal::texthash(
2172: 'err' => "ERROR",
2173: 'uuas' => "This user has an unrecognized authentication scheme",
2174: 'adcs' => "Please alert a domain coordinator of this situation",
2175: 'sldb' => "Please specify login data below",
2176: 'ld' => "Login Data"
2177: );
1.188 raeburn 2178: # Check for a bad authentication type
2179: if ($currentauth !~ /^(krb4|krb5|unix|internal|localauth):/) {
2180: # bad authentication scheme
2181: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
1.227 raeburn 2182: &initialize_authen_forms($ccdomain,$formname);
2183:
1.190 raeburn 2184: my $choices = &Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc);
1.188 raeburn 2185: $outcome = <<ENDBADAUTH;
2186: <script type="text/javascript" language="Javascript">
1.301 bisitz 2187: // <![CDATA[
1.188 raeburn 2188: $loginscript
1.301 bisitz 2189: // ]]>
1.188 raeburn 2190: </script>
2191: <span class="LC_error">$lt{'err'}:
2192: $lt{'uuas'} ($currentauth). $lt{'sldb'}.</span>
2193: <h3>$lt{'ld'}</h3>
2194: $choices
2195: ENDBADAUTH
2196: } else {
2197: # This user is not allowed to modify the user's
2198: # authentication scheme, so just notify them of the problem
2199: $outcome = <<ENDBADAUTH;
2200: <span class="LC_error"> $lt{'err'}:
2201: $lt{'uuas'} ($currentauth). $lt{'adcs'}.
2202: </span>
2203: ENDBADAUTH
2204: }
2205: } else { # Authentication type is valid
1.227 raeburn 2206: &initialize_authen_forms($ccdomain,$formname,$currentauth,'modifyuser');
1.205 raeburn 2207: my ($authformcurrent,$can_modify,@authform_others) =
1.188 raeburn 2208: &modify_login_block($ccdomain,$currentauth);
2209: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
2210: # Current user has login modification privileges
2211: $outcome =
2212: '<script type="text/javascript" language="Javascript">'."\n".
1.301 bisitz 2213: '// <![CDATA['."\n".
1.188 raeburn 2214: $loginscript."\n".
1.301 bisitz 2215: '// ]]>'."\n".
1.188 raeburn 2216: '</script>'."\n".
2217: '<h3>'.$lt{'ld'}.'</h3>'.
2218: &Apache::loncommon::start_data_table().
1.205 raeburn 2219: &Apache::loncommon::start_data_table_row().
1.188 raeburn 2220: '<td>'.$authformnop;
1.406.2.6 raeburn 2221: if (($can_modify) && (&Apache::lonnet::allowed('mau',$ccdomain))) {
1.188 raeburn 2222: $outcome .= '</td>'."\n".
2223: &Apache::loncommon::end_data_table_row().
2224: &Apache::loncommon::start_data_table_row().
2225: '<td>'.$authformcurrent.'</td>'.
2226: &Apache::loncommon::end_data_table_row()."\n";
2227: } else {
1.200 raeburn 2228: $outcome .= ' ('.$authformcurrent.')</td>'.
2229: &Apache::loncommon::end_data_table_row()."\n";
1.188 raeburn 2230: }
1.406.2.6 raeburn 2231: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
2232: foreach my $item (@authform_others) {
2233: $outcome .= &Apache::loncommon::start_data_table_row().
2234: '<td>'.$item.'</td>'.
2235: &Apache::loncommon::end_data_table_row()."\n";
2236: }
1.188 raeburn 2237: }
1.205 raeburn 2238: $outcome .= &Apache::loncommon::end_data_table();
1.188 raeburn 2239: } else {
1.406.2.17 raeburn 2240: if (($currentauth =~ /^internal:/) &&
2241: (&Apache::lonuserutils::can_change_internalpass($ccuname,$ccdomain,$crstype,$permission))) {
2242: $outcome = <<"ENDJS";
2243: <script type="text/javascript">
2244: // <![CDATA[
2245: function togglePwd(form) {
2246: if (form.newintpwd.length) {
2247: if (document.getElementById('LC_ownersetpwd')) {
2248: for (var i=0; i<form.newintpwd.length; i++) {
2249: if (form.newintpwd[i].checked) {
2250: if (form.newintpwd[i].value == 1) {
2251: document.getElementById('LC_ownersetpwd').style.display = 'inline-block';
2252: } else {
2253: document.getElementById('LC_ownersetpwd').style.display = 'none';
2254: }
2255: }
2256: }
2257: }
2258: }
2259: }
2260: // ]]>
2261: </script>
2262: ENDJS
2263:
2264: $outcome .= '<h3>'.$lt{'ld'}.'</h3>'.
2265: &Apache::loncommon::start_data_table().
2266: &Apache::loncommon::start_data_table_row().
2267: '<td>'.&mt('Internally authenticated').'<br />'.&mt("Change user's password?").
2268: '<label><input type="radio" name="newintpwd" value="0" checked="checked" onclick="togglePwd(this.form);" />'.
2269: &mt('No').'</label>'.(' 'x2).
2270: '<label><input type="radio" name="newintpwd" value="1" onclick="togglePwd(this.form);" />'.&mt('Yes').'</label>'.
2271: '<div id="LC_ownersetpwd" style="display:none">'.
2272: ' '.&mt('Password').' <input type="password" size="15" name="intarg" value="" />'.
2273: '<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>'.
2274: &Apache::loncommon::end_data_table_row().
2275: &Apache::loncommon::end_data_table();
2276: }
1.406.2.6 raeburn 2277: if (&Apache::lonnet::allowed('udp',$ccdomain)) {
2278: # Current user has rights to view domain preferences for user's domain
2279: my $result;
2280: if ($currentauth =~ /^krb(4|5):([^:]*)$/) {
2281: my ($krbver,$krbrealm) = ($1,$2);
2282: if ($krbrealm eq '') {
2283: $result = &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2284: } else {
2285: $result = &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
1.406.2.9 raeburn 2286: $krbrealm,$krbver);
1.406.2.6 raeburn 2287: }
2288: } elsif ($currentauth =~ /^internal:/) {
2289: $result = &mt('Currently internally authenticated.');
2290: } elsif ($currentauth =~ /^localauth:/) {
2291: $result = &mt('Currently using local (institutional) authentication.');
2292: } elsif ($currentauth =~ /^unix:/) {
2293: $result = &mt('Currently Filesystem Authenticated.');
2294: }
2295: $outcome = '<h3>'.$lt{'ld'}.'</h3>'.
2296: &Apache::loncommon::start_data_table().
2297: &Apache::loncommon::start_data_table_row().
2298: '<td>'.$result.'</td>'.
2299: &Apache::loncommon::end_data_table_row()."\n".
2300: &Apache::loncommon::end_data_table();
2301: } elsif (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
1.188 raeburn 2302: my %lt=&Apache::lonlocal::texthash(
2303: 'ccld' => "Change Current Login Data",
2304: 'yodo' => "You do not have privileges to modify the authentication configuration for this user.",
2305: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
2306: );
2307: $outcome .= <<ENDNOPRIV;
2308: <h3>$lt{'ccld'}</h3>
2309: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1.235 raeburn 2310: <input type="hidden" name="login" value="nochange" />
1.188 raeburn 2311: ENDNOPRIV
2312: }
2313: }
2314: } ## End of "check for bad authentication type" logic
2315: return $outcome;
2316: }
2317:
1.187 raeburn 2318: sub modify_login_block {
2319: my ($dom,$currentauth) = @_;
2320: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2321: my ($authnum,%can_assign) =
2322: &Apache::loncommon::get_assignable_auth($dom);
1.205 raeburn 2323: my ($authformcurrent,@authform_others,$show_override_msg);
1.187 raeburn 2324: if ($currentauth=~/^krb(4|5):/) {
2325: $authformcurrent=$authformkrb;
2326: if ($can_assign{'int'}) {
1.205 raeburn 2327: push(@authform_others,$authformint);
1.187 raeburn 2328: }
2329: if ($can_assign{'loc'}) {
1.205 raeburn 2330: push(@authform_others,$authformloc);
1.187 raeburn 2331: }
2332: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
2333: $show_override_msg = 1;
2334: }
2335: } elsif ($currentauth=~/^internal:/) {
2336: $authformcurrent=$authformint;
2337: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2338: push(@authform_others,$authformkrb);
1.187 raeburn 2339: }
2340: if ($can_assign{'loc'}) {
1.205 raeburn 2341: push(@authform_others,$authformloc);
1.187 raeburn 2342: }
2343: if ($can_assign{'int'}) {
2344: $show_override_msg = 1;
2345: }
2346: } elsif ($currentauth=~/^unix:/) {
2347: $authformcurrent=$authformfsys;
2348: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2349: push(@authform_others,$authformkrb);
1.187 raeburn 2350: }
2351: if ($can_assign{'int'}) {
1.205 raeburn 2352: push(@authform_others,$authformint);
1.187 raeburn 2353: }
2354: if ($can_assign{'loc'}) {
1.205 raeburn 2355: push(@authform_others,$authformloc);
1.187 raeburn 2356: }
2357: if ($can_assign{'fsys'}) {
2358: $show_override_msg = 1;
2359: }
2360: } elsif ($currentauth=~/^localauth:/) {
2361: $authformcurrent=$authformloc;
2362: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2363: push(@authform_others,$authformkrb);
1.187 raeburn 2364: }
2365: if ($can_assign{'int'}) {
1.205 raeburn 2366: push(@authform_others,$authformint);
1.187 raeburn 2367: }
2368: if ($can_assign{'loc'}) {
2369: $show_override_msg = 1;
2370: }
2371: }
2372: if ($show_override_msg) {
1.205 raeburn 2373: $authformcurrent = '<table><tr><td colspan="3">'.$authformcurrent.
2374: '</td></tr>'."\n".
2375: '<tr><td> </td>'.
2376: '<td><b>'.&mt('Currently in use').'</b></td>'.
2377: '<td align="right"><span class="LC_cusr_emph">'.
1.187 raeburn 2378: &mt('will override current values').
1.205 raeburn 2379: '</span></td></tr></table>';
1.187 raeburn 2380: }
1.205 raeburn 2381: return ($authformcurrent,$show_override_msg,@authform_others);
1.187 raeburn 2382: }
2383:
1.188 raeburn 2384: sub personal_data_display {
1.406.2.20 raeburn 2385: my ($ccuname,$ccdomain,$newuser,$context,$inst_results,$rolesarray,$now,
2386: $captchaform,$emailusername,$usertype,$usernameset,$condition,$excluded,$showsubmit) = @_;
1.388 bisitz 2387: my ($output,%userenv,%canmodify,%canmodify_status);
1.219 raeburn 2388: my @userinfo = ('firstname','middlename','lastname','generation',
2389: 'permanentemail','id');
1.252 raeburn 2390: my $rowcount = 0;
2391: my $editable = 0;
1.391 raeburn 2392: my %textboxsize = (
2393: firstname => '15',
2394: middlename => '15',
2395: lastname => '15',
2396: generation => '5',
2397: permanentemail => '25',
2398: id => '15',
2399: );
2400:
2401: my %lt=&Apache::lonlocal::texthash(
2402: 'pd' => "Personal Data",
2403: 'firstname' => "First Name",
2404: 'middlename' => "Middle Name",
2405: 'lastname' => "Last Name",
2406: 'generation' => "Generation",
2407: 'permanentemail' => "Permanent e-mail address",
2408: 'id' => "Student/Employee ID",
2409: 'lg' => "Login Data",
2410: 'inststatus' => "Affiliation",
2411: 'email' => 'E-mail address',
2412: 'valid' => 'Validation',
1.406.2.16 raeburn 2413: 'username' => 'Username',
1.391 raeburn 2414: );
2415:
2416: %canmodify_status =
1.286 raeburn 2417: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
2418: ['inststatus'],$rolesarray);
1.253 raeburn 2419: if (!$newuser) {
1.188 raeburn 2420: # Get the users information
2421: %userenv = &Apache::lonnet::get('environment',
2422: ['firstname','middlename','lastname','generation',
1.286 raeburn 2423: 'permanentemail','id','inststatus'],$ccdomain,$ccuname);
1.219 raeburn 2424: %canmodify =
2425: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
1.252 raeburn 2426: \@userinfo,$rolesarray);
1.257 raeburn 2427: } elsif ($context eq 'selfcreate') {
1.391 raeburn 2428: if ($newuser eq 'email') {
1.396 raeburn 2429: if (ref($emailusername) eq 'HASH') {
2430: if (ref($emailusername->{$usertype}) eq 'HASH') {
2431: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.406.2.16 raeburn 2432: @userinfo = ();
1.396 raeburn 2433: if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
2434: foreach my $field (@{$infofields}) {
2435: if ($emailusername->{$usertype}->{$field}) {
2436: push(@userinfo,$field);
2437: $canmodify{$field} = 1;
2438: unless ($textboxsize{$field}) {
2439: $textboxsize{$field} = 25;
2440: }
2441: unless ($lt{$field}) {
2442: $lt{$field} = $infotitles->{$field};
2443: }
2444: if ($emailusername->{$usertype}->{$field} eq 'required') {
2445: $lt{$field} .= '<b>*</b>';
2446: }
1.391 raeburn 2447: }
2448: }
2449: }
2450: }
2451: }
2452: } else {
2453: %canmodify = &selfcreate_canmodify($context,$ccdomain,\@userinfo,
2454: $inst_results,$rolesarray);
2455: }
1.188 raeburn 2456: }
1.391 raeburn 2457:
1.188 raeburn 2458: my $genhelp=&Apache::loncommon::help_open_topic('Generation');
2459: $output = '<h3>'.$lt{'pd'}.'</h3>'.
2460: &Apache::lonhtmlcommon::start_pick_box();
1.391 raeburn 2461: if (($context eq 'selfcreate') && ($newuser eq 'email')) {
1.406.2.16 raeburn 2462: my $size = 25;
2463: if ($condition) {
2464: if ($condition =~ /^\@[^\@]+$/) {
2465: $size = 10;
2466: } else {
2467: undef($condition);
2468: }
2469: }
2470: if ($excluded) {
2471: unless ($excluded =~ /^\@[^\@]+$/) {
2472: undef($condition);
2473: }
2474: }
1.396 raeburn 2475: $output .= &Apache::lonhtmlcommon::row_title($lt{'email'}.'<b>*</b>',undef,
1.391 raeburn 2476: 'LC_oddrow_value')."\n".
1.406.2.16 raeburn 2477: '<input type="text" name="uname" size="'.$size.'" value="" autocomplete="off" />';
2478: if ($condition) {
2479: $output .= $condition;
2480: } elsif ($excluded) {
2481: $output .= '<br /><span style="font-size: smaller">'.&mt('You must use an e-mail address that does not end with [_1]',
2482: $excluded).'</span>';
2483: }
2484: if ($usernameset eq 'first') {
2485: $output .= '<br /><span style="font-size: smaller">';
2486: if ($condition) {
2487: $output .= &mt('Your username in LON-CAPA will be the part of your e-mail address before [_1]',
2488: $condition);
2489: } else {
2490: $output .= &mt('Your username in LON-CAPA will be the part of your e-mail address before the @');
2491: }
2492: $output .= '</span>';
2493: }
1.391 raeburn 2494: $rowcount ++;
2495: $output .= &Apache::lonhtmlcommon::row_closure(1);
1.406.2.1 raeburn 2496: my $upassone = '<input type="password" name="upass'.$now.'" size="20" autocomplete="off" />';
2497: my $upasstwo = '<input type="password" name="upasscheck'.$now.'" size="20" autocomplete="off" />';
1.396 raeburn 2498: $output .= &Apache::lonhtmlcommon::row_title(&mt('Password').'<b>*</b>',
1.391 raeburn 2499: 'LC_pick_box_title',
2500: 'LC_oddrow_value')."\n".
2501: $upassone."\n".
2502: &Apache::lonhtmlcommon::row_closure(1)."\n".
1.396 raeburn 2503: &Apache::lonhtmlcommon::row_title(&mt('Confirm password').'<b>*</b>',
1.391 raeburn 2504: 'LC_pick_box_title',
2505: 'LC_oddrow_value')."\n".
2506: $upasstwo.
2507: &Apache::lonhtmlcommon::row_closure()."\n";
1.406.2.16 raeburn 2508: if ($usernameset eq 'free') {
2509: my $onclick = "toggleUsernameDisp(this,'selfcreateusername');";
2510: $output .= &Apache::lonhtmlcommon::row_title($lt{'username'},undef,'LC_oddrow_value')."\n".
1.406.2.20 raeburn 2511: '<span class="LC_nobreak">'.&mt('Use e-mail address: ').
2512: '<label><input type="radio" name="emailused" value="1" checked="checked" onclick="'.$onclick.'" />'.
2513: &mt('Yes').'</label>'.(' 'x2).
2514: '<label><input type="radio" name="emailused" value="0" onclick="'.$onclick.'" />'.
2515: &mt('No').'</label></span>'."\n".
1.406.2.16 raeburn 2516: '<div id="selfcreateusername" style="display: none; font-size: smaller">'.
2517: '<br /><span class="LC_nobreak">'.&mt('Preferred username').
2518: ' <input type="text" name="username" value="" size="20" autocomplete="off"/>'.
2519: '</span></div>'."\n".&Apache::lonhtmlcommon::row_closure(1);
2520: $rowcount ++;
2521: }
1.391 raeburn 2522: }
1.188 raeburn 2523: foreach my $item (@userinfo) {
2524: my $rowtitle = $lt{$item};
1.252 raeburn 2525: my $hiderow = 0;
1.188 raeburn 2526: if ($item eq 'generation') {
2527: $rowtitle = $genhelp.$rowtitle;
2528: }
1.252 raeburn 2529: my $row = &Apache::lonhtmlcommon::row_title($rowtitle,undef,'LC_oddrow_value')."\n";
1.188 raeburn 2530: if ($newuser) {
1.210 raeburn 2531: if (ref($inst_results) eq 'HASH') {
2532: if ($inst_results->{$item} ne '') {
1.252 raeburn 2533: $row .= '<input type="hidden" name="c'.$item.'" value="'.$inst_results->{$item}.'" />'.$inst_results->{$item};
1.210 raeburn 2534: } else {
1.252 raeburn 2535: if ($context eq 'selfcreate') {
1.391 raeburn 2536: if ($canmodify{$item}) {
1.394 raeburn 2537: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.252 raeburn 2538: $editable ++;
2539: } else {
2540: $hiderow = 1;
2541: }
1.253 raeburn 2542: } else {
2543: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1.252 raeburn 2544: }
1.210 raeburn 2545: }
1.188 raeburn 2546: } else {
1.252 raeburn 2547: if ($context eq 'selfcreate') {
1.401 raeburn 2548: if ($canmodify{$item}) {
2549: if ($newuser eq 'email') {
2550: $row .= '<input type="text" name="'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.287 raeburn 2551: } else {
1.401 raeburn 2552: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.287 raeburn 2553: }
1.401 raeburn 2554: $editable ++;
2555: } else {
2556: $hiderow = 1;
1.252 raeburn 2557: }
1.253 raeburn 2558: } else {
2559: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1.252 raeburn 2560: }
1.188 raeburn 2561: }
2562: } else {
1.219 raeburn 2563: if ($canmodify{$item}) {
1.252 raeburn 2564: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="'.$userenv{$item}.'" />';
1.393 raeburn 2565: if (($item eq 'id') && (!$newuser)) {
2566: $row .= '<br />'.&Apache::lonuserutils::forceid_change($context);
2567: }
1.188 raeburn 2568: } else {
1.252 raeburn 2569: $row .= $userenv{$item};
1.188 raeburn 2570: }
2571: }
1.252 raeburn 2572: $row .= &Apache::lonhtmlcommon::row_closure(1);
2573: if (!$hiderow) {
2574: $output .= $row;
2575: $rowcount ++;
2576: }
1.188 raeburn 2577: }
1.286 raeburn 2578: if (($canmodify_status{'inststatus'}) || ($context ne 'selfcreate')) {
2579: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($ccdomain);
2580: if (ref($types) eq 'ARRAY') {
2581: if (@{$types} > 0) {
2582: my ($hiderow,$shown);
2583: if ($canmodify_status{'inststatus'}) {
2584: $shown = &pick_inst_statuses($userenv{'inststatus'},$usertypes,$types);
2585: } else {
2586: if ($userenv{'inststatus'} eq '') {
2587: $hiderow = 1;
1.334 raeburn 2588: } else {
2589: my @showitems;
2590: foreach my $item ( map { &unescape($_); } split(':',$userenv{'inststatus'})) {
2591: if (exists($usertypes->{$item})) {
2592: push(@showitems,$usertypes->{$item});
2593: } else {
2594: push(@showitems,$item);
2595: }
2596: }
2597: if (@showitems) {
2598: $shown = join(', ',@showitems);
2599: } else {
2600: $hiderow = 1;
2601: }
1.286 raeburn 2602: }
2603: }
2604: if (!$hiderow) {
1.389 bisitz 2605: my $row = &Apache::lonhtmlcommon::row_title(&mt('Affiliations'),undef,'LC_oddrow_value')."\n".
1.286 raeburn 2606: $shown.&Apache::lonhtmlcommon::row_closure(1);
2607: if ($context eq 'selfcreate') {
2608: $rowcount ++;
2609: }
2610: $output .= $row;
2611: }
2612: }
2613: }
2614: }
1.391 raeburn 2615: if (($context eq 'selfcreate') && ($newuser eq 'email')) {
2616: if ($captchaform) {
1.406.2.2 raeburn 2617: $output .= &Apache::lonhtmlcommon::row_title($lt{'valid'}.'*',
1.391 raeburn 2618: 'LC_pick_box_title')."\n".
2619: $captchaform."\n".'<br /><br />'.
2620: &Apache::lonhtmlcommon::row_closure(1);
2621: $rowcount ++;
2622: }
1.406.2.20 raeburn 2623: if ($showsubmit) {
2624: my $submit_text = &mt('Create account');
2625: $output .= &Apache::lonhtmlcommon::row_title()."\n".
2626: '<br /><input type="submit" name="createaccount" value="'.
2627: $submit_text.'" />';
2628: if ($usertype ne '') {
2629: $output .= '<input type="hidden" name="type" value="'.$usertype.'" />'.
2630: &Apache::lonhtmlcommon::row_closure(1);
2631: }
2632: }
1.391 raeburn 2633: }
1.188 raeburn 2634: $output .= &Apache::lonhtmlcommon::end_pick_box();
1.206 raeburn 2635: if (wantarray) {
1.252 raeburn 2636: if ($context eq 'selfcreate') {
2637: return($output,$rowcount,$editable);
2638: } else {
1.388 bisitz 2639: return $output;
1.252 raeburn 2640: }
1.206 raeburn 2641: } else {
2642: return $output;
2643: }
1.188 raeburn 2644: }
2645:
1.286 raeburn 2646: sub pick_inst_statuses {
2647: my ($curr,$usertypes,$types) = @_;
2648: my ($output,$rem,@currtypes);
2649: if ($curr ne '') {
2650: @currtypes = map { &unescape($_); } split(/:/,$curr);
2651: }
2652: my $numinrow = 2;
2653: if (ref($types) eq 'ARRAY') {
2654: $output = '<table>';
2655: my $lastcolspan;
2656: for (my $i=0; $i<@{$types}; $i++) {
2657: if (defined($usertypes->{$types->[$i]})) {
2658: my $rem = $i%($numinrow);
2659: if ($rem == 0) {
2660: if ($i<@{$types}-1) {
2661: if ($i > 0) {
2662: $output .= '</tr>';
2663: }
2664: $output .= '<tr>';
2665: }
2666: } elsif ($i==@{$types}-1) {
2667: my $colsleft = $numinrow - $rem;
2668: if ($colsleft > 1) {
2669: $lastcolspan = ' colspan="'.$colsleft.'"';
2670: }
2671: }
2672: my $check = ' ';
2673: if (grep(/^\Q$types->[$i]\E$/,@currtypes)) {
2674: $check = ' checked="checked" ';
2675: }
2676: $output .= '<td class="LC_left_item"'.$lastcolspan.'>'.
2677: '<span class="LC_nobreak"><label>'.
2678: '<input type="checkbox" name="inststatus" '.
2679: 'value="'.$types->[$i].'"'.$check.'/>'.
2680: $usertypes->{$types->[$i]}.'</label></span></td>';
2681: }
2682: }
2683: $output .= '</tr></table>';
2684: }
2685: return $output;
2686: }
2687:
1.257 raeburn 2688: sub selfcreate_canmodify {
2689: my ($context,$dom,$userinfo,$inst_results,$rolesarray) = @_;
2690: if (ref($inst_results) eq 'HASH') {
2691: my @inststatuses = &get_inststatuses($inst_results);
2692: if (@inststatuses == 0) {
2693: @inststatuses = ('default');
2694: }
2695: $rolesarray = \@inststatuses;
2696: }
2697: my %canmodify =
2698: &Apache::lonuserutils::can_modify_userinfo($context,$dom,$userinfo,
2699: $rolesarray);
2700: return %canmodify;
2701: }
2702:
1.252 raeburn 2703: sub get_inststatuses {
2704: my ($insthashref) = @_;
2705: my @inststatuses = ();
2706: if (ref($insthashref) eq 'HASH') {
2707: if (ref($insthashref->{'inststatus'}) eq 'ARRAY') {
2708: @inststatuses = @{$insthashref->{'inststatus'}};
2709: }
2710: }
2711: return @inststatuses;
2712: }
2713:
1.4 www 2714: # ================================================================= Phase Three
1.42 matthew 2715: sub update_user_data {
1.406.2.17 raeburn 2716: my ($r,$context,$crstype,$brcrum,$showcredits,$permission) = @_;
1.101 albertel 2717: my $uhome=&Apache::lonnet::homeserver($env{'form.ccuname'},
2718: $env{'form.ccdomain'});
1.27 matthew 2719: # Error messages
1.188 raeburn 2720: my $error = '<span class="LC_error">'.&mt('Error').': ';
1.193 raeburn 2721: my $end = '</span><br /><br />';
2722: my $rtnlink = '<a href="javascript:backPage(document.userupdate,'.
1.188 raeburn 2723: "'$env{'form.prevphase'}','modify')".'" />'.
1.219 raeburn 2724: &mt('Return to previous page').'</a>'.
2725: &Apache::loncommon::end_page();
2726: my $now = time;
1.40 www 2727: my $title;
1.101 albertel 2728: if (exists($env{'form.makeuser'})) {
1.40 www 2729: $title='Set Privileges for New User';
2730: } else {
2731: $title='Modify User Privileges';
2732: }
1.213 raeburn 2733: my $newuser = 0;
1.160 raeburn 2734: my ($jsback,$elements) = &crumb_utilities();
2735: my $jscript = '<script type="text/javascript">'."\n".
1.301 bisitz 2736: '// <![CDATA['."\n".
2737: $jsback."\n".
2738: '// ]]>'."\n".
2739: '</script>'."\n";
1.406.2.7 raeburn 2740: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$env{'form.ccdomain'});
1.351 raeburn 2741: push (@{$brcrum},
2742: {href => "javascript:backPage(document.userupdate)",
2743: text => $breadcrumb_text{'search'},
2744: faq => 282,
2745: bug => 'Instructor Interface',}
2746: );
2747: if ($env{'form.prevphase'} eq 'userpicked') {
2748: push(@{$brcrum},
2749: {href => "javascript:backPage(document.userupdate,'get_user_info','select')",
2750: text => $breadcrumb_text{'userpicked'},
2751: faq => 282,
2752: bug => 'Instructor Interface',});
1.233 raeburn 2753: }
1.224 raeburn 2754: my $helpitem = 'Course_Change_Privileges';
2755: if ($env{'form.action'} eq 'singlestudent') {
2756: $helpitem = 'Course_Add_Student';
1.406.2.14 raeburn 2757: } elsif ($context eq 'author') {
2758: $helpitem = 'Author_Change_Privileges';
2759: } elsif ($context eq 'domain') {
2760: $helpitem = 'Domain_Change_Privileges';
1.224 raeburn 2761: }
1.351 raeburn 2762: push(@{$brcrum},
2763: {href => "javascript:backPage(document.userupdate,'$env{'form.prevphase'}','modify')",
2764: text => $breadcrumb_text{'modify'},
2765: faq => 282,
2766: bug => 'Instructor Interface',},
2767: {href => "/adm/createuser",
2768: text => "Result",
2769: faq => 282,
2770: bug => 'Instructor Interface',
2771: help => $helpitem});
2772: my $args = {bread_crumbs => $brcrum,
2773: bread_crumbs_component => 'User Management'};
2774: if ($env{'form.popup'}) {
2775: $args->{'no_nav_bar'} = 1;
2776: }
2777: $r->print(&Apache::loncommon::start_page($title,$jscript,$args));
1.188 raeburn 2778: $r->print(&update_result_form($uhome));
1.27 matthew 2779: # Check Inputs
1.101 albertel 2780: if (! $env{'form.ccuname'} ) {
1.193 raeburn 2781: $r->print($error.&mt('No login name specified').'.'.$end.$rtnlink);
1.27 matthew 2782: return;
2783: }
1.138 albertel 2784: if ( $env{'form.ccuname'} ne
2785: &LONCAPA::clean_username($env{'form.ccuname'}) ) {
1.281 bisitz 2786: $r->print($error.&mt('Invalid login name.').' '.
2787: &mt('Only letters, numbers, periods, dashes, @, and underscores are valid.').
1.193 raeburn 2788: $end.$rtnlink);
1.27 matthew 2789: return;
2790: }
1.101 albertel 2791: if (! $env{'form.ccdomain'} ) {
1.193 raeburn 2792: $r->print($error.&mt('No domain specified').'.'.$end.$rtnlink);
1.27 matthew 2793: return;
2794: }
1.138 albertel 2795: if ( $env{'form.ccdomain'} ne
2796: &LONCAPA::clean_domain($env{'form.ccdomain'}) ) {
1.281 bisitz 2797: $r->print($error.&mt('Invalid domain name.').' '.
2798: &mt('Only letters, numbers, periods, dashes, and underscores are valid.').
1.193 raeburn 2799: $end.$rtnlink);
1.27 matthew 2800: return;
2801: }
1.219 raeburn 2802: if ($uhome eq 'no_host') {
2803: $newuser = 1;
2804: }
1.101 albertel 2805: if (! exists($env{'form.makeuser'})) {
1.29 matthew 2806: # Modifying an existing user, so check the validity of the name
2807: if ($uhome eq 'no_host') {
1.389 bisitz 2808: $r->print(
2809: $error
2810: .'<p class="LC_error">'
2811: .&mt('Unable to determine home server for [_1] in domain [_2].',
2812: '"'.$env{'form.ccuname'}.'"','"'.$env{'form.ccdomain'}.'"')
2813: .'</p>');
1.29 matthew 2814: return;
2815: }
2816: }
1.27 matthew 2817: # Determine authentication method and password for the user being modified
2818: my $amode='';
2819: my $genpwd='';
1.101 albertel 2820: if ($env{'form.login'} eq 'krb') {
1.41 albertel 2821: $amode='krb';
1.101 albertel 2822: $amode.=$env{'form.krbver'};
2823: $genpwd=$env{'form.krbarg'};
2824: } elsif ($env{'form.login'} eq 'int') {
1.27 matthew 2825: $amode='internal';
1.101 albertel 2826: $genpwd=$env{'form.intarg'};
2827: } elsif ($env{'form.login'} eq 'fsys') {
1.27 matthew 2828: $amode='unix';
1.101 albertel 2829: $genpwd=$env{'form.fsysarg'};
2830: } elsif ($env{'form.login'} eq 'loc') {
1.27 matthew 2831: $amode='localauth';
1.101 albertel 2832: $genpwd=$env{'form.locarg'};
1.27 matthew 2833: $genpwd=" " if (!$genpwd);
1.101 albertel 2834: } elsif (($env{'form.login'} eq 'nochange') ||
2835: ($env{'form.login'} eq '' )) {
1.34 matthew 2836: # There is no need to tell the user we did not change what they
2837: # did not ask us to change.
1.35 matthew 2838: # If they are creating a new user but have not specified login
2839: # information this will be caught below.
1.30 matthew 2840: } else {
1.367 golterma 2841: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
2842: return;
1.27 matthew 2843: }
1.164 albertel 2844:
1.188 raeburn 2845: $r->print('<h3>'.&mt('User [_1] in domain [_2]',
1.367 golterma 2846: $env{'form.ccuname'}.' ('.&Apache::loncommon::plainname($env{'form.ccuname'},
2847: $env{'form.ccdomain'}).')', $env{'form.ccdomain'}).'</h3>');
2848: my %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($r,2);
1.344 bisitz 2849:
1.193 raeburn 2850: my (%alerts,%rulematch,%inst_results,%curr_rules);
1.334 raeburn 2851: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
1.361 raeburn 2852: my @usertools = ('aboutme','blog','webdav','portfolio');
1.384 raeburn 2853: my @requestcourses = ('official','unofficial','community','textbook');
1.362 raeburn 2854: my @requestauthor = ('requestauthor');
1.286 raeburn 2855: my ($othertitle,$usertypes,$types) =
2856: &Apache::loncommon::sorted_inst_types($env{'form.ccdomain'});
1.334 raeburn 2857: my %canmodify_status =
2858: &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},
2859: ['inststatus']);
1.101 albertel 2860: if ($env{'form.makeuser'}) {
1.164 albertel 2861: $r->print('<h3>'.&mt('Creating new account.').'</h3>');
1.27 matthew 2862: # Check for the authentication mode and password
2863: if (! $amode || ! $genpwd) {
1.193 raeburn 2864: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
1.27 matthew 2865: return;
1.18 albertel 2866: }
1.29 matthew 2867: # Determine desired host
1.101 albertel 2868: my $desiredhost = $env{'form.hserver'};
1.29 matthew 2869: if (lc($desiredhost) eq 'default') {
2870: $desiredhost = undef;
2871: } else {
1.147 albertel 2872: my %home_servers =
2873: &Apache::lonnet::get_servers($env{'form.ccdomain'},'library');
1.29 matthew 2874: if (! exists($home_servers{$desiredhost})) {
1.193 raeburn 2875: $r->print($error.&mt('Invalid home server specified').$end.$rtnlink);
2876: return;
2877: }
2878: }
2879: # Check ID format
2880: my %checkhash;
2881: my %checks = ('id' => 1);
2882: %{$checkhash{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}}} = (
1.219 raeburn 2883: 'newuser' => $newuser,
1.196 raeburn 2884: 'id' => $env{'form.cid'},
1.193 raeburn 2885: );
1.196 raeburn 2886: if ($env{'form.cid'} ne '') {
2887: &Apache::loncommon::user_rule_check(\%checkhash,\%checks,\%alerts,
2888: \%rulematch,\%inst_results,\%curr_rules);
2889: if (ref($alerts{'id'}) eq 'HASH') {
2890: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
2891: my $domdesc =
2892: &Apache::lonnet::domain($env{'form.ccdomain'},'description');
2893: if ($alerts{'id'}{$env{'form.ccdomain'}}{$env{'form.cid'}}) {
2894: my $userchkmsg;
2895: if (ref($curr_rules{$env{'form.ccdomain'}}) eq 'HASH') {
2896: $userchkmsg =
2897: &Apache::loncommon::instrule_disallow_msg('id',
2898: $domdesc,1).
2899: &Apache::loncommon::user_rule_formats($env{'form.ccdomain'},
2900: $domdesc,$curr_rules{$env{'form.ccdomain'}}{'id'},'id');
2901: }
2902: $r->print($error.&mt('Invalid ID format').$end.
2903: $userchkmsg.$rtnlink);
2904: return;
2905: }
2906: }
1.29 matthew 2907: }
2908: }
1.367 golterma 2909: &Apache::lonhtmlcommon::Increment_PrgWin($r, \%prog_state);
1.27 matthew 2910: # Call modifyuser
2911: my $result = &Apache::lonnet::modifyuser
1.193 raeburn 2912: ($env{'form.ccdomain'},$env{'form.ccuname'},$env{'form.cid'},
1.188 raeburn 2913: $amode,$genpwd,$env{'form.cfirstname'},
2914: $env{'form.cmiddlename'},$env{'form.clastname'},
2915: $env{'form.cgeneration'},undef,$desiredhost,
2916: $env{'form.cpermanentemail'});
1.77 www 2917: $r->print(&mt('Generating user').': '.$result);
1.219 raeburn 2918: $uhome = &Apache::lonnet::homeserver($env{'form.ccuname'},
1.101 albertel 2919: $env{'form.ccdomain'});
1.334 raeburn 2920: my (%changeHash,%newcustom,%changed,%changedinfo);
1.267 raeburn 2921: if ($uhome ne 'no_host') {
1.334 raeburn 2922: if ($context eq 'domain') {
1.378 raeburn 2923: foreach my $name ('portfolio','author') {
2924: if ($env{'form.custom_'.$name.'quota'} == 1) {
2925: if ($env{'form.'.$name.'quota'} eq '') {
2926: $newcustom{$name.'quota'} = 0;
2927: } else {
2928: $newcustom{$name.'quota'} = $env{'form.'.$name.'quota'};
2929: $newcustom{$name.'quota'} =~ s/[^\d\.]//g;
2930: }
2931: if ("a_admin($newcustom{$name.'quota'},\%changeHash,$name)) {
2932: $changed{$name.'quota'} = 1;
2933: }
1.334 raeburn 2934: }
2935: }
2936: foreach my $item (@usertools) {
2937: if ($env{'form.custom'.$item} == 1) {
2938: $newcustom{$item} = $env{'form.tools_'.$item};
2939: $changed{$item} = &tool_admin($item,$newcustom{$item},
2940: \%changeHash,'tools');
2941: }
1.267 raeburn 2942: }
1.334 raeburn 2943: foreach my $item (@requestcourses) {
1.341 raeburn 2944: if ($env{'form.custom'.$item} == 1) {
2945: $newcustom{$item} = $env{'form.crsreq_'.$item};
2946: if ($env{'form.crsreq_'.$item} eq 'autolimit') {
2947: $newcustom{$item} .= '=';
1.383 raeburn 2948: $env{'form.crsreq_'.$item.'_limit'} =~ s/\D+//g;
2949: if ($env{'form.crsreq_'.$item.'_limit'}) {
1.341 raeburn 2950: $newcustom{$item} .= $env{'form.crsreq_'.$item.'_limit'};
2951: }
1.334 raeburn 2952: }
1.341 raeburn 2953: $changed{$item} = &tool_admin($item,$newcustom{$item},
2954: \%changeHash,'requestcourses');
1.334 raeburn 2955: }
1.275 raeburn 2956: }
1.362 raeburn 2957: if ($env{'form.customrequestauthor'} == 1) {
2958: $newcustom{'requestauthor'} = $env{'form.requestauthor'};
2959: $changed{'requestauthor'} = &tool_admin('requestauthor',
2960: $newcustom{'requestauthor'},
2961: \%changeHash,'requestauthor');
2962: }
1.275 raeburn 2963: }
1.334 raeburn 2964: if ($canmodify_status{'inststatus'}) {
2965: if (exists($env{'form.inststatus'})) {
2966: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
2967: if (@inststatuses > 0) {
2968: $changeHash{'inststatus'} = join(',',@inststatuses);
2969: $changed{'inststatus'} = $changeHash{'inststatus'};
1.306 raeburn 2970: }
2971: }
1.232 raeburn 2972: }
1.334 raeburn 2973: if (keys(%changed)) {
2974: foreach my $item (@userinfo) {
2975: $changeHash{$item} = $env{'form.c'.$item};
1.286 raeburn 2976: }
1.267 raeburn 2977: my $chgresult =
2978: &Apache::lonnet::put('environment',\%changeHash,
2979: $env{'form.ccdomain'},$env{'form.ccuname'});
2980: }
1.232 raeburn 2981: }
1.406.2.19 raeburn 2982: $r->print('<br />'.&mt('Home Server').': '.$uhome.' '.
1.219 raeburn 2983: &Apache::lonnet::hostname($uhome));
1.101 albertel 2984: } elsif (($env{'form.login'} ne 'nochange') &&
2985: ($env{'form.login'} ne '' )) {
1.27 matthew 2986: # Modify user privileges
2987: if (! $amode || ! $genpwd) {
1.193 raeburn 2988: $r->print($error.'Invalid login mode or password'.$end.$rtnlink);
1.27 matthew 2989: return;
1.20 harris41 2990: }
1.395 bisitz 2991: # Only allow authentication modification if the person has authority
1.101 albertel 2992: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.20 harris41 2993: $r->print('Modifying authentication: '.
1.31 matthew 2994: &Apache::lonnet::modifyuserauth(
1.101 albertel 2995: $env{'form.ccdomain'},$env{'form.ccuname'},
1.21 harris41 2996: $amode,$genpwd));
1.406.2.19 raeburn 2997: $r->print('<br />'.&mt('Home Server').': '.&Apache::lonnet::homeserver
1.101 albertel 2998: ($env{'form.ccuname'},$env{'form.ccdomain'}));
1.4 www 2999: } else {
1.27 matthew 3000: # Okay, this is a non-fatal error.
1.406.2.17 raeburn 3001: $r->print($error.&mt('You do not have privileges to modify the authentication configuration for this user.').$end);
1.27 matthew 3002: }
1.406.2.17 raeburn 3003: } elsif (($env{'form.intarg'} ne '') &&
3004: (&Apache::lonnet::queryauthenticate($env{'form.ccuname'},$env{'form.ccdomain'}) =~ /^internal:/) &&
3005: (&Apache::lonuserutils::can_change_internalpass($env{'form.ccuname'},$env{'form.ccdomain'},$crstype,$permission))) {
3006: $r->print('Modifying authentication: '.
3007: &Apache::lonnet::modifyuserauth(
3008: $env{'form.ccdomain'},$env{'form.ccuname'},
3009: 'internal',$env{'form.intarg'}));
1.28 matthew 3010: }
1.344 bisitz 3011: $r->rflush(); # Finish display of header before time consuming actions start
1.367 golterma 3012: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state);
1.28 matthew 3013: ##
1.375 raeburn 3014: my (@userroles,%userupdate,$cnum,$cdom,$defaultcredits,%namechanged);
1.213 raeburn 3015: if ($context eq 'course') {
1.375 raeburn 3016: ($cnum,$cdom) =
3017: &Apache::lonuserutils::get_course_identity();
1.318 raeburn 3018: $crstype = &Apache::loncommon::course_type($cdom.'_'.$cnum);
1.375 raeburn 3019: if ($showcredits) {
3020: $defaultcredits = &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
3021: }
1.213 raeburn 3022: }
1.101 albertel 3023: if (! $env{'form.makeuser'} ) {
1.28 matthew 3024: # Check for need to change
3025: my %userenv = &Apache::lonnet::get
1.134 raeburn 3026: ('environment',['firstname','middlename','lastname','generation',
1.378 raeburn 3027: 'id','permanentemail','portfolioquota','authorquota','inststatus',
3028: 'tools.aboutme','tools.blog','tools.webdav','tools.portfolio',
1.361 raeburn 3029: 'requestcourses.official','requestcourses.unofficial',
1.384 raeburn 3030: 'requestcourses.community','requestcourses.textbook',
3031: 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
3032: 'reqcrsotherdom.community','reqcrsotherdom.textbook',
1.406.2.9 raeburn 3033: 'requestauthor'],
1.160 raeburn 3034: $env{'form.ccdomain'},$env{'form.ccuname'});
1.28 matthew 3035: my ($tmp) = keys(%userenv);
3036: if ($tmp =~ /^(con_lost|error)/i) {
3037: %userenv = ();
3038: }
1.206 raeburn 3039: my $no_forceid_alert;
3040: # Check to see if user information can be changed
3041: my %domconfig =
3042: &Apache::lonnet::get_dom('configuration',['usermodification'],
3043: $env{'form.ccdomain'});
1.213 raeburn 3044: my @statuses = ('active','future');
3045: my %roles = &Apache::lonnet::get_my_roles($env{'form.ccuname'},$env{'form.ccdomain'},'userroles',\@statuses,undef,$env{'request.role.domain'});
3046: my ($auname,$audom);
1.220 raeburn 3047: if ($context eq 'author') {
1.206 raeburn 3048: $auname = $env{'user.name'};
3049: $audom = $env{'user.domain'};
3050: }
3051: foreach my $item (keys(%roles)) {
1.220 raeburn 3052: my ($rolenum,$roledom,$role) = split(/:/,$item,-1);
1.206 raeburn 3053: if ($context eq 'course') {
3054: if ($cnum ne '' && $cdom ne '') {
3055: if ($rolenum eq $cnum && $roledom eq $cdom) {
3056: if (!grep(/^\Q$role\E$/,@userroles)) {
3057: push(@userroles,$role);
3058: }
3059: }
3060: }
3061: } elsif ($context eq 'author') {
3062: if ($rolenum eq $auname && $roledom eq $audom) {
3063: if (!grep(/^\Q$role\E$/,@userroles)) {
3064: push(@userroles,$role);
3065: }
3066: }
3067: }
3068: }
1.220 raeburn 3069: if ($env{'form.action'} eq 'singlestudent') {
3070: if (!grep(/^st$/,@userroles)) {
3071: push(@userroles,'st');
3072: }
3073: } else {
3074: # Check for course or co-author roles being activated or re-enabled
3075: if ($context eq 'author' || $context eq 'course') {
3076: foreach my $key (keys(%env)) {
3077: if ($context eq 'author') {
3078: if ($key=~/^form\.act_\Q$audom\E_\Q$auname\E_([^_]+)/) {
3079: if (!grep(/^\Q$1\E$/,@userroles)) {
3080: push(@userroles,$1);
3081: }
3082: } elsif ($key =~/^form\.ren\:\Q$audom\E\/\Q$auname\E_([^_]+)/) {
3083: if (!grep(/^\Q$1\E$/,@userroles)) {
3084: push(@userroles,$1);
3085: }
1.206 raeburn 3086: }
1.220 raeburn 3087: } elsif ($context eq 'course') {
3088: if ($key=~/^form\.act_\Q$cdom\E_\Q$cnum\E_([^_]+)/) {
3089: if (!grep(/^\Q$1\E$/,@userroles)) {
3090: push(@userroles,$1);
3091: }
3092: } elsif ($key =~/^form\.ren\:\Q$cdom\E\/\Q$cnum\E(\/?\w*)_([^_]+)/) {
3093: if (!grep(/^\Q$1\E$/,@userroles)) {
3094: push(@userroles,$1);
3095: }
1.206 raeburn 3096: }
3097: }
3098: }
3099: }
3100: }
3101: #Check to see if we can change personal data for the user
3102: my (@mod_disallowed,@longroles);
3103: foreach my $role (@userroles) {
3104: if ($role eq 'cr') {
3105: push(@longroles,'Custom');
3106: } else {
1.318 raeburn 3107: push(@longroles,&Apache::lonnet::plaintext($role,$crstype));
1.206 raeburn 3108: }
3109: }
1.219 raeburn 3110: my %canmodify = &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},\@userinfo,\@userroles);
3111: foreach my $item (@userinfo) {
1.28 matthew 3112: # Strip leading and trailing whitespace
1.203 raeburn 3113: $env{'form.c'.$item} =~ s/(\s+$|^\s+)//g;
1.219 raeburn 3114: if (!$canmodify{$item}) {
1.207 raeburn 3115: if (defined($env{'form.c'.$item})) {
3116: if ($env{'form.c'.$item} ne $userenv{$item}) {
3117: push(@mod_disallowed,$item);
3118: }
1.206 raeburn 3119: }
3120: $env{'form.c'.$item} = $userenv{$item};
3121: }
1.28 matthew 3122: }
1.259 bisitz 3123: # Check to see if we can change the Student/Employee ID
1.196 raeburn 3124: my $forceid = $env{'form.forceid'};
3125: my $recurseid = $env{'form.recurseid'};
3126: my (%alerts,%rulematch,%idinst_results,%curr_rules,%got_rules);
1.203 raeburn 3127: my %uidhash = &Apache::lonnet::idrget($env{'form.ccdomain'},
3128: $env{'form.ccuname'});
3129: if (($uidhash{$env{'form.ccuname'}}) &&
3130: ($uidhash{$env{'form.ccuname'}}!~/error\:/) &&
3131: (!$forceid)) {
3132: if ($env{'form.cid'} ne $uidhash{$env{'form.ccuname'}}) {
3133: $env{'form.cid'} = $userenv{'id'};
1.293 bisitz 3134: $no_forceid_alert = &mt('New student/employee ID does not match existing ID for this user.')
1.259 bisitz 3135: .'<br />'
3136: .&mt("Change is not permitted without checking the 'Force ID change' checkbox on the previous page.")
3137: .'<br />'."\n";
1.203 raeburn 3138: }
3139: }
3140: if ($env{'form.cid'} ne $userenv{'id'}) {
1.196 raeburn 3141: my $checkhash;
3142: my $checks = { 'id' => 1 };
3143: $checkhash->{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}} =
3144: { 'newuser' => $newuser,
3145: 'id' => $env{'form.cid'},
3146: };
3147: &Apache::loncommon::user_rule_check($checkhash,$checks,
3148: \%alerts,\%rulematch,\%idinst_results,\%curr_rules,\%got_rules);
3149: if (ref($alerts{'id'}) eq 'HASH') {
3150: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
1.203 raeburn 3151: $env{'form.cid'} = $userenv{'id'};
1.196 raeburn 3152: }
3153: }
3154: }
1.378 raeburn 3155: my (%quotachanged,%oldquota,%newquota,%olddefquota,%newdefquota,
3156: $oldinststatus,$newinststatus,%oldisdefault,%newisdefault,%oldsettings,
1.339 raeburn 3157: %oldsettingstext,%newsettings,%newsettingstext,@disporder,
1.378 raeburn 3158: %oldsettingstatus,%newsettingstatus);
1.334 raeburn 3159: @disporder = ('inststatus');
3160: if ($env{'request.role.domain'} eq $env{'form.ccdomain'}) {
1.362 raeburn 3161: push(@disporder,'requestcourses','requestauthor');
1.334 raeburn 3162: } else {
3163: push(@disporder,'reqcrsotherdom');
3164: }
3165: push(@disporder,('quota','tools'));
1.338 raeburn 3166: $oldinststatus = $userenv{'inststatus'};
1.378 raeburn 3167: foreach my $name ('portfolio','author') {
3168: ($olddefquota{$name},$oldsettingstatus{$name}) =
3169: &Apache::loncommon::default_quota($env{'form.ccdomain'},$oldinststatus,$name);
3170: ($newdefquota{$name},$newsettingstatus{$name}) = ($olddefquota{$name},$oldsettingstatus{$name});
3171: }
1.334 raeburn 3172: my %canshow;
1.220 raeburn 3173: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
1.334 raeburn 3174: $canshow{'quota'} = 1;
1.220 raeburn 3175: }
1.267 raeburn 3176: if (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
1.334 raeburn 3177: $canshow{'tools'} = 1;
1.267 raeburn 3178: }
1.275 raeburn 3179: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
1.334 raeburn 3180: $canshow{'requestcourses'} = 1;
1.300 raeburn 3181: } elsif (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.334 raeburn 3182: $canshow{'reqcrsotherdom'} = 1;
1.275 raeburn 3183: }
1.286 raeburn 3184: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.334 raeburn 3185: $canshow{'inststatus'} = 1;
1.286 raeburn 3186: }
1.362 raeburn 3187: if (&Apache::lonnet::allowed('cau',$env{'form.ccdomain'})) {
3188: $canshow{'requestauthor'} = 1;
3189: }
1.267 raeburn 3190: my (%changeHash,%changed);
1.286 raeburn 3191: if ($oldinststatus eq '') {
1.334 raeburn 3192: $oldsettings{'inststatus'} = $othertitle;
1.286 raeburn 3193: } else {
3194: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 3195: $oldsettings{'inststatus'} = join(', ',map{ $usertypes->{ &unescape($_) }; } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 3196: } else {
1.334 raeburn 3197: $oldsettings{'inststatus'} = join(', ',map{ &unescape($_); } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 3198: }
3199: }
3200: $changeHash{'inststatus'} = $userenv{'inststatus'};
1.334 raeburn 3201: if ($canmodify_status{'inststatus'}) {
3202: $canshow{'inststatus'} = 1;
1.286 raeburn 3203: if (exists($env{'form.inststatus'})) {
3204: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
3205: if (@inststatuses > 0) {
3206: $newinststatus = join(':',map { &escape($_); } @inststatuses);
3207: $changeHash{'inststatus'} = $newinststatus;
3208: if ($newinststatus ne $oldinststatus) {
3209: $changed{'inststatus'} = $newinststatus;
1.378 raeburn 3210: foreach my $name ('portfolio','author') {
3211: ($newdefquota{$name},$newsettingstatus{$name}) =
3212: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
3213: }
1.286 raeburn 3214: }
3215: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 3216: $newsettings{'inststatus'} = join(', ',map{ $usertypes->{$_}; } (@inststatuses));
1.286 raeburn 3217: } else {
1.337 raeburn 3218: $newsettings{'inststatus'} = join(', ',@inststatuses);
1.286 raeburn 3219: }
1.334 raeburn 3220: }
3221: } else {
3222: $newinststatus = '';
3223: $changeHash{'inststatus'} = $newinststatus;
3224: $newsettings{'inststatus'} = $othertitle;
3225: if ($newinststatus ne $oldinststatus) {
3226: $changed{'inststatus'} = $changeHash{'inststatus'};
1.378 raeburn 3227: foreach my $name ('portfolio','author') {
3228: ($newdefquota{$name},$newsettingstatus{$name}) =
3229: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
3230: }
1.286 raeburn 3231: }
3232: }
1.334 raeburn 3233: } elsif ($context ne 'selfcreate') {
3234: $canshow{'inststatus'} = 1;
1.337 raeburn 3235: $newsettings{'inststatus'} = $oldsettings{'inststatus'};
1.286 raeburn 3236: }
1.378 raeburn 3237: foreach my $name ('portfolio','author') {
3238: $changeHash{$name.'quota'} = $userenv{$name.'quota'};
3239: }
1.334 raeburn 3240: if ($context eq 'domain') {
1.378 raeburn 3241: foreach my $name ('portfolio','author') {
3242: if ($userenv{$name.'quota'} ne '') {
3243: $oldquota{$name} = $userenv{$name.'quota'};
3244: if ($env{'form.custom_'.$name.'quota'} == 1) {
3245: if ($env{'form.'.$name.'quota'} eq '') {
3246: $newquota{$name} = 0;
3247: } else {
3248: $newquota{$name} = $env{'form.'.$name.'quota'};
3249: $newquota{$name} =~ s/[^\d\.]//g;
3250: }
3251: if ($newquota{$name} != $oldquota{$name}) {
3252: if ("a_admin($newquota{$name},\%changeHash,$name)) {
3253: $changed{$name.'quota'} = 1;
3254: }
3255: }
1.334 raeburn 3256: } else {
1.378 raeburn 3257: if ("a_admin('',\%changeHash,$name)) {
3258: $changed{$name.'quota'} = 1;
3259: $newquota{$name} = $newdefquota{$name};
3260: $newisdefault{$name} = 1;
3261: }
1.334 raeburn 3262: }
1.149 raeburn 3263: } else {
1.378 raeburn 3264: $oldisdefault{$name} = 1;
3265: $oldquota{$name} = $olddefquota{$name};
3266: if ($env{'form.custom_'.$name.'quota'} == 1) {
3267: if ($env{'form.'.$name.'quota'} eq '') {
3268: $newquota{$name} = 0;
3269: } else {
3270: $newquota{$name} = $env{'form.'.$name.'quota'};
3271: $newquota{$name} =~ s/[^\d\.]//g;
3272: }
3273: if ("a_admin($newquota{$name},\%changeHash,$name)) {
3274: $changed{$name.'quota'} = 1;
3275: }
1.334 raeburn 3276: } else {
1.378 raeburn 3277: $newquota{$name} = $newdefquota{$name};
3278: $newisdefault{$name} = 1;
1.334 raeburn 3279: }
1.378 raeburn 3280: }
3281: if ($oldisdefault{$name}) {
3282: $oldsettingstext{'quota'}{$name} = &get_defaultquota_text($oldsettingstatus{$name});
1.383 raeburn 3283: } else {
3284: $oldsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$oldquota{$name});
1.378 raeburn 3285: }
3286: if ($newisdefault{$name}) {
3287: $newsettingstext{'quota'}{$name} = &get_defaultquota_text($newsettingstatus{$name});
1.383 raeburn 3288: } else {
3289: $newsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$newquota{$name});
1.134 raeburn 3290: }
3291: }
1.334 raeburn 3292: &tool_changes('tools',\@usertools,\%oldsettings,\%oldsettingstext,\%userenv,
3293: \%changeHash,\%changed,\%newsettings,\%newsettingstext);
3294: if ($env{'form.ccdomain'} eq $env{'request.role.domain'}) {
3295: &tool_changes('requestcourses',\@requestcourses,\%oldsettings,\%oldsettingstext,
3296: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.384 raeburn 3297: &tool_changes('requestauthor',\@requestauthor,\%oldsettings,\%oldsettingstext,
3298: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 3299: } else {
1.334 raeburn 3300: &tool_changes('reqcrsotherdom',\@requestcourses,\%oldsettings,\%oldsettingstext,
3301: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 3302: }
3303: }
1.334 raeburn 3304: foreach my $item (@userinfo) {
3305: if ($env{'form.c'.$item} ne $userenv{$item}) {
3306: $namechanged{$item} = 1;
3307: }
1.204 raeburn 3308: }
1.378 raeburn 3309: foreach my $name ('portfolio','author') {
1.390 bisitz 3310: $oldsettings{'quota'}{$name} = &mt('[_1] MB',$oldquota{$name});
3311: $newsettings{'quota'}{$name} = &mt('[_1] MB',$newquota{$name});
1.378 raeburn 3312: }
1.334 raeburn 3313: if ((keys(%namechanged) > 0) || (keys(%changed) > 0)) {
1.267 raeburn 3314: my ($chgresult,$namechgresult);
3315: if (keys(%changed) > 0) {
3316: $chgresult =
1.204 raeburn 3317: &Apache::lonnet::put('environment',\%changeHash,
3318: $env{'form.ccdomain'},$env{'form.ccuname'});
1.267 raeburn 3319: if ($chgresult eq 'ok') {
3320: if (($env{'user.name'} eq $env{'form.ccuname'}) &&
3321: ($env{'user.domain'} eq $env{'form.ccdomain'})) {
1.270 raeburn 3322: my %newenvhash;
3323: foreach my $key (keys(%changed)) {
1.299 raeburn 3324: if (($key eq 'official') || ($key eq 'unofficial')
1.403 raeburn 3325: || ($key eq 'community') || ($key eq 'textbook')) {
1.279 raeburn 3326: $newenvhash{'environment.requestcourses.'.$key} =
3327: $changeHash{'requestcourses.'.$key};
1.362 raeburn 3328: if ($changeHash{'requestcourses.'.$key}) {
1.332 raeburn 3329: $newenvhash{'environment.canrequest.'.$key} = 1;
1.279 raeburn 3330: } else {
3331: $newenvhash{'environment.canrequest.'.$key} =
3332: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3333: $key,'reload','requestcourses');
3334: }
1.362 raeburn 3335: } elsif ($key eq 'requestauthor') {
3336: $newenvhash{'environment.'.$key} = $changeHash{$key};
3337: if ($changeHash{$key}) {
3338: $newenvhash{'environment.canrequest.author'} = 1;
3339: } else {
3340: $newenvhash{'environment.canrequest.author'} =
3341: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3342: $key,'reload','requestauthor');
3343: }
1.275 raeburn 3344: } elsif ($key ne 'quota') {
1.270 raeburn 3345: $newenvhash{'environment.tools.'.$key} =
3346: $changeHash{'tools.'.$key};
1.279 raeburn 3347: if ($changeHash{'tools.'.$key} ne '') {
3348: $newenvhash{'environment.availabletools.'.$key} =
3349: $changeHash{'tools.'.$key};
3350: } else {
3351: $newenvhash{'environment.availabletools.'.$key} =
1.367 golterma 3352: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3353: $key,'reload','tools');
1.279 raeburn 3354: }
1.270 raeburn 3355: }
3356: }
1.271 raeburn 3357: if (keys(%newenvhash)) {
3358: &Apache::lonnet::appenv(\%newenvhash);
3359: }
1.267 raeburn 3360: }
3361: }
1.204 raeburn 3362: }
1.334 raeburn 3363: if (keys(%namechanged) > 0) {
1.337 raeburn 3364: foreach my $field (@userinfo) {
3365: $changeHash{$field} = $env{'form.c'.$field};
3366: }
3367: # Make the change
1.204 raeburn 3368: $namechgresult =
3369: &Apache::lonnet::modifyuser($env{'form.ccdomain'},
3370: $env{'form.ccuname'},$changeHash{'id'},undef,undef,
3371: $changeHash{'firstname'},$changeHash{'middlename'},
3372: $changeHash{'lastname'},$changeHash{'generation'},
1.337 raeburn 3373: $changeHash{'id'},undef,$changeHash{'permanentemail'},undef,\@userinfo);
1.220 raeburn 3374: %userupdate = (
3375: lastname => $env{'form.clastname'},
3376: middlename => $env{'form.cmiddlename'},
3377: firstname => $env{'form.cfirstname'},
3378: generation => $env{'form.cgeneration'},
3379: id => $env{'form.cid'},
3380: );
1.204 raeburn 3381: }
1.334 raeburn 3382: if (((keys(%namechanged) > 0) && $namechgresult eq 'ok') ||
1.267 raeburn 3383: ((keys(%changed) > 0) && $chgresult eq 'ok')) {
1.28 matthew 3384: # Tell the user we changed the name
1.334 raeburn 3385: &display_userinfo($r,1,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 3386: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,
1.334 raeburn 3387: \%oldsettings, \%oldsettingstext,\%newsettings,
3388: \%newsettingstext);
1.203 raeburn 3389: if ($env{'form.cid'} ne $userenv{'id'}) {
3390: &Apache::lonnet::idput($env{'form.ccdomain'},
1.406.2.5 raeburn 3391: {$env{'form.ccuname'} => $env{'form.cid'}});
1.203 raeburn 3392: if (($recurseid) &&
3393: (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}))) {
3394: my $idresult =
3395: &Apache::lonuserutils::propagate_id_change(
3396: $env{'form.ccuname'},$env{'form.ccdomain'},
3397: \%userupdate);
3398: $r->print('<br />'.$idresult.'<br />');
3399: }
1.196 raeburn 3400: }
1.149 raeburn 3401: if (($env{'form.ccdomain'} eq $env{'user.domain'}) &&
3402: ($env{'form.ccuname'} eq $env{'user.name'})) {
3403: my %newenvhash;
3404: foreach my $key (keys(%changeHash)) {
3405: $newenvhash{'environment.'.$key} = $changeHash{$key};
3406: }
1.238 raeburn 3407: &Apache::lonnet::appenv(\%newenvhash);
1.149 raeburn 3408: }
1.28 matthew 3409: } else { # error occurred
1.389 bisitz 3410: $r->print(
3411: '<p class="LC_error">'
3412: .&mt('Unable to successfully change environment for [_1] in domain [_2].',
3413: '"'.$env{'form.ccuname'}.'"',
3414: '"'.$env{'form.ccdomain'}.'"')
3415: .'</p>');
1.28 matthew 3416: }
1.334 raeburn 3417: } else { # End of if ($env ... ) logic
1.275 raeburn 3418: # They did not want to change the users name, quota, tool availability,
3419: # or ability to request creation of courses,
1.267 raeburn 3420: # but we can still tell them what the name and quota and availabilities are
1.334 raeburn 3421: &display_userinfo($r,undef,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 3422: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,\%oldsettings,
1.334 raeburn 3423: \%oldsettingstext,\%newsettings,\%newsettingstext);
1.28 matthew 3424: }
1.206 raeburn 3425: if (@mod_disallowed) {
3426: my ($rolestr,$contextname);
3427: if (@longroles > 0) {
3428: $rolestr = join(', ',@longroles);
3429: } else {
3430: $rolestr = &mt('No roles');
3431: }
3432: if ($context eq 'course') {
1.399 bisitz 3433: $contextname = 'course';
1.206 raeburn 3434: } elsif ($context eq 'author') {
1.399 bisitz 3435: $contextname = 'co-author';
1.206 raeburn 3436: }
3437: $r->print(&mt('The following fields were not updated: ').'<ul>');
3438: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
3439: foreach my $field (@mod_disallowed) {
3440: $r->print('<li>'.$fieldtitles{$field}.'</li>'."\n");
3441: }
1.207 raeburn 3442: $r->print('</ul>');
3443: if (@mod_disallowed == 1) {
1.399 bisitz 3444: $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 3445: } else {
1.399 bisitz 3446: $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 3447: }
1.292 bisitz 3448: my $helplink = 'javascript:helpMenu('."'display'".')';
3449: $r->print('<span class="LC_cusr_emph">'.$rolestr.'</span><br />'
3450: .&mt('Please contact your [_1]helpdesk[_2] for more information.'
3451: ,'<a href="'.$helplink.'">','</a>')
3452: .'<br />');
1.206 raeburn 3453: }
1.259 bisitz 3454: $r->print('<span class="LC_warning">'
3455: .$no_forceid_alert
3456: .&Apache::lonuserutils::print_namespacing_alerts($env{'form.ccdomain'},\%alerts,\%curr_rules)
3457: .'</span>');
1.4 www 3458: }
1.367 golterma 3459: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1.220 raeburn 3460: if ($env{'form.action'} eq 'singlestudent') {
1.375 raeburn 3461: &enroll_single_student($r,$uhome,$amode,$genpwd,$now,$newuser,$context,
3462: $crstype,$showcredits,$defaultcredits);
1.386 bisitz 3463: my $linktext = ($crstype eq 'Community' ?
3464: &mt('Enroll Another Member') : &mt('Enroll Another Student'));
3465: $r->print(
3466: &Apache::lonhtmlcommon::actionbox([
3467: '<a href="javascript:backPage(document.userupdate)">'
3468: .($crstype eq 'Community' ?
3469: &mt('Enroll Another Member') : &mt('Enroll Another Student'))
3470: .'</a>']));
1.220 raeburn 3471: } else {
1.375 raeburn 3472: my @rolechanges = &update_roles($r,$context,$showcredits);
1.334 raeburn 3473: if (keys(%namechanged) > 0) {
1.220 raeburn 3474: if ($context eq 'course') {
3475: if (@userroles > 0) {
1.225 raeburn 3476: if ((@rolechanges == 0) ||
3477: (!(grep(/^st$/,@rolechanges)))) {
3478: if (grep(/^st$/,@userroles)) {
3479: my $classlistupdated =
3480: &Apache::lonuserutils::update_classlist($cdom,
1.220 raeburn 3481: $cnum,$env{'form.ccdomain'},
3482: $env{'form.ccuname'},\%userupdate);
1.225 raeburn 3483: }
1.220 raeburn 3484: }
3485: }
3486: }
3487: }
1.226 raeburn 3488: my $userinfo = &Apache::loncommon::plainname($env{'form.ccuname'},
1.233 raeburn 3489: $env{'form.ccdomain'});
3490: if ($env{'form.popup'}) {
3491: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
3492: } else {
1.367 golterma 3493: $r->print('<br />'.&Apache::lonhtmlcommon::actionbox(['<a href="javascript:backPage(document.userupdate,'."'$env{'form.prevphase'}','modify'".')">'
3494: .&mt('Modify this user: [_1]','<span class="LC_cusr_emph">'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.' ('.$userinfo.')</span>').'</a>',
3495: '<a href="javascript:backPage(document.userupdate)">'.&mt('Create/Modify Another User').'</a>']));
1.233 raeburn 3496: }
1.220 raeburn 3497: }
3498: }
3499:
1.334 raeburn 3500: sub display_userinfo {
1.362 raeburn 3501: my ($r,$changed,$order,$canshow,$requestcourses,$usertools,$requestauthor,
3502: $userenv,$changedhash,$namechangedhash,$oldsetting,$oldsettingtext,
1.334 raeburn 3503: $newsetting,$newsettingtext) = @_;
3504: return unless (ref($order) eq 'ARRAY' &&
3505: ref($canshow) eq 'HASH' &&
3506: ref($requestcourses) eq 'ARRAY' &&
1.362 raeburn 3507: ref($requestauthor) eq 'ARRAY' &&
1.334 raeburn 3508: ref($usertools) eq 'ARRAY' &&
3509: ref($userenv) eq 'HASH' &&
3510: ref($changedhash) eq 'HASH' &&
3511: ref($oldsetting) eq 'HASH' &&
3512: ref($oldsettingtext) eq 'HASH' &&
3513: ref($newsetting) eq 'HASH' &&
3514: ref($newsettingtext) eq 'HASH');
3515: my %lt=&Apache::lonlocal::texthash(
1.372 raeburn 3516: 'ui' => 'User Information',
1.334 raeburn 3517: 'uic' => 'User Information Changed',
3518: 'firstname' => 'First Name',
3519: 'middlename' => 'Middle Name',
3520: 'lastname' => 'Last Name',
3521: 'generation' => 'Generation',
3522: 'id' => 'Student/Employee ID',
3523: 'permanentemail' => 'Permanent e-mail address',
1.378 raeburn 3524: 'portfolioquota' => 'Disk space allocated to portfolio files',
1.385 bisitz 3525: 'authorquota' => 'Disk space allocated to Authoring Space',
1.334 raeburn 3526: 'blog' => 'Blog Availability',
1.361 raeburn 3527: 'webdav' => 'WebDAV Availability',
1.334 raeburn 3528: 'aboutme' => 'Personal Information Page Availability',
3529: 'portfolio' => 'Portfolio Availability',
3530: 'official' => 'Can Request Official Courses',
3531: 'unofficial' => 'Can Request Unofficial Courses',
3532: 'community' => 'Can Request Communities',
1.384 raeburn 3533: 'textbook' => 'Can Request Textbook Courses',
1.362 raeburn 3534: 'requestauthor' => 'Can Request Author Role',
1.334 raeburn 3535: 'inststatus' => "Affiliation",
3536: 'prvs' => 'Previous Value:',
3537: 'chto' => 'Changed To:'
3538: );
3539: if ($changed) {
1.372 raeburn 3540: $r->print('<h3>'.$lt{'uic'}.'</h3>'.
1.367 golterma 3541: &Apache::loncommon::start_data_table().
3542: &Apache::loncommon::start_data_table_header_row());
1.334 raeburn 3543: $r->print("<th> </th>\n");
1.367 golterma 3544: $r->print('<th><b>'.$lt{'prvs'}.'</b></th>');
3545: $r->print('<th><span class="LC_nobreak"><b>'.$lt{'chto'}.'</b></span></th>');
3546: $r->print(&Apache::loncommon::end_data_table_header_row());
3547: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
3548:
1.334 raeburn 3549: foreach my $item (@userinfo) {
3550: my $value = $env{'form.c'.$item};
1.367 golterma 3551: #show changes only:
1.383 raeburn 3552: unless ($value eq $userenv->{$item}){
1.367 golterma 3553: $r->print(&Apache::loncommon::start_data_table_row());
3554: $r->print("<td>$lt{$item}</td>\n");
1.383 raeburn 3555: $r->print("<td>".$userenv->{$item}."</td>\n");
1.367 golterma 3556: $r->print("<td>$value </td>\n");
3557: $r->print(&Apache::loncommon::end_data_table_row());
1.334 raeburn 3558: }
3559: }
3560: foreach my $entry (@{$order}) {
1.383 raeburn 3561: if ($canshow->{$entry}) {
3562: if (($entry eq 'requestcourses') || ($entry eq 'reqcrsotherdom') || ($entry eq 'requestauthor')) {
3563: my @items;
3564: if ($entry eq 'requestauthor') {
3565: @items = ($entry);
3566: } else {
3567: @items = @{$requestcourses};
1.384 raeburn 3568: }
1.383 raeburn 3569: foreach my $item (@items) {
3570: if (($newsetting->{$item} ne $oldsetting->{$item}) ||
3571: ($newsettingtext->{$item} ne $oldsettingtext->{$item})) {
3572: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3573: $r->print("<td>$lt{$item}</td>\n");
3574: $r->print("<td>".$oldsetting->{$item});
3575: if ($oldsettingtext->{$item}) {
3576: if ($oldsetting->{$item}) {
3577: $r->print(' -- ');
3578: }
3579: $r->print($oldsettingtext->{$item});
3580: }
3581: $r->print("</td>\n");
3582: $r->print("<td>".$newsetting->{$item});
3583: if ($newsettingtext->{$item}) {
3584: if ($newsetting->{$item}) {
3585: $r->print(' -- ');
3586: }
3587: $r->print($newsettingtext->{$item});
3588: }
3589: $r->print("</td>\n");
3590: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3591: }
3592: }
3593: } elsif ($entry eq 'tools') {
3594: foreach my $item (@{$usertools}) {
1.383 raeburn 3595: if ($newsetting->{$item} ne $oldsetting->{$item}) {
3596: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3597: $r->print("<td>$lt{$item}</td>\n");
3598: $r->print("<td>".$oldsetting->{$item}.' '.$oldsettingtext->{$item}."</td>\n");
3599: $r->print("<td>".$newsetting->{$item}.' '.$newsettingtext->{$item}."</td>\n");
3600: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3601: }
3602: }
1.378 raeburn 3603: } elsif ($entry eq 'quota') {
3604: if ((ref($oldsetting->{$entry}) eq 'HASH') && (ref($oldsettingtext->{$entry}) eq 'HASH') &&
3605: (ref($newsetting->{$entry}) eq 'HASH') && (ref($newsettingtext->{$entry}) eq 'HASH')) {
3606: foreach my $name ('portfolio','author') {
1.383 raeburn 3607: if ($newsetting->{$entry}->{$name} ne $oldsetting->{$entry}->{$name}) {
3608: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3609: $r->print("<td>$lt{$name.$entry}</td>\n");
3610: $r->print("<td>".$oldsettingtext->{$entry}->{$name}."</td>\n");
3611: $r->print("<td>".$newsettingtext->{$entry}->{$name}."</td>\n");
3612: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.378 raeburn 3613: }
3614: }
3615: }
1.334 raeburn 3616: } else {
1.383 raeburn 3617: if ($newsetting->{$entry} ne $oldsetting->{$entry}) {
3618: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3619: $r->print("<td>$lt{$entry}</td>\n");
3620: $r->print("<td>".$oldsetting->{$entry}.' '.$oldsettingtext->{$entry}."</td>\n");
3621: $r->print("<td>".$newsetting->{$entry}.' '.$newsettingtext->{$entry}."</td>\n");
3622: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3623: }
3624: }
3625: }
3626: }
1.367 golterma 3627: $r->print(&Apache::loncommon::end_data_table().'<br />');
1.372 raeburn 3628: } else {
3629: $r->print('<h3>'.$lt{'ui'}.'</h3>'.
3630: '<p>'.&mt('No changes made to user information').'</p>');
1.334 raeburn 3631: }
3632: return;
3633: }
3634:
1.275 raeburn 3635: sub tool_changes {
3636: my ($context,$usertools,$oldaccess,$oldaccesstext,$userenv,$changeHash,
3637: $changed,$newaccess,$newaccesstext) = @_;
3638: if (!((ref($usertools) eq 'ARRAY') && (ref($oldaccess) eq 'HASH') &&
3639: (ref($oldaccesstext) eq 'HASH') && (ref($userenv) eq 'HASH') &&
3640: (ref($changeHash) eq 'HASH') && (ref($changed) eq 'HASH') &&
3641: (ref($newaccess) eq 'HASH') && (ref($newaccesstext) eq 'HASH'))) {
3642: return;
3643: }
1.383 raeburn 3644: my %reqdisplay = &requestchange_display();
1.300 raeburn 3645: if ($context eq 'reqcrsotherdom') {
1.309 raeburn 3646: my @options = ('approval','validate','autolimit');
1.306 raeburn 3647: my $optregex = join('|',@options);
1.300 raeburn 3648: my $cdom = $env{'request.role.domain'};
3649: foreach my $tool (@{$usertools}) {
1.383 raeburn 3650: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
1.314 raeburn 3651: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
1.300 raeburn 3652: $changeHash->{$context.'.'.$tool} = $userenv->{$context.'.'.$tool};
1.383 raeburn 3653: my ($newop,$limit);
1.314 raeburn 3654: if ($env{'form.'.$context.'_'.$tool}) {
3655: $newop = $env{'form.'.$context.'_'.$tool};
3656: if ($newop eq 'autolimit') {
1.383 raeburn 3657: $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
1.314 raeburn 3658: $limit =~ s/\D+//g;
3659: $newop .= '='.$limit;
3660: }
3661: }
1.300 raeburn 3662: if ($userenv->{$context.'.'.$tool} eq '') {
1.314 raeburn 3663: if ($newop) {
3664: $changed->{$tool}=&tool_admin($tool,$cdom.':'.$newop,
1.300 raeburn 3665: $changeHash,$context);
3666: if ($changed->{$tool}) {
1.383 raeburn 3667: if ($newop =~ /^autolimit/) {
3668: if ($limit) {
3669: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3670: } else {
3671: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3672: }
3673: } else {
3674: $newaccesstext->{$tool} = $reqdisplay{$newop};
3675: }
1.300 raeburn 3676: } else {
3677: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3678: }
3679: }
3680: } else {
3681: my @curr = split(',',$userenv->{$context.'.'.$tool});
3682: my @new;
3683: my $changedoms;
1.314 raeburn 3684: foreach my $req (@curr) {
3685: if ($req =~ /^\Q$cdom\E\:($optregex\=?\d*)$/) {
3686: my $oldop = $1;
1.383 raeburn 3687: if ($oldop =~ /^autolimit=(\d*)/) {
3688: my $limit = $1;
3689: if ($limit) {
3690: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3691: } else {
3692: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3693: }
3694: } else {
3695: $oldaccesstext->{$tool} = $reqdisplay{$oldop};
3696: }
1.314 raeburn 3697: if ($oldop ne $newop) {
3698: $changedoms = 1;
3699: foreach my $item (@curr) {
3700: my ($reqdom,$option) = split(':',$item);
3701: unless ($reqdom eq $cdom) {
3702: push(@new,$item);
3703: }
3704: }
3705: if ($newop) {
3706: push(@new,$cdom.':'.$newop);
1.300 raeburn 3707: }
1.314 raeburn 3708: @new = sort(@new);
1.300 raeburn 3709: }
1.314 raeburn 3710: last;
1.300 raeburn 3711: }
1.314 raeburn 3712: }
3713: if ((!$changedoms) && ($newop)) {
1.300 raeburn 3714: $changedoms = 1;
1.306 raeburn 3715: @new = sort(@curr,$cdom.':'.$newop);
1.300 raeburn 3716: }
3717: if ($changedoms) {
1.314 raeburn 3718: my $newdomstr;
1.300 raeburn 3719: if (@new) {
3720: $newdomstr = join(',',@new);
3721: }
3722: $changed->{$tool}=&tool_admin($tool,$newdomstr,$changeHash,
3723: $context);
3724: if ($changed->{$tool}) {
3725: if ($env{'form.'.$context.'_'.$tool}) {
1.306 raeburn 3726: if ($env{'form.'.$context.'_'.$tool} eq 'autolimit') {
1.314 raeburn 3727: my $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
3728: $limit =~ s/\D+//g;
3729: if ($limit) {
1.383 raeburn 3730: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
1.314 raeburn 3731: } else {
1.383 raeburn 3732: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
1.306 raeburn 3733: }
1.314 raeburn 3734: } else {
1.306 raeburn 3735: $newaccesstext->{$tool} = $reqdisplay{$env{'form.'.$context.'_'.$tool}};
3736: }
1.300 raeburn 3737: } else {
1.383 raeburn 3738: $newaccesstext->{$tool} = &mt("availability set to 'off'");
1.300 raeburn 3739: }
3740: }
3741: }
3742: }
3743: }
3744: return;
3745: }
1.275 raeburn 3746: foreach my $tool (@{$usertools}) {
1.383 raeburn 3747: my ($newval,$limit,$envkey);
1.362 raeburn 3748: $envkey = $context.'.'.$tool;
1.306 raeburn 3749: if ($context eq 'requestcourses') {
3750: $newval = $env{'form.crsreq_'.$tool};
3751: if ($newval eq 'autolimit') {
1.383 raeburn 3752: $limit = $env{'form.crsreq_'.$tool.'_limit'};
3753: $limit =~ s/\D+//g;
3754: $newval .= '='.$limit;
1.306 raeburn 3755: }
1.362 raeburn 3756: } elsif ($context eq 'requestauthor') {
3757: $newval = $env{'form.'.$context};
3758: $envkey = $context;
1.314 raeburn 3759: } else {
1.306 raeburn 3760: $newval = $env{'form.'.$context.'_'.$tool};
3761: }
1.362 raeburn 3762: if ($userenv->{$envkey} ne '') {
1.275 raeburn 3763: $oldaccess->{$tool} = &mt('custom');
1.383 raeburn 3764: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3765: if ($userenv->{$envkey} =~ /^autolimit=(\d*)$/) {
3766: my $currlimit = $1;
3767: if ($currlimit eq '') {
3768: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3769: } else {
3770: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$currlimit);
3771: }
3772: } elsif ($userenv->{$envkey}) {
3773: $oldaccesstext->{$tool} = $reqdisplay{$userenv->{$envkey}};
3774: } else {
3775: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
3776: }
1.275 raeburn 3777: } else {
1.383 raeburn 3778: if ($userenv->{$envkey}) {
3779: $oldaccesstext->{$tool} = &mt("availability set to 'on'");
3780: } else {
3781: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
3782: }
1.275 raeburn 3783: }
1.362 raeburn 3784: $changeHash->{$envkey} = $userenv->{$envkey};
1.275 raeburn 3785: if ($env{'form.custom'.$tool} == 1) {
1.362 raeburn 3786: if ($newval ne $userenv->{$envkey}) {
1.306 raeburn 3787: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
3788: $context);
1.275 raeburn 3789: if ($changed->{$tool}) {
3790: $newaccess->{$tool} = &mt('custom');
1.383 raeburn 3791: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3792: if ($newval =~ /^autolimit/) {
3793: if ($limit) {
3794: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3795: } else {
3796: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3797: }
3798: } elsif ($newval) {
3799: $newaccesstext->{$tool} = $reqdisplay{$newval};
3800: } else {
3801: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3802: }
1.275 raeburn 3803: } else {
1.383 raeburn 3804: if ($newval) {
3805: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3806: } else {
3807: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3808: }
1.275 raeburn 3809: }
3810: } else {
3811: $newaccess->{$tool} = $oldaccess->{$tool};
1.383 raeburn 3812: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3813: if ($newval =~ /^autolimit/) {
3814: if ($limit) {
3815: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3816: } else {
3817: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3818: }
3819: } elsif ($newval) {
3820: $newaccesstext->{$tool} = $reqdisplay{$newval};
3821: } else {
3822: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3823: }
1.275 raeburn 3824: } else {
1.383 raeburn 3825: if ($userenv->{$context.'.'.$tool}) {
3826: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3827: } else {
3828: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3829: }
1.275 raeburn 3830: }
3831: }
3832: } else {
3833: $newaccess->{$tool} = $oldaccess->{$tool};
3834: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3835: }
3836: } else {
3837: $changed->{$tool} = &tool_admin($tool,'',$changeHash,$context);
3838: if ($changed->{$tool}) {
3839: $newaccess->{$tool} = &mt('default');
3840: } else {
3841: $newaccess->{$tool} = $oldaccess->{$tool};
1.383 raeburn 3842: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3843: if ($newval =~ /^autolimit/) {
3844: if ($limit) {
3845: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3846: } else {
3847: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3848: }
3849: } elsif ($newval) {
3850: $newaccesstext->{$tool} = $reqdisplay{$newval};
3851: } else {
3852: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3853: }
1.275 raeburn 3854: } else {
1.383 raeburn 3855: if ($userenv->{$context.'.'.$tool}) {
3856: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3857: } else {
3858: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3859: }
1.275 raeburn 3860: }
3861: }
3862: }
3863: } else {
3864: $oldaccess->{$tool} = &mt('default');
3865: if ($env{'form.custom'.$tool} == 1) {
1.306 raeburn 3866: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
3867: $context);
1.275 raeburn 3868: if ($changed->{$tool}) {
3869: $newaccess->{$tool} = &mt('custom');
1.383 raeburn 3870: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3871: if ($newval =~ /^autolimit/) {
3872: if ($limit) {
3873: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3874: } else {
3875: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3876: }
3877: } elsif ($newval) {
3878: $newaccesstext->{$tool} = $reqdisplay{$newval};
3879: } else {
3880: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3881: }
1.275 raeburn 3882: } else {
1.383 raeburn 3883: if ($newval) {
3884: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3885: } else {
3886: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3887: }
1.275 raeburn 3888: }
3889: } else {
3890: $newaccess->{$tool} = $oldaccess->{$tool};
3891: }
3892: } else {
3893: $newaccess->{$tool} = $oldaccess->{$tool};
3894: }
3895: }
3896: }
3897: return;
3898: }
3899:
1.220 raeburn 3900: sub update_roles {
1.375 raeburn 3901: my ($r,$context,$showcredits) = @_;
1.4 www 3902: my $now=time;
1.225 raeburn 3903: my @rolechanges;
1.220 raeburn 3904: my %disallowed;
1.73 sakharuk 3905: $r->print('<h3>'.&mt('Modifying Roles').'</h3>');
1.404 raeburn 3906: foreach my $key (keys(%env)) {
1.135 raeburn 3907: next if (! $env{$key});
1.190 raeburn 3908: next if ($key eq 'form.action');
1.27 matthew 3909: # Revoke roles
1.135 raeburn 3910: if ($key=~/^form\.rev/) {
3911: if ($key=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) {
1.64 www 3912: # Revoke standard role
1.170 albertel 3913: my ($scope,$role) = ($1,$2);
3914: my $result =
3915: &Apache::lonnet::revokerole($env{'form.ccdomain'},
3916: $env{'form.ccuname'},
1.239 raeburn 3917: $scope,$role,'','',$context);
1.367 golterma 3918: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 3919: &mt('Revoking [_1] in [_2]',
3920: &Apache::lonnet::plaintext($role),
1.372 raeburn 3921: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 3922: $result ne "ok").'<br />');
3923: if ($result ne "ok") {
3924: $r->print(&mt('Error: [_1]',$result).'<br />');
3925: }
1.170 albertel 3926: if ($role eq 'st') {
1.202 raeburn 3927: my $result =
1.198 raeburn 3928: &Apache::lonuserutils::classlist_drop($scope,
3929: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 3930: $now);
1.367 golterma 3931: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.53 www 3932: }
1.225 raeburn 3933: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3934: push(@rolechanges,$role);
3935: }
1.196 raeburn 3936: }
1.195 raeburn 3937: if ($key=~m{^form\.rev\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}s) {
1.64 www 3938: # Revoke custom role
1.369 bisitz 3939: my $result = &Apache::lonnet::revokecustomrole(
3940: $env{'form.ccdomain'},$env{'form.ccuname'},$1,$2,$3,$4,'','',$context);
1.367 golterma 3941: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 3942: &mt('Revoking custom role [_1] by [_2] in [_3]',
1.372 raeburn 3943: $4,$3.':'.$2,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 3944: $result ne 'ok').'<br />');
3945: if ($result ne "ok") {
3946: $r->print(&mt('Error: [_1]',$result).'<br />');
3947: }
1.225 raeburn 3948: if (!grep(/^cr$/,@rolechanges)) {
3949: push(@rolechanges,'cr');
3950: }
1.64 www 3951: }
1.135 raeburn 3952: } elsif ($key=~/^form\.del/) {
3953: if ($key=~/^form\.del\:([^\_]+)\_([^\_\.]+)$/) {
1.116 raeburn 3954: # Delete standard role
1.170 albertel 3955: my ($scope,$role) = ($1,$2);
3956: my $result =
3957: &Apache::lonnet::assignrole($env{'form.ccdomain'},
3958: $env{'form.ccuname'},
1.239 raeburn 3959: $scope,$role,$now,0,1,'',
3960: $context);
1.367 golterma 3961: $r->print(&Apache::lonhtmlcommon::confirm_success(
3962: &mt('Deleting [_1] in [_2]',
1.369 bisitz 3963: &Apache::lonnet::plaintext($role),
1.372 raeburn 3964: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 3965: $result ne 'ok').'<br />');
3966: if ($result ne "ok") {
3967: $r->print(&mt('Error: [_1]',$result).'<br />');
3968: }
1.367 golterma 3969:
1.170 albertel 3970: if ($role eq 'st') {
1.202 raeburn 3971: my $result =
1.198 raeburn 3972: &Apache::lonuserutils::classlist_drop($scope,
3973: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 3974: $now);
1.369 bisitz 3975: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.81 albertel 3976: }
1.225 raeburn 3977: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3978: push(@rolechanges,$role);
3979: }
1.116 raeburn 3980: }
1.139 albertel 3981: if ($key=~m{^form\.del\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 3982: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
3983: # Delete custom role
1.369 bisitz 3984: my $result =
3985: &Apache::lonnet::assigncustomrole($env{'form.ccdomain'},
3986: $env{'form.ccuname'},$url,$rdom,$rnam,$rolename,$now,
3987: 0,1,$context);
3988: $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('Deleting custom role [_1] by [_2] in [_3]',
1.372 raeburn 3989: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 3990: $result ne "ok").'<br />');
3991: if ($result ne "ok") {
3992: $r->print(&mt('Error: [_1]',$result).'<br />');
3993: }
1.367 golterma 3994:
1.225 raeburn 3995: if (!grep(/^cr$/,@rolechanges)) {
3996: push(@rolechanges,'cr');
3997: }
1.116 raeburn 3998: }
1.135 raeburn 3999: } elsif ($key=~/^form\.ren/) {
1.101 albertel 4000: my $udom = $env{'form.ccdomain'};
4001: my $uname = $env{'form.ccuname'};
1.116 raeburn 4002: # Re-enable standard role
1.135 raeburn 4003: if ($key=~/^form\.ren\:([^\_]+)\_([^\_\.]+)$/) {
1.89 raeburn 4004: my $url = $1;
4005: my $role = $2;
4006: my $logmsg;
4007: my $output;
4008: if ($role eq 'st') {
1.141 albertel 4009: if ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
1.374 raeburn 4010: my ($cdom,$cnum,$csec) = ($1,$2,$3);
1.375 raeburn 4011: my $credits;
4012: if ($showcredits) {
4013: my $defaultcredits =
4014: &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
4015: $credits = &get_user_credits($defaultcredits,$cdom,$cnum);
4016: }
4017: my $result = &Apache::loncommon::commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$cdom,$cnum,$csec,$context,$credits);
1.220 raeburn 4018: if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course') || ($result eq 'refused')) {
1.223 raeburn 4019: if ($result eq 'refused' && $logmsg) {
4020: $output = $logmsg;
4021: } else {
1.369 bisitz 4022: $output = &mt('Error: [_1]',$result)."\n";
1.223 raeburn 4023: }
1.89 raeburn 4024: } else {
1.372 raeburn 4025: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Assigning [_1] in [_2] starting [_3]',
4026: &Apache::lonnet::plaintext($role),
4027: &Apache::loncommon::show_role_extent($url,$context,'st'),
4028: &Apache::lonlocal::locallocaltime($now))).'<br />'.$logmsg.'<br />';
1.89 raeburn 4029: }
4030: }
4031: } else {
1.101 albertel 4032: my $result=&Apache::lonnet::assignrole($env{'form.ccdomain'},
1.239 raeburn 4033: $env{'form.ccuname'},$url,$role,0,$now,'','',
4034: $context);
1.367 golterma 4035: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Re-enabling [_1] in [_2]',
1.372 raeburn 4036: &Apache::lonnet::plaintext($role),
4037: &Apache::loncommon::show_role_extent($url,$context,$role)),$result ne "ok").'<br />';
1.369 bisitz 4038: if ($result ne "ok") {
4039: $output .= &mt('Error: [_1]',$result).'<br />';
4040: }
4041: }
1.89 raeburn 4042: $r->print($output);
1.225 raeburn 4043: if (!grep(/^\Q$role\E$/,@rolechanges)) {
4044: push(@rolechanges,$role);
4045: }
1.113 raeburn 4046: }
1.116 raeburn 4047: # Re-enable custom role
1.139 albertel 4048: if ($key=~m{^form\.ren\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 4049: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
4050: my $result = &Apache::lonnet::assigncustomrole(
4051: $env{'form.ccdomain'}, $env{'form.ccuname'},
1.240 raeburn 4052: $url,$rdom,$rnam,$rolename,0,$now,undef,$context);
1.369 bisitz 4053: $r->print(&Apache::lonhtmlcommon::confirm_success(
4054: &mt('Re-enabling custom role [_1] by [_2] in [_3]',
1.372 raeburn 4055: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 4056: $result ne "ok").'<br />');
4057: if ($result ne "ok") {
4058: $r->print(&mt('Error: [_1]',$result).'<br />');
4059: }
1.225 raeburn 4060: if (!grep(/^cr$/,@rolechanges)) {
4061: push(@rolechanges,'cr');
4062: }
1.116 raeburn 4063: }
1.135 raeburn 4064: } elsif ($key=~/^form\.act/) {
1.101 albertel 4065: my $udom = $env{'form.ccdomain'};
4066: my $uname = $env{'form.ccuname'};
1.141 albertel 4067: if ($key=~/^form\.act\_($match_domain)\_($match_courseid)\_cr_cr_($match_domain)_($match_username)_([^\_]+)$/) {
1.65 www 4068: # Activate a custom role
1.83 albertel 4069: my ($one,$two,$three,$four,$five)=($1,$2,$3,$4,$5);
4070: my $url='/'.$one.'/'.$two;
4071: my $full=$one.'_'.$two.'_cr_cr_'.$three.'_'.$four.'_'.$five;
1.65 www 4072:
1.101 albertel 4073: my $start = ( $env{'form.start_'.$full} ?
4074: $env{'form.start_'.$full} :
1.88 raeburn 4075: $now );
1.101 albertel 4076: my $end = ( $env{'form.end_'.$full} ?
4077: $env{'form.end_'.$full} :
1.88 raeburn 4078: 0 );
4079:
4080: # split multiple sections
4081: my %sections = ();
1.101 albertel 4082: my $num_sections = &build_roles($env{'form.sec_'.$full},\%sections,$5);
1.88 raeburn 4083: if ($num_sections == 0) {
1.240 raeburn 4084: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end,$context));
1.88 raeburn 4085: } else {
1.114 albertel 4086: my %curr_groups =
1.117 raeburn 4087: &Apache::longroup::coursegroups($one,$two);
1.404 raeburn 4088: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.113 raeburn 4089: if (($sec eq 'none') || ($sec eq 'all') ||
4090: exists($curr_groups{$sec})) {
4091: $disallowed{$sec} = $url;
4092: next;
4093: }
4094: my $securl = $url.'/'.$sec;
1.240 raeburn 4095: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end,$context));
1.88 raeburn 4096: }
4097: }
1.225 raeburn 4098: if (!grep(/^cr$/,@rolechanges)) {
4099: push(@rolechanges,'cr');
4100: }
1.142 raeburn 4101: } elsif ($key=~/^form\.act\_($match_domain)\_($match_name)\_([^\_]+)$/) {
1.27 matthew 4102: # Activate roles for sections with 3 id numbers
4103: # set start, end times, and the url for the class
1.83 albertel 4104: my ($one,$two,$three)=($1,$2,$3);
1.101 albertel 4105: my $start = ( $env{'form.start_'.$one.'_'.$two.'_'.$three} ?
4106: $env{'form.start_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 4107: $now );
1.101 albertel 4108: my $end = ( $env{'form.end_'.$one.'_'.$two.'_'.$three} ?
4109: $env{'form.end_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 4110: 0 );
1.83 albertel 4111: my $url='/'.$one.'/'.$two;
1.88 raeburn 4112: my $type = 'three';
4113: # split multiple sections
4114: my %sections = ();
1.101 albertel 4115: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections,$three);
1.375 raeburn 4116: my $credits;
4117: if ($three eq 'st') {
4118: if ($showcredits) {
4119: my $defaultcredits =
4120: &Apache::lonuserutils::get_defaultcredits($one,$two);
4121: $credits = $env{'form.credits_'.$one.'_'.$two.'_'.$three};
4122: $credits =~ s/[^\d\.]//g;
4123: if ($credits eq $defaultcredits) {
4124: undef($credits);
4125: }
4126: }
4127: }
1.88 raeburn 4128: if ($num_sections == 0) {
1.375 raeburn 4129: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 4130: } else {
1.114 albertel 4131: my %curr_groups =
1.117 raeburn 4132: &Apache::longroup::coursegroups($one,$two);
1.88 raeburn 4133: my $emptysec = 0;
1.404 raeburn 4134: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.88 raeburn 4135: $sec =~ s/\W//g;
1.113 raeburn 4136: if ($sec ne '') {
4137: if (($sec eq 'none') || ($sec eq 'all') ||
4138: exists($curr_groups{$sec})) {
4139: $disallowed{$sec} = $url;
4140: next;
4141: }
1.88 raeburn 4142: my $securl = $url.'/'.$sec;
1.375 raeburn 4143: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec,$context,$credits));
1.88 raeburn 4144: } else {
4145: $emptysec = 1;
4146: }
4147: }
4148: if ($emptysec) {
1.375 raeburn 4149: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 4150: }
1.225 raeburn 4151: }
4152: if (!grep(/^\Q$three\E$/,@rolechanges)) {
4153: push(@rolechanges,$three);
4154: }
1.135 raeburn 4155: } elsif ($key=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
1.27 matthew 4156: # Activate roles for sections with two id numbers
4157: # set start, end times, and the url for the class
1.101 albertel 4158: my $start = ( $env{'form.start_'.$1.'_'.$2} ?
4159: $env{'form.start_'.$1.'_'.$2} :
1.27 matthew 4160: $now );
1.101 albertel 4161: my $end = ( $env{'form.end_'.$1.'_'.$2} ?
4162: $env{'form.end_'.$1.'_'.$2} :
1.27 matthew 4163: 0 );
1.225 raeburn 4164: my $one = $1;
4165: my $two = $2;
4166: my $url='/'.$one.'/';
1.88 raeburn 4167: # split multiple sections
4168: my %sections = ();
1.225 raeburn 4169: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two},\%sections,$two);
1.88 raeburn 4170: if ($num_sections == 0) {
1.240 raeburn 4171: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 4172: } else {
4173: my $emptysec = 0;
1.404 raeburn 4174: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.88 raeburn 4175: if ($sec ne '') {
4176: my $securl = $url.'/'.$sec;
1.240 raeburn 4177: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$two,$start,$end,$one,undef,$sec,$context));
1.88 raeburn 4178: } else {
4179: $emptysec = 1;
4180: }
4181: }
4182: if ($emptysec) {
1.240 raeburn 4183: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 4184: }
4185: }
1.225 raeburn 4186: if (!grep(/^\Q$two\E$/,@rolechanges)) {
4187: push(@rolechanges,$two);
4188: }
1.64 www 4189: } else {
1.190 raeburn 4190: $r->print('<p><span class="LC_error">'.&mt('ERROR').': '.&mt('Unknown command').' <tt>'.$key.'</tt></span></p><br />');
1.64 www 4191: }
1.113 raeburn 4192: foreach my $key (sort(keys(%disallowed))) {
1.274 bisitz 4193: $r->print('<p class="LC_warning">');
1.113 raeburn 4194: if (($key eq 'none') || ($key eq 'all')) {
1.274 bisitz 4195: $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 4196: } else {
1.274 bisitz 4197: $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 4198: }
1.274 bisitz 4199: $r->print('</p><p>'
4200: .&mt('Please [_1]go back[_2] and choose a different section name.'
4201: ,'<a href="javascript:history.go(-1)'
4202: ,'</a>')
4203: .'</p><br />'
4204: );
1.113 raeburn 4205: }
4206: }
1.101 albertel 4207: } # End of foreach (keys(%env))
1.75 www 4208: # Flush the course logs so reverse user roles immediately updated
1.349 raeburn 4209: $r->register_cleanup(\&Apache::lonnet::flushcourselogs);
1.225 raeburn 4210: if (@rolechanges == 0) {
1.372 raeburn 4211: $r->print('<p>'.&mt('No roles to modify').'</p>');
1.193 raeburn 4212: }
1.225 raeburn 4213: return @rolechanges;
1.220 raeburn 4214: }
4215:
1.375 raeburn 4216: sub get_user_credits {
4217: my ($uname,$udom,$defaultcredits,$cdom,$cnum) = @_;
4218: if ($cdom eq '' || $cnum eq '') {
4219: return unless ($env{'request.course.id'});
4220: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4221: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
4222: }
4223: my $credits;
4224: my %currhash =
4225: &Apache::lonnet::get('classlist',[$uname.':'.$udom],$cdom,$cnum);
4226: if (keys(%currhash) > 0) {
4227: my @items = split(/:/,$currhash{$uname.':'.$udom});
4228: my $crdidx = &Apache::loncoursedata::CL_CREDITS() - 3;
4229: $credits = $items[$crdidx];
4230: $credits =~ s/[^\d\.]//g;
4231: }
4232: if ($credits eq $defaultcredits) {
4233: undef($credits);
4234: }
4235: return $credits;
4236: }
4237:
1.220 raeburn 4238: sub enroll_single_student {
1.375 raeburn 4239: my ($r,$uhome,$amode,$genpwd,$now,$newuser,$context,$crstype,
4240: $showcredits,$defaultcredits) = @_;
1.318 raeburn 4241: $r->print('<h3>');
4242: if ($crstype eq 'Community') {
4243: $r->print(&mt('Enrolling Member'));
4244: } else {
4245: $r->print(&mt('Enrolling Student'));
4246: }
4247: $r->print('</h3>');
1.220 raeburn 4248:
4249: # Remove non alphanumeric values from section
4250: $env{'form.sections'}=~s/\W//g;
4251:
1.375 raeburn 4252: my $credits;
4253: if (($showcredits) && ($env{'form.credits'} ne '')) {
4254: $credits = $env{'form.credits'};
4255: $credits =~ s/[^\d\.]//g;
4256: if ($credits ne '') {
4257: if ($credits eq $defaultcredits) {
4258: undef($credits);
4259: }
4260: }
4261: }
4262:
1.220 raeburn 4263: # Clean out any old student roles the user has in this class.
4264: &Apache::lonuserutils::modifystudent($env{'form.ccdomain'},
4265: $env{'form.ccuname'},$env{'request.course.id'},undef,$uhome);
4266: my ($startdate,$enddate) = &Apache::lonuserutils::get_dates_from_form();
4267: my $enroll_result =
4268: &Apache::lonnet::modify_student_enrollment($env{'form.ccdomain'},
4269: $env{'form.ccuname'},$env{'form.cid'},$env{'form.cfirstname'},
4270: $env{'form.cmiddlename'},$env{'form.clastname'},
4271: $env{'form.generation'},$env{'form.sections'},$enddate,
1.375 raeburn 4272: $startdate,'manual',undef,$env{'request.course.id'},'',$context,
4273: $credits);
1.220 raeburn 4274: if ($enroll_result =~ /^ok/) {
1.381 bisitz 4275: $r->print(&mt('[_1] enrolled','<b>'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.'</b>'));
1.220 raeburn 4276: if ($env{'form.sections'} ne '') {
4277: $r->print(' '.&mt('in section [_1]',$env{'form.sections'}));
4278: }
4279: my ($showstart,$showend);
4280: if ($startdate <= $now) {
4281: $showstart = &mt('Access starts immediately');
4282: } else {
4283: $showstart = &mt('Access starts: ').&Apache::lonlocal::locallocaltime($startdate);
4284: }
4285: if ($enddate == 0) {
4286: $showend = &mt('ends: no ending date');
4287: } else {
4288: $showend = &mt('ends: ').&Apache::lonlocal::locallocaltime($enddate);
4289: }
4290: $r->print('.<br />'.$showstart.'; '.$showend);
4291: if ($startdate <= $now && !$newuser) {
1.386 bisitz 4292: $r->print('<p class="LC_info">');
1.318 raeburn 4293: if ($crstype eq 'Community') {
1.392 raeburn 4294: $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 4295: } else {
1.392 raeburn 4296: $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 4297: }
4298: $r->print('</p>');
1.220 raeburn 4299: }
4300: } else {
4301: $r->print(&mt('unable to enroll').": ".$enroll_result);
4302: }
4303: return;
1.188 raeburn 4304: }
4305:
1.204 raeburn 4306: sub get_defaultquota_text {
4307: my ($settingstatus) = @_;
4308: my $defquotatext;
4309: if ($settingstatus eq '') {
1.383 raeburn 4310: $defquotatext = &mt('default');
1.204 raeburn 4311: } else {
4312: my ($usertypes,$order) =
4313: &Apache::lonnet::retrieve_inst_usertypes($env{'form.ccdomain'});
4314: if ($usertypes->{$settingstatus} eq '') {
1.383 raeburn 4315: $defquotatext = &mt('default');
1.204 raeburn 4316: } else {
1.383 raeburn 4317: $defquotatext = &mt('default for [_1]',$usertypes->{$settingstatus});
1.204 raeburn 4318: }
4319: }
4320: return $defquotatext;
4321: }
4322:
1.188 raeburn 4323: sub update_result_form {
4324: my ($uhome) = @_;
4325: my $outcome =
1.367 golterma 4326: '<form name="userupdate" method="post" action="">'."\n";
1.160 raeburn 4327: foreach my $item ('srchby','srchin','srchtype','srchterm','srchdomain','ccuname','ccdomain') {
1.188 raeburn 4328: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 4329: }
1.207 raeburn 4330: if ($env{'form.origname'} ne '') {
4331: $outcome .= '<input type="hidden" name="origname" value="'.$env{'form.origname'}.'" />'."\n";
4332: }
1.160 raeburn 4333: foreach my $item ('sortby','seluname','seludom') {
4334: if (exists($env{'form.'.$item})) {
1.188 raeburn 4335: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 4336: }
4337: }
1.188 raeburn 4338: if ($uhome eq 'no_host') {
4339: $outcome .= '<input type="hidden" name="forcenewuser" value="1" />'."\n";
4340: }
4341: $outcome .= '<input type="hidden" name="phase" value="" />'."\n".
1.383 raeburn 4342: '<input type="hidden" name="currstate" value="" />'."\n".
4343: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
1.188 raeburn 4344: '</form>';
4345: return $outcome;
1.4 www 4346: }
4347:
1.149 raeburn 4348: sub quota_admin {
1.378 raeburn 4349: my ($setquota,$changeHash,$name) = @_;
1.149 raeburn 4350: my $quotachanged;
4351: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
4352: # Current user has quota modification privileges
1.267 raeburn 4353: if (ref($changeHash) eq 'HASH') {
4354: $quotachanged = 1;
1.378 raeburn 4355: $changeHash->{$name.'quota'} = $setquota;
1.267 raeburn 4356: }
1.149 raeburn 4357: }
4358: return $quotachanged;
4359: }
4360:
1.267 raeburn 4361: sub tool_admin {
1.275 raeburn 4362: my ($tool,$settool,$changeHash,$context) = @_;
4363: my $canchange = 0;
1.279 raeburn 4364: if ($context eq 'requestcourses') {
1.275 raeburn 4365: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
4366: $canchange = 1;
4367: }
1.300 raeburn 4368: } elsif ($context eq 'reqcrsotherdom') {
4369: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
4370: $canchange = 1;
4371: }
1.362 raeburn 4372: } elsif ($context eq 'requestauthor') {
4373: if (&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) {
4374: $canchange = 1;
4375: }
1.275 raeburn 4376: } elsif (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
4377: # Current user has quota modification privileges
4378: $canchange = 1;
4379: }
1.267 raeburn 4380: my $toolchanged;
1.275 raeburn 4381: if ($canchange) {
1.267 raeburn 4382: if (ref($changeHash) eq 'HASH') {
4383: $toolchanged = 1;
1.362 raeburn 4384: if ($tool eq 'requestauthor') {
4385: $changeHash->{$context} = $settool;
4386: } else {
4387: $changeHash->{$context.'.'.$tool} = $settool;
4388: }
1.267 raeburn 4389: }
4390: }
4391: return $toolchanged;
4392: }
4393:
1.88 raeburn 4394: sub build_roles {
1.89 raeburn 4395: my ($sectionstr,$sections,$role) = @_;
1.88 raeburn 4396: my $num_sections = 0;
4397: if ($sectionstr=~ /,/) {
4398: my @secnums = split/,/,$sectionstr;
1.89 raeburn 4399: if ($role eq 'st') {
4400: $secnums[0] =~ s/\W//g;
4401: $$sections{$secnums[0]} = 1;
4402: $num_sections = 1;
4403: } else {
4404: foreach my $sec (@secnums) {
4405: $sec =~ ~s/\W//g;
1.150 banghart 4406: if (!($sec eq "")) {
1.89 raeburn 4407: if (exists($$sections{$sec})) {
4408: $$sections{$sec} ++;
4409: } else {
4410: $$sections{$sec} = 1;
4411: $num_sections ++;
4412: }
1.88 raeburn 4413: }
4414: }
4415: }
4416: } else {
4417: $sectionstr=~s/\W//g;
4418: unless ($sectionstr eq '') {
4419: $$sections{$sectionstr} = 1;
4420: $num_sections ++;
4421: }
4422: }
1.129 albertel 4423:
1.88 raeburn 4424: return $num_sections;
4425: }
4426:
1.58 www 4427: # ========================================================== Custom Role Editor
4428:
4429: sub custom_role_editor {
1.406.2.14 raeburn 4430: my ($r,$context,$brcrum,$prefix,$permission) = @_;
1.324 raeburn 4431: my $action = $env{'form.customroleaction'};
1.406.2.14 raeburn 4432: my ($rolename,$helpitem);
1.324 raeburn 4433: if ($action eq 'new') {
4434: $rolename=$env{'form.newrolename'};
4435: } else {
4436: $rolename=$env{'form.rolename'};
1.59 www 4437: }
4438:
1.324 raeburn 4439: my ($crstype,$context);
4440: if ($env{'request.course.id'}) {
4441: $crstype = &Apache::loncommon::course_type();
4442: $context = 'course';
1.406.2.14 raeburn 4443: $helpitem = 'Course_Editing_Custom_Roles';
1.324 raeburn 4444: } else {
4445: $context = 'domain';
1.406.2.5 raeburn 4446: $crstype = 'course';
1.406.2.14 raeburn 4447: $helpitem = 'Domain_Editing_Custom_Roles';
1.324 raeburn 4448: }
1.351 raeburn 4449:
4450: $rolename=~s/[^A-Za-z0-9]//gs;
4451: if (!$rolename || $env{'form.phase'} eq 'pickrole') {
1.406.2.14 raeburn 4452: &print_username_entry_form($r,$context,undef,undef,undef,$crstype,$brcrum,
4453: $permission);
1.351 raeburn 4454: return;
4455: }
4456:
1.406.2.5 raeburn 4457: my $formname = 'form1';
4458: my %privs=();
4459: my $body_top = '<h2>';
4460: # ------------------------------------------------------- Does this role exist?
1.59 www 4461: my ($rdummy,$roledef)=
4462: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
4463: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.406.2.5 raeburn 4464: $body_top .= &mt('Existing Role').' "';
1.61 www 4465: # ------------------------------------------------- Get current role privileges
1.406.2.5 raeburn 4466: ($privs{'system'},$privs{'domain'},$privs{'course'})=split(/\_/,$roledef);
4467: if ($privs{'system'} =~ /bre\&S/) {
4468: if ($context eq 'domain') {
4469: $crstype = 'Course';
4470: } elsif ($crstype eq 'Community') {
4471: $privs{'system'} =~ s/bre\&S//;
4472: }
4473: } elsif ($context eq 'domain') {
4474: $crstype = 'Course';
1.324 raeburn 4475: }
1.59 www 4476: } else {
1.406.2.5 raeburn 4477: $body_top .= &mt('New Role').' "';
4478: $roledef='';
1.59 www 4479: }
1.153 banghart 4480: $body_top .= $rolename.'"</h2>';
1.406.2.5 raeburn 4481:
4482: # ------------------------------------------------------- What can be assigned?
4483: my %full=();
4484: my %levels=(
4485: course => {},
4486: domain => {},
4487: system => {},
4488: );
4489: my %levelscurrent=(
4490: course => {},
4491: domain => {},
4492: system => {},
4493: );
4494: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
1.160 raeburn 4495: my ($jsback,$elements) = &crumb_utilities();
1.406.2.5 raeburn 4496: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
4497: my $head_script =
4498: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,
4499: \%full,\@templateroles,$jsback);
1.351 raeburn 4500: push (@{$brcrum},
1.406.2.5 raeburn 4501: {href => "javascript:backPage(document.$formname,'pickrole','')",
1.351 raeburn 4502: text => "Pick custom role",
4503: faq => 282,bug=>'Instructor Interface',},
1.406.2.5 raeburn 4504: {href => "javascript:backPage(document.$formname,'','')",
1.351 raeburn 4505: text => "Edit custom role",
4506: faq => 282,
4507: bug => 'Instructor Interface',
1.406.2.14 raeburn 4508: help => $helpitem}
1.351 raeburn 4509: );
4510: my $args = { bread_crumbs => $brcrum,
4511: bread_crumbs_component => 'User Management'};
4512: $r->print(&Apache::loncommon::start_page('Custom Role Editor',
4513: $head_script,$args).
4514: $body_top);
1.406.2.5 raeburn 4515: $r->print('<form name="'.$formname.'" method="post" action="">'."\n".
4516: &Apache::lonuserutils::custom_role_header($context,$crstype,
4517: \@templateroles,$prefix));
1.264 bisitz 4518:
1.61 www 4519: $r->print(<<ENDCCF);
4520: <input type="hidden" name="phase" value="set_custom_roles" />
4521: <input type="hidden" name="rolename" value="$rolename" />
4522: ENDCCF
1.406.2.5 raeburn 4523: $r->print(&Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
4524: \%levelscurrent,$prefix));
1.135 raeburn 4525: $r->print(&Apache::loncommon::end_data_table().
1.190 raeburn 4526: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
1.160 raeburn 4527: '<input type="hidden" name="startrolename" value="'.$env{'form.rolename'}.
1.406.2.5 raeburn 4528: '" />'."\n".'<input type="hidden" name="currstate" value="" />'."\n".
1.160 raeburn 4529: '<input type="reset" value="'.&mt("Reset").'" />'."\n".
1.351 raeburn 4530: '<input type="submit" value="'.&mt('Save').'" /></form>');
1.61 www 4531: }
1.406.2.5 raeburn 4532:
1.61 www 4533: # ---------------------------------------------------------- Call to definerole
4534: sub set_custom_role {
1.406.2.14 raeburn 4535: my ($r,$context,$brcrum,$prefix,$permission) = @_;
1.101 albertel 4536: my $rolename=$env{'form.rolename'};
1.63 www 4537: $rolename=~s/[^A-Za-z0-9]//gs;
1.150 banghart 4538: if (!$rolename) {
1.406.2.14 raeburn 4539: &custom_role_editor($r,$context,$brcrum,$prefix,$permission);
1.61 www 4540: return;
4541: }
1.160 raeburn 4542: my ($jsback,$elements) = &crumb_utilities();
1.301 bisitz 4543: my $jscript = '<script type="text/javascript">'
4544: .'// <![CDATA['."\n"
4545: .$jsback."\n"
4546: .'// ]]>'."\n"
4547: .'</script>'."\n";
1.406.2.14 raeburn 4548: my $helpitem = 'Course_Editing_Custom_Roles';
4549: if ($context eq 'domain') {
4550: $helpitem = 'Domain_Editing_Custom_Roles';
4551: }
1.352 raeburn 4552: push(@{$brcrum},
4553: {href => "javascript:backPage(document.customresult,'pickrole','')",
4554: text => "Pick custom role",
4555: faq => 282,
4556: bug => 'Instructor Interface',},
4557: {href => "javascript:backPage(document.customresult,'selected_custom_edit','')",
4558: text => "Edit custom role",
4559: faq => 282,
4560: bug => 'Instructor Interface',},
4561: {href => "javascript:backPage(document.customresult,'set_custom_roles','')",
4562: text => "Result",
4563: faq => 282,
4564: bug => 'Instructor Interface',
1.406.2.14 raeburn 4565: help => $helpitem,}
1.352 raeburn 4566: );
4567: my $args = { bread_crumbs => $brcrum,
1.406.2.5 raeburn 4568: bread_crumbs_component => 'User Management'};
1.351 raeburn 4569: $r->print(&Apache::loncommon::start_page('Save Custom Role',$jscript,$args));
1.160 raeburn 4570:
1.393 raeburn 4571: my $newrole;
1.61 www 4572: my ($rdummy,$roledef)=
1.110 albertel 4573: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
4574:
1.61 www 4575: # ------------------------------------------------------- Does this role exist?
1.188 raeburn 4576: $r->print('<h3>');
1.61 www 4577: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.73 sakharuk 4578: $r->print(&mt('Existing Role').' "');
1.61 www 4579: } else {
1.73 sakharuk 4580: $r->print(&mt('New Role').' "');
1.61 www 4581: $roledef='';
1.393 raeburn 4582: $newrole = 1;
1.61 www 4583: }
1.188 raeburn 4584: $r->print($rolename.'"</h3>');
1.406.2.5 raeburn 4585: # ------------------------------------------------- Assign role and show result
1.61 www 4586:
1.387 bisitz 4587: my $errmsg;
1.406.2.5 raeburn 4588: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$prefix);
4589: # Assign role and return result
4590: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
4591: $newprivs{'c'});
1.387 bisitz 4592: if ($result ne 'ok') {
4593: $errmsg = ': '.$result;
4594: }
4595: my $message =
4596: &Apache::lonhtmlcommon::confirm_success(
4597: &mt('Defining Role').$errmsg, ($result eq 'ok' ? 0 : 1));
1.101 albertel 4598: if ($env{'request.course.id'}) {
4599: my $url='/'.$env{'request.course.id'};
1.63 www 4600: $url=~s/\_/\//g;
1.387 bisitz 4601: $result =
4602: &Apache::lonnet::assigncustomrole(
4603: $env{'user.domain'},$env{'user.name'},
4604: $url,
4605: $env{'user.domain'},$env{'user.name'},
4606: $rolename,undef,undef,undef,$context);
4607: if ($result ne 'ok') {
4608: $errmsg = ': '.$result;
4609: }
4610: $message .=
4611: '<br />'
4612: .&Apache::lonhtmlcommon::confirm_success(
4613: &mt('Assigning Role to Self').$errmsg, ($result eq 'ok' ? 0 : 1));
1.63 www 4614: }
1.380 bisitz 4615: $r->print(
1.387 bisitz 4616: &Apache::loncommon::confirmwrapper($message)
4617: .'<br />'
4618: .&Apache::lonhtmlcommon::actionbox([
4619: '<a href="javascript:backPage(document.customresult,'."'pickrole'".')">'
4620: .&mt('Create or edit another custom role')
4621: .'</a>'])
1.380 bisitz 4622: .'<form name="customresult" method="post" action="">'
1.387 bisitz 4623: .&Apache::lonhtmlcommon::echo_form_input([])
4624: .'</form>'
1.380 bisitz 4625: );
1.58 www 4626: }
4627:
1.2 www 4628: # ================================================================ Main Handler
4629: sub handler {
4630: my $r = shift;
4631: if ($r->header_only) {
1.68 www 4632: &Apache::loncommon::content_type($r,'text/html');
1.2 www 4633: $r->send_http_header;
4634: return OK;
4635: }
1.406.2.14 raeburn 4636: my ($context,$crstype,$cid,$cnum,$cdom,$allhelpitems);
4637:
1.190 raeburn 4638: if ($env{'request.course.id'}) {
4639: $context = 'course';
1.318 raeburn 4640: $crstype = &Apache::loncommon::course_type();
1.190 raeburn 4641: } elsif ($env{'request.role'} =~ /^au\./) {
1.206 raeburn 4642: $context = 'author';
1.190 raeburn 4643: } else {
4644: $context = 'domain';
4645: }
1.375 raeburn 4646:
1.406.2.14 raeburn 4647: my ($permission,$allowed) =
4648: &Apache::lonuserutils::get_permission($context,$crstype);
4649:
4650: if ($allowed) {
4651: my @allhelp;
4652: if ($context eq 'course') {
4653: $cid = $env{'request.course.id'};
4654: $cdom = $env{'course.'.$cid.'.domain'};
4655: $cnum = $env{'course.'.$cid.'.num'};
4656:
4657: if ($permission->{'cusr'}) {
4658: push(@allhelp,'Course_Create_Class_List');
4659: }
4660: if ($permission->{'view'} || $permission->{'cusr'}) {
4661: push(@allhelp,('Course_Change_Privileges','Course_View_Class_List'));
4662: }
4663: if ($permission->{'custom'}) {
4664: push(@allhelp,'Course_Editing_Custom_Roles');
4665: }
4666: if ($permission->{'cusr'}) {
4667: push(@allhelp,('Course_Add_Student','Course_Drop_Student'));
4668: }
4669: unless ($permission->{'cusr_section'}) {
4670: if (&Apache::lonnet::auto_run($cnum,$cdom) && (($permission->{'cusr'}) || ($permission->{'view'}))) {
4671: push(@allhelp,'Course_Automated_Enrollment');
4672: }
1.406.2.21! raeburn 4673: if (($permission->{'selfenrolladmin'}) || ($permission->{'selfenrollview'})) {
1.406.2.14 raeburn 4674: push(@allhelp,'Course_Approve_Selfenroll');
4675: }
4676: }
4677: if ($permission->{'grp_manage'}) {
4678: push(@allhelp,'Course_Manage_Group');
4679: }
4680: if ($permission->{'view'} || $permission->{'cusr'}) {
4681: push(@allhelp,'Course_User_Logs');
4682: }
4683: } elsif ($context eq 'author') {
4684: push(@allhelp,('Author_Change_Privileges','Author_Create_Coauthor_List',
4685: 'Author_View_Coauthor_List','Author_User_Logs'));
4686: } else {
4687: if ($permission->{'cusr'}) {
4688: push(@allhelp,'Domain_Change_Privileges');
4689: if ($permission->{'activity'}) {
4690: push(@allhelp,'Domain_User_Access_Logs');
4691: }
4692: push(@allhelp,('Domain_Create_Users','Domain_View_Users_List'));
4693: if ($permission->{'custom'}) {
4694: push(@allhelp,'Domain_Editing_Custom_Roles');
4695: }
4696: push(@allhelp,('Domain_Role_Approvals','Domain_Username_Approvals','Domain_Change_Logs'));
4697: } elsif ($permission->{'view'}) {
4698: push(@allhelp,'Domain_View_Privileges');
4699: if ($permission->{'activity'}) {
4700: push(@allhelp,'Domain_User_Access_Logs');
4701: }
4702: push(@allhelp,('Domain_View_Users_List','Domain_Change_Logs'));
4703: }
4704: }
4705: if (@allhelp) {
4706: $allhelpitems = join(',',@allhelp);
4707: }
4708: }
4709:
1.190 raeburn 4710: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.233 raeburn 4711: ['action','state','callingform','roletype','showrole','bulkaction','popup','phase',
1.391 raeburn 4712: 'username','domain','srchterm','srchdomain','srchin','srchby','srchtype','queue']);
1.190 raeburn 4713: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.351 raeburn 4714: my $args;
4715: my $brcrum = [];
4716: my $bread_crumbs_component = 'User Management';
1.391 raeburn 4717: if (($env{'form.action'} ne 'dateselect') && ($env{'form.action'} ne 'displayuserreq')) {
1.351 raeburn 4718: $brcrum = [{href=>"/adm/createuser",
4719: text=>"User Management",
1.406.2.14 raeburn 4720: help=>$allhelpitems}
1.351 raeburn 4721: ];
1.202 raeburn 4722: }
1.190 raeburn 4723: if (!$allowed) {
1.358 raeburn 4724: if ($context eq 'course') {
4725: $r->internal_redirect('/adm/viewclasslist');
4726: return OK;
4727: }
1.190 raeburn 4728: $env{'user.error.msg'}=
4729: "/adm/createuser:cst:0:0:Cannot create/modify user data ".
4730: "or view user status.";
4731: return HTTP_NOT_ACCEPTABLE;
4732: }
4733:
4734: &Apache::loncommon::content_type($r,'text/html');
4735: $r->send_http_header;
4736:
1.375 raeburn 4737: my $showcredits;
4738: if ((($context eq 'course') && ($crstype eq 'Course')) ||
4739: ($context eq 'domain')) {
4740: my %domdefaults =
4741: &Apache::lonnet::get_domain_defaults($env{'request.role.domain'});
4742: if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'}) {
4743: $showcredits = 1;
4744: }
4745: }
4746:
1.190 raeburn 4747: # Main switch on form.action and form.state, as appropriate
4748: if (! exists($env{'form.action'})) {
1.351 raeburn 4749: $args = {bread_crumbs => $brcrum,
4750: bread_crumbs_component => $bread_crumbs_component};
4751: $r->print(&header(undef,$args));
1.318 raeburn 4752: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 4753: } elsif ($env{'form.action'} eq 'upload' && $permission->{'cusr'}) {
1.406.2.14 raeburn 4754: my $helpitem = 'Course_Create_Class_List';
4755: if ($context eq 'author') {
4756: $helpitem = 'Author_Create_Coauthor_List';
4757: } elsif ($context eq 'domain') {
4758: $helpitem = 'Domain_Create_Users';
4759: }
1.351 raeburn 4760: push(@{$brcrum},
4761: { href => '/adm/createuser?action=upload&state=',
4762: text => 'Upload Users List',
1.406.2.14 raeburn 4763: help => $helpitem,
1.351 raeburn 4764: });
4765: $bread_crumbs_component = 'Upload Users List';
4766: $args = {bread_crumbs => $brcrum,
4767: bread_crumbs_component => $bread_crumbs_component};
4768: $r->print(&header(undef,$args));
1.190 raeburn 4769: $r->print('<form name="studentform" method="post" '.
4770: 'enctype="multipart/form-data" '.
4771: ' action="/adm/createuser">'."\n");
4772: if (! exists($env{'form.state'})) {
4773: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4774: } elsif ($env{'form.state'} eq 'got_file') {
1.406.2.15 raeburn 4775: my $result =
4776: &Apache::lonuserutils::print_upload_manager_form($r,$context,
4777: $permission,
4778: $crstype,$showcredits);
4779: if ($result eq 'missingdata') {
4780: delete($env{'form.state'});
4781: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4782: }
1.190 raeburn 4783: } elsif ($env{'form.state'} eq 'enrolling') {
4784: if ($env{'form.datatoken'}) {
1.406.2.15 raeburn 4785: my $result = &Apache::lonuserutils::upfile_drop_add($r,$context,
4786: $permission,
4787: $showcredits);
4788: if ($result eq 'missingdata') {
4789: delete($env{'form.state'});
4790: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4791: } elsif ($result eq 'invalidhome') {
4792: $env{'form.state'} = 'got_file';
4793: delete($env{'form.lcserver'});
4794: my $result =
4795: &Apache::lonuserutils::print_upload_manager_form($r,$context,$permission,
4796: $crstype,$showcredits);
4797: if ($result eq 'missingdata') {
4798: delete($env{'form.state'});
4799: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4800: }
4801: }
4802: } else {
4803: delete($env{'form.state'});
4804: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
1.190 raeburn 4805: }
4806: } else {
4807: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4808: }
1.406.2.15 raeburn 4809: $r->print('</form>');
1.406.2.5 raeburn 4810: } elsif (((($env{'form.action'} eq 'singleuser') || ($env{'form.action'}
4811: eq 'singlestudent')) && ($permission->{'cusr'})) ||
1.406.2.6 raeburn 4812: (($env{'form.action'} eq 'singleuser') && ($permission->{'view'})) ||
1.406.2.5 raeburn 4813: (($env{'form.action'} eq 'accesslogs') && ($permission->{'activity'}))) {
1.190 raeburn 4814: my $phase = $env{'form.phase'};
4815: my @search = ('srchterm','srchby','srchin','srchtype','srchdomain');
1.192 albertel 4816: &Apache::loncreateuser::restore_prev_selections();
4817: my $srch;
4818: foreach my $item (@search) {
4819: $srch->{$item} = $env{'form.'.$item};
4820: }
1.207 raeburn 4821: if (($phase eq 'get_user_info') || ($phase eq 'userpicked') ||
1.406.2.5 raeburn 4822: ($phase eq 'createnewuser') || ($phase eq 'activity')) {
1.207 raeburn 4823: if ($env{'form.phase'} eq 'createnewuser') {
4824: my $response;
4825: if ($env{'form.srchterm'} !~ /^$match_username$/) {
1.366 bisitz 4826: my $response =
4827: '<span class="LC_warning">'
4828: .&mt('You must specify a valid username. Only the following are allowed:'
4829: .' letters numbers - . @')
4830: .'</span>';
1.221 raeburn 4831: $env{'form.phase'} = '';
1.375 raeburn 4832: &print_username_entry_form($r,$context,$response,$srch,undef,
1.406.2.14 raeburn 4833: $crstype,$brcrum,$permission);
1.207 raeburn 4834: } else {
4835: my $ccuname =&LONCAPA::clean_username($srch->{'srchterm'});
4836: my $ccdomain=&LONCAPA::clean_domain($srch->{'srchdomain'});
4837: &print_user_modification_page($r,$ccuname,$ccdomain,
1.221 raeburn 4838: $srch,$response,$context,
1.375 raeburn 4839: $permission,$crstype,$brcrum,
4840: $showcredits);
1.207 raeburn 4841: }
4842: } elsif ($env{'form.phase'} eq 'get_user_info') {
1.190 raeburn 4843: my ($currstate,$response,$forcenewuser,$results) =
1.221 raeburn 4844: &user_search_result($context,$srch);
1.190 raeburn 4845: if ($env{'form.currstate'} eq 'modify') {
4846: $currstate = $env{'form.currstate'};
4847: }
4848: if ($currstate eq 'select') {
4849: &print_user_selection_page($r,$response,$srch,$results,
1.351 raeburn 4850: \@search,$context,undef,$crstype,
4851: $brcrum);
1.406.2.5 raeburn 4852: } elsif (($currstate eq 'modify') || ($env{'form.action'} eq 'accesslogs')) {
4853: my ($ccuname,$ccdomain,$uhome);
1.190 raeburn 4854: if (($srch->{'srchby'} eq 'uname') &&
4855: ($srch->{'srchtype'} eq 'exact')) {
4856: $ccuname = $srch->{'srchterm'};
4857: $ccdomain= $srch->{'srchdomain'};
4858: } else {
4859: my @matchedunames = keys(%{$results});
4860: ($ccuname,$ccdomain) = split(/:/,$matchedunames[0]);
4861: }
4862: $ccuname =&LONCAPA::clean_username($ccuname);
4863: $ccdomain=&LONCAPA::clean_domain($ccdomain);
1.406.2.5 raeburn 4864: if ($env{'form.action'} eq 'accesslogs') {
4865: my $uhome;
4866: if (($ccuname ne '') && ($ccdomain ne '')) {
4867: $uhome = &Apache::lonnet::homeserver($ccuname,$ccdomain);
4868: }
4869: if (($uhome eq '') || ($uhome eq 'no_host')) {
4870: $env{'form.phase'} = '';
4871: undef($forcenewuser);
4872: #if ($response) {
4873: # unless ($response =~ m{\Q<br /><br />\E$}) {
4874: # $response .= '<br /><br />';
4875: # }
4876: #}
4877: &print_username_entry_form($r,$context,$response,$srch,
1.406.2.14 raeburn 4878: $forcenewuser,$crstype,$brcrum,
4879: $permission);
1.406.2.5 raeburn 4880: } else {
4881: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
4882: }
4883: } else {
4884: if ($env{'form.forcenewuser'}) {
4885: $response = '';
4886: }
4887: &print_user_modification_page($r,$ccuname,$ccdomain,
4888: $srch,$response,$context,
4889: $permission,$crstype,$brcrum);
1.190 raeburn 4890: }
4891: } elsif ($currstate eq 'query') {
1.351 raeburn 4892: &print_user_query_page($r,'createuser',$brcrum);
1.190 raeburn 4893: } else {
1.229 raeburn 4894: $env{'form.phase'} = '';
1.207 raeburn 4895: &print_username_entry_form($r,$context,$response,$srch,
1.406.2.14 raeburn 4896: $forcenewuser,$crstype,$brcrum,
4897: $permission);
1.190 raeburn 4898: }
4899: } elsif ($env{'form.phase'} eq 'userpicked') {
4900: my $ccuname = &LONCAPA::clean_username($env{'form.seluname'});
4901: my $ccdomain = &LONCAPA::clean_domain($env{'form.seludom'});
1.406.2.5 raeburn 4902: if ($env{'form.action'} eq 'accesslogs') {
4903: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
4904: } else {
4905: &print_user_modification_page($r,$ccuname,$ccdomain,$srch,'',
4906: $context,$permission,$crstype,
4907: $brcrum);
4908: }
4909: } elsif ($env{'form.action'} eq 'accesslogs') {
4910: my $ccuname = &LONCAPA::clean_username($env{'form.accessuname'});
4911: my $ccdomain = &LONCAPA::clean_domain($env{'form.accessudom'});
4912: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
1.190 raeburn 4913: }
4914: } elsif ($env{'form.phase'} eq 'update_user_data') {
1.406.2.17 raeburn 4915: &update_user_data($r,$context,$crstype,$brcrum,$showcredits,$permission);
1.190 raeburn 4916: } else {
1.351 raeburn 4917: &print_username_entry_form($r,$context,undef,$srch,undef,$crstype,
1.406.2.14 raeburn 4918: $brcrum,$permission);
1.190 raeburn 4919: }
4920: } elsif ($env{'form.action'} eq 'custom' && $permission->{'custom'}) {
1.406.2.5 raeburn 4921: my $prefix;
1.190 raeburn 4922: if ($env{'form.phase'} eq 'set_custom_roles') {
1.406.2.14 raeburn 4923: &set_custom_role($r,$context,$brcrum,$prefix,$permission);
1.190 raeburn 4924: } else {
1.406.2.14 raeburn 4925: &custom_role_editor($r,$context,$brcrum,$prefix,$permission);
1.190 raeburn 4926: }
1.362 raeburn 4927: } elsif (($env{'form.action'} eq 'processauthorreq') &&
4928: ($permission->{'cusr'}) &&
4929: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
4930: push(@{$brcrum},
4931: {href => '/adm/createuser?action=processauthorreq',
1.385 bisitz 4932: text => 'Authoring Space requests',
1.362 raeburn 4933: help => 'Domain_Role_Approvals'});
4934: $bread_crumbs_component = 'Authoring requests';
4935: if ($env{'form.state'} eq 'done') {
4936: push(@{$brcrum},
4937: {href => '/adm/createuser?action=authorreqqueue',
4938: text => 'Result',
4939: help => 'Domain_Role_Approvals'});
4940: $bread_crumbs_component = 'Authoring request result';
4941: }
4942: $args = { bread_crumbs => $brcrum,
4943: bread_crumbs_component => $bread_crumbs_component};
1.391 raeburn 4944: my $js = &usernamerequest_javascript();
4945: $r->print(&header(&add_script($js),$args));
1.362 raeburn 4946: if (!exists($env{'form.state'})) {
4947: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestauthor',
4948: $env{'request.role.domain'}));
4949: } elsif ($env{'form.state'} eq 'done') {
4950: $r->print('<h3>'.&mt('Authoring request processing').'</h3>'."\n");
4951: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestauthor',
4952: $env{'request.role.domain'}));
4953: }
1.391 raeburn 4954: } elsif (($env{'form.action'} eq 'processusernamereq') &&
4955: ($permission->{'cusr'}) &&
4956: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
4957: push(@{$brcrum},
4958: {href => '/adm/createuser?action=processusernamereq',
4959: text => 'LON-CAPA account requests',
4960: help => 'Domain_Username_Approvals'});
4961: $bread_crumbs_component = 'Account requests';
4962: if ($env{'form.state'} eq 'done') {
4963: push(@{$brcrum},
4964: {href => '/adm/createuser?action=usernamereqqueue',
4965: text => 'Result',
4966: help => 'Domain_Username_Approvals'});
4967: $bread_crumbs_component = 'LON-CAPA account request result';
4968: }
4969: $args = { bread_crumbs => $brcrum,
4970: bread_crumbs_component => $bread_crumbs_component};
4971: my $js = &usernamerequest_javascript();
4972: $r->print(&header(&add_script($js),$args));
4973: if (!exists($env{'form.state'})) {
4974: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestusername',
4975: $env{'request.role.domain'}));
4976: } elsif ($env{'form.state'} eq 'done') {
4977: $r->print('<h3>'.&mt('LON-CAPA account request processing').'</h3>'."\n");
4978: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestusername',
4979: $env{'request.role.domain'}));
4980: }
4981: } elsif (($env{'form.action'} eq 'displayuserreq') &&
4982: ($permission->{'cusr'})) {
4983: my $dom = $env{'form.domain'};
4984: my $uname = $env{'form.username'};
4985: my $warning;
4986: if (($dom =~ /^$match_domain$/) && (&Apache::lonnet::domain($dom) ne '')) {
4987: if (($dom eq $env{'request.role.domain'}) && (&Apache::lonnet::allowed('ccc',$dom))) {
4988: if (($uname =~ /^$match_username$/) && ($env{'form.queue'} eq 'approval')) {
4989: my $uhome = &Apache::lonnet::homeserver($uname,$dom);
4990: if ($uhome eq 'no_host') {
4991: my $queue = $env{'form.queue'};
4992: my $reqkey = &escape($uname).'_'.$queue;
4993: my $namespace = 'usernamequeue';
4994: my $domconfig = &Apache::lonnet::get_domainconfiguser($dom);
4995: my %queued =
4996: &Apache::lonnet::get($namespace,[$reqkey],$dom,$domconfig);
4997: unless ($queued{$reqkey}) {
4998: $warning = &mt('No information was found for this LON-CAPA account request.');
4999: }
5000: } else {
5001: $warning = &mt('A LON-CAPA account already exists for the requested username and domain.');
5002: }
5003: } else {
5004: $warning = &mt('LON-CAPA account request status check is for an invalid username.');
5005: }
5006: } else {
5007: $warning = &mt('You do not have rights to view LON-CAPA account requests in the domain specified.');
5008: }
5009: } else {
5010: $warning = &mt('LON-CAPA account request status check is for an invalid domain.');
5011: }
5012: my $args = { only_body => 1 };
5013: $r->print(&header(undef,$args).
5014: '<h3>'.&mt('LON-CAPA Account Request Details').'</h3>');
5015: if ($warning ne '') {
5016: $r->print('<div class="LC_warning">'.$warning.'</div>');
5017: } else {
5018: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
5019: my $domconfiguser = &Apache::lonnet::get_domainconfiguser($dom);
5020: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
5021: if (ref($domconfig{'usercreation'}) eq 'HASH') {
5022: if (ref($domconfig{'usercreation'}{'cancreate'}) eq 'HASH') {
5023: if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}) eq 'HASH') {
5024: my %info =
5025: &Apache::lonnet::get('nohist_requestedusernames',[$uname],$dom,$domconfiguser);
5026: if (ref($info{$uname}) eq 'HASH') {
1.396 raeburn 5027: my $usertype = $info{$uname}{'inststatus'};
5028: unless ($usertype) {
5029: $usertype = 'default';
5030: }
1.406.2.16 raeburn 5031: my ($showstatus,$showemail,$pickstart);
5032: my $numextras = 0;
5033: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5034: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
5035: if (ref($usertypes) eq 'HASH') {
5036: if ($usertypes->{$usertype}) {
5037: $showstatus = $usertypes->{$usertype};
5038: } else {
5039: $showstatus = $othertitle;
5040: }
5041: if ($showstatus) {
5042: $numextras ++;
5043: }
5044: }
5045: }
5046: if (($info{$uname}{'email'} ne '') && ($info{$uname}{'email'} ne $uname)) {
5047: $showemail = $info{$uname}{'email'};
5048: $numextras ++;
5049: }
1.396 raeburn 5050: if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}) eq 'HASH') {
5051: if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
1.406.2.16 raeburn 5052: $pickstart = 1;
1.396 raeburn 5053: $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box());
1.406.2.16 raeburn 5054: my ($num,$count);
1.396 raeburn 5055: $count = scalar(keys(%{$domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}}));
1.406.2.16 raeburn 5056: $count += $numextras;
1.396 raeburn 5057: foreach my $field (@{$infofields}) {
5058: next unless ($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}{$field});
5059: next unless ($infotitles->{$field});
5060: $r->print(&Apache::lonhtmlcommon::row_title($infotitles->{$field}).
5061: $info{$uname}{$field});
5062: $num ++;
1.406.2.16 raeburn 5063: unless ($count == $num) {
1.396 raeburn 5064: $r->print(&Apache::lonhtmlcommon::row_closure());
5065: }
5066: }
1.406.2.16 raeburn 5067: }
5068: }
5069: if ($numextras) {
5070: unless ($pickstart) {
5071: $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box());
5072: $pickstart = 1;
5073: }
5074: if ($showemail) {
5075: my $closure = '';
5076: unless ($showstatus) {
5077: $closure = 1;
1.391 raeburn 5078: }
1.406.2.16 raeburn 5079: $r->print(&Apache::lonhtmlcommon::row_title(&mt('E-mail address')).
5080: $showemail.
5081: &Apache::lonhtmlcommon::row_closure($closure));
5082: }
5083: if ($showstatus) {
5084: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Status type[_1](self-reported)','<br />')).
5085: $showstatus.
5086: &Apache::lonhtmlcommon::row_closure(1));
1.391 raeburn 5087: }
5088: }
1.406.2.16 raeburn 5089: if ($pickstart) {
5090: $r->print(&Apache::lonhtmlcommon::end_pick_box().'</div>');
5091: } else {
5092: $r->print('<div>'.&mt('No information to display for this account request.').'</div>');
5093: }
5094: } else {
5095: $r->print('<div>'.&mt('No information available for this account request.').'</div>');
1.391 raeburn 5096: }
5097: }
5098: }
5099: }
5100: }
1.406.2.16 raeburn 5101: $r->print(&close_popup_form());
1.207 raeburn 5102: } elsif (($env{'form.action'} eq 'listusers') &&
5103: ($permission->{'view'} || $permission->{'cusr'})) {
1.406.2.14 raeburn 5104: my $helpitem = 'Course_View_Class_List';
5105: if ($context eq 'author') {
5106: $helpitem = 'Author_View_Coauthor_List';
5107: } elsif ($context eq 'domain') {
5108: $helpitem = 'Domain_View_Users_List';
5109: }
1.202 raeburn 5110: if ($env{'form.phase'} eq 'bulkchange') {
1.351 raeburn 5111: push(@{$brcrum},
5112: {href => '/adm/createuser?action=listusers',
5113: text => "List Users"},
5114: {href => "/adm/createuser",
5115: text => "Result",
1.406.2.14 raeburn 5116: help => $helpitem});
1.351 raeburn 5117: $bread_crumbs_component = 'Update Users';
5118: $args = {bread_crumbs => $brcrum,
5119: bread_crumbs_component => $bread_crumbs_component};
5120: $r->print(&header(undef,$args));
1.202 raeburn 5121: my $setting = $env{'form.roletype'};
5122: my $choice = $env{'form.bulkaction'};
5123: if ($permission->{'cusr'}) {
1.336 raeburn 5124: &Apache::lonuserutils::update_user_list($r,$context,$setting,$choice,$crstype);
1.221 raeburn 5125: } else {
5126: $r->print(&mt('You are not authorized to make bulk changes to user roles'));
1.223 raeburn 5127: $r->print('<p><a href="/adm/createuser?action=listusers">'.&mt('Display User Lists').'</a>');
1.202 raeburn 5128: }
5129: } else {
1.351 raeburn 5130: push(@{$brcrum},
5131: {href => '/adm/createuser?action=listusers',
5132: text => "List Users",
1.406.2.14 raeburn 5133: help => $helpitem});
1.351 raeburn 5134: $bread_crumbs_component = 'List Users';
5135: $args = {bread_crumbs => $brcrum,
5136: bread_crumbs_component => $bread_crumbs_component};
1.202 raeburn 5137: my ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles);
5138: my $formname = 'studentform';
1.364 raeburn 5139: my $hidecall = "hide_searching();";
1.321 raeburn 5140: if (($context eq 'domain') && (($env{'form.roletype'} eq 'course') ||
5141: ($env{'form.roletype'} eq 'community'))) {
5142: if ($env{'form.roletype'} eq 'course') {
5143: ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles) =
5144: &Apache::lonuserutils::courses_selector($env{'request.role.domain'},
5145: $formname);
5146: } elsif ($env{'form.roletype'} eq 'community') {
5147: $cb_jscript =
5148: &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
5149: my %elements = (
5150: coursepick => 'radio',
5151: coursetotal => 'text',
5152: courselist => 'text',
5153: );
5154: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements);
5155: }
1.364 raeburn 5156: $jscript .= &verify_user_display($context)."\n".
5157: &Apache::loncommon::check_uncheck_jscript();
1.202 raeburn 5158: my $js = &add_script($jscript).$cb_jscript;
5159: my $loadcode =
5160: &Apache::lonuserutils::course_selector_loadcode($formname);
5161: if ($loadcode ne '') {
1.364 raeburn 5162: $args->{add_entries} = {onload => "$loadcode;$hidecall"};
5163: } else {
5164: $args->{add_entries} = {onload => $hidecall};
1.202 raeburn 5165: }
1.351 raeburn 5166: $r->print(&header($js,$args));
1.191 raeburn 5167: } else {
1.364 raeburn 5168: $args->{add_entries} = {onload => $hidecall};
5169: $jscript = &verify_user_display($context).
5170: &Apache::loncommon::check_uncheck_jscript();
5171: $r->print(&header(&add_script($jscript),$args));
1.191 raeburn 5172: }
1.202 raeburn 5173: &Apache::lonuserutils::print_userlist($r,undef,$permission,$context,
1.375 raeburn 5174: $formname,$totcodes,$codetitles,$idlist,$idlist_titles,
5175: $showcredits);
1.191 raeburn 5176: }
1.213 raeburn 5177: } elsif ($env{'form.action'} eq 'drop' && $permission->{'cusr'}) {
1.318 raeburn 5178: my $brtext;
5179: if ($crstype eq 'Community') {
5180: $brtext = 'Drop Members';
5181: } else {
5182: $brtext = 'Drop Students';
5183: }
1.351 raeburn 5184: push(@{$brcrum},
5185: {href => '/adm/createuser?action=drop',
5186: text => $brtext,
5187: help => 'Course_Drop_Student'});
5188: if ($env{'form.state'} eq 'done') {
5189: push(@{$brcrum},
5190: {href=>'/adm/createuser?action=drop',
5191: text=>"Result"});
5192: }
5193: $bread_crumbs_component = $brtext;
5194: $args = {bread_crumbs => $brcrum,
5195: bread_crumbs_component => $bread_crumbs_component};
5196: $r->print(&header(undef,$args));
1.213 raeburn 5197: if (!exists($env{'form.state'})) {
1.318 raeburn 5198: &Apache::lonuserutils::print_drop_menu($r,$context,$permission,$crstype);
1.213 raeburn 5199: } elsif ($env{'form.state'} eq 'done') {
5200: &Apache::lonuserutils::update_user_list($r,$context,undef,
5201: $env{'form.action'});
5202: }
1.202 raeburn 5203: } elsif ($env{'form.action'} eq 'dateselect') {
5204: if ($permission->{'cusr'}) {
1.351 raeburn 5205: $r->print(&header(undef,{'no_nav_bar' => 1}).
1.375 raeburn 5206: &Apache::lonuserutils::date_section_selector($context,$permission,
5207: $crstype,$showcredits));
1.202 raeburn 5208: } else {
1.351 raeburn 5209: $r->print(&header(undef,{'no_nav_bar' => 1}).
5210: '<span class="LC_error">'.&mt('You do not have permission to modify dates or sections for users').'</span>');
1.202 raeburn 5211: }
1.237 raeburn 5212: } elsif ($env{'form.action'} eq 'selfenroll') {
1.406.2.21! raeburn 5213: my %currsettings;
! 5214: if ($permission->{selfenrolladmin} || $permission->{selfenrollview}) {
! 5215: %currsettings = (
1.398 raeburn 5216: selfenroll_types => $env{'course.'.$cid.'.internal.selfenroll_types'},
5217: selfenroll_registered => $env{'course.'.$cid.'.internal.selfenroll_registered'},
5218: selfenroll_section => $env{'course.'.$cid.'.internal.selfenroll_section'},
5219: selfenroll_notifylist => $env{'course.'.$cid.'.internal.selfenroll_notifylist'},
5220: selfenroll_approval => $env{'course.'.$cid.'.internal.selfenroll_approval'},
5221: selfenroll_limit => $env{'course.'.$cid.'.internal.selfenroll_limit'},
5222: selfenroll_cap => $env{'course.'.$cid.'.internal.selfenroll_cap'},
5223: selfenroll_start_date => $env{'course.'.$cid.'.internal.selfenroll_start_date'},
5224: selfenroll_end_date => $env{'course.'.$cid.'.internal.selfenroll_end_date'},
5225: selfenroll_start_access => $env{'course.'.$cid.'.internal.selfenroll_start_access'},
5226: selfenroll_end_access => $env{'course.'.$cid.'.internal.selfenroll_end_access'},
5227: default_enrollment_start_date => $env{'course.'.$cid.'.default_enrollment_start_date'},
5228: default_enrollment_end_date => $env{'course.'.$cid.'.default_enrollment_end_date'},
1.400 raeburn 5229: uniquecode => $env{'course.'.$cid.'.internal.uniquecode'},
1.398 raeburn 5230: );
1.406.2.21! raeburn 5231: }
! 5232: if ($permission->{selfenrolladmin}) {
1.398 raeburn 5233: push(@{$brcrum},
5234: {href => '/adm/createuser?action=selfenroll',
5235: text => "Configure Self-enrollment",
5236: help => 'Course_Self_Enrollment'});
5237: if (!exists($env{'form.state'})) {
5238: $args = { bread_crumbs => $brcrum,
5239: bread_crumbs_component => 'Configure Self-enrollment'};
5240: $r->print(&header(undef,$args));
5241: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
5242: &print_selfenroll_menu($r,'course',$cid,$cdom,$cnum,\%currsettings);
5243: } elsif ($env{'form.state'} eq 'done') {
5244: push (@{$brcrum},
5245: {href=>'/adm/createuser?action=selfenroll',
5246: text=>"Result"});
5247: $args = { bread_crumbs => $brcrum,
5248: bread_crumbs_component => 'Self-enrollment result'};
5249: $r->print(&header(undef,$args));
5250: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
1.400 raeburn 5251: &update_selfenroll_config($r,$cid,$cdom,$cnum,$context,$crstype,\%currsettings);
1.398 raeburn 5252: }
1.406.2.21! raeburn 5253: } elsif ($permission->{selfenrollview}) {
! 5254: push(@{$brcrum},
! 5255: {href => '/adm/createuser?action=selfenroll',
! 5256: text => "View Self-enrollment configuration",
! 5257: help => 'Course_Self_Enrollment'});
! 5258: $args = { bread_crumbs => $brcrum,
! 5259: bread_crumbs_component => 'Self-enrollment Settings'};
! 5260: $r->print(&header(undef,$args));
! 5261: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
! 5262: &print_selfenroll_menu($r,'course',$cid,$cdom,$cnum,\%currsettings,'',1);
1.398 raeburn 5263: } else {
5264: $r->print(&header(undef,{'no_nav_bar' => 1}).
5265: '<span class="LC_error">'.&mt('You do not have permission to configure self-enrollment').'</span>');
1.237 raeburn 5266: }
1.277 raeburn 5267: } elsif ($env{'form.action'} eq 'selfenrollqueue') {
1.406.2.6 raeburn 5268: if ($permission->{selfenrolladmin}) {
1.351 raeburn 5269: push(@{$brcrum},
5270: {href => '/adm/createuser?action=selfenrollqueue',
1.406.2.6 raeburn 5271: text => 'Enrollment requests',
1.406.2.14 raeburn 5272: help => 'Course_Approve_Selfenroll'});
1.406.2.6 raeburn 5273: $bread_crumbs_component = 'Enrollment requests';
5274: if ($env{'form.state'} eq 'done') {
5275: push(@{$brcrum},
5276: {href => '/adm/createuser?action=selfenrollqueue',
5277: text => 'Result',
1.406.2.14 raeburn 5278: help => 'Course_Approve_Selfenroll'});
1.406.2.6 raeburn 5279: $bread_crumbs_component = 'Enrollment result';
5280: }
5281: $args = { bread_crumbs => $brcrum,
5282: bread_crumbs_component => $bread_crumbs_component};
5283: $r->print(&header(undef,$args));
5284: my $coursedesc = $env{'course.'.$cid.'.description'};
5285: if (!exists($env{'form.state'})) {
5286: $r->print('<h3>'.&mt('Pending enrollment requests').'</h3>'."\n");
5287: $r->print(&Apache::loncoursequeueadmin::display_queued_requests($context,
5288: $cdom,$cnum));
5289: } elsif ($env{'form.state'} eq 'done') {
5290: $r->print('<h3>'.&mt('Enrollment request processing').'</h3>'."\n");
5291: $r->print(&Apache::loncoursequeueadmin::update_request_queue($context,
5292: $cdom,$cnum,$coursedesc));
5293: }
5294: } else {
5295: $r->print(&header(undef,{'no_nav_bar' => 1}).
5296: '<span class="LC_error">'.&mt('You do not have permission to manage self-enrollment').'</span>');
1.277 raeburn 5297: }
1.239 raeburn 5298: } elsif ($env{'form.action'} eq 'changelogs') {
1.406.2.6 raeburn 5299: if ($permission->{cusr} || $permission->{view}) {
5300: &print_userchangelogs_display($r,$context,$permission,$brcrum);
5301: } else {
5302: $r->print(&header(undef,{'no_nav_bar' => 1}).
5303: '<span class="LC_error">'.&mt('You do not have permission to view change logs').'</span>');
5304: }
1.406.2.10 raeburn 5305: } elsif ($env{'form.action'} eq 'helpdesk') {
5306: if (($permission->{'owner'}) || ($permission->{'co-owner'})) {
5307: if ($env{'form.state'} eq 'process') {
5308: if ($permission->{'owner'}) {
5309: &update_helpdeskaccess($r,$permission,$brcrum);
5310: } else {
5311: &print_helpdeskaccess_display($r,$permission,$brcrum);
5312: }
5313: } else {
5314: &print_helpdeskaccess_display($r,$permission,$brcrum);
5315: }
5316: } else {
5317: $r->print(&header(undef,{'no_nav_bar' => 1}).
5318: '<span class="LC_error">'.&mt('You do not have permission to view helpdesk access').'</span>');
5319: }
1.190 raeburn 5320: } else {
1.351 raeburn 5321: $bread_crumbs_component = 'User Management';
5322: $args = { bread_crumbs => $brcrum,
5323: bread_crumbs_component => $bread_crumbs_component};
5324: $r->print(&header(undef,$args));
1.318 raeburn 5325: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 5326: }
1.351 raeburn 5327: $r->print(&Apache::loncommon::end_page());
1.190 raeburn 5328: return OK;
5329: }
5330:
5331: sub header {
1.351 raeburn 5332: my ($jscript,$args) = @_;
1.190 raeburn 5333: my $start_page;
1.351 raeburn 5334: if (ref($args) eq 'HASH') {
5335: $start_page=&Apache::loncommon::start_page('User Management',$jscript,$args);
1.190 raeburn 5336: } else {
1.351 raeburn 5337: $start_page=&Apache::loncommon::start_page('User Management',$jscript);
1.190 raeburn 5338: }
5339: return $start_page;
5340: }
1.2 www 5341:
1.191 raeburn 5342: sub add_script {
5343: my ($js) = @_;
1.301 bisitz 5344: return '<script type="text/javascript">'."\n"
5345: .'// <![CDATA['."\n"
5346: .$js."\n"
5347: .'// ]]>'."\n"
5348: .'</script>'."\n";
1.191 raeburn 5349: }
5350:
1.391 raeburn 5351: sub usernamerequest_javascript {
5352: my $js = <<ENDJS;
5353:
5354: function openusernamereqdisplay(dom,uname,queue) {
5355: var url = '/adm/createuser?action=displayuserreq';
5356: url += '&domain='+dom+'&username='+uname+'&queue='+queue;
5357: var title = 'Account_Request_Browser';
5358: var options = 'scrollbars=1,resizable=1,menubar=0';
5359: options += ',width=700,height=600';
5360: var stdeditbrowser = open(url,title,options,'1');
5361: stdeditbrowser.focus();
5362: return;
5363: }
5364:
5365: ENDJS
5366: }
5367:
5368: sub close_popup_form {
5369: my $close= &mt('Close Window');
5370: return << "END";
5371: <p><form name="displayreq" action="" method="post">
5372: <input type="button" name="closeme" value="$close" onclick="javascript:self.close();" />
5373: </form></p>
5374: END
5375: }
5376:
1.202 raeburn 5377: sub verify_user_display {
1.364 raeburn 5378: my ($context) = @_;
1.374 raeburn 5379: my %lt = &Apache::lonlocal::texthash (
5380: course => 'course(s): description, section(s), status',
5381: community => 'community(s): description, section(s), status',
5382: author => 'author',
5383: );
1.364 raeburn 5384: my $photos;
5385: if (($context eq 'course') && $env{'request.course.id'}) {
5386: $photos = $env{'course.'.$env{'request.course.id'}.'.internal.showphoto'};
5387: }
1.202 raeburn 5388: my $output = <<"END";
5389:
1.364 raeburn 5390: function hide_searching() {
5391: if (document.getElementById('searching')) {
5392: document.getElementById('searching').style.display = 'none';
5393: }
5394: return;
5395: }
5396:
1.202 raeburn 5397: function display_update() {
5398: document.studentform.action.value = 'listusers';
5399: document.studentform.phase.value = 'display';
5400: document.studentform.submit();
5401: }
5402:
1.364 raeburn 5403: function updateCols(caller) {
5404: var context = '$context';
5405: var photos = '$photos';
5406: if (caller == 'Status') {
1.374 raeburn 5407: if ((context == 'domain') &&
5408: ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
5409: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community'))) {
1.364 raeburn 5410: document.getElementById('showcolstatus').checked = false;
5411: document.getElementById('showcolstatus').disabled = 'disabled';
5412: document.getElementById('showcolstart').checked = false;
5413: document.getElementById('showcolend').checked = false;
1.374 raeburn 5414: } else {
5415: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
5416: document.getElementById('showcolstatus').checked = true;
5417: document.getElementById('showcolstatus').disabled = '';
5418: document.getElementById('showcolstart').checked = true;
5419: document.getElementById('showcolend').checked = true;
5420: } else {
5421: document.getElementById('showcolstatus').checked = false;
5422: document.getElementById('showcolstatus').disabled = 'disabled';
5423: document.getElementById('showcolstart').checked = false;
5424: document.getElementById('showcolend').checked = false;
5425: }
1.364 raeburn 5426: }
5427: }
5428: if (caller == 'output') {
5429: if (photos == 1) {
5430: if (document.getElementById('showcolphoto')) {
5431: var photoitem = document.getElementById('showcolphoto');
5432: if (document.studentform.output.options[document.studentform.output.selectedIndex].value == 'html') {
5433: photoitem.checked = true;
5434: photoitem.disabled = '';
5435: } else {
5436: photoitem.checked = false;
5437: photoitem.disabled = 'disabled';
5438: }
5439: }
5440: }
5441: }
5442: if (caller == 'showrole') {
1.371 raeburn 5443: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any') ||
5444: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'cr')) {
1.364 raeburn 5445: document.getElementById('showcolrole').checked = true;
5446: document.getElementById('showcolrole').disabled = '';
5447: } else {
5448: document.getElementById('showcolrole').checked = false;
5449: document.getElementById('showcolrole').disabled = 'disabled';
5450: }
1.374 raeburn 5451: if (context == 'domain') {
1.382 raeburn 5452: var quotausageshow = 0;
1.374 raeburn 5453: if ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
5454: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community')) {
5455: document.getElementById('showcolstatus').checked = false;
5456: document.getElementById('showcolstatus').disabled = 'disabled';
5457: document.getElementById('showcolstart').checked = false;
5458: document.getElementById('showcolend').checked = false;
5459: } else {
5460: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
5461: document.getElementById('showcolstatus').checked = true;
5462: document.getElementById('showcolstatus').disabled = '';
5463: document.getElementById('showcolstart').checked = true;
5464: document.getElementById('showcolend').checked = true;
5465: }
5466: }
5467: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'domain') {
5468: document.getElementById('showcolextent').disabled = 'disabled';
5469: document.getElementById('showcolextent').checked = 'false';
5470: document.getElementById('showextent').style.display='none';
5471: document.getElementById('showcoltextextent').innerHTML = '';
1.382 raeburn 5472: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'au') ||
5473: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any')) {
5474: if (document.getElementById('showcolauthorusage')) {
5475: document.getElementById('showcolauthorusage').disabled = '';
5476: }
5477: if (document.getElementById('showcolauthorquota')) {
5478: document.getElementById('showcolauthorquota').disabled = '';
5479: }
5480: quotausageshow = 1;
5481: }
1.374 raeburn 5482: } else {
5483: document.getElementById('showextent').style.display='block';
5484: document.getElementById('showextent').style.textAlign='left';
5485: document.getElementById('showextent').style.textFace='normal';
5486: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'author') {
5487: document.getElementById('showcolextent').disabled = '';
5488: document.getElementById('showcolextent').checked = 'true';
5489: document.getElementById('showcoltextextent').innerHTML="$lt{'author'}";
5490: } else {
5491: document.getElementById('showcolextent').disabled = '';
5492: document.getElementById('showcolextent').checked = 'true';
5493: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community') {
5494: document.getElementById('showcoltextextent').innerHTML="$lt{'community'}";
5495: } else {
5496: document.getElementById('showcoltextextent').innerHTML="$lt{'course'}";
5497: }
5498: }
5499: }
1.382 raeburn 5500: if (quotausageshow == 0) {
5501: if (document.getElementById('showcolauthorusage')) {
5502: document.getElementById('showcolauthorusage').checked = false;
5503: document.getElementById('showcolauthorusage').disabled = 'disabled';
5504: }
5505: if (document.getElementById('showcolauthorquota')) {
5506: document.getElementById('showcolauthorquota').checked = false;
5507: document.getElementById('showcolauthorquota').disabled = 'disabled';
5508: }
5509: }
1.374 raeburn 5510: }
1.364 raeburn 5511: }
5512: return;
5513: }
5514:
1.202 raeburn 5515: END
5516: return $output;
5517:
5518: }
5519:
1.190 raeburn 5520: ###############################################################
5521: ###############################################################
5522: # Menu Phase One
5523: sub print_main_menu {
1.318 raeburn 5524: my ($permission,$context,$crstype) = @_;
5525: my $linkcontext = $context;
5526: my $stuterm = lc(&Apache::lonnet::plaintext('st',$crstype));
5527: if (($context eq 'course') && ($crstype eq 'Community')) {
5528: $linkcontext = lc($crstype);
5529: $stuterm = 'Members';
5530: }
1.208 raeburn 5531: my %links = (
1.298 droeschl 5532: domain => {
5533: upload => 'Upload a File of Users',
5534: singleuser => 'Add/Modify a User',
5535: listusers => 'Manage Users',
5536: },
5537: author => {
5538: upload => 'Upload a File of Co-authors',
5539: singleuser => 'Add/Modify a Co-author',
5540: listusers => 'Manage Co-authors',
5541: },
5542: course => {
5543: upload => 'Upload a File of Course Users',
5544: singleuser => 'Add/Modify a Course User',
1.354 www 5545: listusers => 'List and Modify Multiple Course Users',
1.298 droeschl 5546: },
1.318 raeburn 5547: community => {
5548: upload => 'Upload a File of Community Users',
5549: singleuser => 'Add/Modify a Community User',
1.354 www 5550: listusers => 'List and Modify Multiple Community Users',
1.318 raeburn 5551: },
5552: );
5553: my %linktitles = (
5554: domain => {
5555: singleuser => 'Add a user to the domain, and/or a course or community in the domain.',
5556: listusers => 'Show and manage users in this domain.',
5557: },
5558: author => {
5559: singleuser => 'Add a user with a co- or assistant author role.',
5560: listusers => 'Show and manage co- or assistant authors.',
5561: },
5562: course => {
5563: singleuser => 'Add a user with a certain role to this course.',
5564: listusers => 'Show and manage users in this course.',
5565: },
5566: community => {
5567: singleuser => 'Add a user with a certain role to this community.',
5568: listusers => 'Show and manage users in this community.',
5569: },
1.298 droeschl 5570: );
1.406.2.6 raeburn 5571: if ($linkcontext eq 'domain') {
5572: unless ($permission->{'cusr'}) {
5573: $links{'domain'}{'singleuser'} = 'View a User';
5574: $linktitles{'domain'}{'singleuser'} = 'View information about a user in the domain';
5575: }
5576: } elsif ($linkcontext eq 'course') {
5577: unless ($permission->{'cusr'}) {
5578: $links{'course'}{'singleuser'} = 'View a Course User';
5579: $linktitles{'course'}{'singleuser'} = 'View information about a user in this course';
5580: $links{'course'}{'listusers'} = 'List Course Users';
5581: $linktitles{'course'}{'listusers'} = 'Show information about users in this course';
5582: }
5583: } elsif ($linkcontext eq 'community') {
5584: unless ($permission->{'cusr'}) {
5585: $links{'community'}{'singleuser'} = 'View a Community User';
5586: $linktitles{'community'}{'singleuser'} = 'View information about a user in this community';
5587: $links{'community'}{'listusers'} = 'List Community Users';
5588: $linktitles{'community'}{'listusers'} = 'Show information about users in this community';
5589: }
5590: }
1.298 droeschl 5591: my @menu = ( {categorytitle => 'Single Users',
5592: items =>
5593: [
5594: {
1.318 raeburn 5595: linktext => $links{$linkcontext}{'singleuser'},
1.298 droeschl 5596: icon => 'edit-redo.png',
5597: #help => 'Course_Change_Privileges',
5598: url => '/adm/createuser?action=singleuser',
1.406.2.6 raeburn 5599: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.318 raeburn 5600: linktitle => $linktitles{$linkcontext}{'singleuser'},
1.298 droeschl 5601: },
5602: ]},
5603:
5604: {categorytitle => 'Multiple Users',
5605: items =>
5606: [
5607: {
1.318 raeburn 5608: linktext => $links{$linkcontext}{'upload'},
1.340 wenzelju 5609: icon => 'uplusr.png',
1.298 droeschl 5610: #help => 'Course_Create_Class_List',
5611: url => '/adm/createuser?action=upload',
5612: permission => $permission->{'cusr'},
5613: linktitle => 'Upload a CSV or a text file containing users.',
5614: },
5615: {
1.318 raeburn 5616: linktext => $links{$linkcontext}{'listusers'},
1.340 wenzelju 5617: icon => 'mngcu.png',
1.298 droeschl 5618: #help => 'Course_View_Class_List',
5619: url => '/adm/createuser?action=listusers',
5620: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.318 raeburn 5621: linktitle => $linktitles{$linkcontext}{'listusers'},
1.298 droeschl 5622: },
5623:
5624: ]},
5625:
5626: {categorytitle => 'Administration',
5627: items => [ ]},
5628: );
1.406.2.5 raeburn 5629:
1.265 mielkec 5630: if ($context eq 'domain'){
1.406.2.5 raeburn 5631: push(@{ $menu[0]->{items} }, # Single Users
5632: {
5633: linktext => 'User Access Log',
5634: icon => 'document-properties.png',
1.406.2.8 raeburn 5635: #help => 'Domain_User_Access_Logs',
1.406.2.5 raeburn 5636: url => '/adm/createuser?action=accesslogs',
5637: permission => $permission->{'activity'},
5638: linktitle => 'View user access log.',
5639: }
5640: );
1.298 droeschl 5641:
5642: push(@{ $menu[2]->{items} }, #Category: Administration
5643: {
5644: linktext => 'Custom Roles',
5645: icon => 'emblem-photos.png',
5646: #help => 'Course_Editing_Custom_Roles',
5647: url => '/adm/createuser?action=custom',
5648: permission => $permission->{'custom'},
5649: linktitle => 'Configure a custom role.',
5650: },
1.362 raeburn 5651: {
5652: linktext => 'Authoring Space Requests',
5653: icon => 'selfenrl-queue.png',
5654: #help => 'Domain_Role_Approvals',
5655: url => '/adm/createuser?action=processauthorreq',
5656: permission => $permission->{'cusr'},
5657: linktitle => 'Approve or reject author role requests',
5658: },
1.363 raeburn 5659: {
1.391 raeburn 5660: linktext => 'LON-CAPA Account Requests',
5661: icon => 'list-add.png',
5662: #help => 'Domain_Username_Approvals',
5663: url => '/adm/createuser?action=processusernamereq',
5664: permission => $permission->{'cusr'},
5665: linktitle => 'Approve or reject LON-CAPA account requests',
5666: },
5667: {
1.363 raeburn 5668: linktext => 'Change Log',
5669: icon => 'document-properties.png',
5670: #help => 'Course_User_Logs',
5671: url => '/adm/createuser?action=changelogs',
1.406.2.6 raeburn 5672: permission => ($permission->{'cusr'} || $permission->{'view'}),
1.363 raeburn 5673: linktitle => 'View change log.',
5674: },
1.298 droeschl 5675: );
5676:
1.265 mielkec 5677: }elsif ($context eq 'course'){
1.298 droeschl 5678: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity();
1.318 raeburn 5679:
5680: my %linktext = (
5681: 'Course' => {
5682: single => 'Add/Modify a Student',
5683: drop => 'Drop Students',
5684: groups => 'Course Groups',
5685: },
5686: 'Community' => {
5687: single => 'Add/Modify a Member',
5688: drop => 'Drop Members',
5689: groups => 'Community Groups',
5690: },
5691: );
5692:
5693: my %linktitle = (
5694: 'Course' => {
5695: single => 'Add a user with the role of student to this course',
5696: drop => 'Remove a student from this course.',
5697: groups => 'Manage course groups',
5698: },
5699: 'Community' => {
5700: single => 'Add a user with the role of member to this community',
5701: drop => 'Remove a member from this community.',
5702: groups => 'Manage community groups',
5703: },
5704: );
5705:
1.298 droeschl 5706: push(@{ $menu[0]->{items} }, #Category: Single Users
5707: {
1.318 raeburn 5708: linktext => $linktext{$crstype}{'single'},
1.298 droeschl 5709: #help => 'Course_Add_Student',
5710: icon => 'list-add.png',
5711: url => '/adm/createuser?action=singlestudent',
5712: permission => $permission->{'cusr'},
1.318 raeburn 5713: linktitle => $linktitle{$crstype}{'single'},
1.298 droeschl 5714: },
5715: );
5716:
5717: push(@{ $menu[1]->{items} }, #Category: Multiple Users
5718: {
1.318 raeburn 5719: linktext => $linktext{$crstype}{'drop'},
1.298 droeschl 5720: icon => 'edit-undo.png',
5721: #help => 'Course_Drop_Student',
5722: url => '/adm/createuser?action=drop',
5723: permission => $permission->{'cusr'},
1.318 raeburn 5724: linktitle => $linktitle{$crstype}{'drop'},
1.298 droeschl 5725: },
5726: );
5727: push(@{ $menu[2]->{items} }, #Category: Administration
1.406.2.11 raeburn 5728: {
5729: linktext => 'Helpdesk Access',
5730: icon => 'helpdesk-access.png',
5731: #help => 'Course_Helpdesk_Access',
5732: url => '/adm/createuser?action=helpdesk',
5733: permission => ($permission->{'owner'} || $permission->{'co-owner'}),
5734: linktitle => 'Helpdesk access options',
5735: },
5736: {
1.298 droeschl 5737: linktext => 'Custom Roles',
5738: icon => 'emblem-photos.png',
5739: #help => 'Course_Editing_Custom_Roles',
5740: url => '/adm/createuser?action=custom',
5741: permission => $permission->{'custom'},
5742: linktitle => 'Configure a custom role.',
5743: },
5744: {
1.318 raeburn 5745: linktext => $linktext{$crstype}{'groups'},
1.333 wenzelju 5746: icon => 'grps.png',
1.298 droeschl 5747: #help => 'Course_Manage_Group',
5748: url => '/adm/coursegroups?refpage=cusr',
5749: permission => $permission->{'grp_manage'},
1.318 raeburn 5750: linktitle => $linktitle{$crstype}{'groups'},
1.298 droeschl 5751: },
5752: {
1.328 wenzelju 5753: linktext => 'Change Log',
1.298 droeschl 5754: icon => 'document-properties.png',
5755: #help => 'Course_User_Logs',
5756: url => '/adm/createuser?action=changelogs',
1.406.2.6 raeburn 5757: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.298 droeschl 5758: linktitle => 'View change log.',
5759: },
5760: );
1.277 raeburn 5761: if ($env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'}) {
1.298 droeschl 5762: push(@{ $menu[2]->{items} },
1.398 raeburn 5763: {
1.298 droeschl 5764: linktext => 'Enrollment Requests',
5765: icon => 'selfenrl-queue.png',
5766: #help => 'Course_Approve_Selfenroll',
5767: url => '/adm/createuser?action=selfenrollqueue',
1.406.2.21! raeburn 5768: permission => $permission->{'selfenrolladmin'} || $permission->{'selfenrollview'},
1.298 droeschl 5769: linktitle =>'Approve or reject enrollment requests.',
5770: },
5771: );
1.277 raeburn 5772: }
1.298 droeschl 5773:
1.265 mielkec 5774: if (!exists($permission->{'cusr_section'})){
1.320 raeburn 5775: if ($crstype ne 'Community') {
5776: push(@{ $menu[2]->{items} },
5777: {
5778: linktext => 'Automated Enrollment',
5779: icon => 'roles.png',
5780: #help => 'Course_Automated_Enrollment',
5781: permission => (&Apache::lonnet::auto_run($cnum,$cdom)
1.406.2.6 raeburn 5782: && (($permission->{'cusr'}) ||
5783: ($permission->{'view'}))),
1.320 raeburn 5784: url => '/adm/populate',
5785: linktitle => 'Automated enrollment manager.',
5786: }
5787: );
5788: }
5789: push(@{ $menu[2]->{items} },
1.298 droeschl 5790: {
5791: linktext => 'User Self-Enrollment',
1.342 wenzelju 5792: icon => 'self_enroll.png',
1.298 droeschl 5793: #help => 'Course_Self_Enrollment',
5794: url => '/adm/createuser?action=selfenroll',
1.406.2.21! raeburn 5795: permission => $permission->{'selfenrolladmin'} || $permission->{'selfenrollview'},
1.317 bisitz 5796: linktitle => 'Configure user self-enrollment.',
1.298 droeschl 5797: },
5798: );
5799: }
1.363 raeburn 5800: } elsif ($context eq 'author') {
1.370 raeburn 5801: push(@{ $menu[2]->{items} }, #Category: Administration
1.363 raeburn 5802: {
5803: linktext => 'Change Log',
5804: icon => 'document-properties.png',
5805: #help => 'Course_User_Logs',
5806: url => '/adm/createuser?action=changelogs',
5807: permission => $permission->{'cusr'},
5808: linktitle => 'View change log.',
5809: },
1.370 raeburn 5810: );
1.363 raeburn 5811: }
5812: return Apache::lonhtmlcommon::generate_menu(@menu);
1.250 raeburn 5813: # { text => 'View Log-in History',
5814: # help => 'Course_User_Logins',
5815: # action => 'logins',
5816: # permission => $permission->{'cusr'},
5817: # });
1.190 raeburn 5818: }
5819:
1.189 albertel 5820: sub restore_prev_selections {
5821: my %saveable_parameters = ('srchby' => 'scalar',
5822: 'srchin' => 'scalar',
5823: 'srchtype' => 'scalar',
5824: );
5825: &Apache::loncommon::store_settings('user','user_picker',
5826: \%saveable_parameters);
5827: &Apache::loncommon::restore_settings('user','user_picker',
5828: \%saveable_parameters);
5829: }
5830:
1.237 raeburn 5831: sub print_selfenroll_menu {
1.406.2.6 raeburn 5832: my ($r,$context,$cid,$cdom,$cnum,$currsettings,$additional,$readonly) = @_;
1.322 raeburn 5833: my $crstype = &Apache::loncommon::course_type();
1.398 raeburn 5834: my $formname = 'selfenroll';
1.237 raeburn 5835: my $nolink = 1;
1.398 raeburn 5836: my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles();
1.237 raeburn 5837: my $groupslist = &Apache::lonuserutils::get_groupslist();
5838: my $setsec_js =
5839: &Apache::lonuserutils::setsections_javascript($formname,$groupslist);
1.249 raeburn 5840: my %alerts = &Apache::lonlocal::texthash(
5841: acto => 'Activation of self-enrollment was selected for the following domain(s)',
5842: butn => 'but no user types have been checked.',
5843: wilf => "Please uncheck 'activate' or check at least one type.",
5844: );
1.406.2.6 raeburn 5845: my $disabled;
5846: if ($readonly) {
5847: $disabled = ' disabled="disabled"';
5848: }
1.405 damieng 5849: &js_escape(\%alerts);
1.249 raeburn 5850: my $selfenroll_js = <<"ENDSCRIPT";
5851: function update_types(caller,num) {
5852: var delidx = getIndexByName('selfenroll_delete');
5853: var actidx = getIndexByName('selfenroll_activate');
5854: if (caller == 'selfenroll_all') {
5855: var selall;
5856: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5857: if (document.$formname.selfenroll_all[i].checked) {
5858: selall = document.$formname.selfenroll_all[i].value;
5859: }
5860: }
5861: if (selall == 1) {
5862: if (delidx != -1) {
5863: if (document.$formname.selfenroll_delete.length) {
5864: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
5865: document.$formname.selfenroll_delete[j].checked = true;
5866: }
5867: } else {
5868: document.$formname.elements[delidx].checked = true;
5869: }
5870: }
5871: if (actidx != -1) {
5872: if (document.$formname.selfenroll_activate.length) {
5873: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5874: document.$formname.selfenroll_activate[j].checked = false;
5875: }
5876: } else {
5877: document.$formname.elements[actidx].checked = false;
5878: }
5879: }
5880: document.$formname.selfenroll_newdom.selectedIndex = 0;
5881: }
5882: }
5883: if (caller == 'selfenroll_activate') {
5884: if (document.$formname.selfenroll_activate.length) {
5885: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5886: if (document.$formname.selfenroll_activate[j].value == num) {
5887: if (document.$formname.selfenroll_activate[j].checked) {
5888: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5889: if (document.$formname.selfenroll_all[i].value == '1') {
5890: document.$formname.selfenroll_all[i].checked = false;
5891: }
5892: if (document.$formname.selfenroll_all[i].value == '0') {
5893: document.$formname.selfenroll_all[i].checked = true;
5894: }
5895: }
5896: }
5897: }
5898: }
5899: } else {
5900: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5901: if (document.$formname.selfenroll_all[i].value == '1') {
5902: document.$formname.selfenroll_all[i].checked = false;
5903: }
5904: if (document.$formname.selfenroll_all[i].value == '0') {
5905: document.$formname.selfenroll_all[i].checked = true;
5906: }
5907: }
5908: }
5909: }
5910: if (caller == 'selfenroll_delete') {
5911: if (document.$formname.selfenroll_delete.length) {
5912: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
5913: if (document.$formname.selfenroll_delete[j].value == num) {
5914: if (document.$formname.selfenroll_delete[j].checked) {
5915: var delindex = getIndexByName('selfenroll_types_'+num);
5916: if (delindex != -1) {
5917: if (document.$formname.elements[delindex].length) {
5918: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
5919: document.$formname.elements[delindex][k].checked = false;
5920: }
5921: } else {
5922: document.$formname.elements[delindex].checked = false;
5923: }
5924: }
5925: }
5926: }
5927: }
5928: } else {
5929: if (document.$formname.selfenroll_delete.checked) {
5930: var delindex = getIndexByName('selfenroll_types_'+num);
5931: if (delindex != -1) {
5932: if (document.$formname.elements[delindex].length) {
5933: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
5934: document.$formname.elements[delindex][k].checked = false;
5935: }
5936: } else {
5937: document.$formname.elements[delindex].checked = false;
5938: }
5939: }
5940: }
5941: }
5942: }
5943: return;
5944: }
5945:
5946: function validate_types(form) {
5947: var needaction = new Array();
5948: var countfail = 0;
5949: var actidx = getIndexByName('selfenroll_activate');
5950: if (actidx != -1) {
5951: if (document.$formname.selfenroll_activate.length) {
5952: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5953: var num = document.$formname.selfenroll_activate[j].value;
5954: if (document.$formname.selfenroll_activate[j].checked) {
5955: countfail = check_types(num,countfail,needaction)
5956: }
5957: }
5958: } else {
5959: if (document.$formname.selfenroll_activate.checked) {
1.398 raeburn 5960: var num = document.$formname.selfenroll_activate.value;
1.249 raeburn 5961: countfail = check_types(num,countfail,needaction)
5962: }
5963: }
5964: }
5965: if (countfail > 0) {
5966: var msg = "$alerts{'acto'}\\n";
5967: var loopend = needaction.length -1;
5968: if (loopend > 0) {
5969: for (var m=0; m<loopend; m++) {
5970: msg += needaction[m]+", ";
5971: }
5972: }
5973: msg += needaction[loopend]+"\\n$alerts{'butn'}\\n$alerts{'wilf'}";
5974: alert(msg);
5975: return;
5976: }
5977: setSections(form);
5978: }
5979:
5980: function check_types(num,countfail,needaction) {
1.406.2.15 raeburn 5981: var boxname = 'selfenroll_types_'+num;
5982: var typeidx = getIndexByName(boxname);
1.249 raeburn 5983: var count = 0;
5984: if (typeidx != -1) {
1.406.2.15 raeburn 5985: if (document.$formname.elements[boxname].length) {
5986: for (var k=0; k<document.$formname.elements[boxname].length; k++) {
5987: if (document.$formname.elements[boxname][k].checked) {
1.249 raeburn 5988: count ++;
5989: }
5990: }
5991: } else {
5992: if (document.$formname.elements[typeidx].checked) {
5993: count ++;
5994: }
5995: }
5996: if (count == 0) {
5997: var domidx = getIndexByName('selfenroll_dom_'+num);
5998: if (domidx != -1) {
5999: var domname = document.$formname.elements[domidx].value;
6000: needaction[countfail] = domname;
6001: countfail ++;
6002: }
6003: }
6004: }
6005: return countfail;
6006: }
6007:
1.398 raeburn 6008: function toggleNotify() {
6009: var selfenrollApproval = 0;
6010: if (document.$formname.selfenroll_approval.length) {
6011: for (var i=0; i<document.$formname.selfenroll_approval.length; i++) {
6012: if (document.$formname.selfenroll_approval[i].checked) {
6013: selfenrollApproval = document.$formname.selfenroll_approval[i].value;
6014: break;
6015: }
6016: }
6017: }
6018: if (document.getElementById('notified')) {
6019: if (selfenrollApproval == 0) {
6020: document.getElementById('notified').style.display='none';
6021: } else {
6022: document.getElementById('notified').style.display='block';
6023: }
6024: }
6025: return;
6026: }
6027:
1.249 raeburn 6028: function getIndexByName(item) {
6029: for (var i=0;i<document.$formname.elements.length;i++) {
6030: if (document.$formname.elements[i].name == item) {
6031: return i;
6032: }
6033: }
6034: return -1;
6035: }
6036: ENDSCRIPT
1.256 raeburn 6037:
1.237 raeburn 6038: my $output = '<script type="text/javascript">'."\n".
1.301 bisitz 6039: '// <![CDATA['."\n".
1.249 raeburn 6040: $setsec_js."\n".$selfenroll_js."\n".
1.301 bisitz 6041: '// ]]>'."\n".
1.237 raeburn 6042: '</script>'."\n".
1.256 raeburn 6043: '<h3>'.$lt->{'selfenroll'}.'</h3>'."\n";
1.406.2.21! raeburn 6044: my $visactions = &cat_visibility($cdom);
1.400 raeburn 6045: my ($cathash,%cattype);
6046: my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
6047: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
6048: $cathash = $domconfig{'coursecategories'}{'cats'};
6049: $cattype{'auth'} = $domconfig{'coursecategories'}{'auth'};
6050: $cattype{'unauth'} = $domconfig{'coursecategories'}{'unauth'};
1.406 raeburn 6051: if ($cattype{'auth'} eq '') {
6052: $cattype{'auth'} = 'std';
6053: }
6054: if ($cattype{'unauth'} eq '') {
6055: $cattype{'unauth'} = 'std';
6056: }
1.400 raeburn 6057: } else {
6058: $cathash = {};
6059: $cattype{'auth'} = 'std';
6060: $cattype{'unauth'} = 'std';
6061: }
6062: if (($cattype{'auth'} eq 'none') && ($cattype{'unauth'} eq 'none')) {
6063: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
6064: '<br />'.
6065: '<br />'.$visactions->{'take'}.'<ul>'.
6066: '<li>'.$visactions->{'dc_chgconf'}.'</li>'.
6067: '</ul>');
6068: } elsif (($cattype{'auth'} !~ /^(std|domonly)$/) && ($cattype{'unauth'} !~ /^(std|domonly)$/)) {
6069: if ($currsettings->{'uniquecode'}) {
6070: $r->print('<span class="LC_info">'.$visactions->{'vis'}.'</span>');
6071: } else {
6072: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
6073: '<br />'.
6074: '<br />'.$visactions->{'take'}.'<ul>'.
6075: '<li>'.$visactions->{'dc_setcode'}.'</li>'.
6076: '</ul><br />');
6077: }
6078: } else {
6079: my ($visible,$cansetvis,$vismsgs) = &visible_in_stdcat($cdom,$cnum,\%domconfig);
6080: if (ref($visactions) eq 'HASH') {
6081: if ($visible) {
6082: $output .= '<p class="LC_info">'.$visactions->{'vis'}.'</p>';
6083: } else {
6084: $output .= '<p class="LC_warning">'.$visactions->{'miss'}.'</p>'
6085: .$visactions->{'yous'}.
6086: '<p>'.$visactions->{'gen'}.'<br />'.$visactions->{'coca'};
6087: if (ref($vismsgs) eq 'ARRAY') {
6088: $output .= '<br />'.$visactions->{'make'}.'<ul>';
6089: foreach my $item (@{$vismsgs}) {
6090: $output .= '<li>'.$visactions->{$item}.'</li>';
6091: }
6092: $output .= '</ul>';
1.256 raeburn 6093: }
1.400 raeburn 6094: $output .= '</p>';
1.256 raeburn 6095: }
6096: }
6097: }
1.398 raeburn 6098: my $actionhref = '/adm/createuser';
6099: if ($context eq 'domain') {
6100: $actionhref = '/adm/modifycourse';
6101: }
1.400 raeburn 6102:
6103: my %noedit;
6104: unless ($context eq 'domain') {
6105: %noedit = &get_noedit_fields($cdom,$cnum,$crstype,$row);
6106: }
1.398 raeburn 6107: $output .= '<form name="'.$formname.'" method="post" action="'.$actionhref.'">'."\n".
1.256 raeburn 6108: &Apache::lonhtmlcommon::start_pick_box();
1.237 raeburn 6109: if (ref($row) eq 'ARRAY') {
6110: foreach my $item (@{$row}) {
6111: my $title = $item;
6112: if (ref($lt) eq 'HASH') {
6113: $title = $lt->{$item};
6114: }
1.297 bisitz 6115: $output .= &Apache::lonhtmlcommon::row_title($title);
1.237 raeburn 6116: if ($item eq 'types') {
1.398 raeburn 6117: my $curr_types;
6118: if (ref($currsettings) eq 'HASH') {
6119: $curr_types = $currsettings->{'selfenroll_types'};
6120: }
1.400 raeburn 6121: if ($noedit{$item}) {
6122: if ($curr_types eq '*') {
6123: $output .= &mt('Any user in any domain');
6124: } else {
6125: my @entries = split(/;/,$curr_types);
6126: if (@entries > 0) {
6127: $output .= '<ul>';
6128: foreach my $entry (@entries) {
6129: my ($currdom,$typestr) = split(/:/,$entry);
6130: next if ($typestr eq '');
6131: my $domdesc = &Apache::lonnet::domain($currdom);
6132: my @currinsttypes = split(',',$typestr);
6133: my ($othertitle,$usertypes,$types) =
6134: &Apache::loncommon::sorted_inst_types($currdom);
6135: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
6136: $usertypes->{'any'} = &mt('any user');
6137: if (keys(%{$usertypes}) > 0) {
6138: $usertypes->{'other'} = &mt('other users');
6139: }
6140: my @longinsttypes = map { $usertypes->{$_}; } @currinsttypes;
6141: $output .= '<li>'.$domdesc.':'.join(', ',@longinsttypes).'</li>';
6142: }
6143: }
6144: $output .= '</ul>';
6145: } else {
6146: $output .= &mt('None');
6147: }
6148: }
6149: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6150: next;
6151: }
1.241 raeburn 6152: my $showdomdesc = 1;
6153: my $includeempty = 1;
6154: my $num = 0;
6155: $output .= &Apache::loncommon::start_data_table().
6156: &Apache::loncommon::start_data_table_row()
6157: .'<td colspan="2"><span class="LC_nobreak"><label>'
6158: .&mt('Any user in any domain:')
6159: .' <input type="radio" name="selfenroll_all" value="1" ';
6160: if ($curr_types eq '*') {
6161: $output .= ' checked="checked" ';
6162: }
1.249 raeburn 6163: $output .= 'onchange="javascript:update_types('.
1.406.2.6 raeburn 6164: "'selfenroll_all'".');"'.$disabled.' />'.&mt('Yes').'</label>'.
1.249 raeburn 6165: ' <input type="radio" name="selfenroll_all" value="0" ';
1.241 raeburn 6166: if ($curr_types ne '*') {
6167: $output .= ' checked="checked" ';
6168: }
1.249 raeburn 6169: $output .= ' onchange="javascript:update_types('.
1.406.2.6 raeburn 6170: "'selfenroll_all'".');"'.$disabled.' />'.&mt('No').'</label></td>'.
1.249 raeburn 6171: &Apache::loncommon::end_data_table_row().
6172: &Apache::loncommon::end_data_table().
6173: &mt('Or').'<br />'.
6174: &Apache::loncommon::start_data_table();
1.241 raeburn 6175: my %currdoms;
1.249 raeburn 6176: if ($curr_types eq '') {
1.241 raeburn 6177: $output .= &new_selfenroll_dom_row($cdom,'0');
6178: } elsif ($curr_types ne '*') {
6179: my @entries = split(/;/,$curr_types);
6180: if (@entries > 0) {
6181: foreach my $entry (@entries) {
6182: my ($currdom,$typestr) = split(/:/,$entry);
6183: $currdoms{$currdom} = 1;
6184: my $domdesc = &Apache::lonnet::domain($currdom);
1.249 raeburn 6185: my @currinsttypes = split(',',$typestr);
1.241 raeburn 6186: $output .= &Apache::loncommon::start_data_table_row()
6187: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').'<b>'
6188: .' '.$domdesc.' ('.$currdom.')'
6189: .'</b><input type="hidden" name="selfenroll_dom_'.$num
6190: .'" value="'.$currdom.'" /></span><br />'
6191: .'<span class="LC_nobreak"><label><input type="checkbox" '
1.406.2.6 raeburn 6192: .'name="selfenroll_delete" value="'.$num.'" onchange="javascript:update_types('."'selfenroll_delete','$num'".');"'.$disabled.' />'
1.241 raeburn 6193: .&mt('Delete').'</label></span></td>';
1.249 raeburn 6194: $output .= '<td valign="top"> '.&mt('User types:').'<br />'
1.406.2.6 raeburn 6195: .&selfenroll_inst_types($num,$currdom,\@currinsttypes,$readonly).'</td>'
1.241 raeburn 6196: .&Apache::loncommon::end_data_table_row();
6197: $num ++;
6198: }
6199: }
6200: }
1.249 raeburn 6201: my $add_domtitle = &mt('Users in additional domain:');
1.241 raeburn 6202: if ($curr_types eq '*') {
1.249 raeburn 6203: $add_domtitle = &mt('Users in specific domain:');
1.241 raeburn 6204: } elsif ($curr_types eq '') {
1.249 raeburn 6205: $add_domtitle = &mt('Users in other domain:');
1.241 raeburn 6206: }
6207: $output .= &Apache::loncommon::start_data_table_row()
6208: .'<td colspan="2"><span class="LC_nobreak">'.$add_domtitle.'</span><br />'
6209: .&Apache::loncommon::select_dom_form('','selfenroll_newdom',
1.406.2.6 raeburn 6210: $includeempty,$showdomdesc,'','','',$readonly)
1.241 raeburn 6211: .'<input type="hidden" name="selfenroll_types_total" value="'.$num.'" />'
6212: .'</td>'.&Apache::loncommon::end_data_table_row()
6213: .&Apache::loncommon::end_data_table();
1.237 raeburn 6214: } elsif ($item eq 'registered') {
6215: my ($regon,$regoff);
1.398 raeburn 6216: my $registered;
6217: if (ref($currsettings) eq 'HASH') {
6218: $registered = $currsettings->{'selfenroll_registered'};
6219: }
1.400 raeburn 6220: if ($noedit{$item}) {
6221: if ($registered) {
6222: $output .= &mt('Must be registered in course');
6223: } else {
6224: $output .= &mt('No requirement');
6225: }
6226: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6227: next;
6228: }
1.398 raeburn 6229: if ($registered) {
1.237 raeburn 6230: $regon = ' checked="checked" ';
1.406.2.6 raeburn 6231: $regoff = '';
1.237 raeburn 6232: } else {
1.406.2.6 raeburn 6233: $regon = '';
1.237 raeburn 6234: $regoff = ' checked="checked" ';
6235: }
6236: $output .= '<label>'.
1.406.2.6 raeburn 6237: '<input type="radio" name="selfenroll_registered" value="1"'.$regon.$disabled.' />'.
1.244 bisitz 6238: &mt('Yes').'</label> <label>'.
1.406.2.6 raeburn 6239: '<input type="radio" name="selfenroll_registered" value="0"'.$regoff.$disabled.' />'.
1.244 bisitz 6240: &mt('No').'</label>';
1.237 raeburn 6241: } elsif ($item eq 'enroll_dates') {
1.398 raeburn 6242: my ($starttime,$endtime);
6243: if (ref($currsettings) eq 'HASH') {
6244: $starttime = $currsettings->{'selfenroll_start_date'};
6245: $endtime = $currsettings->{'selfenroll_end_date'};
6246: if ($starttime eq '') {
6247: $starttime = $currsettings->{'default_enrollment_start_date'};
6248: }
6249: if ($endtime eq '') {
6250: $endtime = $currsettings->{'default_enrollment_end_date'};
6251: }
1.237 raeburn 6252: }
1.400 raeburn 6253: if ($noedit{$item}) {
6254: $output .= &mt('From: [_1], to: [_2]',&Apache::lonlocal::locallocaltime($starttime),
6255: &Apache::lonlocal::locallocaltime($endtime));
6256: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6257: next;
6258: }
1.237 raeburn 6259: my $startform =
6260: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_date',$starttime,
1.406.2.6 raeburn 6261: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6262: my $endform =
6263: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_date',$endtime,
1.406.2.6 raeburn 6264: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6265: $output .= &selfenroll_date_forms($startform,$endform);
6266: } elsif ($item eq 'access_dates') {
1.398 raeburn 6267: my ($starttime,$endtime);
6268: if (ref($currsettings) eq 'HASH') {
6269: $starttime = $currsettings->{'selfenroll_start_access'};
6270: $endtime = $currsettings->{'selfenroll_end_access'};
6271: if ($starttime eq '') {
6272: $starttime = $currsettings->{'default_enrollment_start_date'};
6273: }
6274: if ($endtime eq '') {
6275: $endtime = $currsettings->{'default_enrollment_end_date'};
6276: }
1.237 raeburn 6277: }
1.400 raeburn 6278: if ($noedit{$item}) {
6279: $output .= &mt('From: [_1], to: [_2]',&Apache::lonlocal::locallocaltime($starttime),
6280: &Apache::lonlocal::locallocaltime($endtime));
6281: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6282: next;
6283: }
1.237 raeburn 6284: my $startform =
6285: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_access',$starttime,
1.406.2.6 raeburn 6286: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6287: my $endform =
6288: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_access',$endtime,
1.406.2.6 raeburn 6289: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6290: $output .= &selfenroll_date_forms($startform,$endform);
6291: } elsif ($item eq 'section') {
1.398 raeburn 6292: my $currsec;
6293: if (ref($currsettings) eq 'HASH') {
6294: $currsec = $currsettings->{'selfenroll_section'};
6295: }
1.237 raeburn 6296: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
6297: my $newsecval;
6298: if ($currsec ne 'none' && $currsec ne '') {
6299: if (!defined($sections_count{$currsec})) {
6300: $newsecval = $currsec;
6301: }
6302: }
1.400 raeburn 6303: if ($noedit{$item}) {
6304: if ($currsec ne '') {
6305: $output .= $currsec;
6306: } else {
6307: $output .= &mt('No specific section');
6308: }
6309: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6310: next;
6311: }
1.237 raeburn 6312: my $sections_select =
1.406.2.6 raeburn 6313: &Apache::lonuserutils::course_sections(\%sections_count,'st',$currsec,$disabled);
1.237 raeburn 6314: $output .= '<table class="LC_createuser">'."\n".
6315: '<tr class="LC_section_row">'."\n".
6316: '<td align="center">'.&mt('Existing sections')."\n".
6317: '<br />'.$sections_select.'</td><td align="center">'.
6318: &mt('New section').'<br />'."\n".
1.406.2.6 raeburn 6319: '<input type="text" name="newsec" size="15" value="'.$newsecval.'"'.$disabled.' />'."\n".
1.237 raeburn 6320: '<input type="hidden" name="sections" value="" />'."\n".
6321: '</td></tr></table>'."\n";
1.276 raeburn 6322: } elsif ($item eq 'approval') {
1.398 raeburn 6323: my ($currnotified,$currapproval,%appchecked);
6324: my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs();
1.406.2.6 raeburn 6325: if (ref($currsettings) eq 'HASH') {
1.398 raeburn 6326: $currnotified = $currsettings->{'selfenroll_notifylist'};
6327: $currapproval = $currsettings->{'selfenroll_approval'};
6328: }
6329: if ($currapproval !~ /^[012]$/) {
6330: $currapproval = 0;
6331: }
1.400 raeburn 6332: if ($noedit{$item}) {
6333: $output .= $selfdescs{'approval'}{$currapproval}.
6334: '<br />'.&mt('(Set by Domain Coordinator)');
6335: next;
6336: }
1.398 raeburn 6337: $appchecked{$currapproval} = ' checked="checked"';
6338: for my $i (0..2) {
6339: $output .= '<label>'.
6340: '<input type="radio" name="selfenroll_approval" value="'.$i.'"'.
1.406.2.6 raeburn 6341: $appchecked{$i}.' onclick="toggleNotify();"'.$disabled.' />'.
6342: $selfdescs{'approval'}{$i}.'</label>'.(' 'x2);
1.276 raeburn 6343: }
6344: my %advhash = &Apache::lonnet::get_course_adv_roles($cid,1);
6345: my (@ccs,%notified);
1.322 raeburn 6346: my $ccrole = 'cc';
6347: if ($crstype eq 'Community') {
6348: $ccrole = 'co';
6349: }
6350: if ($advhash{$ccrole}) {
6351: @ccs = split(/,/,$advhash{$ccrole});
1.276 raeburn 6352: }
6353: if ($currnotified) {
6354: foreach my $current (split(/,/,$currnotified)) {
6355: $notified{$current} = 1;
6356: if (!grep(/^\Q$current\E$/,@ccs)) {
6357: push(@ccs,$current);
6358: }
6359: }
6360: }
6361: if (@ccs) {
1.398 raeburn 6362: my $style;
6363: unless ($currapproval) {
6364: $style = ' style="display: none;"';
6365: }
6366: $output .= '<br /><div id="notified"'.$style.'>'.
6367: &mt('Personnel to be notified when an enrollment request needs approval, or has been approved:').' '.
6368: &Apache::loncommon::start_data_table().
1.276 raeburn 6369: &Apache::loncommon::start_data_table_row();
6370: my $count = 0;
6371: my $numcols = 4;
6372: foreach my $cc (sort(@ccs)) {
6373: my $notifyon;
6374: my ($ccuname,$ccudom) = split(/:/,$cc);
6375: if ($notified{$cc}) {
6376: $notifyon = ' checked="checked" ';
6377: }
6378: if ($count && !$count%$numcols) {
6379: $output .= &Apache::loncommon::end_data_table_row().
6380: &Apache::loncommon::start_data_table_row()
6381: }
6382: $output .= '<td><span class="LC_nobreak"><label>'.
1.406.2.6 raeburn 6383: '<input type="checkbox" name="selfenroll_notify"'.$notifyon.' value="'.$cc.'"'.$disabled.' />'.
1.276 raeburn 6384: &Apache::loncommon::plainname($ccuname,$ccudom).
6385: '</label></span></td>';
1.343 raeburn 6386: $count ++;
1.276 raeburn 6387: }
6388: my $rem = $count%$numcols;
6389: if ($rem) {
6390: my $emptycols = $numcols - $rem;
6391: for (my $i=0; $i<$emptycols; $i++) {
6392: $output .= '<td> </td>';
6393: }
6394: }
6395: $output .= &Apache::loncommon::end_data_table_row().
1.398 raeburn 6396: &Apache::loncommon::end_data_table().
6397: '</div>';
1.276 raeburn 6398: }
6399: } elsif ($item eq 'limit') {
1.398 raeburn 6400: my ($crslimit,$selflimit,$nolimit,$currlim,$currcap);
6401: if (ref($currsettings) eq 'HASH') {
6402: $currlim = $currsettings->{'selfenroll_limit'};
6403: $currcap = $currsettings->{'selfenroll_cap'};
6404: }
1.400 raeburn 6405: if ($noedit{$item}) {
6406: if (($currlim eq 'allstudents') || ($currlim eq 'selfenrolled')) {
6407: if ($currlim eq 'allstudents') {
6408: $output .= &mt('Limit by total students');
6409: } elsif ($currlim eq 'selfenrolled') {
6410: $output .= &mt('Limit by total self-enrolled students');
6411: }
6412: $output .= ' '.&mt('Maximum: [_1]',$currcap).
6413: '<br />'.&mt('(Set by Domain Coordinator)');
6414: } else {
6415: $output .= &mt('No limit').'<br />'.&mt('(Set by Domain Coordinator)');
6416: }
6417: next;
6418: }
1.276 raeburn 6419: if ($currlim eq 'allstudents') {
6420: $crslimit = ' checked="checked" ';
6421: $selflimit = ' ';
6422: $nolimit = ' ';
6423: } elsif ($currlim eq 'selfenrolled') {
6424: $crslimit = ' ';
6425: $selflimit = ' checked="checked" ';
6426: $nolimit = ' ';
6427: } else {
6428: $crslimit = ' ';
6429: $selflimit = ' ';
1.398 raeburn 6430: $nolimit = ' checked="checked" ';
1.276 raeburn 6431: }
6432: $output .= '<table><tr><td><label>'.
1.406.2.6 raeburn 6433: '<input type="radio" name="selfenroll_limit" value="none"'.$nolimit.$disabled.'/>'.
1.276 raeburn 6434: &mt('No limit').'</label></td><td><label>'.
1.406.2.6 raeburn 6435: '<input type="radio" name="selfenroll_limit" value="allstudents"'.$crslimit.$disabled.'/>'.
1.276 raeburn 6436: &mt('Limit by total students').'</label></td><td><label>'.
1.406.2.6 raeburn 6437: '<input type="radio" name="selfenroll_limit" value="selfenrolled"'.$selflimit.$disabled.'/>'.
1.276 raeburn 6438: &mt('Limit by total self-enrolled students').
6439: '</td></tr><tr>'.
6440: '<td> </td><td colspan="2"><span class="LC_nobreak">'.
6441: (' 'x3).&mt('Maximum number allowed: ').
1.406.2.6 raeburn 6442: '<input type="text" name="selfenroll_cap" size = "5" value="'.$currcap.'"'.$disabled.' /></td></tr></table>';
1.237 raeburn 6443: }
6444: $output .= &Apache::lonhtmlcommon::row_closure(1);
6445: }
6446: }
1.406.2.6 raeburn 6447: $output .= &Apache::lonhtmlcommon::end_pick_box().'<br />';
6448: unless ($readonly) {
6449: $output .= '<input type="button" name="selfenrollconf" value="'
6450: .&mt('Save').'" onclick="validate_types(this.form);" />';
6451: }
6452: $output .= '<input type="hidden" name="action" value="selfenroll" />'
1.406.2.11 raeburn 6453: .'<input type="hidden" name="state" value="done" />'."\n"
6454: .$additional.'</form>';
1.237 raeburn 6455: $r->print($output);
6456: return;
6457: }
6458:
1.400 raeburn 6459: sub get_noedit_fields {
6460: my ($cdom,$cnum,$crstype,$row) = @_;
6461: my %noedit;
6462: if (ref($row) eq 'ARRAY') {
6463: my %settings = &Apache::lonnet::get('environment',['internal.coursecode','internal.textbook',
6464: 'internal.selfenrollmgrdc',
6465: 'internal.selfenrollmgrcc'],$cdom,$cnum);
6466: my $type = &Apache::lonuserutils::get_extended_type($cdom,$cnum,$crstype,\%settings);
6467: my (%specific_managebydc,%specific_managebycc,%default_managebydc);
6468: map { $specific_managebydc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrdc'}));
6469: map { $specific_managebycc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrcc'}));
6470: my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
6471: map { $default_managebydc{$_} = 1; } (split(/,/,$domdefaults{$type.'selfenrolladmdc'}));
6472:
6473: foreach my $item (@{$row}) {
6474: next if ($specific_managebycc{$item});
6475: if (($specific_managebydc{$item}) || ($default_managebydc{$item})) {
6476: $noedit{$item} = 1;
6477: }
6478: }
6479: }
6480: return %noedit;
6481: }
6482:
6483: sub visible_in_stdcat {
6484: my ($cdom,$cnum,$domconf) = @_;
6485: my ($cathash,%settable,@vismsgs,$cansetvis,$visible);
6486: unless (ref($domconf) eq 'HASH') {
6487: return ($visible,$cansetvis,\@vismsgs);
6488: }
6489: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6490: if ($domconf->{'coursecategories'}{'togglecats'} eq 'crs') {
1.256 raeburn 6491: $settable{'togglecats'} = 1;
6492: }
1.400 raeburn 6493: if ($domconf->{'coursecategories'}{'categorize'} eq 'crs') {
1.256 raeburn 6494: $settable{'categorize'} = 1;
6495: }
1.400 raeburn 6496: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6497: }
1.260 raeburn 6498: if ($settable{'togglecats'} && $settable{'categorize'}) {
1.256 raeburn 6499: $cansetvis = &mt('You are able to both assign a course category and choose to exclude this course from the catalog.');
6500: } elsif ($settable{'togglecats'}) {
6501: $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 6502: } elsif ($settable{'categorize'}) {
1.256 raeburn 6503: $cansetvis = &mt('You may assign a course category, but only a Domain Coordinator may choose to exclude this course from the catalog.');
6504: } else {
6505: $cansetvis = &mt('Only a Domain Coordinator may assign a course category or choose to exclude this course from the catalog.');
6506: }
6507:
6508: my %currsettings =
6509: &Apache::lonnet::get('environment',['hidefromcat','categories','internal.coursecode'],
6510: $cdom,$cnum);
1.400 raeburn 6511: $visible = 0;
1.256 raeburn 6512: if ($currsettings{'internal.coursecode'} ne '') {
1.400 raeburn 6513: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6514: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6515: if (ref($cathash) eq 'HASH') {
6516: if ($cathash->{'instcode::0'} eq '') {
6517: push(@vismsgs,'dc_addinst');
6518: } else {
6519: $visible = 1;
6520: }
6521: } else {
6522: $visible = 1;
6523: }
6524: } else {
6525: $visible = 1;
6526: }
6527: } else {
6528: if (ref($cathash) eq 'HASH') {
6529: if ($cathash->{'instcode::0'} ne '') {
6530: push(@vismsgs,'dc_instcode');
6531: }
6532: } else {
6533: push(@vismsgs,'dc_instcode');
6534: }
6535: }
6536: if ($currsettings{'categories'} ne '') {
6537: my $cathash;
1.400 raeburn 6538: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6539: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6540: if (ref($cathash) eq 'HASH') {
6541: if (keys(%{$cathash}) == 0) {
6542: push(@vismsgs,'dc_catalog');
6543: } elsif ((keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} ne '')) {
6544: push(@vismsgs,'dc_categories');
6545: } else {
6546: my @currcategories = split('&',$currsettings{'categories'});
6547: my $matched = 0;
6548: foreach my $cat (@currcategories) {
6549: if ($cathash->{$cat} ne '') {
6550: $visible = 1;
6551: $matched = 1;
6552: last;
6553: }
6554: }
6555: if (!$matched) {
1.260 raeburn 6556: if ($settable{'categorize'}) {
1.256 raeburn 6557: push(@vismsgs,'chgcat');
6558: } else {
6559: push(@vismsgs,'dc_chgcat');
6560: }
6561: }
6562: }
6563: }
6564: }
6565: } else {
6566: if (ref($cathash) eq 'HASH') {
6567: if ((keys(%{$cathash}) > 1) ||
6568: (keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} eq '')) {
1.260 raeburn 6569: if ($settable{'categorize'}) {
1.256 raeburn 6570: push(@vismsgs,'addcat');
6571: } else {
6572: push(@vismsgs,'dc_addcat');
6573: }
6574: }
6575: }
6576: }
6577: if ($currsettings{'hidefromcat'} eq 'yes') {
6578: $visible = 0;
6579: if ($settable{'togglecats'}) {
6580: unshift(@vismsgs,'unhide');
6581: } else {
6582: unshift(@vismsgs,'dc_unhide')
6583: }
6584: }
1.400 raeburn 6585: return ($visible,$cansetvis,\@vismsgs);
6586: }
6587:
6588: sub cat_visibility {
1.406.2.21! raeburn 6589: my ($cdom) = @_;
1.400 raeburn 6590: my %visactions = &Apache::lonlocal::texthash(
6591: vis => 'This course/community currently appears in the Course/Community Catalog for this domain.',
6592: 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.',
6593: miss => 'This course/community does not currently appear in the Course/Community Catalog for this domain.',
6594: none => 'Display of a course catalog is disabled for this domain.',
6595: yous => 'You should remedy this if you plan to allow self-enrollment, otherwise students will have difficulty finding this course.',
6596: 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.',
6597: make => 'Make any changes to self-enrollment settings below, click "Save", then take action to include the course in the Catalog:',
6598: take => 'Take the following action to ensure the course appears in the Catalog:',
6599: dc_chgconf => 'Ask a domain coordinator to change the Catalog type for this domain.',
6600: dc_setcode => 'Ask a domain coordinator to assign a six character code to the course',
6601: dc_unhide => 'Ask a domain coordinator to change the "Exclude from course catalog" setting.',
1.406.2.21! raeburn 6602: dc_addinst => 'Ask a domain coordinator to enable catalog display of "Official courses (with institutional codes)".',
1.400 raeburn 6603: dc_instcode => 'Ask a domain coordinator to assign an institutional code (if this is an official course).',
6604: dc_catalog => 'Ask a domain coordinator to enable or create at least one course category in the domain.',
6605: dc_categories => 'Ask a domain coordinator to create a hierarchy of categories and sub categories for courses in the domain.',
6606: 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',
6607: dc_addcat => 'Ask a domain coordinator to assign a category to the course.',
6608: );
1.406.2.21! raeburn 6609: if ($env{'request.role'} eq "dc./$cdom/") {
! 6610: $visactions{'dc_chgconf'} = &mt('Use: "Main menu" [_1] "Set domain configuration" [_1] "Cataloging of courses/communities" to change the Catalog type for this domain.','»');
! 6611: $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.','»');
! 6612: $visactions{'dc_unhide'} = &mt('Use: "Main menu" [_1] "Set domain configuration" [_1] "Cataloging of courses/communities" to change the "Exclude from course catalog" setting.','»');
! 6613: $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)".','»');
! 6614: $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).','»');
! 6615: $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.','»');
! 6616: $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.','»');
! 6617: $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.','»');
! 6618: $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.','»');
! 6619: }
1.400 raeburn 6620: $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>"');
6621: $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>"');
6622: $visactions{'addcat'} = &mt('Use [_1]Categorize course[_2] to assign a category to the course.','"<a href="/adm/courseprefs?phase=display&actions=courseinfo">','</a>"');
6623: return \%visactions;
1.256 raeburn 6624: }
6625:
1.241 raeburn 6626: sub new_selfenroll_dom_row {
6627: my ($newdom,$num) = @_;
6628: my $domdesc = &Apache::lonnet::domain($newdom);
6629: my $output;
6630: if ($domdesc ne '') {
6631: $output .= &Apache::loncommon::start_data_table_row()
6632: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').' <b>'.$domdesc
6633: .' ('.$newdom.')</b><input type="hidden" name="selfenroll_dom_'.$num
1.249 raeburn 6634: .'" value="'.$newdom.'" /></span><br />'
6635: .'<span class="LC_nobreak"><label><input type="checkbox" '
6636: .'name="selfenroll_activate" value="'.$num.'" '
6637: .'onchange="javascript:update_types('
6638: ."'selfenroll_activate','$num'".');" />'
6639: .&mt('Activate').'</label></span></td>';
1.241 raeburn 6640: my @currinsttypes;
6641: $output .= '<td>'.&mt('User types:').'<br />'
6642: .&selfenroll_inst_types($num,$newdom,\@currinsttypes).'</td>'
6643: .&Apache::loncommon::end_data_table_row();
6644: }
6645: return $output;
6646: }
6647:
6648: sub selfenroll_inst_types {
1.406.2.6 raeburn 6649: my ($num,$currdom,$currinsttypes,$readonly) = @_;
1.241 raeburn 6650: my $output;
6651: my $numinrow = 4;
6652: my $count = 0;
6653: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($currdom);
1.247 raeburn 6654: my $othervalue = 'any';
1.406.2.6 raeburn 6655: my $disabled;
6656: if ($readonly) {
6657: $disabled = ' disabled="disabled"';
6658: }
1.241 raeburn 6659: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
1.251 raeburn 6660: if (keys(%{$usertypes}) > 0) {
1.247 raeburn 6661: $othervalue = 'other';
6662: }
1.241 raeburn 6663: $output .= '<table><tr>';
6664: foreach my $type (@{$types}) {
6665: if (($count > 0) && ($count%$numinrow == 0)) {
6666: $output .= '</tr><tr>';
6667: }
6668: if (defined($usertypes->{$type})) {
1.257 raeburn 6669: my $esc_type = &escape($type);
1.241 raeburn 6670: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.
1.257 raeburn 6671: $esc_type.'" ';
1.241 raeburn 6672: if (ref($currinsttypes) eq 'ARRAY') {
6673: if (@{$currinsttypes} > 0) {
1.249 raeburn 6674: if (grep(/^any$/,@{$currinsttypes})) {
6675: $output .= 'checked="checked"';
1.257 raeburn 6676: } elsif (grep(/^\Q$esc_type\E$/,@{$currinsttypes})) {
1.241 raeburn 6677: $output .= 'checked="checked"';
6678: }
1.249 raeburn 6679: } else {
6680: $output .= 'checked="checked"';
1.241 raeburn 6681: }
6682: }
1.406.2.6 raeburn 6683: $output .= ' name="selfenroll_types_'.$num.'"'.$disabled.' />'.$usertypes->{$type}.'</label></span></td>';
1.241 raeburn 6684: }
6685: $count ++;
6686: }
6687: if (($count > 0) && ($count%$numinrow == 0)) {
6688: $output .= '</tr><tr>';
6689: }
1.249 raeburn 6690: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.$othervalue.'"';
1.241 raeburn 6691: if (ref($currinsttypes) eq 'ARRAY') {
6692: if (@{$currinsttypes} > 0) {
1.249 raeburn 6693: if (grep(/^any$/,@{$currinsttypes})) {
6694: $output .= ' checked="checked"';
6695: } elsif ($othervalue eq 'other') {
6696: if (grep(/^\Q$othervalue\E$/,@{$currinsttypes})) {
6697: $output .= ' checked="checked"';
6698: }
1.241 raeburn 6699: }
1.249 raeburn 6700: } else {
6701: $output .= ' checked="checked"';
1.241 raeburn 6702: }
1.249 raeburn 6703: } else {
6704: $output .= ' checked="checked"';
1.241 raeburn 6705: }
1.406.2.6 raeburn 6706: $output .= ' name="selfenroll_types_'.$num.'"'.$disabled.' />'.$othertitle.'</label></span></td></tr></table>';
1.241 raeburn 6707: }
6708: return $output;
6709: }
6710:
1.237 raeburn 6711: sub selfenroll_date_forms {
6712: my ($startform,$endform) = @_;
6713: my $output .= &Apache::lonhtmlcommon::start_pick_box()."\n".
1.244 bisitz 6714: &Apache::lonhtmlcommon::row_title(&mt('Start date'),
1.237 raeburn 6715: 'LC_oddrow_value')."\n".
6716: $startform."\n".
6717: &Apache::lonhtmlcommon::row_closure(1).
1.244 bisitz 6718: &Apache::lonhtmlcommon::row_title(&mt('End date'),
1.237 raeburn 6719: 'LC_oddrow_value')."\n".
6720: $endform."\n".
6721: &Apache::lonhtmlcommon::row_closure(1).
6722: &Apache::lonhtmlcommon::end_pick_box();
6723: return $output;
6724: }
6725:
1.239 raeburn 6726: sub print_userchangelogs_display {
1.406.2.5 raeburn 6727: my ($r,$context,$permission,$brcrum) = @_;
1.363 raeburn 6728: my $formname = 'rolelog';
1.406.2.6 raeburn 6729: my ($username,$domain,$crstype,$viewablesec,%roleslog);
1.363 raeburn 6730: if ($context eq 'domain') {
6731: $domain = $env{'request.role.domain'};
6732: %roleslog=&Apache::lonnet::dump_dom('nohist_rolelog',$domain);
6733: } else {
6734: if ($context eq 'course') {
6735: $domain = $env{'course.'.$env{'request.course.id'}.'.domain'};
6736: $username = $env{'course.'.$env{'request.course.id'}.'.num'};
6737: $crstype = &Apache::loncommon::course_type();
1.406.2.6 raeburn 6738: $viewablesec = &Apache::lonuserutils::viewable_section($permission);
1.363 raeburn 6739: my %saveable_parameters = ('show' => 'scalar',);
6740: &Apache::loncommon::store_course_settings('roles_log',
6741: \%saveable_parameters);
6742: &Apache::loncommon::restore_course_settings('roles_log',
6743: \%saveable_parameters);
6744: } elsif ($context eq 'author') {
6745: $domain = $env{'user.domain'};
6746: if ($env{'request.role'} =~ m{^au\./\Q$domain\E/$}) {
6747: $username = $env{'user.name'};
6748: } else {
6749: undef($domain);
6750: }
6751: }
6752: if ($domain ne '' && $username ne '') {
6753: %roleslog=&Apache::lonnet::dump('nohist_rolelog',$domain,$username);
6754: }
6755: }
1.239 raeburn 6756: if ((keys(%roleslog))[0]=~/^error\:/) { undef(%roleslog); }
6757:
1.406.2.5 raeburn 6758: my $helpitem;
6759: if ($context eq 'course') {
6760: $helpitem = 'Course_User_Logs';
1.406.2.14 raeburn 6761: } elsif ($context eq 'domain') {
6762: $helpitem = 'Domain_Role_Logs';
6763: } elsif ($context eq 'author') {
6764: $helpitem = 'Author_User_Logs';
1.406.2.5 raeburn 6765: }
6766: push (@{$brcrum},
6767: {href => '/adm/createuser?action=changelogs',
6768: text => 'User Management Logs',
6769: help => $helpitem});
6770: my $bread_crumbs_component = 'User Changes';
6771: my $args = { bread_crumbs => $brcrum,
6772: bread_crumbs_component => $bread_crumbs_component};
6773:
6774: # Create navigation javascript
6775: my $jsnav = &userlogdisplay_js($formname);
6776:
6777: my $jscript = (<<ENDSCRIPT);
6778: <script type="text/javascript">
6779: // <![CDATA[
6780: $jsnav
6781: // ]]>
6782: </script>
6783: ENDSCRIPT
6784:
6785: # print page header
6786: $r->print(&header($jscript,$args));
6787:
1.239 raeburn 6788: # set defaults
6789: my $now = time();
6790: my $defstart = $now - (7*24*3600); #7 days ago
6791: my %defaults = (
6792: page => '1',
6793: show => '10',
6794: role => 'any',
6795: chgcontext => 'any',
6796: rolelog_start_date => $defstart,
6797: rolelog_end_date => $now,
6798: );
6799: my $more_records = 0;
6800:
6801: # set current
6802: my %curr;
6803: foreach my $item ('show','page','role','chgcontext') {
6804: $curr{$item} = $env{'form.'.$item};
6805: }
6806: my ($startdate,$enddate) =
6807: &Apache::lonuserutils::get_dates_from_form('rolelog_start_date','rolelog_end_date');
6808: $curr{'rolelog_start_date'} = $startdate;
6809: $curr{'rolelog_end_date'} = $enddate;
6810: foreach my $key (keys(%defaults)) {
6811: if ($curr{$key} eq '') {
6812: $curr{$key} = $defaults{$key};
6813: }
6814: }
1.248 raeburn 6815: my (%whodunit,%changed,$version);
6816: ($version) = ($r->dir_config('lonVersion') =~ /^([\d\.]+)\-/);
1.239 raeburn 6817: my ($minshown,$maxshown);
1.255 raeburn 6818: $minshown = 1;
1.239 raeburn 6819: my $count = 0;
1.406.2.5 raeburn 6820: if ($curr{'show'} =~ /\D/) {
6821: $curr{'page'} = 1;
6822: } else {
1.239 raeburn 6823: $maxshown = $curr{'page'} * $curr{'show'};
6824: if ($curr{'page'} > 1) {
6825: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
6826: }
6827: }
1.301 bisitz 6828:
1.327 raeburn 6829: # Form Header
6830: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
1.363 raeburn 6831: &role_display_filter($context,$formname,$domain,$username,\%curr,
6832: $version,$crstype));
1.327 raeburn 6833:
6834: my $showntableheader = 0;
6835:
6836: # Table Header
6837: my $tableheader =
6838: &Apache::loncommon::start_data_table_header_row()
6839: .'<th> </th>'
6840: .'<th>'.&mt('When').'</th>'
6841: .'<th>'.&mt('Who made the change').'</th>'
6842: .'<th>'.&mt('Changed User').'</th>'
1.363 raeburn 6843: .'<th>'.&mt('Role').'</th>';
6844:
6845: if ($context eq 'course') {
6846: $tableheader .= '<th>'.&mt('Section').'</th>';
6847: }
6848: $tableheader .=
6849: '<th>'.&mt('Context').'</th>'
1.327 raeburn 6850: .'<th>'.&mt('Start').'</th>'
6851: .'<th>'.&mt('End').'</th>'
6852: .&Apache::loncommon::end_data_table_header_row();
6853:
6854: # Display user change log data
1.239 raeburn 6855: foreach my $id (sort { $roleslog{$b}{'exe_time'}<=>$roleslog{$a}{'exe_time'} } (keys(%roleslog))) {
6856: next if (($roleslog{$id}{'exe_time'} < $curr{'rolelog_start_date'}) ||
6857: ($roleslog{$id}{'exe_time'} > $curr{'rolelog_end_date'}));
1.406.2.5 raeburn 6858: if ($curr{'show'} !~ /\D/) {
1.239 raeburn 6859: if ($count >= $curr{'page'} * $curr{'show'}) {
6860: $more_records = 1;
6861: last;
6862: }
6863: }
6864: if ($curr{'role'} ne 'any') {
6865: next if ($roleslog{$id}{'logentry'}{'role'} ne $curr{'role'});
6866: }
6867: if ($curr{'chgcontext'} ne 'any') {
6868: if ($curr{'chgcontext'} eq 'selfenroll') {
6869: next if (!$roleslog{$id}{'logentry'}{'selfenroll'});
6870: } else {
6871: next if ($roleslog{$id}{'logentry'}{'context'} ne $curr{'chgcontext'});
6872: }
6873: }
1.406.2.6 raeburn 6874: if (($context eq 'course') && ($viewablesec ne '')) {
6875: next if ($roleslog{$id}{'logentry'}{'section'} ne $viewablesec);
6876: }
1.239 raeburn 6877: $count ++;
6878: next if ($count < $minshown);
1.327 raeburn 6879: unless ($showntableheader) {
1.406.2.5 raeburn 6880: $r->print(&Apache::loncommon::start_data_table()
1.327 raeburn 6881: .$tableheader);
6882: $r->rflush();
6883: $showntableheader = 1;
6884: }
1.239 raeburn 6885: if ($whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} eq '') {
6886: $whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} =
6887: &Apache::loncommon::plainname($roleslog{$id}{'exe_uname'},$roleslog{$id}{'exe_udom'});
6888: }
6889: if ($changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} eq '') {
6890: $changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} =
6891: &Apache::loncommon::plainname($roleslog{$id}{'uname'},$roleslog{$id}{'udom'});
6892: }
6893: my $sec = $roleslog{$id}{'logentry'}{'section'};
6894: if ($sec eq '') {
6895: $sec = &mt('None');
6896: }
6897: my ($rolestart,$roleend);
6898: if ($roleslog{$id}{'delflag'}) {
6899: $rolestart = &mt('deleted');
6900: $roleend = &mt('deleted');
6901: } else {
6902: $rolestart = $roleslog{$id}{'logentry'}{'start'};
6903: $roleend = $roleslog{$id}{'logentry'}{'end'};
6904: if ($rolestart eq '' || $rolestart == 0) {
6905: $rolestart = &mt('No start date');
6906: } else {
6907: $rolestart = &Apache::lonlocal::locallocaltime($rolestart);
6908: }
6909: if ($roleend eq '' || $roleend == 0) {
6910: $roleend = &mt('No end date');
6911: } else {
6912: $roleend = &Apache::lonlocal::locallocaltime($roleend);
6913: }
6914: }
6915: my $chgcontext = $roleslog{$id}{'logentry'}{'context'};
6916: if ($roleslog{$id}{'logentry'}{'selfenroll'}) {
6917: $chgcontext = 'selfenroll';
6918: }
1.363 raeburn 6919: my %lt = &rolechg_contexts($context,$crstype);
1.239 raeburn 6920: if ($chgcontext ne '' && $lt{$chgcontext} ne '') {
6921: $chgcontext = $lt{$chgcontext};
6922: }
1.327 raeburn 6923: $r->print(
1.301 bisitz 6924: &Apache::loncommon::start_data_table_row()
6925: .'<td>'.$count.'</td>'
6926: .'<td>'.&Apache::lonlocal::locallocaltime($roleslog{$id}{'exe_time'}).'</td>'
6927: .'<td>'.$whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}}.'</td>'
6928: .'<td>'.$changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}}.'</td>'
1.363 raeburn 6929: .'<td>'.&Apache::lonnet::plaintext($roleslog{$id}{'logentry'}{'role'},$crstype).'</td>');
6930: if ($context eq 'course') {
6931: $r->print('<td>'.$sec.'</td>');
6932: }
6933: $r->print(
6934: '<td>'.$chgcontext.'</td>'
1.301 bisitz 6935: .'<td>'.$rolestart.'</td>'
6936: .'<td>'.$roleend.'</td>'
1.327 raeburn 6937: .&Apache::loncommon::end_data_table_row()."\n");
1.301 bisitz 6938: }
6939:
1.327 raeburn 6940: if ($showntableheader) { # Table footer, if content displayed above
1.406.2.5 raeburn 6941: $r->print(&Apache::loncommon::end_data_table().
6942: &userlogdisplay_navlinks(\%curr,$more_records));
1.327 raeburn 6943: } else { # No content displayed above
1.301 bisitz 6944: $r->print('<p class="LC_info">'
6945: .&mt('There are no records to display.')
6946: .'</p>'
6947: );
1.239 raeburn 6948: }
1.301 bisitz 6949:
1.327 raeburn 6950: # Form Footer
6951: $r->print(
6952: '<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
6953: .'<input type="hidden" name="action" value="changelogs" />'
6954: .'</form>');
6955: return;
6956: }
1.301 bisitz 6957:
1.406.2.5 raeburn 6958: sub print_useraccesslogs_display {
6959: my ($r,$uname,$udom,$permission,$brcrum) = @_;
6960: my $formname = 'accesslog';
6961: my $form = 'document.accesslog';
6962:
6963: # set breadcrumbs
1.406.2.7 raeburn 6964: my %breadcrumb_text = &singleuser_breadcrumb('','domain',$udom);
1.406.2.12 raeburn 6965: my $prevphasestr;
6966: if ($env{'form.popup'}) {
6967: $brcrum = [];
6968: } else {
6969: push (@{$brcrum},
6970: {href => "javascript:backPage($form)",
6971: text => $breadcrumb_text{'search'}});
6972: my @prevphases;
6973: if ($env{'form.prevphases'}) {
6974: @prevphases = split(/,/,$env{'form.prevphases'});
6975: $prevphasestr = $env{'form.prevphases'};
6976: }
6977: if (($env{'form.phase'} eq 'userpicked') || (grep(/^userpicked$/,@prevphases))) {
6978: push(@{$brcrum},
6979: {href => "javascript:backPage($form,'get_user_info','select')",
6980: text => $breadcrumb_text{'userpicked'}});
6981: if ($env{'form.phase'} eq 'userpicked') {
6982: $prevphasestr = 'userpicked';
6983: }
1.406.2.5 raeburn 6984: }
6985: }
6986: push(@{$brcrum},
6987: {href => '/adm/createuser?action=accesslogs',
6988: text => 'User access logs',
1.406.2.8 raeburn 6989: help => 'Domain_User_Access_Logs'});
1.406.2.5 raeburn 6990: my $bread_crumbs_component = 'User Access Logs';
6991: my $args = { bread_crumbs => $brcrum,
6992: bread_crumbs_component => 'User Management'};
1.406.2.8 raeburn 6993: if ($env{'form.popup'}) {
6994: $args->{'no_nav_bar'} = 1;
1.406.2.12 raeburn 6995: $args->{'bread_crumbs_nomenu'} = 1;
1.406.2.8 raeburn 6996: }
1.406.2.5 raeburn 6997:
6998: # set javascript
6999: my ($jsback,$elements) = &crumb_utilities();
7000: my $jsnav = &userlogdisplay_js($formname);
7001:
7002: my $jscript = (<<ENDSCRIPT);
1.239 raeburn 7003: <script type="text/javascript">
1.301 bisitz 7004: // <![CDATA[
1.406.2.5 raeburn 7005:
7006: $jsback
7007: $jsnav
7008:
7009: // ]]>
7010: </script>
7011:
7012: ENDSCRIPT
7013:
7014: # print page header
7015: $r->print(&header($jscript,$args));
7016:
7017: # early out unless log data can be displayed.
7018: unless ($permission->{'activity'}) {
7019: $r->print('<p class="LC_warning">'
7020: .&mt('You do not have rights to display user access logs.')
1.406.2.12 raeburn 7021: .'</p>');
7022: if ($env{'form.popup'}) {
7023: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
7024: } else {
7025: $r->print(&earlyout_accesslog_form($formname,$prevphasestr,$udom));
7026: }
1.406.2.5 raeburn 7027: return;
7028: }
7029:
7030: unless ($udom eq $env{'request.role.domain'}) {
7031: $r->print('<p class="LC_warning">'
7032: .&mt("User's domain must match role's domain")
7033: .'</p>'
7034: .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
7035: return;
7036: }
7037:
7038: if (($uname eq '') || ($udom eq '')) {
7039: $r->print('<p class="LC_warning">'
7040: .&mt('Invalid username or domain')
7041: .'</p>'
7042: .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
7043: return;
7044: }
7045:
1.406.2.13 raeburn 7046: if (&Apache::lonnet::privileged($uname,$udom,
7047: [$env{'request.role.domain'}],['dc','su'])) {
7048: unless (&Apache::lonnet::privileged($env{'user.name'},$env{'user.domain'},
7049: [$env{'request.role.domain'}],['dc','su'])) {
7050: $r->print('<p class="LC_warning">'
7051: .&mt('You need to be a privileged user to display user access logs for [_1]',
7052: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),
7053: $uname,$udom))
7054: .'</p>');
7055: if ($env{'form.popup'}) {
7056: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
7057: } else {
7058: $r->print(&earlyout_accesslog_form($formname,$prevphasestr,$udom));
7059: }
7060: return;
7061: }
7062: }
7063:
1.406.2.5 raeburn 7064: # set defaults
7065: my $now = time();
7066: my $defstart = $now - (7*24*3600);
7067: my %defaults = (
7068: page => '1',
7069: show => '10',
7070: activity => 'any',
7071: accesslog_start_date => $defstart,
7072: accesslog_end_date => $now,
7073: );
7074: my $more_records = 0;
7075:
7076: # set current
7077: my %curr;
7078: foreach my $item ('show','page','activity') {
7079: $curr{$item} = $env{'form.'.$item};
7080: }
7081: my ($startdate,$enddate) =
7082: &Apache::lonuserutils::get_dates_from_form('accesslog_start_date','accesslog_end_date');
7083: $curr{'accesslog_start_date'} = $startdate;
7084: $curr{'accesslog_end_date'} = $enddate;
7085: foreach my $key (keys(%defaults)) {
7086: if ($curr{$key} eq '') {
7087: $curr{$key} = $defaults{$key};
7088: }
7089: }
7090: my ($minshown,$maxshown);
7091: $minshown = 1;
7092: my $count = 0;
7093: if ($curr{'show'} =~ /\D/) {
7094: $curr{'page'} = 1;
7095: } else {
7096: $maxshown = $curr{'page'} * $curr{'show'};
7097: if ($curr{'page'} > 1) {
7098: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
7099: }
7100: }
7101:
7102: # form header
7103: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
7104: &activity_display_filter($formname,\%curr));
7105:
7106: my $showntableheader = 0;
7107: my ($nav_script,$nav_links);
7108:
7109: # table header
1.406.2.18 raeburn 7110: my $heading = '<h3>'.
1.406.2.12 raeburn 7111: &mt('User access logs for: [_1]',
1.406.2.18 raeburn 7112: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom)).'</h3>';
7113: my $tableheader = $heading
1.406.2.12 raeburn 7114: .&Apache::loncommon::start_data_table_header_row()
1.406.2.5 raeburn 7115: .'<th> </th>'
7116: .'<th>'.&mt('When').'</th>'
7117: .'<th>'.&mt('HostID').'</th>'
7118: .'<th>'.&mt('Event').'</th>'
7119: .'<th>'.&mt('Other data').'</th>'
7120: .&Apache::loncommon::end_data_table_header_row();
7121:
7122: my %filters=(
7123: start => $curr{'accesslog_start_date'},
7124: end => $curr{'accesslog_end_date'},
7125: action => $curr{'activity'},
7126: );
7127:
7128: my $reply = &Apache::lonnet::userlog_query($uname,$udom,%filters);
7129: unless ( ($reply =~/^timeout/) || ($reply =~/^error/) ) {
7130: my (%courses,%missing);
7131: my @results = split(/\&/,$reply);
7132: foreach my $item (reverse(@results)) {
7133: my ($timestamp,$host,$event) = split(/:/,$item);
7134: next unless ($event =~ /^(Log|Role)/);
7135: if ($curr{'show'} !~ /\D/) {
7136: if ($count >= $curr{'page'} * $curr{'show'}) {
7137: $more_records = 1;
7138: last;
7139: }
7140: }
7141: $count ++;
7142: next if ($count < $minshown);
7143: unless ($showntableheader) {
7144: $r->print($nav_script
7145: .&Apache::loncommon::start_data_table()
7146: .$tableheader);
7147: $r->rflush();
7148: $showntableheader = 1;
7149: }
1.406.2.6 raeburn 7150: my ($shown,$extra);
1.406.2.13 raeburn 7151: my ($event,$data) = split(/\s+/,&unescape($event),2);
1.406.2.5 raeburn 7152: if ($event eq 'Role') {
7153: my ($rolecode,$extent) = split(/\./,$data,2);
7154: next if ($extent eq '');
7155: my ($crstype,$desc,$info);
1.406.2.6 raeburn 7156: if ($extent =~ m{^/($match_domain)/($match_courseid)(?:/(\w+)|)$}) {
7157: my ($cdom,$cnum,$sec) = ($1,$2,$3);
1.406.2.5 raeburn 7158: my $cid = $cdom.'_'.$cnum;
7159: if (exists($courses{$cid})) {
7160: $crstype = $courses{$cid}{'type'};
7161: $desc = $courses{$cid}{'description'};
7162: } elsif ($missing{$cid}) {
7163: $crstype = 'Course';
7164: $desc = 'Course/Community';
7165: } else {
7166: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',$cnum,undef,undef,'.');
7167: if (ref($crsinfo{$cdom.'_'.$cnum}) eq 'HASH') {
7168: $courses{$cid} = $crsinfo{$cid};
7169: $crstype = $crsinfo{$cid}{'type'};
7170: $desc = $crsinfo{$cid}{'description'};
7171: } else {
7172: $missing{$cid} = 1;
7173: }
7174: }
7175: $extra = &mt($crstype).': <a href="/public/'.$cdom.'/'.$cnum.'/syllabus">'.$desc.'</a>';
1.406.2.6 raeburn 7176: if ($sec ne '') {
7177: $extra .= ' ('.&mt('Section: [_1]',$sec).')';
7178: }
1.406.2.5 raeburn 7179: } elsif ($extent =~ m{^/($match_domain)/($match_username|$)}) {
7180: my ($dom,$name) = ($1,$2);
7181: if ($rolecode eq 'au') {
7182: $extra = '';
7183: } elsif ($rolecode =~ /^(ca|aa)$/) {
7184: $extra = &mt('Authoring Space: [_1]',$name.':'.$dom);
7185: } elsif ($rolecode =~ /^(li|dg|dh|dc|sc)$/) {
7186: $extra = &mt('Domain: [_1]',$dom);
7187: }
7188: }
7189: my $rolename;
7190: if ($rolecode =~ m{^cr/($match_domain)/($match_username)/(\w+)}) {
7191: my $role = $3;
7192: my $owner = "($2:$1)";
7193: if ($2 eq $1.'-domainconfig') {
7194: $owner = '(ad hoc)';
7195: }
7196: $rolename = &mt('Custom role: [_1]',$role.' '.$owner);
7197: } else {
7198: $rolename = &Apache::lonnet::plaintext($rolecode,$crstype);
7199: }
7200: $shown = &mt('Role selection: [_1]',$rolename);
7201: } else {
7202: $shown = &mt($event);
1.406.2.13 raeburn 7203: if ($data =~ /^webdav/) {
7204: my ($path,$clientip) = split(/\s+/,$data,2);
7205: $path =~ s/^webdav//;
7206: if ($clientip ne '') {
7207: $extra = &mt('Client IP address: [_1]',$clientip);
7208: }
7209: if ($path ne '') {
7210: $shown .= ' '.&mt('(WebDAV access to [_1])',$path);
7211: }
7212: } elsif ($data ne '') {
7213: $extra = &mt('Client IP address: [_1]',$data);
1.406.2.5 raeburn 7214: }
7215: }
7216: $r->print(
7217: &Apache::loncommon::start_data_table_row()
7218: .'<td>'.$count.'</td>'
7219: .'<td>'.&Apache::lonlocal::locallocaltime($timestamp).'</td>'
7220: .'<td>'.$host.'</td>'
7221: .'<td>'.$shown.'</td>'
7222: .'<td>'.$extra.'</td>'
7223: .&Apache::loncommon::end_data_table_row()."\n");
7224: }
7225: }
7226:
7227: if ($showntableheader) { # Table footer, if content displayed above
7228: $r->print(&Apache::loncommon::end_data_table().
7229: &userlogdisplay_navlinks(\%curr,$more_records));
7230: } else { # No content displayed above
1.406.2.18 raeburn 7231: $r->print($heading.'<p class="LC_info">'
1.406.2.5 raeburn 7232: .&mt('There are no records to display.')
7233: .'</p>');
7234: }
7235:
1.406.2.8 raeburn 7236: if ($env{'form.popup'} == 1) {
7237: $r->print('<input type="hidden" name="popup" value="1" />'."\n");
7238: }
7239:
1.406.2.5 raeburn 7240: # Form Footer
7241: $r->print(
7242: '<input type="hidden" name="currstate" value="" />'
7243: .'<input type="hidden" name="accessuname" value="'.$uname.'" />'
7244: .'<input type="hidden" name="accessudom" value="'.$udom.'" />'
7245: .'<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
7246: .'<input type="hidden" name="prevphases" value="'.$prevphasestr.'" />'
7247: .'<input type="hidden" name="phase" value="activity" />'
7248: .'<input type="hidden" name="action" value="accesslogs" />'
7249: .'<input type="hidden" name="srchdomain" value="'.$udom.'" />'
7250: .'<input type="hidden" name="srchby" value="'.$env{'form.srchby'}.'" />'
7251: .'<input type="hidden" name="srchtype" value="'.$env{'form.srchtype'}.'" />'
7252: .'<input type="hidden" name="srchterm" value="'.&HTML::Entities::encode($env{'form.srchterm'},'<>"&').'" />'
7253: .'<input type="hidden" name="srchin" value="'.$env{'form.srchin'}.'" />'
7254: .'</form>');
7255: return;
7256: }
7257:
7258: sub earlyout_accesslog_form {
7259: my ($formname,$prevphasestr,$udom) = @_;
7260: my $srchterm = &HTML::Entities::encode($env{'form.srchterm'},'<>"&');
7261: return <<"END";
7262: <form action="/adm/createuser" method="post" name="$formname">
7263: <input type="hidden" name="currstate" value="" />
7264: <input type="hidden" name="prevphases" value="$prevphasestr" />
7265: <input type="hidden" name="phase" value="activity" />
7266: <input type="hidden" name="action" value="accesslogs" />
7267: <input type="hidden" name="srchdomain" value="$udom" />
7268: <input type="hidden" name="srchby" value="$env{'form.srchby'}" />
7269: <input type="hidden" name="srchtype" value="$env{'form.srchtype'}" />
7270: <input type="hidden" name="srchterm" value="$srchterm" />
7271: <input type="hidden" name="srchin" value="$env{'form.srchin'}" />
7272: </form>
7273: END
7274: }
7275:
7276: sub activity_display_filter {
7277: my ($formname,$curr) = @_;
7278: my $nolink = 1;
7279: my $output = '<table><tr><td valign="top">'.
7280: '<span class="LC_nobreak"><b>'.&mt('Actions/page:').'</b></span><br />'.
7281: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
7282: (&mt('all'),5,10,20,50,100,1000,10000)).
7283: '</td><td> </td>';
7284: my $startform =
7285: &Apache::lonhtmlcommon::date_setter($formname,'accesslog_start_date',
7286: $curr->{'accesslog_start_date'},undef,
7287: undef,undef,undef,undef,undef,undef,$nolink);
7288: my $endform =
7289: &Apache::lonhtmlcommon::date_setter($formname,'accesslog_end_date',
7290: $curr->{'accesslog_end_date'},undef,
7291: undef,undef,undef,undef,undef,undef,$nolink);
7292: my %lt = &Apache::lonlocal::texthash (
7293: activity => 'Activity',
7294: Role => 'Role selection',
7295: log => 'Log-in or Logout',
7296: );
7297: $output .= '<td valign="top"><b>'.&mt('Window during which actions occurred:').'</b><br />'.
7298: '<table><tr><td>'.&mt('After:').
7299: '</td><td>'.$startform.'</td></tr>'.
7300: '<tr><td>'.&mt('Before:').'</td>'.
7301: '<td>'.$endform.'</td></tr></table>'.
7302: '</td>'.
7303: '<td> </td>'.
7304: '<td valign="top"><b>'.&mt('Activities').'</b><br />'.
7305: '<select name="activity"><option value="any"';
7306: if ($curr->{'activity'} eq 'any') {
7307: $output .= ' selected="selected"';
7308: }
7309: $output .= '>'.&mt('Any').'</option>'."\n";
7310: foreach my $activity ('Role','log') {
7311: my $selstr = '';
7312: if ($activity eq $curr->{'activity'}) {
7313: $selstr = ' selected="selected"';
7314: }
7315: $output .= '<option value="'.$activity.'"'.$selstr.'>'.$lt{$activity}.'</option>';
7316: }
7317: $output .= '</select></td>'.
7318: '</tr></table>';
7319: # Update Display button
7320: $output .= '<p>'
7321: .'<input type="submit" value="'.&mt('Update Display').'" />'
1.406.2.12 raeburn 7322: .'</p><hr />';
1.406.2.5 raeburn 7323: return $output;
7324: }
7325:
7326: sub userlogdisplay_js {
7327: my ($formname) = @_;
7328: return <<"ENDSCRIPT";
7329:
1.239 raeburn 7330: function chgPage(caller) {
7331: if (caller == 'previous') {
7332: document.$formname.page.value --;
7333: }
7334: if (caller == 'next') {
7335: document.$formname.page.value ++;
7336: }
1.327 raeburn 7337: document.$formname.submit();
1.239 raeburn 7338: return;
7339: }
7340: ENDSCRIPT
1.406.2.5 raeburn 7341: }
7342:
7343: sub userlogdisplay_navlinks {
7344: my ($curr,$more_records) = @_;
7345: return unless(ref($curr) eq 'HASH');
7346: # Navigation Buttons
7347: my $nav_links = '<p>';
7348: if (($curr->{'page'} > 1) || ($more_records)) {
7349: if (($curr->{'page'} > 1) && ($curr->{'show'} !~ /\D/)) {
7350: $nav_links .= '<input type="button"'
7351: .' onclick="javascript:chgPage('."'previous'".');"'
7352: .' value="'.&mt('Previous [_1] changes',$curr->{'show'})
7353: .'" /> ';
7354: }
7355: if ($more_records) {
7356: $nav_links .= '<input type="button"'
7357: .' onclick="javascript:chgPage('."'next'".');"'
7358: .' value="'.&mt('Next [_1] changes',$curr->{'show'})
7359: .'" />';
1.301 bisitz 7360: }
7361: }
1.406.2.5 raeburn 7362: $nav_links .= '</p>';
7363: return $nav_links;
1.239 raeburn 7364: }
7365:
7366: sub role_display_filter {
1.363 raeburn 7367: my ($context,$formname,$cdom,$cnum,$curr,$version,$crstype) = @_;
7368: my $lctype;
7369: if ($context eq 'course') {
7370: $lctype = lc($crstype);
7371: }
1.239 raeburn 7372: my $nolink = 1;
7373: my $output = '<table><tr><td valign="top">'.
1.301 bisitz 7374: '<span class="LC_nobreak"><b>'.&mt('Changes/page:').'</b></span><br />'.
1.239 raeburn 7375: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
7376: (&mt('all'),5,10,20,50,100,1000,10000)).
7377: '</td><td> </td>';
7378: my $startform =
7379: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_start_date',
7380: $curr->{'rolelog_start_date'},undef,
7381: undef,undef,undef,undef,undef,undef,$nolink);
7382: my $endform =
7383: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_end_date',
7384: $curr->{'rolelog_end_date'},undef,
7385: undef,undef,undef,undef,undef,undef,$nolink);
1.363 raeburn 7386: my %lt = &rolechg_contexts($context,$crstype);
1.301 bisitz 7387: $output .= '<td valign="top"><b>'.&mt('Window during which changes occurred:').'</b><br />'.
7388: '<table><tr><td>'.&mt('After:').
7389: '</td><td>'.$startform.'</td></tr>'.
7390: '<tr><td>'.&mt('Before:').'</td>'.
7391: '<td>'.$endform.'</td></tr></table>'.
7392: '</td>'.
7393: '<td> </td>'.
1.239 raeburn 7394: '<td valign="top"><b>'.&mt('Role:').'</b><br />'.
7395: '<select name="role"><option value="any"';
7396: if ($curr->{'role'} eq 'any') {
7397: $output .= ' selected="selected"';
7398: }
7399: $output .= '>'.&mt('Any').'</option>'."\n";
1.363 raeburn 7400: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
1.239 raeburn 7401: foreach my $role (@roles) {
7402: my $plrole;
7403: if ($role eq 'cr') {
7404: $plrole = &mt('Custom Role');
7405: } else {
1.318 raeburn 7406: $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.239 raeburn 7407: }
7408: my $selstr = '';
7409: if ($role eq $curr->{'role'}) {
7410: $selstr = ' selected="selected"';
7411: }
7412: $output .= ' <option value="'.$role.'"'.$selstr.'>'.$plrole.'</option>';
7413: }
1.301 bisitz 7414: $output .= '</select></td>'.
7415: '<td> </td>'.
7416: '<td valign="top"><b>'.
1.239 raeburn 7417: &mt('Context:').'</b><br /><select name="chgcontext">';
1.363 raeburn 7418: my @posscontexts;
7419: if ($context eq 'course') {
1.406.2.20 raeburn 7420: @posscontexts = ('any','automated','updatenow','createcourse','course','domain','selfenroll','requestcourses','chgtype');
1.363 raeburn 7421: } elsif ($context eq 'domain') {
7422: @posscontexts = ('any','domain','requestauthor','domconfig','server');
7423: } else {
7424: @posscontexts = ('any','author','domain');
1.406.2.20 raeburn 7425: }
1.363 raeburn 7426: foreach my $chgtype (@posscontexts) {
1.239 raeburn 7427: my $selstr = '';
7428: if ($curr->{'chgcontext'} eq $chgtype) {
1.301 bisitz 7429: $selstr = ' selected="selected"';
1.239 raeburn 7430: }
1.363 raeburn 7431: if ($context eq 'course') {
1.376 raeburn 7432: if (($chgtype eq 'automated') || ($chgtype eq 'updatenow')) {
1.363 raeburn 7433: next if (!&Apache::lonnet::auto_run($cnum,$cdom));
7434: }
1.239 raeburn 7435: }
7436: $output .= '<option value="'.$chgtype.'"'.$selstr.'>'.$lt{$chgtype}.'</option>'."\n";
1.248 raeburn 7437: }
1.303 bisitz 7438: $output .= '</select></td>'
7439: .'</tr></table>';
7440:
7441: # Update Display button
7442: $output .= '<p>'
7443: .'<input type="submit" value="'.&mt('Update Display').'" />'
7444: .'</p>';
7445:
7446: # Server version info
1.363 raeburn 7447: my $needsrev = '2.11.0';
7448: if ($context eq 'course') {
7449: $needsrev = '2.7.0';
7450: }
7451:
1.303 bisitz 7452: $output .= '<p class="LC_info">'
7453: .&mt('Only changes made from servers running LON-CAPA [_1] or later are displayed.'
1.363 raeburn 7454: ,$needsrev);
1.248 raeburn 7455: if ($version) {
1.303 bisitz 7456: $output .= ' '.&mt('This LON-CAPA server is version [_1]',$version);
7457: }
7458: $output .= '</p><hr />';
1.239 raeburn 7459: return $output;
7460: }
7461:
7462: sub rolechg_contexts {
1.363 raeburn 7463: my ($context,$crstype) = @_;
7464: my %lt;
7465: if ($context eq 'course') {
7466: %lt = &Apache::lonlocal::texthash (
1.239 raeburn 7467: any => 'Any',
1.376 raeburn 7468: automated => 'Automated Enrollment',
1.406.2.20 raeburn 7469: chgtype => 'Enrollment Type/Lock Change',
1.239 raeburn 7470: updatenow => 'Roster Update',
7471: createcourse => 'Course Creation',
7472: course => 'User Management in course',
7473: domain => 'User Management in domain',
1.313 raeburn 7474: selfenroll => 'Self-enrolled',
1.318 raeburn 7475: requestcourses => 'Course Request',
1.239 raeburn 7476: );
1.363 raeburn 7477: if ($crstype eq 'Community') {
7478: $lt{'createcourse'} = &mt('Community Creation');
7479: $lt{'course'} = &mt('User Management in community');
7480: $lt{'requestcourses'} = &mt('Community Request');
7481: }
7482: } elsif ($context eq 'domain') {
7483: %lt = &Apache::lonlocal::texthash (
7484: any => 'Any',
7485: domain => 'User Management in domain',
7486: requestauthor => 'Authoring Request',
7487: server => 'Command line script (DC role)',
7488: domconfig => 'Self-enrolled',
7489: );
7490: } else {
7491: %lt = &Apache::lonlocal::texthash (
7492: any => 'Any',
7493: domain => 'User Management in domain',
7494: author => 'User Management by author',
7495: );
7496: }
1.239 raeburn 7497: return %lt;
7498: }
7499:
1.406.2.10 raeburn 7500: sub print_helpdeskaccess_display {
7501: my ($r,$permission,$brcrum) = @_;
7502: my $formname = 'helpdeskaccess';
7503: my $helpitem = 'Course_Helpdesk_Access';
7504: push (@{$brcrum},
7505: {href => '/adm/createuser?action=helpdesk',
7506: text => 'Helpdesk Access',
7507: help => $helpitem});
7508: my $bread_crumbs_component = 'Helpdesk Staff Access';
7509: my $args = { bread_crumbs => $brcrum,
7510: bread_crumbs_component => $bread_crumbs_component};
7511:
7512: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
7513: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
7514: my $confname = $cdom.'-domainconfig';
7515: my $crstype = &Apache::loncommon::course_type();
7516:
1.406.2.12 raeburn 7517: my @accesstypes = ('all','dh','da','none');
1.406.2.10 raeburn 7518: my ($numstatustypes,@jsarray);
7519: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($cdom);
7520: if (ref($types) eq 'ARRAY') {
7521: if (@{$types} > 0) {
7522: $numstatustypes = scalar(@{$types});
7523: push(@accesstypes,'status');
7524: @jsarray = ('bystatus');
7525: }
7526: }
7527: my %customroles = &get_domain_customroles($cdom,$confname);
1.406.2.12 raeburn 7528: my %domhelpdesk = &Apache::lonnet::get_active_domroles($cdom,['dh','da']);
1.406.2.10 raeburn 7529: if (keys(%domhelpdesk)) {
7530: push(@accesstypes,('inc','exc'));
7531: push(@jsarray,('notinc','notexc'));
7532: }
7533: push(@jsarray,'privs');
7534: my $hiddenstr = join("','",@jsarray);
7535: my $rolestr = join("','",sort(keys(%customroles)));
7536:
7537: my $jscript;
7538: my (%settings,%overridden);
7539: if (keys(%customroles)) {
7540: &get_adhocrole_settings($env{'request.course.id'},\@accesstypes,
7541: $types,\%customroles,\%settings,\%overridden);
7542: my %jsfull=();
7543: my %jslevels= (
7544: course => {},
7545: domain => {},
7546: system => {},
7547: );
7548: my %jslevelscurrent=(
7549: course => {},
7550: domain => {},
7551: system => {},
7552: );
7553: my (%privs,%jsprivs);
7554: &Apache::lonuserutils::custom_role_privs(\%privs,\%jsfull,\%jslevels,\%jslevelscurrent);
7555: foreach my $priv (keys(%jsfull)) {
7556: if ($jslevels{'course'}{$priv}) {
7557: $jsprivs{$priv} = 1;
7558: }
7559: }
7560: my (%elements,%stored);
7561: foreach my $role (keys(%customroles)) {
7562: $elements{$role.'_access'} = 'radio';
7563: $elements{$role.'_incrs'} = 'radio';
7564: if ($numstatustypes) {
7565: $elements{$role.'_status'} = 'checkbox';
7566: }
7567: if (keys(%domhelpdesk) > 0) {
7568: $elements{$role.'_staff_inc'} = 'checkbox';
7569: $elements{$role.'_staff_exc'} = 'checkbox';
7570: }
7571: $elements{$role.'_override'} = 'checkbox';
7572: if (ref($settings{$role}) eq 'HASH') {
7573: if ($settings{$role}{'access'} ne '') {
7574: my $curraccess = $settings{$role}{'access'};
7575: $stored{$role.'_access'} = $curraccess;
7576: $stored{$role.'_incrs'} = 1;
7577: if ($curraccess eq 'status') {
7578: if (ref($settings{$role}{'status'}) eq 'ARRAY') {
7579: $stored{$role.'_status'} = $settings{$role}{'status'};
7580: }
7581: } elsif (($curraccess eq 'exc') || ($curraccess eq 'inc')) {
7582: if (ref($settings{$role}{$curraccess}) eq 'ARRAY') {
7583: $stored{$role.'_staff_'.$curraccess} = $settings{$role}{$curraccess};
7584: }
7585: }
7586: } else {
7587: $stored{$role.'_incrs'} = 0;
7588: }
7589: $stored{$role.'_override'} = [];
7590: if ($env{'course.'.$env{'request.course.id'}.'.internal.adhocpriv.'.$role}) {
7591: if (ref($settings{$role}{'off'}) eq 'ARRAY') {
7592: foreach my $priv (@{$settings{$role}{'off'}}) {
7593: push(@{$stored{$role.'_override'}},$priv);
7594: }
7595: }
7596: if (ref($settings{$role}{'on'}) eq 'ARRAY') {
7597: foreach my $priv (@{$settings{$role}{'on'}}) {
7598: unless (grep(/^$priv$/,@{$stored{$role.'_override'}})) {
7599: push(@{$stored{$role.'_override'}},$priv);
7600: }
7601: }
7602: }
7603: }
7604: } else {
7605: $stored{$role.'_incrs'} = 0;
7606: }
7607: }
7608: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements,\%stored);
7609: }
7610:
7611: my $js = <<"ENDJS";
7612: <script type="text/javascript">
7613: // <![CDATA[
7614: $jscript;
7615:
7616: function switchRoleTab(caller,role) {
7617: if (document.getElementById(role+'_maindiv')) {
7618: if (caller.id != 'LC_current_minitab') {
7619: if (document.getElementById('LC_current_minitab')) {
7620: document.getElementById('LC_current_minitab').id=null;
7621: }
7622: var roledivs = Array('$rolestr');
7623: if (roledivs.length > 0) {
7624: for (var i=0; i<roledivs.length; i++) {
7625: if (document.getElementById(roledivs[i]+'_maindiv')) {
7626: document.getElementById(roledivs[i]+'_maindiv').style.display='none';
7627: }
7628: }
7629: }
7630: caller.id = 'LC_current_minitab';
7631: document.getElementById(role+'_maindiv').style.display='block';
7632: }
7633: }
7634: return false;
7635: }
7636:
7637: function helpdeskAccess(role) {
7638: var curraccess = null;
7639: if (document.$formname.elements[role+'_access'].length) {
7640: for (var i=0; i<document.$formname.elements[role+'_access'].length; i++) {
7641: if (document.$formname.elements[role+'_access'][i].checked) {
7642: curraccess = document.$formname.elements[role+'_access'][i].value;
7643: }
7644: }
7645: }
7646: var shown = Array();
7647: var hidden = Array();
7648: if (curraccess == 'none') {
7649: hidden = Array ('$hiddenstr');
7650: } else {
7651: if (curraccess == 'status') {
7652: shown = Array ('bystatus','privs');
7653: hidden = Array ('notinc','notexc');
7654: } else {
7655: if (curraccess == 'exc') {
7656: shown = Array ('notexc','privs');
7657: hidden = Array ('notinc','bystatus');
7658: }
7659: if (curraccess == 'inc') {
7660: shown = Array ('notinc','privs');
7661: hidden = Array ('notexc','bystatus');
7662: }
7663: if (curraccess == 'all') {
7664: shown = Array ('privs');
7665: hidden = Array ('notinc','notexc','bystatus');
7666: }
7667: }
7668: }
7669: if (hidden.length > 0) {
7670: for (var i=0; i<hidden.length; i++) {
7671: if (document.getElementById(role+'_'+hidden[i])) {
7672: document.getElementById(role+'_'+hidden[i]).style.display = 'none';
7673: }
7674: }
7675: }
7676: if (shown.length > 0) {
7677: for (var i=0; i<shown.length; i++) {
7678: if (document.getElementById(role+'_'+shown[i])) {
7679: if (shown[i] == 'privs') {
7680: document.getElementById(role+'_'+shown[i]).style.display = 'block';
7681: } else {
7682: document.getElementById(role+'_'+shown[i]).style.display = 'inline';
7683: }
7684: }
7685: }
7686: }
7687: return;
7688: }
7689:
7690: function toggleAccess(role) {
7691: if ((document.getElementById(role+'_setincrs')) &&
7692: (document.getElementById(role+'_setindom'))) {
7693: for (var i=0; i<document.$formname.elements[role+'_incrs'].length; i++) {
7694: if (document.$formname.elements[role+'_incrs'][i].checked) {
7695: if (document.$formname.elements[role+'_incrs'][i].value == 1) {
7696: document.getElementById(role+'_setindom').style.display = 'none';
7697: document.getElementById(role+'_setincrs').style.display = 'block';
7698: } else {
7699: document.getElementById(role+'_setincrs').style.display = 'none';
7700: document.getElementById(role+'_setindom').style.display = 'block';
7701: }
7702: break;
7703: }
7704: }
7705: }
7706: return;
7707: }
7708:
7709: // ]]>
7710: </script>
7711: ENDJS
7712:
7713: $args->{add_entries} = {onload => "javascript:setFormElements(document.$formname)"};
7714:
7715: # print page header
7716: $r->print(&header($js,$args));
7717: # print form header
7718: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">');
7719:
7720: if (keys(%customroles)) {
7721: my %lt = &Apache::lonlocal::texthash(
7722: 'aco' => 'As course owner you may override the defaults set in the domain for role usage and/or privileges.',
7723: 'rou' => 'Role usage',
7724: 'whi' => 'Which helpdesk personnel may use this role?',
7725: 'udd' => 'Use domain default',
1.406.2.12 raeburn 7726: 'all' => 'All with domain helpdesk or helpdesk assistant role',
7727: 'dh' => 'All with domain helpdesk role',
7728: 'da' => 'All with domain helpdesk assistant role',
1.406.2.10 raeburn 7729: 'none' => 'None',
7730: 'status' => 'Determined based on institutional status',
7731: 'inc' => 'Include all, but exclude specific personnel',
7732: 'exc' => 'Exclude all, but include specific personnel',
7733: 'hel' => 'Helpdesk',
7734: 'rpr' => 'Role privileges',
7735: );
7736: $lt{'tfh'} = &mt("Custom [_1]ad hoc[_2] course roles available for use by the domain's helpdesk are as follows",'<i>','</i>');
7737: my %domconfig = &Apache::lonnet::get_dom('configuration',['helpsettings'],$cdom);
7738: my (%domcurrent,%ordered,%description,%domusage,$disabled);
7739: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
7740: if (ref($domconfig{'helpsettings'}{'adhoc'}) eq 'HASH') {
7741: %domcurrent = %{$domconfig{'helpsettings'}{'adhoc'}};
7742: }
7743: }
7744: my $count = 0;
7745: foreach my $role (sort(keys(%customroles))) {
7746: my ($order,$desc,$access_in_dom);
7747: if (ref($domcurrent{$role}) eq 'HASH') {
7748: $order = $domcurrent{$role}{'order'};
7749: $desc = $domcurrent{$role}{'desc'};
7750: $access_in_dom = $domcurrent{$role}{'access'};
7751: }
7752: if ($order eq '') {
7753: $order = $count;
7754: }
7755: $ordered{$order} = $role;
7756: if ($desc ne '') {
7757: $description{$role} = $desc;
7758: } else {
7759: $description{$role}= $role;
7760: }
7761: $count++;
7762: }
7763: %domusage = &domain_adhoc_access(\%customroles,\%domcurrent,\@accesstypes,$usertypes,$othertitle);
7764: my @roles_by_num = ();
7765: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
7766: push(@roles_by_num,$ordered{$item});
7767: }
7768: $r->print('<p>'.$lt{'tfh'}.': <i>'.join('</i>, <i>',map { $description{$_}; } @roles_by_num).'</i>.');
7769: if ($permission->{'owner'}) {
7770: $r->print('<br />'.$lt{'aco'}.'</p><p>');
7771: $r->print('<input type="hidden" name="state" value="process" />'.
7772: '<input type="submit" value="'.&mt('Save changes').'" />');
7773: } else {
7774: if ($env{'course.'.$env{'request.course.id'}.'.internal.courseowner'}) {
7775: my ($ownername,$ownerdom) = split(/:/,$env{'course.'.$env{'request.course.id'}.'.internal.courseowner'});
7776: $r->print('<br />'.&mt('The course owner -- [_1] -- can override the default access and/or privileges for these ad hoc roles.',
7777: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($ownername,$ownerdom),$ownername,$ownerdom)));
7778: }
7779: $disabled = ' disabled="disabled"';
7780: }
7781: $r->print('</p>');
7782:
7783: $r->print('<div id="LC_minitab_header"><ul>');
7784: my $count = 0;
7785: my %visibility;
7786: foreach my $role (@roles_by_num) {
7787: my $id;
7788: if ($count == 0) {
7789: $id=' id="LC_current_minitab"';
7790: $visibility{$role} = ' style="display:block"';
7791: } else {
7792: $visibility{$role} = ' style="display:none"';
7793: }
7794: $count ++;
7795: $r->print('<li'.$id.'><a href="#" onclick="javascript:switchRoleTab(this.parentNode,'."'$role'".');">'.$description{$role}.'</a></li>');
7796: }
7797: $r->print('</ul></div>');
7798:
7799: foreach my $role (@roles_by_num) {
7800: my %usecheck = (
7801: all => ' checked="checked"',
7802: );
7803: my %displaydiv = (
7804: status => 'none',
7805: inc => 'none',
7806: exc => 'none',
7807: priv => 'block',
7808: );
7809: my (%selected,$overridden,$incrscheck,$indomcheck,$indomvis,$incrsvis);
7810: if (ref($settings{$role}) eq 'HASH') {
7811: if ($settings{$role}{'access'} ne '') {
7812: $indomvis = ' style="display:none"';
7813: $incrsvis = ' style="display:block"';
7814: $incrscheck = ' checked="checked"';
7815: if ($settings{$role}{'access'} ne 'all') {
7816: $usecheck{$settings{$role}{'access'}} = $usecheck{'all'};
7817: delete($usecheck{'all'});
7818: if ($settings{$role}{'access'} eq 'status') {
7819: my $access = 'status';
7820: $displaydiv{$access} = 'inline';
7821: if (ref($settings{$role}{$access}) eq 'ARRAY') {
7822: $selected{$access} = $settings{$role}{$access};
7823: }
7824: } elsif ($settings{$role}{'access'} =~ /^(inc|exc)$/) {
7825: my $access = $1;
7826: $displaydiv{$access} = 'inline';
7827: if (ref($settings{$role}{$access}) eq 'ARRAY') {
7828: $selected{$access} = $settings{$role}{$access};
7829: }
7830: } elsif ($settings{$role}{'access'} eq 'none') {
7831: $displaydiv{'priv'} = 'none';
7832: }
7833: }
7834: } else {
7835: $indomcheck = ' checked="checked"';
7836: $indomvis = ' style="display:block"';
7837: $incrsvis = ' style="display:none"';
7838: }
7839: } else {
7840: $indomcheck = ' checked="checked"';
7841: $indomvis = ' style="display:block"';
7842: $incrsvis = ' style="display:none"';
7843: }
7844: $r->print('<div class="LC_left_float" id="'.$role.'_maindiv"'.$visibility{$role}.'>'.
7845: '<fieldset><legend>'.$lt{'rou'}.'</legend>'.
7846: '<p>'.$lt{'whi'}.' <span class="LC_nobreak">'.
7847: '<label><input type="radio" name="'.$role.'_incrs" value="1"'.$incrscheck.' onclick="toggleAccess('."'$role'".');"'.$disabled.'>'.
7848: &mt('Set here in [_1]',lc($crstype)).'</label>'.
7849: '<span>'.(' 'x2).
7850: '<label><input type="radio" name="'.$role.'_incrs" value="0"'.$indomcheck.' onclick="toggleAccess('."'$role'".');"'.$disabled.'>'.
7851: $lt{'udd'}.'</label><span></p>'.
7852: '<div id="'.$role.'_setindom"'.$indomvis.'>'.
7853: '<span class="LC_cusr_emph">'.$domusage{$role}.'</span></div>'.
7854: '<div id="'.$role.'_setincrs"'.$incrsvis.'>');
7855: foreach my $access (@accesstypes) {
7856: $r->print('<p><label><input type="radio" name="'.$role.'_access" value="'.$access.'" '.$usecheck{$access}.
7857: ' onclick="helpdeskAccess('."'$role'".');"'.$disabled.' />'.$lt{$access}.'</label>');
7858: if ($access eq 'status') {
7859: $r->print('<div id="'.$role.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
7860: &Apache::lonuserutils::adhoc_status_types($cdom,undef,$role,$selected{$access},
7861: $othertitle,$usertypes,$types,$disabled).
7862: '</div>');
7863: } elsif (($access eq 'inc') && (keys(%domhelpdesk) > 0)) {
7864: $r->print('<div id="'.$role.'_notinc" style="display:'.$displaydiv{$access}.'">'.
7865: &Apache::lonuserutils::adhoc_staff($access,undef,$role,$selected{$access},
7866: \%domhelpdesk,$disabled).
7867: '</div>');
7868: } elsif (($access eq 'exc') && (keys(%domhelpdesk) > 0)) {
7869: $r->print('<div id="'.$role.'_notexc" style="display:'.$displaydiv{$access}.'">'.
7870: &Apache::lonuserutils::adhoc_staff($access,undef,$role,$selected{$access},
7871: \%domhelpdesk,$disabled).
7872: '</div>');
7873: }
7874: $r->print('</p>');
7875: }
7876: $r->print('</div></fieldset>');
7877: my %full=();
7878: my %levels= (
7879: course => {},
7880: domain => {},
7881: system => {},
7882: );
7883: my %levelscurrent=(
7884: course => {},
7885: domain => {},
7886: system => {},
7887: );
7888: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
7889: $r->print('<fieldset id="'.$role.'_privs" style="display:'.$displaydiv{'priv'}.'">'.
7890: '<legend>'.$lt{'rpr'}.'</legend>'.
7891: &role_priv_table($role,$permission,$crstype,\%full,\%levels,\%levelscurrent,$overridden{$role}).
7892: '</fieldset></div><div style="padding:0;clear:both;margin:0;border:0"></div>');
7893: }
7894: if ($permission->{'owner'}) {
7895: $r->print('<p><input type="submit" value="'.&mt('Save changes').'" /></p>');
7896: }
7897: } else {
7898: $r->print(&mt('Helpdesk roles have not yet been created in this domain.'));
7899: }
7900: # Form Footer
7901: $r->print('<input type="hidden" name="action" value="helpdesk" />'
7902: .'</form>');
7903: return;
7904: }
7905:
7906: sub domain_adhoc_access {
7907: my ($roles,$domcurrent,$accesstypes,$usertypes,$othertitle) = @_;
7908: my %domusage;
7909: return unless ((ref($roles) eq 'HASH') && (ref($domcurrent) eq 'HASH') && (ref($accesstypes) eq 'ARRAY'));
7910: foreach my $role (keys(%{$roles})) {
7911: if (ref($domcurrent->{$role}) eq 'HASH') {
7912: my $access = $domcurrent->{$role}{'access'};
7913: if (($access eq '') || (!grep(/^\Q$access\E$/,@{$accesstypes}))) {
7914: $access = 'all';
1.406.2.12 raeburn 7915: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',&Apache::lonnet::plaintext('dh'),
7916: &Apache::lonnet::plaintext('da'));
1.406.2.10 raeburn 7917: } elsif ($access eq 'status') {
7918: if (ref($domcurrent->{$role}{$access}) eq 'ARRAY') {
7919: my @shown;
7920: foreach my $type (@{$domcurrent->{$role}{$access}}) {
7921: unless ($type eq 'default') {
7922: if ($usertypes->{$type}) {
7923: push(@shown,$usertypes->{$type});
7924: }
7925: }
7926: }
7927: if (grep(/^default$/,@{$domcurrent->{$role}{$access}})) {
7928: push(@shown,$othertitle);
7929: }
7930: if (@shown) {
7931: my $shownstatus = join(' '.&mt('or').' ',@shown);
1.406.2.12 raeburn 7932: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role, and institutional status: [_3]',
7933: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$shownstatus);
1.406.2.10 raeburn 7934: } else {
7935: $domusage{$role} = &mt('No one in the domain');
7936: }
7937: }
7938: } elsif ($access eq 'inc') {
7939: my @dominc = ();
7940: if (ref($domcurrent->{$role}{'inc'}) eq 'ARRAY') {
7941: foreach my $user (@{$domcurrent->{$role}{'inc'}}) {
7942: my ($uname,$udom) = split(/:/,$user);
7943: push(@dominc,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom));
7944: }
7945: my $showninc = join(', ',@dominc);
7946: if ($showninc ne '') {
1.406.2.12 raeburn 7947: $domusage{$role} = &mt('Include any user in domain with active [_1] or [_2] role, except: [_3]',
7948: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$showninc);
1.406.2.10 raeburn 7949: } else {
1.406.2.12 raeburn 7950: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
7951: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.406.2.10 raeburn 7952: }
7953: }
7954: } elsif ($access eq 'exc') {
7955: my @domexc = ();
7956: if (ref($domcurrent->{$role}{'exc'}) eq 'ARRAY') {
7957: foreach my $user (@{$domcurrent->{$role}{'exc'}}) {
7958: my ($uname,$udom) = split(/:/,$user);
7959: push(@domexc,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom));
7960: }
7961: }
7962: my $shownexc = join(', ',@domexc);
7963: if ($shownexc ne '') {
1.406.2.12 raeburn 7964: $domusage{$role} = &mt('Only the following in the domain with active [_1] or [_2] role: [_3]',
7965: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$shownexc);
1.406.2.10 raeburn 7966: } else {
7967: $domusage{$role} = &mt('No one in the domain');
7968: }
7969: } elsif ($access eq 'none') {
7970: $domusage{$role} = &mt('No one in the domain');
1.406.2.12 raeburn 7971: } elsif ($access eq 'dh') {
1.406.2.10 raeburn 7972: $domusage{$role} = &mt('Any user in domain with active [_1] role',&Apache::lonnet::plaintext('dh'));
1.406.2.12 raeburn 7973: } elsif ($access eq 'da') {
7974: $domusage{$role} = &mt('Any user in domain with active [_1] role',&Apache::lonnet::plaintext('da'));
7975: } elsif ($access eq 'all') {
7976: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
7977: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.406.2.10 raeburn 7978: }
7979: } else {
1.406.2.12 raeburn 7980: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
7981: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.406.2.10 raeburn 7982: }
7983: }
7984: return %domusage;
7985: }
7986:
7987: sub get_domain_customroles {
7988: my ($cdom,$confname) = @_;
7989: my %existing=&Apache::lonnet::dump('roles',$cdom,$confname,'rolesdef_');
7990: my %customroles;
7991: foreach my $key (keys(%existing)) {
7992: if ($key=~/^rolesdef\_(\w+)$/) {
7993: my $rolename = $1;
7994: my %privs;
7995: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
7996: $customroles{$rolename} = \%privs;
7997: }
7998: }
7999: return %customroles;
8000: }
8001:
8002: sub role_priv_table {
8003: my ($role,$permission,$crstype,$full,$levels,$levelscurrent,$overridden) = @_;
8004: return unless ((ref($full) eq 'HASH') && (ref($levels) eq 'HASH') &&
8005: (ref($levelscurrent) eq 'HASH'));
8006: my %lt=&Apache::lonlocal::texthash (
8007: 'crl' => 'Course Level Privilege',
8008: 'def' => 'Domain Defaults',
8009: 'ove' => 'Override in Course',
8010: 'ine' => 'In effect',
8011: 'dis' => 'Disabled',
8012: 'ena' => 'Enabled',
8013: );
8014: if ($crstype eq 'Community') {
8015: $lt{'ove'} = 'Override in Community',
8016: }
8017: my @status = ('Disabled','Enabled');
8018: my (%on,%off);
8019: if (ref($overridden) eq 'HASH') {
8020: if (ref($overridden->{'on'}) eq 'ARRAY') {
8021: map { $on{$_} = 1; } (@{$overridden->{'on'}});
8022: }
8023: if (ref($overridden->{'off'}) eq 'ARRAY') {
8024: map { $off{$_} = 1; } (@{$overridden->{'off'}});
8025: }
8026: }
8027: my $output=&Apache::loncommon::start_data_table().
8028: &Apache::loncommon::start_data_table_header_row().
8029: '<th>'.$lt{'crl'}.'</th><th>'.$lt{'def'}.'</th><th>'.$lt{'ove'}.
8030: '</th><th>'.$lt{'ine'}.'</th>'.
8031: &Apache::loncommon::end_data_table_header_row();
8032: foreach my $priv (sort(keys(%{$full}))) {
8033: next unless ($levels->{'course'}{$priv});
8034: my $privtext = &Apache::lonnet::plaintext($priv,$crstype);
8035: my ($default,$ineffect);
8036: if ($levelscurrent->{'course'}{$priv}) {
8037: $default = '<img src="/adm/lonIcons/navmap.correct.gif" alt="'.$lt{'ena'}.'" />';
8038: $ineffect = $default;
8039: }
8040: my ($customstatus,$checked);
8041: $output .= &Apache::loncommon::start_data_table_row().
8042: '<td>'.$privtext.'</td>'.
8043: '<td>'.$default.'</td><td>';
8044: if (($levelscurrent->{'course'}{$priv}) && ($off{$priv})) {
8045: if ($permission->{'owner'}) {
8046: $checked = ' checked="checked"';
8047: }
8048: $customstatus = '<img src="/adm/lonIcons/navmap.wrong.gif" alt="'.$lt{'dis'}.'" />';
8049: $ineffect = $customstatus;
8050: } elsif ((!$levelscurrent->{'course'}{$priv}) && ($on{$priv})) {
8051: if ($permission->{'owner'}) {
8052: $checked = ' checked="checked"';
8053: }
8054: $customstatus = '<img src="/adm/lonIcons/navmap.correct.gif" alt="'.$lt{'ena'}.'" />';
8055: $ineffect = $customstatus;
8056: }
8057: if ($permission->{'owner'}) {
8058: $output .= '<input type="checkbox" name="'.$role.'_override" value="'.$priv.'"'.$checked.' />';
8059: } else {
8060: $output .= $customstatus;
8061: }
8062: $output .= '</td><td>'.$ineffect.'</td>'.
8063: &Apache::loncommon::end_data_table_row();
8064: }
8065: $output .= &Apache::loncommon::end_data_table();
8066: return $output;
8067: }
8068:
8069: sub get_adhocrole_settings {
8070: my ($cid,$accesstypes,$types,$customroles,$settings,$overridden) = @_;
8071: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($customroles) eq 'HASH') &&
8072: (ref($settings) eq 'HASH') && (ref($overridden) eq 'HASH'));
8073: foreach my $role (split(/,/,$env{'course.'.$cid.'.internal.adhocaccess'})) {
8074: my ($curraccess,$rest) = split(/=/,$env{'course.'.$cid.'.internal.adhoc.'.$role});
8075: if (($curraccess ne '') && (grep(/^\Q$curraccess\E$/,@{$accesstypes}))) {
8076: $settings->{$role}{'access'} = $curraccess;
8077: if (($curraccess eq 'status') && (ref($types) eq 'ARRAY')) {
8078: my @status = split(/,/,$rest);
8079: my @currstatus;
8080: foreach my $type (@status) {
8081: if ($type eq 'default') {
8082: push(@currstatus,$type);
8083: } elsif (grep(/^\Q$type\E$/,@{$types})) {
8084: push(@currstatus,$type);
8085: }
8086: }
8087: if (@currstatus) {
8088: $settings->{$role}{$curraccess} = \@currstatus;
8089: } elsif (($curraccess eq 'exc') || ($curraccess eq 'inc')) {
8090: my @personnel = split(/,/,$rest);
8091: $settings->{$role}{$curraccess} = \@personnel;
8092: }
8093: }
8094: }
8095: }
8096: foreach my $role (keys(%{$customroles})) {
8097: if ($env{'course.'.$cid.'.internal.adhocpriv.'.$role}) {
8098: my %currentprivs;
8099: if (ref($customroles->{$role}) eq 'HASH') {
8100: if (exists($customroles->{$role}{'course'})) {
8101: my %full=();
8102: my %levels= (
8103: course => {},
8104: domain => {},
8105: system => {},
8106: );
8107: my %levelscurrent=(
8108: course => {},
8109: domain => {},
8110: system => {},
8111: );
8112: &Apache::lonuserutils::custom_role_privs($customroles->{$role},\%full,\%levels,\%levelscurrent);
8113: %currentprivs = %{$levelscurrent{'course'}};
8114: }
8115: }
8116: foreach my $item (split(/,/,$env{'course.'.$cid.'.internal.adhocpriv.'.$role})) {
8117: next if ($item eq '');
8118: my ($rule,$rest) = split(/=/,$item);
8119: next unless (($rule eq 'off') || ($rule eq 'on'));
8120: foreach my $priv (split(/:/,$rest)) {
8121: if ($priv ne '') {
8122: if ($rule eq 'off') {
8123: push(@{$overridden->{$role}{'off'}},$priv);
8124: if ($currentprivs{$priv}) {
8125: push(@{$settings->{$role}{'off'}},$priv);
8126: }
8127: } else {
8128: push(@{$overridden->{$role}{'on'}},$priv);
8129: unless ($currentprivs{$priv}) {
8130: push(@{$settings->{$role}{'on'}},$priv);
8131: }
8132: }
8133: }
8134: }
8135: }
8136: }
8137: }
8138: return;
8139: }
8140:
8141: sub update_helpdeskaccess {
8142: my ($r,$permission,$brcrum) = @_;
8143: my $helpitem = 'Course_Helpdesk_Access';
8144: push (@{$brcrum},
8145: {href => '/adm/createuser?action=helpdesk',
8146: text => 'Helpdesk Access',
8147: help => $helpitem},
8148: {href => '/adm/createuser?action=helpdesk',
8149: text => 'Result',
8150: help => $helpitem}
8151: );
8152: my $bread_crumbs_component = 'Helpdesk Staff Access';
8153: my $args = { bread_crumbs => $brcrum,
8154: bread_crumbs_component => $bread_crumbs_component};
8155:
8156: # print page header
8157: $r->print(&header('',$args));
8158: unless ((ref($permission) eq 'HASH') && ($permission->{'owner'})) {
8159: $r->print('<p class="LC_error">'.&mt('You do not have permission to change helpdesk access.').'</p>');
8160: return;
8161: }
1.406.2.12 raeburn 8162: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.406.2.10 raeburn 8163: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8164: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
8165: my $confname = $cdom.'-domainconfig';
8166: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($cdom);
8167: my $crstype = &Apache::loncommon::course_type();
8168: my %customroles = &get_domain_customroles($cdom,$confname);
8169: my (%settings,%overridden);
8170: &get_adhocrole_settings($env{'request.course.id'},\@accesstypes,
8171: $types,\%customroles,\%settings,\%overridden);
1.406.2.12 raeburn 8172: my %domhelpdesk = &Apache::lonnet::get_active_domroles($cdom,['dh','da']);
1.406.2.10 raeburn 8173: my (%changed,%storehash,@todelete);
8174:
8175: if (keys(%customroles)) {
8176: my (%newsettings,@incrs);
8177: foreach my $role (keys(%customroles)) {
8178: $newsettings{$role} = {
8179: access => '',
8180: status => '',
8181: exc => '',
8182: inc => '',
8183: on => '',
8184: off => '',
8185: };
8186: my %current;
8187: if (ref($settings{$role}) eq 'HASH') {
8188: %current = %{$settings{$role}};
8189: }
8190: if (ref($overridden{$role}) eq 'HASH') {
8191: $current{'overridden'} = $overridden{$role};
8192: }
8193: if ($env{'form.'.$role.'_incrs'}) {
8194: my $access = $env{'form.'.$role.'_access'};
8195: if (grep(/^\Q$access\E$/,@accesstypes)) {
8196: push(@incrs,$role);
8197: unless ($current{'access'} eq $access) {
8198: $changed{$role}{'access'} = 1;
8199: $storehash{'internal.adhoc.'.$role} = $access;
8200: }
8201: if ($access eq 'status') {
8202: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$role.'_status');
8203: my @stored;
8204: my @shownstatus;
8205: if (ref($types) eq 'ARRAY') {
8206: foreach my $type (sort(@statuses)) {
8207: if ($type eq 'default') {
8208: push(@stored,$type);
8209: } elsif (grep(/^\Q$type\E$/,@{$types})) {
8210: push(@stored,$type);
8211: push(@shownstatus,$usertypes->{$type});
8212: }
8213: }
8214: if (grep(/^default$/,@statuses)) {
8215: push(@shownstatus,$othertitle);
8216: }
8217: $storehash{'internal.adhoc.'.$role} .= '='.join(',',@stored);
8218: }
8219: $newsettings{$role}{'status'} = join(' '.&mt('or').' ',@shownstatus);
8220: if (ref($current{'status'}) eq 'ARRAY') {
8221: my @diffs = &Apache::loncommon::compare_arrays(\@stored,$current{'status'});
8222: if (@diffs) {
8223: $changed{$role}{'status'} = 1;
8224: }
8225: } elsif (@stored) {
8226: $changed{$role}{'status'} = 1;
8227: }
8228: } elsif (($access eq 'inc') || ($access eq 'exc')) {
8229: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$role.'_staff_'.$access);
8230: my @newspecstaff;
8231: my @stored;
8232: my @currstaff;
8233: foreach my $person (sort(@personnel)) {
8234: if ($domhelpdesk{$person}) {
8235: push(@stored,$person);
8236: }
8237: }
8238: if (ref($current{$access}) eq 'ARRAY') {
8239: my @diffs = &Apache::loncommon::compare_arrays(\@stored,$current{$access});
8240: if (@diffs) {
8241: $changed{$role}{$access} = 1;
8242: }
8243: } elsif (@stored) {
8244: $changed{$role}{$access} = 1;
8245: }
8246: $storehash{'internal.adhoc.'.$role} .= '='.join(',',@stored);
8247: foreach my $person (@stored) {
8248: my ($uname,$udom) = split(/:/,$person);
8249: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
8250: }
8251: $newsettings{$role}{$access} = join(', ',sort(@newspecstaff));
8252: }
8253: $newsettings{$role}{'access'} = $access;
8254: }
8255: } else {
8256: if (($current{'access'} ne '') && (grep(/^\Q$current{'access'}\E$/,@accesstypes))) {
8257: $changed{$role}{'access'} = 1;
8258: $newsettings{$role} = {};
8259: push(@todelete,'internal.adhoc.'.$role);
8260: }
8261: }
8262: if (($env{'form.'.$role.'_incrs'}) && ($env{'form.'.$role.'_access'} eq 'none')) {
8263: if (ref($current{'overridden'}) eq 'HASH') {
8264: push(@todelete,'internal.adhocpriv.'.$role);
8265: }
8266: } else {
8267: my %full=();
8268: my %levels= (
8269: course => {},
8270: domain => {},
8271: system => {},
8272: );
8273: my %levelscurrent=(
8274: course => {},
8275: domain => {},
8276: system => {},
8277: );
8278: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
8279: my (@updatedon,@updatedoff,@override);
8280: @override = &Apache::loncommon::get_env_multiple('form.'.$role.'_override');
8281: if (@override) {
8282: foreach my $priv (sort(keys(%full))) {
8283: next unless ($levels{'course'}{$priv});
8284: if (grep(/^\Q$priv\E$/,@override)) {
8285: if ($levelscurrent{'course'}{$priv}) {
8286: push(@updatedoff,$priv);
8287: } else {
8288: push(@updatedon,$priv);
8289: }
8290: }
8291: }
8292: }
8293: if (@updatedon) {
8294: $newsettings{$role}{'on'} = join('</li><li>', map { &Apache::lonnet::plaintext($_,$crstype) } (@updatedon));
8295: }
8296: if (@updatedoff) {
8297: $newsettings{$role}{'off'} = join('</li><li>', map { &Apache::lonnet::plaintext($_,$crstype) } (@updatedoff));
8298: }
8299: if (ref($current{'overridden'}) eq 'HASH') {
8300: if (ref($current{'overridden'}{'on'}) eq 'ARRAY') {
8301: if (@updatedon) {
8302: my @diffs = &Apache::loncommon::compare_arrays(\@updatedon,$current{'overridden'}{'on'});
8303: if (@diffs) {
8304: $changed{$role}{'on'} = 1;
8305: }
8306: } else {
8307: $changed{$role}{'on'} = 1;
8308: }
8309: } elsif (@updatedon) {
8310: $changed{$role}{'on'} = 1;
8311: }
8312: if (ref($current{'overridden'}{'off'}) eq 'ARRAY') {
8313: if (@updatedoff) {
8314: my @diffs = &Apache::loncommon::compare_arrays(\@updatedoff,$current{'overridden'}{'off'});
8315: if (@diffs) {
8316: $changed{$role}{'off'} = 1;
8317: }
8318: } else {
8319: $changed{$role}{'off'} = 1;
8320: }
8321: } elsif (@updatedoff) {
8322: $changed{$role}{'off'} = 1;
8323: }
8324: } else {
8325: if (@updatedon) {
8326: $changed{$role}{'on'} = 1;
8327: }
8328: if (@updatedoff) {
8329: $changed{$role}{'off'} = 1;
8330: }
8331: }
8332: if (ref($changed{$role}) eq 'HASH') {
8333: if (($changed{$role}{'on'} || $changed{$role}{'off'})) {
8334: my $newpriv;
8335: if (@updatedon) {
8336: $newpriv = 'on='.join(':',@updatedon);
8337: }
8338: if (@updatedoff) {
8339: $newpriv .= ($newpriv ? ',' : '' ).'off='.join(':',@updatedoff);
8340: }
8341: if ($newpriv eq '') {
8342: push(@todelete,'internal.adhocpriv.'.$role);
8343: } else {
8344: $storehash{'internal.adhocpriv.'.$role} = $newpriv;
8345: }
8346: }
8347: }
8348: }
8349: }
8350: if (@incrs) {
8351: $storehash{'internal.adhocaccess'} = join(',',@incrs);
8352: } elsif (@todelete) {
8353: push(@todelete,'internal.adhocaccess');
8354: }
8355: if (keys(%changed)) {
8356: my ($putres,$delres);
8357: if (keys(%storehash)) {
8358: $putres = &Apache::lonnet::put('environment',\%storehash,$cdom,$cnum);
8359: my %newenvhash;
8360: foreach my $key (keys(%storehash)) {
8361: $newenvhash{'course.'.$env{'request.course.id'}.'.'.$key} = $storehash{$key};
8362: }
8363: &Apache::lonnet::appenv(\%newenvhash);
8364: }
8365: if (@todelete) {
8366: $delres = &Apache::lonnet::del('environment',\@todelete,$cdom,$cnum);
8367: foreach my $key (@todelete) {
8368: &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.'.$key);
8369: }
8370: }
8371: if (($putres eq 'ok') || ($delres eq 'ok')) {
8372: my %domconfig = &Apache::lonnet::get_dom('configuration',['helpsettings'],$cdom);
8373: my (%domcurrent,%ordered,%description,%domusage);
8374: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
8375: if (ref($domconfig{'helpsettings'}{'adhoc'}) eq 'HASH') {
8376: %domcurrent = %{$domconfig{'helpsettings'}{'adhoc'}};
8377: }
8378: }
8379: my $count = 0;
8380: foreach my $role (sort(keys(%customroles))) {
8381: my ($order,$desc);
8382: if (ref($domcurrent{$role}) eq 'HASH') {
8383: $order = $domcurrent{$role}{'order'};
8384: $desc = $domcurrent{$role}{'desc'};
8385: }
8386: if ($order eq '') {
8387: $order = $count;
8388: }
8389: $ordered{$order} = $role;
8390: if ($desc ne '') {
8391: $description{$role} = $desc;
8392: } else {
8393: $description{$role}= $role;
8394: }
8395: $count++;
8396: }
8397: my @roles_by_num = ();
8398: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
8399: push(@roles_by_num,$ordered{$item});
8400: }
8401: %domusage = &domain_adhoc_access(\%changed,\%domcurrent,\@accesstypes,$usertypes,$othertitle);
8402: $r->print(&mt('Helpdesk access settings have been changed as follows').'<br />');
8403: $r->print('<ul>');
8404: foreach my $role (@roles_by_num) {
8405: next unless (ref($changed{$role}) eq 'HASH');
8406: $r->print('<li>'.&mt('Ad hoc role').': <b>'.$description{$role}.'</b>'.
8407: '<ul>');
8408: if ($changed{$role}{'access'} || $changed{$role}{'status'} || $changed{$role}{'inc'} || $changed{$role}{'exc'}) {
8409: $r->print('<li>');
8410: if ($env{'form.'.$role.'_incrs'}) {
8411: if ($newsettings{$role}{'access'} eq 'all') {
8412: $r->print(&mt('All helpdesk staff can access '.lc($crstype).' with this role.'));
1.406.2.12 raeburn 8413: } elsif ($newsettings{$role}{'access'} eq 'dh') {
8414: $r->print(&mt('Helpdesk staff can use this role if they have an active [_1] role',
8415: &Apache::lonnet::plaintext('dh')));
8416: } elsif ($newsettings{$role}{'access'} eq 'da') {
8417: $r->print(&mt('Helpdesk staff can use this role if they have an active [_1] role',
8418: &Apache::lonnet::plaintext('da')));
1.406.2.10 raeburn 8419: } elsif ($newsettings{$role}{'access'} eq 'none') {
8420: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
8421: } elsif ($newsettings{$role}{'access'} eq 'status') {
8422: if ($newsettings{$role}{'status'}) {
8423: my ($access,$rest) = split(/=/,$storehash{'internal.adhoc.'.$role});
8424: if (split(/,/,$rest) > 1) {
8425: $r->print(&mt('Helpdesk staff can use this role if their institutional type is one of: [_1].',
8426: $newsettings{$role}{'status'}));
8427: } else {
8428: $r->print(&mt('Helpdesk staff can use this role if their institutional type is: [_1].',
8429: $newsettings{$role}{'status'}));
8430: }
8431: } else {
8432: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
8433: }
8434: } elsif ($newsettings{$role}{'access'} eq 'exc') {
8435: if ($newsettings{$role}{'exc'}) {
8436: $r->print(&mt('Helpdesk staff who can use this role are as follows:').' '.$newsettings{$role}{'exc'}.'.');
8437: } else {
8438: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
8439: }
8440: } elsif ($newsettings{$role}{'access'} eq 'inc') {
8441: if ($newsettings{$role}{'inc'}) {
8442: $r->print(&mt('All helpdesk staff may use this role except the following:').' '.$newsettings{$role}{'inc'}.'.');
8443: } else {
8444: $r->print(&mt('All helpdesk staff may use this role.'));
8445: }
8446: }
8447: } else {
8448: $r->print(&mt('Default access set in the domain now applies.').'<br />'.
8449: '<span class="LC_cusr_emph">'.$domusage{$role}.'</span>');
8450: }
8451: $r->print('</li>');
8452: }
8453: unless ($newsettings{$role}{'access'} eq 'none') {
8454: if ($changed{$role}{'off'}) {
8455: if ($newsettings{$role}{'off'}) {
8456: $r->print('<li>'.&mt('Privileges which are available by default for this ad hoc role, but are disabled for this specific '.lc($crstype).':').
8457: '<ul><li>'.$newsettings{$role}{'off'}.'</li></ul></li>');
8458: } else {
8459: $r->print('<li>'.&mt('All privileges available by default for this ad hoc role are enabled.').'</li>');
8460: }
8461: }
8462: if ($changed{$role}{'on'}) {
8463: if ($newsettings{$role}{'on'}) {
8464: $r->print('<li>'.&mt('Privileges which are not available by default for this ad hoc role, but are enabled for this specific '.lc($crstype).':').
8465: '<ul><li>'.$newsettings{$role}{'on'}.'</li></ul></li>');
8466: } else {
8467: $r->print('<li>'.&mt('None of the privileges unavailable by default for this ad hoc role are enabled.').'</li>');
8468: }
8469: }
8470: }
8471: $r->print('</ul></li>');
8472: }
8473: $r->print('</ul>');
8474: }
8475: } else {
8476: $r->print(&mt('No changes made to helpdesk access settings.'));
8477: }
8478: }
8479: return;
8480: }
8481:
1.27 matthew 8482: #-------------------------------------------------- functions for &phase_two
1.160 raeburn 8483: sub user_search_result {
1.221 raeburn 8484: my ($context,$srch) = @_;
1.160 raeburn 8485: my %allhomes;
8486: my %inst_matches;
8487: my %srch_results;
1.181 raeburn 8488: my ($response,$currstate,$forcenewuser,$dirsrchres);
1.183 raeburn 8489: $srch->{'srchterm'} =~ s/\s+/ /g;
1.176 raeburn 8490: if ($srch->{'srchby'} !~ /^(uname|lastname|lastfirst)$/) {
1.160 raeburn 8491: $response = &mt('Invalid search.');
8492: }
8493: if ($srch->{'srchin'} !~ /^(crs|dom|alc|instd)$/) {
8494: $response = &mt('Invalid search.');
8495: }
1.177 raeburn 8496: if ($srch->{'srchtype'} !~ /^(exact|contains|begins)$/) {
1.160 raeburn 8497: $response = &mt('Invalid search.');
8498: }
8499: if ($srch->{'srchterm'} eq '') {
8500: $response = &mt('You must enter a search term.');
8501: }
1.183 raeburn 8502: if ($srch->{'srchterm'} =~ /^\s+$/) {
8503: $response = &mt('Your search term must contain more than just spaces.');
8504: }
1.160 raeburn 8505: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'instd')) {
8506: if (($srch->{'srchdomain'} eq '') ||
1.163 albertel 8507: ! (&Apache::lonnet::domain($srch->{'srchdomain'}))) {
1.160 raeburn 8508: $response = &mt('You must specify a valid domain when searching in a domain or institutional directory.')
8509: }
8510: }
8511: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs') ||
8512: ($srch->{'srchin'} eq 'alc')) {
1.176 raeburn 8513: if ($srch->{'srchby'} eq 'uname') {
1.243 raeburn 8514: my $unamecheck = $srch->{'srchterm'};
8515: if ($srch->{'srchtype'} eq 'contains') {
8516: if ($unamecheck !~ /^\w/) {
8517: $unamecheck = 'a'.$unamecheck;
8518: }
8519: }
8520: if ($unamecheck !~ /^$match_username$/) {
1.176 raeburn 8521: $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
8522: }
1.160 raeburn 8523: }
8524: }
1.180 raeburn 8525: if ($response ne '') {
1.406.2.4 raeburn 8526: $response = '<span class="LC_warning">'.$response.'</span><br />';
1.180 raeburn 8527: }
1.160 raeburn 8528: if ($srch->{'srchin'} eq 'instd') {
1.406.2.3 raeburn 8529: my $instd_chk = &instdirectorysrch_check($srch);
1.160 raeburn 8530: if ($instd_chk ne 'ok') {
1.406.2.3 raeburn 8531: my $domd_chk = &domdirectorysrch_check($srch);
1.406.2.4 raeburn 8532: $response .= '<span class="LC_warning">'.$instd_chk.'</span><br />';
1.406.2.3 raeburn 8533: if ($domd_chk eq 'ok') {
1.406.2.4 raeburn 8534: $response .= &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.');
1.406.2.3 raeburn 8535: }
1.406.2.5 raeburn 8536: $response .= '<br />';
1.406.2.3 raeburn 8537: }
8538: } else {
8539: unless (($context eq 'requestcrs') && ($srch->{'srchtype'} eq 'exact')) {
8540: my $domd_chk = &domdirectorysrch_check($srch);
1.406.2.14 raeburn 8541: if (($domd_chk ne 'ok') && ($env{'form.action'} ne 'accesslogs')) {
1.406.2.3 raeburn 8542: my $instd_chk = &instdirectorysrch_check($srch);
1.406.2.4 raeburn 8543: $response .= '<span class="LC_warning">'.$domd_chk.'</span><br />';
1.406.2.3 raeburn 8544: if ($instd_chk eq 'ok') {
1.406.2.4 raeburn 8545: $response .= &mt('You may want to search in the institutional directory instead of the LON-CAPA domain.');
1.406.2.3 raeburn 8546: }
1.406.2.5 raeburn 8547: $response .= '<br />';
1.406.2.3 raeburn 8548: }
1.160 raeburn 8549: }
8550: }
8551: if ($response ne '') {
1.180 raeburn 8552: return ($currstate,$response);
1.160 raeburn 8553: }
8554: if ($srch->{'srchby'} eq 'uname') {
8555: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs')) {
8556: if ($env{'form.forcenew'}) {
8557: if ($srch->{'srchdomain'} ne $env{'request.role.domain'}) {
8558: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
8559: if ($uhome eq 'no_host') {
8560: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
1.180 raeburn 8561: my $showdom = &display_domain_info($env{'request.role.domain'});
8562: $response = &mt('New users can only be created in the domain to which your current role belongs - [_1].',$showdom);
1.160 raeburn 8563: } else {
1.179 raeburn 8564: $currstate = 'modify';
1.160 raeburn 8565: }
8566: } else {
1.179 raeburn 8567: $currstate = 'modify';
1.160 raeburn 8568: }
8569: } else {
8570: if ($srch->{'srchin'} eq 'dom') {
1.162 raeburn 8571: if ($srch->{'srchtype'} eq 'exact') {
8572: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
8573: if ($uhome eq 'no_host') {
1.179 raeburn 8574: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8575: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 8576: } else {
1.179 raeburn 8577: $currstate = 'modify';
1.406.2.5 raeburn 8578: if ($env{'form.action'} eq 'accesslogs') {
8579: $currstate = 'activity';
8580: }
1.310 raeburn 8581: my $uname = $srch->{'srchterm'};
8582: my $udom = $srch->{'srchdomain'};
8583: $srch_results{$uname.':'.$udom} =
8584: { &Apache::lonnet::get('environment',
8585: ['firstname',
8586: 'lastname',
8587: 'permanentemail'],
8588: $udom,$uname)
8589: };
1.162 raeburn 8590: }
8591: } else {
8592: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 8593: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8594: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8595: }
8596: } else {
1.167 albertel 8597: my $courseusers = &get_courseusers();
1.162 raeburn 8598: if ($srch->{'srchtype'} eq 'exact') {
1.167 albertel 8599: if (exists($courseusers->{$srch->{'srchterm'}.':'.$srch->{'srchdomain'}})) {
1.179 raeburn 8600: $currstate = 'modify';
1.162 raeburn 8601: } else {
1.179 raeburn 8602: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8603: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 8604: }
1.160 raeburn 8605: } else {
1.167 albertel 8606: foreach my $user (keys(%$courseusers)) {
1.162 raeburn 8607: my ($cuname,$cudomain) = split(/:/,$user);
8608: if ($cudomain eq $srch->{'srchdomain'}) {
1.177 raeburn 8609: my $matched = 0;
8610: if ($srch->{'srchtype'} eq 'begins') {
8611: if ($cuname =~ /^\Q$srch->{'srchterm'}\E/i) {
8612: $matched = 1;
8613: }
8614: } else {
8615: if ($cuname =~ /\Q$srch->{'srchterm'}\E/i) {
8616: $matched = 1;
8617: }
8618: }
8619: if ($matched) {
1.167 albertel 8620: $srch_results{$user} =
8621: {&Apache::lonnet::get('environment',
8622: ['firstname',
8623: 'lastname',
1.194 albertel 8624: 'permanentemail'],
8625: $cudomain,$cuname)};
1.162 raeburn 8626: }
8627: }
8628: }
1.179 raeburn 8629: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8630: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8631: }
8632: }
8633: }
8634: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 8635: $currstate = 'query';
1.160 raeburn 8636: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 8637: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
8638: if ($dirsrchres eq 'ok') {
8639: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8640: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 8641: } else {
8642: my $showdom = &display_domain_info($srch->{'srchdomain'});
8643: $response = '<span class="LC_warning">'.
8644: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
8645: '</span><br />'.
8646: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
1.406.2.5 raeburn 8647: '<br />';
1.181 raeburn 8648: }
1.160 raeburn 8649: }
8650: } else {
8651: if ($srch->{'srchin'} eq 'dom') {
8652: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 8653: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8654: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8655: } elsif ($srch->{'srchin'} eq 'crs') {
1.167 albertel 8656: my $courseusers = &get_courseusers();
8657: foreach my $user (keys(%$courseusers)) {
1.160 raeburn 8658: my ($uname,$udom) = split(/:/,$user);
8659: my %names = &Apache::loncommon::getnames($uname,$udom);
8660: my %emails = &Apache::loncommon::getemails($uname,$udom);
8661: if ($srch->{'srchby'} eq 'lastname') {
8662: if ((($srch->{'srchtype'} eq 'exact') &&
8663: ($names{'lastname'} eq $srch->{'srchterm'})) ||
1.177 raeburn 8664: (($srch->{'srchtype'} eq 'begins') &&
8665: ($names{'lastname'} =~ /^\Q$srch->{'srchterm'}\E/i)) ||
1.160 raeburn 8666: (($srch->{'srchtype'} eq 'contains') &&
8667: ($names{'lastname'} =~ /\Q$srch->{'srchterm'}\E/i))) {
8668: $srch_results{$user} = {firstname => $names{'firstname'},
8669: lastname => $names{'lastname'},
8670: permanentemail => $emails{'permanentemail'},
8671: };
8672: }
8673: } elsif ($srch->{'srchby'} eq 'lastfirst') {
8674: my ($srchlast,$srchfirst) = split(/,/,$srch->{'srchterm'});
1.177 raeburn 8675: $srchlast =~ s/\s+$//;
8676: $srchfirst =~ s/^\s+//;
1.160 raeburn 8677: if ($srch->{'srchtype'} eq 'exact') {
8678: if (($names{'lastname'} eq $srchlast) &&
8679: ($names{'firstname'} eq $srchfirst)) {
8680: $srch_results{$user} = {firstname => $names{'firstname'},
8681: lastname => $names{'lastname'},
8682: permanentemail => $emails{'permanentemail'},
8683:
8684: };
8685: }
1.177 raeburn 8686: } elsif ($srch->{'srchtype'} eq 'begins') {
8687: if (($names{'lastname'} =~ /^\Q$srchlast\E/i) &&
8688: ($names{'firstname'} =~ /^\Q$srchfirst\E/i)) {
8689: $srch_results{$user} = {firstname => $names{'firstname'},
8690: lastname => $names{'lastname'},
8691: permanentemail => $emails{'permanentemail'},
8692: };
8693: }
8694: } else {
1.160 raeburn 8695: if (($names{'lastname'} =~ /\Q$srchlast\E/i) &&
8696: ($names{'firstname'} =~ /\Q$srchfirst\E/i)) {
8697: $srch_results{$user} = {firstname => $names{'firstname'},
8698: lastname => $names{'lastname'},
8699: permanentemail => $emails{'permanentemail'},
8700: };
8701: }
8702: }
8703: }
8704: }
1.179 raeburn 8705: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8706: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8707: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 8708: $currstate = 'query';
1.160 raeburn 8709: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 8710: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
8711: if ($dirsrchres eq 'ok') {
8712: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8713: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 8714: } else {
1.406.2.5 raeburn 8715: my $showdom = &display_domain_info($srch->{'srchdomain'});
8716: $response = '<span class="LC_warning">'.
1.181 raeburn 8717: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
8718: '</span><br />'.
8719: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
1.406.2.5 raeburn 8720: '<br />';
1.181 raeburn 8721: }
1.160 raeburn 8722: }
8723: }
1.179 raeburn 8724: return ($currstate,$response,$forcenewuser,\%srch_results);
1.160 raeburn 8725: }
8726:
1.406.2.3 raeburn 8727: sub domdirectorysrch_check {
8728: my ($srch) = @_;
8729: my $response;
8730: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
8731: ['directorysrch'],$srch->{'srchdomain'});
8732: my $showdom = &display_domain_info($srch->{'srchdomain'});
8733: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
8734: if ($dom_inst_srch{'directorysrch'}{'lcavailable'} eq '0') {
8735: return &mt('LON-CAPA directory search is not available in domain: [_1]',$showdom);
8736: }
8737: if ($dom_inst_srch{'directorysrch'}{'lclocalonly'}) {
8738: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
8739: return &mt('LON-CAPA directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
8740: }
8741: }
8742: }
8743: return 'ok';
8744: }
8745:
8746: sub instdirectorysrch_check {
1.160 raeburn 8747: my ($srch) = @_;
8748: my $can_search = 0;
8749: my $response;
8750: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
8751: ['directorysrch'],$srch->{'srchdomain'});
1.180 raeburn 8752: my $showdom = &display_domain_info($srch->{'srchdomain'});
1.160 raeburn 8753: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
8754: if (!$dom_inst_srch{'directorysrch'}{'available'}) {
1.180 raeburn 8755: return &mt('Institutional directory search is not available in domain: [_1]',$showdom);
1.160 raeburn 8756: }
8757: if ($dom_inst_srch{'directorysrch'}{'localonly'}) {
8758: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
1.180 raeburn 8759: return &mt('Institutional directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
1.160 raeburn 8760: }
8761: my @usertypes = split(/:/,$env{'environment.inststatus'});
8762: if (!@usertypes) {
8763: push(@usertypes,'default');
8764: }
8765: if (ref($dom_inst_srch{'directorysrch'}{'cansearch'}) eq 'ARRAY') {
8766: foreach my $type (@usertypes) {
8767: if (grep(/^\Q$type\E$/,@{$dom_inst_srch{'directorysrch'}{'cansearch'}})) {
8768: $can_search = 1;
8769: last;
8770: }
8771: }
8772: }
8773: if (!$can_search) {
8774: my ($insttypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($srch->{'srchdomain'});
8775: my @longtypes;
8776: foreach my $item (@usertypes) {
1.229 raeburn 8777: if (defined($insttypes->{$item})) {
8778: push (@longtypes,$insttypes->{$item});
8779: } elsif ($item eq 'default') {
8780: push (@longtypes,&mt('other'));
8781: }
1.160 raeburn 8782: }
8783: my $insttype_str = join(', ',@longtypes);
1.180 raeburn 8784: return &mt('Institutional directory search in domain: [_1] is not available to your user type: ',$showdom).$insttype_str;
1.229 raeburn 8785: }
1.160 raeburn 8786: } else {
8787: $can_search = 1;
8788: }
8789: } else {
1.180 raeburn 8790: return &mt('Institutional directory search has not been configured for domain: [_1]',$showdom);
1.160 raeburn 8791: }
8792: my %longtext = &Apache::lonlocal::texthash (
1.167 albertel 8793: uname => 'username',
1.160 raeburn 8794: lastfirst => 'last name, first name',
1.167 albertel 8795: lastname => 'last name',
1.172 raeburn 8796: contains => 'contains',
1.178 raeburn 8797: exact => 'as exact match to',
8798: begins => 'begins with',
1.160 raeburn 8799: );
8800: if ($can_search) {
8801: if (ref($dom_inst_srch{'directorysrch'}{'searchby'}) eq 'ARRAY') {
8802: if (!grep(/^\Q$srch->{'srchby'}\E$/,@{$dom_inst_srch{'directorysrch'}{'searchby'}})) {
1.180 raeburn 8803: return &mt('Institutional directory search in domain: [_1] is not available for searching by "[_2]"',$showdom,$longtext{$srch->{'srchby'}});
1.160 raeburn 8804: }
8805: } else {
1.180 raeburn 8806: return &mt('Institutional directory search in domain: [_1] is not available.', $showdom);
1.160 raeburn 8807: }
8808: }
8809: if ($can_search) {
1.178 raeburn 8810: if (ref($dom_inst_srch{'directorysrch'}{'searchtypes'}) eq 'ARRAY') {
8811: if (grep(/^\Q$srch->{'srchtype'}\E/,@{$dom_inst_srch{'directorysrch'}{'searchtypes'}})) {
8812: return 'ok';
8813: } else {
1.180 raeburn 8814: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 8815: }
8816: } else {
8817: if ((($dom_inst_srch{'directorysrch'}{'searchtypes'} eq 'specify') &&
8818: ($srch->{'srchtype'} eq 'exact' || $srch->{'srchtype'} eq 'contains')) ||
8819: ($dom_inst_srch{'directorysrch'}{'searchtypes'} eq $srch->{'srchtype'})) {
8820: return 'ok';
8821: } else {
1.180 raeburn 8822: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 8823: }
1.160 raeburn 8824: }
8825: }
8826: }
8827:
8828: sub get_courseusers {
8829: my %advhash;
1.167 albertel 8830: my $classlist = &Apache::loncoursedata::get_classlist();
1.160 raeburn 8831: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles();
8832: foreach my $role (sort(keys(%coursepersonnel))) {
8833: foreach my $user (split(/\,/,$coursepersonnel{$role})) {
1.167 albertel 8834: if (!exists($classlist->{$user})) {
8835: $classlist->{$user} = [];
8836: }
1.160 raeburn 8837: }
8838: }
1.167 albertel 8839: return $classlist;
1.160 raeburn 8840: }
8841:
8842: sub build_search_response {
1.221 raeburn 8843: my ($context,$srch,%srch_results) = @_;
1.179 raeburn 8844: my ($currstate,$response,$forcenewuser);
1.160 raeburn 8845: my %names = (
1.330 bisitz 8846: 'uname' => 'username',
8847: 'lastname' => 'last name',
1.160 raeburn 8848: 'lastfirst' => 'last name, first name',
1.330 bisitz 8849: 'crs' => 'this course',
8850: 'dom' => 'LON-CAPA domain',
8851: 'instd' => 'the institutional directory for domain',
1.160 raeburn 8852: );
8853:
8854: my %single = (
1.180 raeburn 8855: begins => 'A match',
1.160 raeburn 8856: contains => 'A match',
1.180 raeburn 8857: exact => 'An exact match',
1.160 raeburn 8858: );
8859: my %nomatch = (
1.180 raeburn 8860: begins => 'No match',
1.160 raeburn 8861: contains => 'No match',
1.180 raeburn 8862: exact => 'No exact match',
1.160 raeburn 8863: );
8864: if (keys(%srch_results) > 1) {
1.179 raeburn 8865: $currstate = 'select';
1.160 raeburn 8866: } else {
8867: if (keys(%srch_results) == 1) {
1.406.2.5 raeburn 8868: if ($env{'form.action'} eq 'accesslogs') {
8869: $currstate = 'activity';
8870: } else {
8871: $currstate = 'modify';
8872: }
1.180 raeburn 8873: $response = &mt("$single{$srch->{'srchtype'}} was found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}.",$srch->{'srchterm'});
8874: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 8875: $response .= ': '.&display_domain_info($srch->{'srchdomain'});
1.180 raeburn 8876: }
1.330 bisitz 8877: } else { # Search has nothing found. Prepare message to user.
8878: $response = '<span class="LC_warning">';
1.180 raeburn 8879: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 8880: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}: [_2]",
8881: '<b>'.$srch->{'srchterm'}.'</b>',
8882: &display_domain_info($srch->{'srchdomain'}));
8883: } else {
8884: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}.",
8885: '<b>'.$srch->{'srchterm'}.'</b>');
1.180 raeburn 8886: }
8887: $response .= '</span>';
1.330 bisitz 8888:
1.160 raeburn 8889: if ($srch->{'srchin'} ne 'alc') {
8890: $forcenewuser = 1;
8891: my $cansrchinst = 0;
1.406.2.14 raeburn 8892: if (($srch->{'srchdomain'}) && ($env{'form.action'} ne 'accesslogs')) {
1.160 raeburn 8893: my %domconfig = &Apache::lonnet::get_dom('configuration',['directorysrch'],$srch->{'srchdomain'});
8894: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
8895: if ($domconfig{'directorysrch'}{'available'}) {
8896: $cansrchinst = 1;
8897: }
8898: }
8899: }
1.180 raeburn 8900: if ((($srch->{'srchby'} eq 'lastfirst') ||
8901: ($srch->{'srchby'} eq 'lastname')) &&
8902: ($srch->{'srchin'} eq 'dom')) {
8903: if ($cansrchinst) {
8904: $response .= '<br />'.&mt('You may want to broaden your search to a search of the institutional directory for the domain.');
1.160 raeburn 8905: }
8906: }
1.180 raeburn 8907: if ($srch->{'srchin'} eq 'crs') {
8908: $response .= '<br />'.&mt('You may want to broaden your search to the selected LON-CAPA domain.');
8909: }
8910: }
1.305 raeburn 8911: my $createdom = $env{'request.role.domain'};
8912: if ($context eq 'requestcrs') {
8913: if ($env{'form.coursedom'} ne '') {
8914: $createdom = $env{'form.coursedom'};
8915: }
8916: }
1.406.2.5 raeburn 8917: unless (($env{'form.action'} eq 'accesslogs') || (($srch->{'srchby'} eq 'uname') && ($srch->{'srchin'} eq 'dom') &&
8918: ($srch->{'srchtype'} eq 'exact') && ($srch->{'srchdomain'} eq $createdom))) {
1.221 raeburn 8919: my $cancreate =
1.305 raeburn 8920: &Apache::lonuserutils::can_create_user($createdom,$context);
8921: my $targetdom = '<span class="LC_cusr_emph">'.$createdom.'</span>';
1.221 raeburn 8922: if ($cancreate) {
1.305 raeburn 8923: my $showdom = &display_domain_info($createdom);
1.266 bisitz 8924: $response .= '<br /><br />'
8925: .'<b>'.&mt('To add a new user:').'</b>'
1.305 raeburn 8926: .'<br />';
8927: if ($context eq 'requestcrs') {
8928: $response .= &mt("(You can only define new users in the new course's domain - [_1])",$targetdom);
8929: } else {
8930: $response .= &mt("(You can only create new users in your current role's domain - [_1])",$targetdom);
8931: }
8932: $response .='<ul><li>'
1.266 bisitz 8933: .&mt("Set 'Domain/institution to search' to: [_1]",'<span class="LC_cusr_emph">'.$showdom.'</span>')
8934: .'</li><li>'
8935: .&mt("Set 'Search criteria' to: [_1]username is ..... in selected LON-CAPA domain[_2]",'<span class="LC_cusr_emph">','</span>')
8936: .'</li><li>'
8937: .&mt('Provide the proposed username')
8938: .'</li><li>'
8939: .&mt("Click 'Search'")
8940: .'</li></ul><br />';
1.221 raeburn 8941: } else {
1.406.2.7 raeburn 8942: unless (($context eq 'domain') && ($env{'form.action'} eq 'singleuser')) {
8943: my $helplink = ' href="javascript:helpMenu('."'display'".')"';
8944: $response .= '<br /><br />';
8945: if ($context eq 'requestcrs') {
8946: $response .= &mt("You are not authorized to define new users in the new course's domain - [_1].",$targetdom);
8947: } else {
8948: $response .= &mt("You are not authorized to create new users in your current role's domain - [_1].",$targetdom);
8949: }
8950: $response .= '<br />'
8951: .&mt('Please contact the [_1]helpdesk[_2] if you need to create a new user.'
8952: ,' <a'.$helplink.'>'
8953: ,'</a>')
8954: .'<br />';
1.305 raeburn 8955: }
1.221 raeburn 8956: }
1.160 raeburn 8957: }
8958: }
8959: }
1.179 raeburn 8960: return ($currstate,$response,$forcenewuser);
1.160 raeburn 8961: }
8962:
1.180 raeburn 8963: sub display_domain_info {
8964: my ($dom) = @_;
8965: my $output = $dom;
8966: if ($dom ne '') {
8967: my $domdesc = &Apache::lonnet::domain($dom,'description');
8968: if ($domdesc ne '') {
8969: $output .= ' <span class="LC_cusr_emph">('.$domdesc.')</span>';
8970: }
8971: }
8972: return $output;
8973: }
8974:
1.160 raeburn 8975: sub crumb_utilities {
8976: my %elements = (
8977: crtuser => {
8978: srchterm => 'text',
1.172 raeburn 8979: srchin => 'selectbox',
1.160 raeburn 8980: srchby => 'selectbox',
8981: srchtype => 'selectbox',
8982: srchdomain => 'selectbox',
8983: },
1.207 raeburn 8984: crtusername => {
8985: srchterm => 'text',
8986: srchdomain => 'selectbox',
8987: },
1.160 raeburn 8988: docustom => {
8989: rolename => 'selectbox',
8990: newrolename => 'textbox',
8991: },
1.179 raeburn 8992: studentform => {
8993: srchterm => 'text',
8994: srchin => 'selectbox',
8995: srchby => 'selectbox',
8996: srchtype => 'selectbox',
8997: srchdomain => 'selectbox',
8998: },
1.160 raeburn 8999: );
9000:
9001: my $jsback .= qq|
9002: function backPage(formname,prevphase,prevstate) {
1.211 raeburn 9003: if (typeof prevphase == 'undefined') {
9004: formname.phase.value = '';
9005: }
9006: else {
9007: formname.phase.value = prevphase;
9008: }
9009: if (typeof prevstate == 'undefined') {
9010: formname.currstate.value = '';
9011: }
9012: else {
9013: formname.currstate.value = prevstate;
9014: }
1.160 raeburn 9015: formname.submit();
9016: }
9017: |;
9018: return ($jsback,\%elements);
9019: }
9020:
1.26 matthew 9021: sub course_level_table {
1.375 raeburn 9022: my ($inccourses,$showcredits,$defaultcredits) = @_;
9023: return unless (ref($inccourses) eq 'HASH');
1.26 matthew 9024: my $table = '';
1.62 www 9025: # Custom Roles?
9026:
1.190 raeburn 9027: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.89 raeburn 9028: my %lt=&Apache::lonlocal::texthash(
9029: 'exs' => "Existing sections",
9030: 'new' => "Define new section",
9031: 'ssd' => "Set Start Date",
9032: 'sed' => "Set End Date",
1.131 raeburn 9033: 'crl' => "Course Level",
1.89 raeburn 9034: 'act' => "Activate",
9035: 'rol' => "Role",
9036: 'ext' => "Extent",
1.113 raeburn 9037: 'grs' => "Section",
1.375 raeburn 9038: 'crd' => "Credits",
1.89 raeburn 9039: 'sta' => "Start",
9040: 'end' => "End"
9041: );
1.62 www 9042:
1.375 raeburn 9043: foreach my $protectedcourse (sort(keys(%{$inccourses}))) {
1.135 raeburn 9044: my $thiscourse=$protectedcourse;
1.26 matthew 9045: $thiscourse=~s:_:/:g;
9046: my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
1.365 raeburn 9047: my $isowner = &Apache::lonuserutils::is_courseowner($protectedcourse,$coursedata{'internal.courseowner'});
1.26 matthew 9048: my $area=$coursedata{'description'};
1.321 raeburn 9049: my $crstype=$coursedata{'type'};
1.135 raeburn 9050: if (!defined($area)) { $area=&mt('Unavailable course').': '.$protectedcourse; }
1.89 raeburn 9051: my ($domain,$cnum)=split(/\//,$thiscourse);
1.115 albertel 9052: my %sections_count;
1.101 albertel 9053: if (defined($env{'request.course.id'})) {
9054: if ($env{'request.course.id'} eq $domain.'_'.$cnum) {
1.115 albertel 9055: %sections_count =
9056: &Apache::loncommon::get_sections($domain,$cnum);
1.92 raeburn 9057: }
9058: }
1.321 raeburn 9059: my @roles = &Apache::lonuserutils::roles_by_context('course','',$crstype);
1.213 raeburn 9060: foreach my $role (@roles) {
1.321 raeburn 9061: my $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.329 raeburn 9062: if ((&Apache::lonnet::allowed('c'.$role,$thiscourse)) ||
9063: ((($role eq 'cc') || ($role eq 'co')) && ($isowner))) {
1.221 raeburn 9064: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 9065: $plrole,\%sections_count,\%lt,
1.402 raeburn 9066: $showcredits,$defaultcredits,$crstype);
1.221 raeburn 9067: } elsif ($env{'request.course.sec'} ne '') {
9068: if (&Apache::lonnet::allowed('c'.$role,$thiscourse.'/'.
9069: $env{'request.course.sec'})) {
9070: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 9071: $plrole,\%sections_count,\%lt,
1.402 raeburn 9072: $showcredits,$defaultcredits,$crstype);
1.26 matthew 9073: }
9074: }
9075: }
1.221 raeburn 9076: if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
1.324 raeburn 9077: foreach my $cust (sort(keys(%customroles))) {
9078: next if ($crstype eq 'Community' && $customroles{$cust} =~ /bre\&S/);
1.221 raeburn 9079: my $role = 'cr_cr_'.$env{'user.domain'}.'_'.$env{'user.name'}.'_'.$cust;
9080: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.402 raeburn 9081: $cust,\%sections_count,\%lt,
9082: $showcredits,$defaultcredits,$crstype);
1.221 raeburn 9083: }
1.62 www 9084: }
1.26 matthew 9085: }
9086: return '' if ($table eq ''); # return nothing if there is nothing
9087: # in the table
1.188 raeburn 9088: my $result;
9089: if (!$env{'request.course.id'}) {
9090: $result = '<h4>'.$lt{'crl'}.'</h4>'."\n";
9091: }
9092: $result .=
1.136 raeburn 9093: &Apache::loncommon::start_data_table().
9094: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 9095: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
1.402 raeburn 9096: '<th>'.$lt{'ext'}.'</th><th>'."\n";
9097: if ($showcredits) {
9098: $result .= $lt{'crd'}.'</th>';
9099: }
9100: $result .=
1.375 raeburn 9101: '<th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th>'."\n".
9102: '<th>'.$lt{'end'}.'</th>'.
1.136 raeburn 9103: &Apache::loncommon::end_data_table_header_row().
9104: $table.
9105: &Apache::loncommon::end_data_table();
1.26 matthew 9106: return $result;
9107: }
1.88 raeburn 9108:
1.221 raeburn 9109: sub course_level_row {
1.375 raeburn 9110: my ($protectedcourse,$role,$area,$domain,$plrole,$sections_count,
1.402 raeburn 9111: $lt,$showcredits,$defaultcredits,$crstype) = @_;
1.375 raeburn 9112: my $creditem;
1.222 raeburn 9113: my $row = &Apache::loncommon::start_data_table_row().
9114: ' <td><input type="checkbox" name="act_'.
9115: $protectedcourse.'_'.$role.'" /></td>'."\n".
9116: ' <td>'.$plrole.'</td>'."\n".
9117: ' <td>'.$area.'<br />Domain: '.$domain.'</td>'."\n";
1.402 raeburn 9118: if (($showcredits) && ($role eq 'st') && ($crstype eq 'Course')) {
1.375 raeburn 9119: $row .=
9120: '<td><input type="text" name="credits_'.$protectedcourse.'_'.
9121: $role.'" size="3" value="'.$defaultcredits.'" /></td>';
9122: } else {
9123: $row .= '<td> </td>';
9124: }
1.322 raeburn 9125: if (($role eq 'cc') || ($role eq 'co')) {
1.222 raeburn 9126: $row .= '<td> </td>';
1.221 raeburn 9127: } elsif ($env{'request.course.sec'} ne '') {
1.222 raeburn 9128: $row .= ' <td><input type="hidden" value="'.
9129: $env{'request.course.sec'}.'" '.
9130: 'name="sec_'.$protectedcourse.'_'.$role.'" />'.
9131: $env{'request.course.sec'}.'</td>';
1.221 raeburn 9132: } else {
9133: if (ref($sections_count) eq 'HASH') {
9134: my $currsec =
9135: &Apache::lonuserutils::course_sections($sections_count,
9136: $protectedcourse.'_'.$role);
1.222 raeburn 9137: $row .= '<td><table class="LC_createuser">'."\n".
9138: '<tr class="LC_section_row">'."\n".
9139: ' <td valign="top">'.$lt->{'exs'}.'<br />'.
9140: $currsec.'</td>'."\n".
9141: ' <td> </td>'."\n".
9142: ' <td valign="top"> '.$lt->{'new'}.'<br />'.
1.221 raeburn 9143: '<input type="text" name="newsec_'.$protectedcourse.'_'.$role.
9144: '" value="" />'.
9145: '<input type="hidden" '.
9146: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n".
1.222 raeburn 9147: '</tr></table></td>'."\n";
1.221 raeburn 9148: } else {
1.222 raeburn 9149: $row .= '<td><input type="text" size="10" '.
1.375 raeburn 9150: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n";
1.221 raeburn 9151: }
9152: }
1.222 raeburn 9153: $row .= <<ENDTIMEENTRY;
9154: <td><input type="hidden" name="start_$protectedcourse\_$role" value="" />
1.221 raeburn 9155: <a href=
9156: "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 9157: <td><input type="hidden" name="end_$protectedcourse\_$role" value="" />
1.221 raeburn 9158: <a href=
9159: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$role.value,'end_$protectedcourse\_$role','cu.pres','dateset')">$lt->{'sed'}</a></td>
9160: ENDTIMEENTRY
1.222 raeburn 9161: $row .= &Apache::loncommon::end_data_table_row();
9162: return $row;
1.221 raeburn 9163: }
9164:
1.88 raeburn 9165: sub course_level_dc {
1.375 raeburn 9166: my ($dcdom,$showcredits) = @_;
1.190 raeburn 9167: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.213 raeburn 9168: my @roles = &Apache::lonuserutils::roles_by_context('course');
1.88 raeburn 9169: my $hiddenitems = '<input type="hidden" name="dcdomain" value="'.$dcdom.'" />'.
9170: '<input type="hidden" name="origdom" value="'.$dcdom.'" />'.
1.133 raeburn 9171: '<input type="hidden" name="dccourse" value="" />';
1.355 www 9172: my $courseform=&Apache::loncommon::selectcourse_link
1.356 raeburn 9173: ('cu','dccourse','dcdomain','coursedesc',undef,undef,'Select','crstype');
1.375 raeburn 9174: my $credit_elem;
9175: if ($showcredits) {
9176: $credit_elem = 'credits';
9177: }
9178: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,'currsec','cu','role','Course/Community Browser',$credit_elem);
1.88 raeburn 9179: my %lt=&Apache::lonlocal::texthash(
9180: 'rol' => "Role",
1.113 raeburn 9181: 'grs' => "Section",
1.88 raeburn 9182: 'exs' => "Existing sections",
9183: 'new' => "Define new section",
9184: 'sta' => "Start",
9185: 'end' => "End",
9186: 'ssd' => "Set Start Date",
1.355 www 9187: 'sed' => "Set End Date",
1.375 raeburn 9188: 'scc' => "Course/Community",
9189: 'crd' => "Credits",
1.88 raeburn 9190: );
1.323 raeburn 9191: my $header = '<h4>'.&mt('Course/Community Level').'</h4>'.
1.136 raeburn 9192: &Apache::loncommon::start_data_table().
9193: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 9194: '<th>'.$lt{'scc'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
1.397 bisitz 9195: '<th>'.$lt{'grs'}.'</th>'."\n";
9196: $header .= '<th>'.$lt{'crd'}.'</th>'."\n" if ($showcredits);
9197: $header .= '<th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'."\n".
1.136 raeburn 9198: &Apache::loncommon::end_data_table_header_row();
1.143 raeburn 9199: my $otheritems = &Apache::loncommon::start_data_table_row()."\n".
1.356 raeburn 9200: '<td><br /><span class="LC_nobreak"><input type="text" name="coursedesc" value="" onfocus="this.blur();opencrsbrowser('."'cu','dccourse','dcdomain','coursedesc','','','','crstype'".')" />'.
9201: $courseform.(' ' x4).'</span></td>'."\n".
1.389 bisitz 9202: '<td valign="top"><br /><select name="role">'."\n";
1.213 raeburn 9203: foreach my $role (@roles) {
1.135 raeburn 9204: my $plrole=&Apache::lonnet::plaintext($role);
1.389 bisitz 9205: $otheritems .= ' <option value="'.$role.'">'.$plrole.'</option>';
1.88 raeburn 9206: }
1.404 raeburn 9207: if ( keys(%customroles) > 0) {
9208: foreach my $cust (sort(keys(%customroles))) {
1.101 albertel 9209: my $custrole='cr_cr_'.$env{'user.domain'}.
1.135 raeburn 9210: '_'.$env{'user.name'}.'_'.$cust;
1.389 bisitz 9211: $otheritems .= ' <option value="'.$custrole.'">'.$cust.'</option>';
1.88 raeburn 9212: }
9213: }
9214: $otheritems .= '</select></td><td>'.
9215: '<table border="0" cellspacing="0" cellpadding="0">'.
9216: '<tr><td valign="top"><b>'.$lt{'exs'}.'</b><br /><select name="currsec">'.
1.389 bisitz 9217: ' <option value=""><--'.&mt('Pick course first').'</option></select></td>'.
1.88 raeburn 9218: '<td> </td>'.
9219: '<td valign="top"> <b>'.$lt{'new'}.'</b><br />'.
1.113 raeburn 9220: '<input type="text" name="newsec" value="" />'.
1.237 raeburn 9221: '<input type="hidden" name="section" value="" />'.
1.323 raeburn 9222: '<input type="hidden" name="groups" value="" />'.
9223: '<input type="hidden" name="crstype" value="" /></td>'.
1.375 raeburn 9224: '</tr></table></td>'."\n";
9225: if ($showcredits) {
9226: $otheritems .= '<td><br />'."\n".
1.397 bisitz 9227: '<input type="text" size="3" name="credits" value="" /></td>'."\n";
1.375 raeburn 9228: }
1.88 raeburn 9229: $otheritems .= <<ENDTIMEENTRY;
1.323 raeburn 9230: <td><br /><input type="hidden" name="start" value='' />
1.88 raeburn 9231: <a href=
9232: "javascript:pjump('date_start','Start Date',document.cu.start.value,'start','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.323 raeburn 9233: <td><br /><input type="hidden" name="end" value='' />
1.88 raeburn 9234: <a href=
9235: "javascript:pjump('date_end','End Date',document.cu.end.value,'end','cu.pres','dateset')">$lt{'sed'}</a></td>
9236: ENDTIMEENTRY
1.136 raeburn 9237: $otheritems .= &Apache::loncommon::end_data_table_row().
9238: &Apache::loncommon::end_data_table()."\n";
1.88 raeburn 9239: return $cb_jscript.$header.$hiddenitems.$otheritems;
9240: }
9241:
1.237 raeburn 9242: sub update_selfenroll_config {
1.400 raeburn 9243: my ($r,$cid,$cdom,$cnum,$context,$crstype,$currsettings) = @_;
1.398 raeburn 9244: return unless (ref($currsettings) eq 'HASH');
9245: my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles();
9246: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
1.237 raeburn 9247: my (%changes,%warning);
1.241 raeburn 9248: my $curr_types;
1.400 raeburn 9249: my %noedit;
9250: unless ($context eq 'domain') {
9251: %noedit = &get_noedit_fields($cdom,$cnum,$crstype,$row);
9252: }
1.237 raeburn 9253: if (ref($row) eq 'ARRAY') {
9254: foreach my $item (@{$row}) {
1.400 raeburn 9255: next if ($noedit{$item});
1.237 raeburn 9256: if ($item eq 'enroll_dates') {
9257: my (%currenrolldate,%newenrolldate);
9258: foreach my $type ('start','end') {
1.398 raeburn 9259: $currenrolldate{$type} = $currsettings->{'selfenroll_'.$type.'_date'};
1.237 raeburn 9260: $newenrolldate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_date');
9261: if ($newenrolldate{$type} ne $currenrolldate{$type}) {
9262: $changes{'internal.selfenroll_'.$type.'_date'} = $newenrolldate{$type};
9263: }
9264: }
9265: } elsif ($item eq 'access_dates') {
9266: my (%currdate,%newdate);
9267: foreach my $type ('start','end') {
1.398 raeburn 9268: $currdate{$type} = $currsettings->{'selfenroll_'.$type.'_access'};
1.237 raeburn 9269: $newdate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_access');
9270: if ($newdate{$type} ne $currdate{$type}) {
9271: $changes{'internal.selfenroll_'.$type.'_access'} = $newdate{$type};
9272: }
9273: }
1.241 raeburn 9274: } elsif ($item eq 'types') {
1.398 raeburn 9275: $curr_types = $currsettings->{'selfenroll_'.$item};
1.241 raeburn 9276: if ($env{'form.selfenroll_all'}) {
9277: if ($curr_types ne '*') {
9278: $changes{'internal.selfenroll_types'} = '*';
9279: } else {
9280: next;
9281: }
9282: } else {
1.249 raeburn 9283: my %currdoms;
1.241 raeburn 9284: my @entries = split(/;/,$curr_types);
9285: my @deletedoms = &Apache::loncommon::get_env_multiple('form.selfenroll_delete');
1.249 raeburn 9286: my @activations = &Apache::loncommon::get_env_multiple('form.selfenroll_activate');
1.241 raeburn 9287: my $newnum = 0;
1.249 raeburn 9288: my @latesttypes;
9289: foreach my $num (@activations) {
9290: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$num);
9291: if (@types > 0) {
1.241 raeburn 9292: @types = sort(@types);
9293: my $typestr = join(',',@types);
1.249 raeburn 9294: my $typedom = $env{'form.selfenroll_dom_'.$num};
9295: $latesttypes[$newnum] = $typedom.':'.$typestr;
9296: $currdoms{$typedom} = 1;
1.241 raeburn 9297: $newnum ++;
9298: }
9299: }
1.338 raeburn 9300: for (my $j=0; $j<$env{'form.selfenroll_types_total'}; $j++) {
9301: if ((!grep(/^$j$/,@deletedoms)) && (!grep(/^$j$/,@activations))) {
1.249 raeburn 9302: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$j);
9303: if (@types > 0) {
9304: @types = sort(@types);
9305: my $typestr = join(',',@types);
9306: my $typedom = $env{'form.selfenroll_dom_'.$j};
9307: $latesttypes[$newnum] = $typedom.':'.$typestr;
9308: $currdoms{$typedom} = 1;
9309: $newnum ++;
9310: }
9311: }
9312: }
9313: if ($env{'form.selfenroll_newdom'} ne '') {
9314: my $typedom = $env{'form.selfenroll_newdom'};
9315: if ((!defined($currdoms{$typedom})) &&
9316: (&Apache::lonnet::domain($typedom) ne '')) {
9317: my $typestr;
9318: my ($othertitle,$usertypes,$types) =
9319: &Apache::loncommon::sorted_inst_types($typedom);
9320: my $othervalue = 'any';
9321: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
9322: if (@{$types} > 0) {
1.257 raeburn 9323: my @esc_types = map { &escape($_); } @{$types};
1.249 raeburn 9324: $othervalue = 'other';
1.258 raeburn 9325: $typestr = join(',',(@esc_types,$othervalue));
1.249 raeburn 9326: }
9327: $typestr = $othervalue;
9328: } else {
9329: $typestr = $othervalue;
9330: }
9331: $latesttypes[$newnum] = $typedom.':'.$typestr;
9332: $newnum ++ ;
9333: }
9334: }
1.241 raeburn 9335: my $selfenroll_types = join(';',@latesttypes);
9336: if ($selfenroll_types ne $curr_types) {
9337: $changes{'internal.selfenroll_types'} = $selfenroll_types;
9338: }
9339: }
1.276 raeburn 9340: } elsif ($item eq 'limit') {
9341: my $newlimit = $env{'form.selfenroll_limit'};
9342: my $newcap = $env{'form.selfenroll_cap'};
9343: $newcap =~s/\s+//g;
1.398 raeburn 9344: my $currlimit = $currsettings->{'selfenroll_limit'};
1.276 raeburn 9345: $currlimit = 'none' if ($currlimit eq '');
1.398 raeburn 9346: my $currcap = $currsettings->{'selfenroll_cap'};
1.276 raeburn 9347: if ($newlimit ne $currlimit) {
9348: if ($newlimit ne 'none') {
9349: if ($newcap =~ /^\d+$/) {
9350: if ($newcap ne $currcap) {
9351: $changes{'internal.selfenroll_cap'} = $newcap;
9352: }
9353: $changes{'internal.selfenroll_limit'} = $newlimit;
9354: } else {
1.398 raeburn 9355: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.
9356: &mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
1.276 raeburn 9357: }
9358: } elsif ($currcap ne '') {
9359: $changes{'internal.selfenroll_cap'} = '';
9360: $changes{'internal.selfenroll_limit'} = $newlimit;
9361: }
9362: } elsif ($currlimit ne 'none') {
9363: if ($newcap =~ /^\d+$/) {
9364: if ($newcap ne $currcap) {
9365: $changes{'internal.selfenroll_cap'} = $newcap;
9366: }
9367: } else {
1.398 raeburn 9368: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.
9369: &mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
1.276 raeburn 9370: }
9371: }
9372: } elsif ($item eq 'approval') {
9373: my (@currnotified,@newnotified);
1.398 raeburn 9374: my $currapproval = $currsettings->{'selfenroll_approval'};
9375: my $currnotifylist = $currsettings->{'selfenroll_notifylist'};
1.276 raeburn 9376: if ($currnotifylist ne '') {
9377: @currnotified = split(/,/,$currnotifylist);
9378: @currnotified = sort(@currnotified);
9379: }
9380: my $newapproval = $env{'form.selfenroll_approval'};
9381: @newnotified = &Apache::loncommon::get_env_multiple('form.selfenroll_notify');
9382: @newnotified = sort(@newnotified);
9383: if ($newapproval ne $currapproval) {
9384: $changes{'internal.selfenroll_approval'} = $newapproval;
9385: if (!$newapproval) {
9386: if ($currnotifylist ne '') {
9387: $changes{'internal.selfenroll_notifylist'} = '';
9388: }
9389: } else {
9390: my @differences =
1.295 raeburn 9391: &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 9392: if (@differences > 0) {
9393: if (@newnotified > 0) {
9394: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
9395: } else {
9396: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
9397: }
9398: }
9399: }
9400: } else {
1.295 raeburn 9401: my @differences = &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 9402: if (@differences > 0) {
9403: if (@newnotified > 0) {
9404: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
9405: } else {
9406: $changes{'internal.selfenroll_notifylist'} = '';
9407: }
9408: }
9409: }
1.237 raeburn 9410: } else {
1.398 raeburn 9411: my $curr_val = $currsettings->{'selfenroll_'.$item};
1.237 raeburn 9412: my $newval = $env{'form.selfenroll_'.$item};
9413: if ($item eq 'section') {
9414: $newval = $env{'form.sections'};
1.241 raeburn 9415: if (defined($curr_groups{$newval})) {
1.237 raeburn 9416: $newval = $curr_val;
1.398 raeburn 9417: $warning{$item} = &mt('Section for self-enrolled users unchanged as the proposed section is a group').'<br />'.
9418: &mt('Group names and section names must be distinct');
1.237 raeburn 9419: } elsif ($newval eq 'all') {
9420: $newval = $curr_val;
1.274 bisitz 9421: $warning{$item} = &mt('Section for self-enrolled users unchanged, as "all" is a reserved section name.');
1.237 raeburn 9422: }
9423: if ($newval eq '') {
9424: $newval = 'none';
9425: }
9426: }
9427: if ($newval ne $curr_val) {
9428: $changes{'internal.selfenroll_'.$item} = $newval;
9429: }
1.241 raeburn 9430: }
1.237 raeburn 9431: }
9432: if (keys(%warning) > 0) {
9433: foreach my $item (@{$row}) {
9434: if (exists($warning{$item})) {
9435: $r->print($warning{$item}.'<br />');
9436: }
9437: }
9438: }
9439: if (keys(%changes) > 0) {
9440: my $putresult = &Apache::lonnet::put('environment',\%changes,$cdom,$cnum);
9441: if ($putresult eq 'ok') {
9442: if ((exists($changes{'internal.selfenroll_types'})) ||
9443: (exists($changes{'internal.selfenroll_start_date'})) ||
9444: (exists($changes{'internal.selfenroll_end_date'}))) {
9445: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',
9446: $cnum,undef,undef,'Course');
9447: my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
1.398 raeburn 9448: if (ref($crsinfo{$cid}) eq 'HASH') {
1.237 raeburn 9449: foreach my $item ('selfenroll_types','selfenroll_start_date','selfenroll_end_date') {
9450: if (exists($changes{'internal.'.$item})) {
1.398 raeburn 9451: $crsinfo{$cid}{$item} = $changes{'internal.'.$item};
1.237 raeburn 9452: }
9453: }
9454: my $crsputresult =
9455: &Apache::lonnet::courseidput($cdom,\%crsinfo,
9456: $chome,'notime');
9457: }
9458: }
9459: $r->print(&mt('The following changes were made to self-enrollment settings:').'<ul>');
9460: foreach my $item (@{$row}) {
9461: my $title = $item;
9462: if (ref($lt) eq 'HASH') {
9463: $title = $lt->{$item};
9464: }
9465: if ($item eq 'enroll_dates') {
9466: foreach my $type ('start','end') {
9467: if (exists($changes{'internal.selfenroll_'.$type.'_date'})) {
9468: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_date'});
1.244 bisitz 9469: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 9470: $title,$type,$newdate).'</li>');
9471: }
9472: }
9473: } elsif ($item eq 'access_dates') {
9474: foreach my $type ('start','end') {
9475: if (exists($changes{'internal.selfenroll_'.$type.'_access'})) {
9476: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_access'});
1.244 bisitz 9477: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 9478: $title,$type,$newdate).'</li>');
9479: }
9480: }
1.276 raeburn 9481: } elsif ($item eq 'limit') {
9482: if ((exists($changes{'internal.selfenroll_limit'})) ||
9483: (exists($changes{'internal.selfenroll_cap'}))) {
9484: my ($newval,$newcap);
9485: if ($changes{'internal.selfenroll_cap'} ne '') {
9486: $newcap = $changes{'internal.selfenroll_cap'}
9487: } else {
1.398 raeburn 9488: $newcap = $currsettings->{'selfenroll_cap'};
1.276 raeburn 9489: }
9490: if ($changes{'internal.selfenroll_limit'} eq 'none') {
9491: $newval = &mt('No limit');
9492: } elsif ($changes{'internal.selfenroll_limit'} eq
9493: 'allstudents') {
9494: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
9495: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
9496: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
9497: } else {
1.398 raeburn 9498: my $currlimit = $currsettings->{'selfenroll_limit'};
1.276 raeburn 9499: if ($currlimit eq 'allstudents') {
9500: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
9501: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
1.308 raeburn 9502: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
1.276 raeburn 9503: }
9504: }
9505: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
9506: }
9507: } elsif ($item eq 'approval') {
9508: if ((exists($changes{'internal.selfenroll_approval'})) ||
9509: (exists($changes{'internal.selfenroll_notifylist'}))) {
1.398 raeburn 9510: my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs();
1.276 raeburn 9511: my ($newval,$newnotify);
9512: if (exists($changes{'internal.selfenroll_notifylist'})) {
9513: $newnotify = $changes{'internal.selfenroll_notifylist'};
9514: } else {
1.398 raeburn 9515: $newnotify = $currsettings->{'selfenroll_notifylist'};
1.276 raeburn 9516: }
1.398 raeburn 9517: if (exists($changes{'internal.selfenroll_approval'})) {
9518: if ($changes{'internal.selfenroll_approval'} !~ /^[012]$/) {
9519: $changes{'internal.selfenroll_approval'} = '0';
9520: }
9521: $newval = $selfdescs{'approval'}{$changes{'internal.selfenroll_approval'}};
1.276 raeburn 9522: } else {
1.398 raeburn 9523: my $currapproval = $currsettings->{'selfenroll_approval'};
9524: if ($currapproval !~ /^[012]$/) {
9525: $currapproval = 0;
1.276 raeburn 9526: }
1.398 raeburn 9527: $newval = $selfdescs{'approval'}{$currapproval};
1.276 raeburn 9528: }
9529: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval));
9530: if ($newnotify) {
1.277 raeburn 9531: $r->print('<br />'.&mt('The following will be notified when an enrollment request needs approval, or has been approved: [_1].',$newnotify));
1.276 raeburn 9532: } else {
1.277 raeburn 9533: $r->print('<br />'.&mt('No notifications sent when an enrollment request needs approval, or has been approved.'));
1.276 raeburn 9534: }
9535: $r->print('</li>'."\n");
9536: }
1.237 raeburn 9537: } else {
9538: if (exists($changes{'internal.selfenroll_'.$item})) {
1.241 raeburn 9539: my $newval = $changes{'internal.selfenroll_'.$item};
9540: if ($item eq 'types') {
9541: if ($newval eq '') {
9542: $newval = &mt('None');
9543: } elsif ($newval eq '*') {
9544: $newval = &mt('Any user in any domain');
9545: }
1.245 raeburn 9546: } elsif ($item eq 'registered') {
9547: if ($newval eq '1') {
9548: $newval = &mt('Yes');
9549: } elsif ($newval eq '0') {
9550: $newval = &mt('No');
9551: }
1.241 raeburn 9552: }
1.244 bisitz 9553: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
1.237 raeburn 9554: }
9555: }
9556: }
9557: $r->print('</ul>');
1.398 raeburn 9558: if ($env{'course.'.$cid.'.description'} ne '') {
9559: my %newenvhash;
9560: foreach my $key (keys(%changes)) {
9561: $newenvhash{'course.'.$cid.'.'.$key} = $changes{$key};
9562: }
9563: &Apache::lonnet::appenv(\%newenvhash);
1.237 raeburn 9564: }
9565: } else {
1.398 raeburn 9566: $r->print(&mt('An error occurred when saving changes to self-enrollment settings in this course.').'<br />'.
9567: &mt('The error was: [_1].',$putresult));
1.237 raeburn 9568: }
9569: } else {
1.249 raeburn 9570: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.237 raeburn 9571: }
9572: } else {
1.249 raeburn 9573: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.241 raeburn 9574: }
1.406.2.21! raeburn 9575: my $visactions = &cat_visibility($cdom);
1.400 raeburn 9576: my ($cathash,%cattype);
9577: my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
9578: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
9579: $cathash = $domconfig{'coursecategories'}{'cats'};
9580: $cattype{'auth'} = $domconfig{'coursecategories'}{'auth'};
9581: $cattype{'unauth'} = $domconfig{'coursecategories'}{'unauth'};
9582: } else {
9583: $cathash = {};
9584: $cattype{'auth'} = 'std';
9585: $cattype{'unauth'} = 'std';
9586: }
9587: if (($cattype{'auth'} eq 'none') && ($cattype{'unauth'} eq 'none')) {
9588: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
9589: '<br />'.
9590: '<br />'.$visactions->{'take'}.'<ul>'.
9591: '<li>'.$visactions->{'dc_chgconf'}.'</li>'.
9592: '</ul>');
9593: } elsif (($cattype{'auth'} !~ /^(std|domonly)$/) && ($cattype{'unauth'} !~ /^(std|domonly)$/)) {
9594: if ($currsettings->{'uniquecode'}) {
9595: $r->print('<span class="LC_info">'.$visactions->{'vis'}.'</span>');
9596: } else {
1.366 bisitz 9597: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
1.400 raeburn 9598: '<br />'.
9599: '<br />'.$visactions->{'take'}.'<ul>'.
9600: '<li>'.$visactions->{'dc_setcode'}.'</li>'.
9601: '</ul><br />');
9602: }
9603: } else {
9604: my ($visible,$cansetvis,$vismsgs) = &visible_in_stdcat($cdom,$cnum,\%domconfig);
9605: if (ref($visactions) eq 'HASH') {
9606: if (!$visible) {
9607: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
9608: '<br />');
9609: if (ref($vismsgs) eq 'ARRAY') {
9610: $r->print('<br />'.$visactions->{'take'}.'<ul>');
9611: foreach my $item (@{$vismsgs}) {
9612: $r->print('<li>'.$visactions->{$item}.'</li>');
9613: }
9614: $r->print('</ul>');
1.256 raeburn 9615: }
1.400 raeburn 9616: $r->print($cansetvis);
1.256 raeburn 9617: }
9618: }
9619: }
1.237 raeburn 9620: return;
9621: }
9622:
1.27 matthew 9623: #---------------------------------------------- end functions for &phase_two
1.29 matthew 9624:
9625: #--------------------------------- functions for &phase_two and &phase_three
9626:
9627: #--------------------------end of functions for &phase_two and &phase_three
1.372 raeburn 9628:
1.1 www 9629: 1;
9630: __END__
1.2 www 9631:
9632:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>