Annotation of loncom/interface/loncreateuser.pm, revision 1.456
1.20 harris41 1: # The LearningOnline Network with CAPA
1.1 www 2: # Create a user
3: #
1.456 ! raeburn 4: # $Id: loncreateuser.pm,v 1.455 2021/09/25 20:35:26 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.456 ! 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;
1.449 raeburn 82: my $authformlti;
1.20 harris41 83:
1.94 matthew 84: sub initialize_authen_forms {
1.227 raeburn 85: my ($dom,$formname,$curr_authtype,$mode) = @_;
86: my ($krbdef,$krbdefdom) = &Apache::loncommon::get_kerberos_defaults($dom);
87: my %param = ( formname => $formname,
1.187 raeburn 88: kerb_def_dom => $krbdefdom,
1.227 raeburn 89: kerb_def_auth => $krbdef,
1.187 raeburn 90: domain => $dom,
91: );
1.188 raeburn 92: my %abv_auth = &auth_abbrev();
1.449 raeburn 93: if ($curr_authtype =~ /^(krb4|krb5|internal|localauth|unix|lti):(.*)$/) {
1.188 raeburn 94: my $long_auth = $1;
1.227 raeburn 95: my $curr_autharg = $2;
1.188 raeburn 96: my %abv_auth = &auth_abbrev();
97: $param{'curr_authtype'} = $abv_auth{$long_auth};
98: if ($long_auth =~ /^krb(4|5)$/) {
99: $param{'curr_kerb_ver'} = $1;
1.227 raeburn 100: $param{'curr_autharg'} = $curr_autharg;
1.188 raeburn 101: }
1.205 raeburn 102: if ($mode eq 'modifyuser') {
103: $param{'mode'} = $mode;
104: }
1.187 raeburn 105: }
1.227 raeburn 106: $loginscript = &Apache::loncommon::authform_header(%param);
107: $authformkrb = &Apache::loncommon::authform_kerberos(%param);
1.31 matthew 108: $authformnop = &Apache::loncommon::authform_nochange(%param);
109: $authformint = &Apache::loncommon::authform_internal(%param);
110: $authformfsys = &Apache::loncommon::authform_filesystem(%param);
111: $authformloc = &Apache::loncommon::authform_local(%param);
1.449 raeburn 112: $authformlti = &Apache::loncommon::authform_lti(%param);
1.20 harris41 113: }
114:
1.188 raeburn 115: sub auth_abbrev {
116: my %abv_auth = (
1.368 raeburn 117: krb5 => 'krb',
118: krb4 => 'krb',
119: internal => 'int',
120: localauth => 'loc',
121: unix => 'fsys',
1.449 raeburn 122: lti => 'lti',
1.188 raeburn 123: );
124: return %abv_auth;
125: }
1.43 www 126:
1.134 raeburn 127: # ====================================================
128:
1.378 raeburn 129: sub user_quotas {
1.134 raeburn 130: my ($ccuname,$ccdomain) = @_;
131: my %lt = &Apache::lonlocal::texthash(
1.267 raeburn 132: 'usrt' => "User Tools",
133: 'cust' => "Custom quota",
134: 'chqu' => "Change quota",
1.134 raeburn 135: );
1.378 raeburn 136:
1.149 raeburn 137: my $quota_javascript = <<"END_SCRIPT";
138: <script type="text/javascript">
1.301 bisitz 139: // <![CDATA[
1.378 raeburn 140: function quota_changes(caller,context) {
141: var customoff = document.getElementById('custom_'+context+'quota_off');
142: var customon = document.getElementById('custom_'+context+'quota_on');
143: var number = document.getElementById(context+'quota');
1.149 raeburn 144: if (caller == "custom") {
1.378 raeburn 145: if (customoff) {
146: if (customoff.checked) {
147: number.value = "";
148: }
1.149 raeburn 149: }
150: }
151: if (caller == "quota") {
1.378 raeburn 152: if (customon) {
153: customon.checked = true;
154: }
1.149 raeburn 155: }
1.378 raeburn 156: return;
1.149 raeburn 157: }
1.301 bisitz 158: // ]]>
1.149 raeburn 159: </script>
160: END_SCRIPT
1.378 raeburn 161: my $longinsttype;
162: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($ccdomain);
1.267 raeburn 163: my $output = $quota_javascript."\n".
164: '<h3>'.$lt{'usrt'}.'</h3>'."\n".
165: &Apache::loncommon::start_data_table();
166:
1.418 raeburn 167: if ((&Apache::lonnet::allowed('mut',$ccdomain)) ||
168: (&Apache::lonnet::allowed('udp',$ccdomain))) {
1.275 raeburn 169: $output .= &build_tools_display($ccuname,$ccdomain,'tools');
1.267 raeburn 170: }
1.378 raeburn 171:
172: my %titles = &Apache::lonlocal::texthash (
173: portfolio => "Disk space allocated to user's portfolio files",
1.385 bisitz 174: author => "Disk space allocated to user's Authoring Space (if role assigned)",
1.378 raeburn 175: );
176: foreach my $name ('portfolio','author') {
177: my ($currquota,$quotatype,$inststatus,$defquota) =
178: &Apache::loncommon::get_user_quota($ccuname,$ccdomain,$name);
179: if ($longinsttype eq '') {
180: if ($inststatus ne '') {
181: if ($usertypes->{$inststatus} ne '') {
182: $longinsttype = $usertypes->{$inststatus};
183: }
184: }
185: }
186: my ($showquota,$custom_on,$custom_off,$defaultinfo);
187: $custom_on = ' ';
188: $custom_off = ' checked="checked" ';
189: if ($quotatype eq 'custom') {
190: $custom_on = $custom_off;
191: $custom_off = ' ';
192: $showquota = $currquota;
193: if ($longinsttype eq '') {
194: $defaultinfo = &mt('For this user, the default quota would be [_1]'
1.383 raeburn 195: .' MB.',$defquota);
1.378 raeburn 196: } else {
197: $defaultinfo = &mt("For this user, the default quota would be [_1]".
1.383 raeburn 198: " MB, as determined by the user's institutional".
1.378 raeburn 199: " affiliation ([_2]).",$defquota,$longinsttype);
200: }
201: } else {
202: if ($longinsttype eq '') {
203: $defaultinfo = &mt('For this user, the default quota is [_1]'
1.383 raeburn 204: .' MB.',$defquota);
1.378 raeburn 205: } else {
206: $defaultinfo = &mt("For this user, the default quota of [_1]".
1.383 raeburn 207: " MB, is determined by the user's institutional".
1.378 raeburn 208: " affiliation ([_2]).",$defquota,$longinsttype);
209: }
210: }
211:
212: if (&Apache::lonnet::allowed('mpq',$ccdomain)) {
213: $output .= '<tr class="LC_info_row">'."\n".
214: ' <td>'.$titles{$name}.'</td>'."\n".
215: ' </tr>'."\n".
216: &Apache::loncommon::start_data_table_row()."\n".
1.390 bisitz 217: ' <td><span class="LC_nobreak">'.
218: &mt('Current quota: [_1] MB',$currquota).'</span> '.
1.378 raeburn 219: $defaultinfo.'</td>'."\n".
220: &Apache::loncommon::end_data_table_row()."\n".
221: &Apache::loncommon::start_data_table_row()."\n".
222: ' <td><span class="LC_nobreak">'.$lt{'chqu'}.
223: ': <label>'.
224: '<input type="radio" name="custom_'.$name.'quota" id="custom_'.$name.'quota_off" '.
1.379 raeburn 225: 'value="0" '.$custom_off.' onchange="javascript:quota_changes('."'custom','$name'".');"'.
1.390 bisitz 226: ' /><span class="LC_nobreak">'.
227: &mt('Default ([_1] MB)',$defquota).'</span></label> '.
1.378 raeburn 228: ' <label><input type="radio" name="custom_'.$name.'quota" id="custom_'.$name.'quota_on" '.
1.379 raeburn 229: 'value="1" '.$custom_on.' onchange="javascript:quota_changes('."'custom','$name'".');"'.
1.378 raeburn 230: ' />'.$lt{'cust'}.':</label> '.
1.379 raeburn 231: '<input type="text" name="'.$name.'quota" id="'.$name.'quota" size ="5" '.
232: 'value="'.$showquota.'" onfocus="javascript:quota_changes('."'quota','$name'".');"'.
1.390 bisitz 233: ' /> '.&mt('MB').'</span></td>'."\n".
1.378 raeburn 234: &Apache::loncommon::end_data_table_row()."\n";
235: }
236: }
1.267 raeburn 237: $output .= &Apache::loncommon::end_data_table();
1.134 raeburn 238: return $output;
239: }
240:
1.275 raeburn 241: sub build_tools_display {
242: my ($ccuname,$ccdomain,$context) = @_;
1.306 raeburn 243: my (@usertools,%userenv,$output,@options,%validations,%reqtitles,%reqdisplay,
1.332 raeburn 244: $colspan,$isadv,%domconfig);
1.275 raeburn 245: my %lt = &Apache::lonlocal::texthash (
246: 'blog' => "Personal User Blog",
247: 'aboutme' => "Personal Information Page",
1.385 bisitz 248: 'webdav' => "WebDAV access to Authoring Spaces (if SSL and author/co-author)",
1.275 raeburn 249: 'portfolio' => "Personal User Portfolio",
250: 'avai' => "Available",
251: 'cusa' => "availability",
252: 'chse' => "Change setting",
253: 'usde' => "Use default",
254: 'uscu' => "Use custom",
255: 'official' => 'Can request creation of official courses',
1.299 raeburn 256: 'unofficial' => 'Can request creation of unofficial courses',
257: 'community' => 'Can request creation of communities',
1.384 raeburn 258: 'textbook' => 'Can request creation of textbook courses',
1.411 raeburn 259: 'placement' => 'Can request creation of placement tests',
1.449 raeburn 260: 'lti' => 'Can request creation of LTI courses',
1.362 raeburn 261: 'requestauthor' => 'Can request author space',
1.275 raeburn 262: );
1.279 raeburn 263: if ($context eq 'requestcourses') {
1.275 raeburn 264: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
1.299 raeburn 265: 'requestcourses.official','requestcourses.unofficial',
1.411 raeburn 266: 'requestcourses.community','requestcourses.textbook',
1.449 raeburn 267: 'requestcourses.placement','requestcourses.lti');
268: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.309 raeburn 269: @options =('norequest','approval','autolimit','validate');
1.306 raeburn 270: %validations = &Apache::lonnet::auto_courserequest_checks($ccdomain);
271: %reqtitles = &courserequest_titles();
272: %reqdisplay = &courserequest_display();
273: $colspan = ' colspan="2"';
1.332 raeburn 274: %domconfig =
275: &Apache::lonnet::get_dom('configuration',['requestcourses'],$ccdomain);
1.418 raeburn 276: $isadv = &Apache::lonnet::is_advanced_user($ccdomain,$ccuname);
1.362 raeburn 277: } elsif ($context eq 'requestauthor') {
278: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
279: 'requestauthor');
280: @usertools = ('requestauthor');
281: @options =('norequest','approval','automatic');
282: %reqtitles = &requestauthor_titles();
283: %reqdisplay = &requestauthor_display();
284: $colspan = ' colspan="2"';
285: %domconfig =
286: &Apache::lonnet::get_dom('configuration',['requestauthor'],$ccdomain);
1.275 raeburn 287: } else {
288: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
1.361 raeburn 289: 'tools.aboutme','tools.portfolio','tools.blog',
290: 'tools.webdav');
291: @usertools = ('aboutme','blog','webdav','portfolio');
1.275 raeburn 292: }
293: foreach my $item (@usertools) {
1.306 raeburn 294: my ($custom_access,$curr_access,$cust_on,$cust_off,$tool_on,$tool_off,
295: $currdisp,$custdisp,$custradio);
1.275 raeburn 296: $cust_off = 'checked="checked" ';
297: $tool_on = 'checked="checked" ';
298: $curr_access =
299: &Apache::lonnet::usertools_access($ccuname,$ccdomain,$item,undef,
300: $context);
1.362 raeburn 301: if ($context eq 'requestauthor') {
302: if ($userenv{$context} ne '') {
303: $cust_on = ' checked="checked" ';
304: $cust_off = '';
305: }
306: } elsif ($userenv{$context.'.'.$item} ne '') {
1.306 raeburn 307: $cust_on = ' checked="checked" ';
308: $cust_off = '';
309: }
310: if ($context eq 'requestcourses') {
311: if ($userenv{$context.'.'.$item} eq '') {
1.314 raeburn 312: $custom_access = &mt('Currently from default setting.');
1.306 raeburn 313: } else {
314: $custom_access = &mt('Currently from custom setting.');
1.275 raeburn 315: }
1.362 raeburn 316: } elsif ($context eq 'requestauthor') {
317: if ($userenv{$context} eq '') {
318: $custom_access = &mt('Currently from default setting.');
319: } else {
320: $custom_access = &mt('Currently from custom setting.');
321: }
1.275 raeburn 322: } else {
1.306 raeburn 323: if ($userenv{$context.'.'.$item} eq '') {
1.314 raeburn 324: $custom_access =
1.306 raeburn 325: &mt('Availability determined currently from default setting.');
326: if (!$curr_access) {
327: $tool_off = 'checked="checked" ';
328: $tool_on = '';
329: }
330: } else {
1.314 raeburn 331: $custom_access =
1.306 raeburn 332: &mt('Availability determined currently from custom setting.');
333: if ($userenv{$context.'.'.$item} == 0) {
334: $tool_off = 'checked="checked" ';
335: $tool_on = '';
336: }
1.275 raeburn 337: }
338: }
339: $output .= ' <tr class="LC_info_row">'."\n".
1.306 raeburn 340: ' <td'.$colspan.'>'.$lt{$item}.'</td>'."\n".
1.275 raeburn 341: ' </tr>'."\n".
1.306 raeburn 342: &Apache::loncommon::start_data_table_row()."\n";
1.418 raeburn 343:
1.362 raeburn 344: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.306 raeburn 345: my ($curroption,$currlimit);
1.362 raeburn 346: my $envkey = $context.'.'.$item;
347: if ($context eq 'requestauthor') {
348: $envkey = $context;
349: }
350: if ($userenv{$envkey} ne '') {
351: $curroption = $userenv{$envkey};
1.332 raeburn 352: } else {
353: my (@inststatuses);
1.362 raeburn 354: if ($context eq 'requestcourses') {
355: $curroption =
356: &Apache::loncoursequeueadmin::get_processtype('course',$ccuname,$ccdomain,
357: $isadv,$ccdomain,$item,
358: \@inststatuses,\%domconfig);
359: } else {
360: $curroption =
361: &Apache::loncoursequeueadmin::get_processtype('requestauthor',$ccuname,$ccdomain,
362: $isadv,$ccdomain,undef,
363: \@inststatuses,\%domconfig);
364: }
1.332 raeburn 365: }
1.306 raeburn 366: if (!$curroption) {
367: $curroption = 'norequest';
368: }
369: if ($curroption =~ /^autolimit=(\d*)$/) {
370: $currlimit = $1;
1.314 raeburn 371: if ($currlimit eq '') {
372: $currdisp = &mt('Yes, automatic creation');
373: } else {
374: $currdisp = &mt('Yes, up to [quant,_1,request]/user',$currlimit);
375: }
1.306 raeburn 376: } else {
377: $currdisp = $reqdisplay{$curroption};
378: }
379: $custdisp = '<table>';
380: foreach my $option (@options) {
381: my $val = $option;
382: if ($option eq 'norequest') {
383: $val = 0;
384: }
385: if ($option eq 'validate') {
386: my $canvalidate = 0;
387: if (ref($validations{$item}) eq 'HASH') {
388: if ($validations{$item}{'_custom_'}) {
389: $canvalidate = 1;
390: }
391: }
392: next if (!$canvalidate);
393: }
394: my $checked = '';
395: if ($option eq $curroption) {
396: $checked = ' checked="checked"';
397: } elsif ($option eq 'autolimit') {
398: if ($curroption =~ /^autolimit/) {
399: $checked = ' checked="checked"';
400: }
401: }
1.362 raeburn 402: my $name = 'crsreq_'.$item;
403: if ($context eq 'requestauthor') {
404: $name = $item;
405: }
1.306 raeburn 406: $custdisp .= '<tr><td><span class="LC_nobreak"><label>'.
1.362 raeburn 407: '<input type="radio" name="'.$name.'" '.
408: 'value="'.$val.'"'.$checked.' />'.
1.306 raeburn 409: $reqtitles{$option}.'</label> ';
410: if ($option eq 'autolimit') {
1.362 raeburn 411: $custdisp .= '<input type="text" name="'.$name.
412: '_limit" size="1" '.
1.314 raeburn 413: 'value="'.$currlimit.'" /></span><br />'.
414: $reqtitles{'unlimited'};
1.362 raeburn 415: } else {
416: $custdisp .= '</span>';
417: }
418: $custdisp .= '</td></tr>';
1.306 raeburn 419: }
420: $custdisp .= '</table>';
421: $custradio = '</span></td><td>'.&mt('Custom setting').'<br />'.$custdisp;
422: } else {
423: $currdisp = ($curr_access?&mt('Yes'):&mt('No'));
1.362 raeburn 424: my $name = $context.'_'.$item;
425: if ($context eq 'requestauthor') {
426: $name = $context;
427: }
1.306 raeburn 428: $custdisp = '<span class="LC_nobreak"><label>'.
1.362 raeburn 429: '<input type="radio" name="'.$name.'"'.
1.361 raeburn 430: ' value="1" '.$tool_on.'/>'.&mt('On').'</label> <label>'.
1.362 raeburn 431: '<input type="radio" name="'.$name.'" value="0" '.
1.306 raeburn 432: $tool_off.'/>'.&mt('Off').'</label></span>';
433: $custradio = (' 'x2).'--'.$lt{'cusa'}.': '.$custdisp.
434: '</span>';
435: }
436: $output .= ' <td'.$colspan.'>'.$custom_access.(' 'x4).
1.419 raeburn 437: $lt{'avai'}.': '.$currdisp.'</td>'."\n".
1.418 raeburn 438: &Apache::loncommon::end_data_table_row()."\n";
439: unless (&Apache::lonnet::allowed('udp',$ccdomain)) {
440: $output .=
1.275 raeburn 441: &Apache::loncommon::start_data_table_row()."\n".
1.306 raeburn 442: ' <td style="vertical-align:top;"><span class="LC_nobreak">'.
443: $lt{'chse'}.': <label>'.
1.275 raeburn 444: '<input type="radio" name="custom'.$item.'" value="0" '.
1.306 raeburn 445: $cust_off.'/>'.$lt{'usde'}.'</label>'.(' ' x3).
446: '<label><input type="radio" name="custom'.$item.'" value="1" '.
447: $cust_on.'/>'.$lt{'uscu'}.'</label>'.$custradio.'</td>'.
1.275 raeburn 448: &Apache::loncommon::end_data_table_row()."\n";
1.418 raeburn 449: }
1.275 raeburn 450: }
451: return $output;
452: }
453:
1.300 raeburn 454: sub coursereq_externaluser {
455: my ($ccuname,$ccdomain,$cdom) = @_;
1.306 raeburn 456: my (@usertools,@options,%validations,%userenv,$output);
1.300 raeburn 457: my %lt = &Apache::lonlocal::texthash (
458: 'official' => 'Can request creation of official courses',
459: 'unofficial' => 'Can request creation of unofficial courses',
460: 'community' => 'Can request creation of communities',
1.384 raeburn 461: 'textbook' => 'Can request creation of textbook courses',
1.411 raeburn 462: 'placement' => 'Can request creation of placement tests',
1.300 raeburn 463: );
464:
465: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
466: 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
1.411 raeburn 467: 'reqcrsotherdom.community','reqcrsotherdom.textbook',
468: 'reqcrsotherdom.placement');
469: @usertools = ('official','unofficial','community','textbook','placement');
1.309 raeburn 470: @options = ('approval','validate','autolimit');
1.306 raeburn 471: %validations = &Apache::lonnet::auto_courserequest_checks($cdom);
472: my $optregex = join('|',@options);
473: my %reqtitles = &courserequest_titles();
1.300 raeburn 474: foreach my $item (@usertools) {
1.306 raeburn 475: my ($curroption,$currlimit,$tooloff);
1.300 raeburn 476: if ($userenv{'reqcrsotherdom.'.$item} ne '') {
477: my @curr = split(',',$userenv{'reqcrsotherdom.'.$item});
1.314 raeburn 478: foreach my $req (@curr) {
479: if ($req =~ /^\Q$cdom\E\:($optregex)=?(\d*)$/) {
480: $curroption = $1;
481: $currlimit = $2;
482: last;
1.306 raeburn 483: }
484: }
1.314 raeburn 485: if (!$curroption) {
486: $curroption = 'norequest';
487: $tooloff = ' checked="checked"';
488: }
1.306 raeburn 489: } else {
490: $curroption = 'norequest';
491: $tooloff = ' checked="checked"';
492: }
493: $output.= &Apache::loncommon::start_data_table_row()."\n".
1.314 raeburn 494: ' <td><span class="LC_nobreak">'.$lt{$item}.': </span></td><td>'.
495: '<table><tr><td valign="top">'."\n".
1.306 raeburn 496: '<label><input type="radio" name="reqcrsotherdom_'.$item.
1.314 raeburn 497: '" value=""'.$tooloff.' />'.$reqtitles{'norequest'}.
498: '</label></td>';
1.306 raeburn 499: foreach my $option (@options) {
500: if ($option eq 'validate') {
501: my $canvalidate = 0;
502: if (ref($validations{$item}) eq 'HASH') {
503: if ($validations{$item}{'_external_'}) {
504: $canvalidate = 1;
505: }
506: }
507: next if (!$canvalidate);
508: }
509: my $checked = '';
510: if ($option eq $curroption) {
511: $checked = ' checked="checked"';
512: }
1.314 raeburn 513: $output .= '<td valign="top"><span class="LC_nobreak"><label>'.
1.306 raeburn 514: '<input type="radio" name="reqcrsotherdom_'.$item.
515: '" value="'.$option.'"'.$checked.' />'.
1.314 raeburn 516: $reqtitles{$option}.'</label>';
1.306 raeburn 517: if ($option eq 'autolimit') {
1.314 raeburn 518: $output .= ' <input type="text" name="reqcrsotherdom_'.
1.306 raeburn 519: $item.'_limit" size="1" '.
1.314 raeburn 520: 'value="'.$currlimit.'" /></span>'.
521: '<br />'.$reqtitles{'unlimited'};
522: } else {
523: $output .= '</span>';
1.300 raeburn 524: }
1.314 raeburn 525: $output .= '</td>';
1.300 raeburn 526: }
1.314 raeburn 527: $output .= '</td></tr></table></td>'."\n".
1.300 raeburn 528: &Apache::loncommon::end_data_table_row()."\n";
529: }
530: return $output;
531: }
532:
1.362 raeburn 533: sub domainrole_req {
534: my ($ccuname,$ccdomain) = @_;
535: return '<br /><h3>'.
536: &mt('User Can Request Assignment of Domain Roles?').
537: '</h3>'."\n".
538: &Apache::loncommon::start_data_table().
539: &build_tools_display($ccuname,$ccdomain,
540: 'requestauthor').
541: &Apache::loncommon::end_data_table();
542: }
543:
1.306 raeburn 544: sub courserequest_titles {
545: my %titles = &Apache::lonlocal::texthash (
546: official => 'Official',
547: unofficial => 'Unofficial',
548: community => 'Communities',
1.384 raeburn 549: textbook => 'Textbook',
1.411 raeburn 550: placement => 'Placement Tests',
1.449 raeburn 551: lti => 'LTI Provider',
1.306 raeburn 552: norequest => 'Not allowed',
1.309 raeburn 553: approval => 'Approval by Dom. Coord.',
1.306 raeburn 554: validate => 'With validation',
555: autolimit => 'Numerical limit',
1.314 raeburn 556: unlimited => '(blank for unlimited)',
1.306 raeburn 557: );
558: return %titles;
559: }
560:
561: sub courserequest_display {
562: my %titles = &Apache::lonlocal::texthash (
1.309 raeburn 563: approval => 'Yes, need approval',
1.306 raeburn 564: validate => 'Yes, with validation',
565: norequest => 'No',
566: );
567: return %titles;
568: }
569:
1.362 raeburn 570: sub requestauthor_titles {
571: my %titles = &Apache::lonlocal::texthash (
572: norequest => 'Not allowed',
573: approval => 'Approval by Dom. Coord.',
574: automatic => 'Automatic approval',
575: );
576: return %titles;
577:
578: }
579:
580: sub requestauthor_display {
581: my %titles = &Apache::lonlocal::texthash (
582: approval => 'Yes, need approval',
583: automatic => 'Yes, automatic approval',
584: norequest => 'No',
585: );
586: return %titles;
587: }
588:
1.383 raeburn 589: sub requestchange_display {
590: my %titles = &Apache::lonlocal::texthash (
591: approval => "availability set to 'on' (approval required)",
592: automatic => "availability set to 'on' (automatic approval)",
593: norequest => "availability set to 'off'",
594: );
595: return %titles;
596: }
597:
1.362 raeburn 598: sub curr_requestauthor {
599: my ($uname,$udom,$isadv,$inststatuses,$domconfig) = @_;
600: return unless ((ref($inststatuses) eq 'ARRAY') && (ref($domconfig) eq 'HASH'));
601: if ($uname eq '' || $udom eq '') {
602: $uname = $env{'user.name'};
603: $udom = $env{'user.domain'};
604: $isadv = $env{'user.adv'};
605: }
606: my (%userenv,%settings,$val);
607: my @options = ('automatic','approval');
608: %userenv =
609: &Apache::lonnet::userenvironment($udom,$uname,'requestauthor','inststatus');
610: if ($userenv{'requestauthor'}) {
611: $val = $userenv{'requestauthor'};
612: @{$inststatuses} = ('_custom_');
613: } else {
614: my %alltasks;
615: if (ref($domconfig->{'requestauthor'}) eq 'HASH') {
616: %settings = %{$domconfig->{'requestauthor'}};
617: if (($isadv) && ($settings{'_LC_adv'} ne '')) {
618: $val = $settings{'_LC_adv'};
619: @{$inststatuses} = ('_LC_adv_');
620: } else {
621: if ($userenv{'inststatus'} ne '') {
622: @{$inststatuses} = split(',',$userenv{'inststatus'});
623: } else {
624: @{$inststatuses} = ('default');
625: }
626: foreach my $status (@{$inststatuses}) {
627: if (exists($settings{$status})) {
628: my $value = $settings{$status};
629: next unless ($value);
630: unless (exists($alltasks{$value})) {
631: if (ref($alltasks{$value}) eq 'ARRAY') {
632: unless(grep(/^\Q$status\E$/,@{$alltasks{$value}})) {
633: push(@{$alltasks{$value}},$status);
634: }
635: } else {
636: @{$alltasks{$value}} = ($status);
637: }
638: }
639: }
640: }
641: foreach my $option (@options) {
642: if ($alltasks{$option}) {
643: $val = $option;
644: last;
645: }
646: }
647: }
648: }
649: }
650: return $val;
651: }
652:
1.2 www 653: # =================================================================== Phase one
1.1 www 654:
1.42 matthew 655: sub print_username_entry_form {
1.439 raeburn 656: my ($r,$context,$response,$srch,$forcenewuser,$crstype,$brcrum,
657: $permission) = @_;
1.101 albertel 658: my $defdom=$env{'request.role.domain'};
1.160 raeburn 659: my $formtoset = 'crtuser';
660: if (exists($env{'form.startrolename'})) {
661: $formtoset = 'docustom';
662: $env{'form.rolename'} = $env{'form.startrolename'};
1.207 raeburn 663: } elsif ($env{'form.origform'} eq 'crtusername') {
664: $formtoset = $env{'form.origform'};
1.160 raeburn 665: }
666:
667: my ($jsback,$elements) = &crumb_utilities();
668:
669: my $jscript = &Apache::loncommon::studentbrowser_javascript()."\n".
1.165 albertel 670: '<script type="text/javascript">'."\n".
1.301 bisitz 671: '// <![CDATA['."\n".
672: &Apache::lonhtmlcommon::set_form_elements($elements->{$formtoset})."\n".
673: '// ]]>'."\n".
1.162 raeburn 674: '</script>'."\n";
1.160 raeburn 675:
1.324 raeburn 676: my %existingroles=&Apache::lonuserutils::my_custom_roles($crstype);
677: if (($env{'form.action'} eq 'custom') && (keys(%existingroles) > 0)
678: && (&Apache::lonnet::allowed('mcr','/'))) {
679: $jscript .= &customrole_javascript();
680: }
1.224 raeburn 681: my $helpitem = 'Course_Change_Privileges';
682: if ($env{'form.action'} eq 'custom') {
1.439 raeburn 683: if ($context eq 'course') {
684: $helpitem = 'Course_Editing_Custom_Roles';
685: } elsif ($context eq 'domain') {
686: $helpitem = 'Domain_Editing_Custom_Roles';
687: }
1.224 raeburn 688: } elsif ($env{'form.action'} eq 'singlestudent') {
689: $helpitem = 'Course_Add_Student';
1.416 raeburn 690: } elsif ($env{'form.action'} eq 'accesslogs') {
691: $helpitem = 'Domain_User_Access_Logs';
1.439 raeburn 692: } elsif ($context eq 'author') {
693: $helpitem = 'Author_Change_Privileges';
694: } elsif ($context eq 'domain') {
695: if ($permission->{'cusr'}) {
696: $helpitem = 'Domain_Change_Privileges';
697: } elsif ($permission->{'view'}) {
698: $helpitem = 'Domain_View_Privileges';
699: } else {
700: undef($helpitem);
701: }
1.224 raeburn 702: }
1.422 raeburn 703: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$defdom);
1.351 raeburn 704: if ($env{'form.action'} eq 'custom') {
705: push(@{$brcrum},
706: {href=>"javascript:backPage(document.crtuser)",
707: text=>"Pick custom role",
708: help => $helpitem,}
709: );
710: } else {
711: push (@{$brcrum},
712: {href => "javascript:backPage(document.crtuser)",
713: text => $breadcrumb_text{'search'},
714: help => $helpitem,
715: faq => 282,
716: bug => 'Instructor Interface',}
717: );
718: }
719: my %loaditems = (
720: 'onload' => "javascript:setFormElements(document.$formtoset)",
721: );
722: my $args = {bread_crumbs => $brcrum,
723: bread_crumbs_component => 'User Management',
724: add_entries => \%loaditems,};
725: $r->print(&Apache::loncommon::start_page('User Management',$jscript,$args));
726:
1.71 sakharuk 727: my %lt=&Apache::lonlocal::texthash(
1.229 raeburn 728: 'srst' => 'Search for a user and enroll as a student',
1.318 raeburn 729: 'srme' => 'Search for a user and enroll as a member',
1.229 raeburn 730: 'srad' => 'Search for a user and modify/add user information or roles',
1.422 raeburn 731: 'srvu' => 'Search for a user and view user information and roles',
1.416 raeburn 732: 'srva' => 'Search for a user and view access log information',
1.71 sakharuk 733: 'usr' => "Username",
734: 'dom' => "Domain",
1.324 raeburn 735: 'ecrp' => "Define or Edit Custom Role",
736: 'nr' => "role name",
1.282 schafran 737: 'cre' => "Next",
1.71 sakharuk 738: );
1.351 raeburn 739:
1.214 raeburn 740: if ($env{'form.action'} eq 'custom') {
1.190 raeburn 741: if (&Apache::lonnet::allowed('mcr','/')) {
1.324 raeburn 742: my $newroletext = &mt('Define new custom role:');
743: $r->print('<form action="/adm/createuser" method="post" name="docustom">'.
744: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
745: '<input type="hidden" name="phase" value="selected_custom_edit" />'.
746: '<h3>'.$lt{'ecrp'}.'</h3>'.
747: &Apache::loncommon::start_data_table().
748: &Apache::loncommon::start_data_table_row().
749: '<td>');
750: if (keys(%existingroles) > 0) {
751: $r->print('<br /><label><input type="radio" name="customroleaction" value="new" checked="checked" onclick="setCustomFields();" /><b>'.$newroletext.'</b></label>');
752: } else {
753: $r->print('<br /><input type="hidden" name="customroleaction" value="new" /><b>'.$newroletext.'</b>');
754: }
755: $r->print('</td><td align="center">'.$lt{'nr'}.'<br /><input type="text" size="15" name="newrolename" onfocus="setCustomAction('."'new'".');" /></td>'.
756: &Apache::loncommon::end_data_table_row());
757: if (keys(%existingroles) > 0) {
758: $r->print(&Apache::loncommon::start_data_table_row().'<td><br />'.
759: '<label><input type="radio" name="customroleaction" value="edit" onclick="setCustomFields();"/><b>'.
760: &mt('View/Modify existing role:').'</b></label></td>'.
761: '<td align="center"><br />'.
762: '<select name="rolename" onchange="setCustomAction('."'edit'".');">'.
1.326 raeburn 763: '<option value="" selected="selected">'.
1.324 raeburn 764: &mt('Select'));
765: foreach my $role (sort(keys(%existingroles))) {
1.326 raeburn 766: $r->print('<option value="'.$role.'">'.$role.'</option>');
1.324 raeburn 767: }
768: $r->print('</select>'.
769: '</td>'.
770: &Apache::loncommon::end_data_table_row());
771: }
772: $r->print(&Apache::loncommon::end_data_table().'<p>'.
773: '<input name="customeditor" type="submit" value="'.
774: $lt{'cre'}.'" /></p>'.
775: '</form>');
1.190 raeburn 776: }
1.213 raeburn 777: } else {
1.229 raeburn 778: my $actiontext = $lt{'srad'};
1.436 raeburn 779: my $fixeddom;
1.213 raeburn 780: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 781: if ($crstype eq 'Community') {
782: $actiontext = $lt{'srme'};
783: } else {
784: $actiontext = $lt{'srst'};
785: }
1.416 raeburn 786: } elsif ($env{'form.action'} eq 'accesslogs') {
1.417 raeburn 787: $actiontext = $lt{'srva'};
1.436 raeburn 788: $fixeddom = 1;
1.422 raeburn 789: } elsif (($env{'form.action'} eq 'singleuser') &&
790: ($context eq 'domain') && (!&Apache::lonnet::allowed('mau',$defdom))) {
791: $actiontext = $lt{'srvu'};
1.439 raeburn 792: $fixeddom = 1;
1.213 raeburn 793: }
1.324 raeburn 794: $r->print("<h3>$actiontext</h3>");
1.213 raeburn 795: if ($env{'form.origform'} ne 'crtusername') {
1.415 raeburn 796: if ($response) {
797: $r->print("\n<div>$response</div>".
798: '<br clear="all" />');
799: }
1.213 raeburn 800: }
1.436 raeburn 801: $r->print(&entry_form($defdom,$srch,$forcenewuser,$context,$response,$crstype,$fixeddom));
1.107 www 802: }
1.110 albertel 803: }
804:
1.324 raeburn 805: sub customrole_javascript {
806: my $js = <<"END";
807: <script type="text/javascript">
808: // <![CDATA[
809:
810: function setCustomFields() {
811: if (document.docustom.customroleaction.length > 0) {
812: for (var i=0; i<document.docustom.customroleaction.length; i++) {
813: if (document.docustom.customroleaction[i].checked) {
814: if (document.docustom.customroleaction[i].value == 'new') {
815: document.docustom.rolename.selectedIndex = 0;
816: } else {
817: document.docustom.newrolename.value = '';
818: }
819: }
820: }
821: }
822: return;
823: }
824:
825: function setCustomAction(caller) {
826: if (document.docustom.customroleaction.length > 0) {
827: for (var i=0; i<document.docustom.customroleaction.length; i++) {
828: if (document.docustom.customroleaction[i].value == caller) {
829: document.docustom.customroleaction[i].checked = true;
830: }
831: }
832: }
833: setCustomFields();
834: return;
835: }
836:
837: // ]]>
838: </script>
839: END
840: return $js;
841: }
842:
1.160 raeburn 843: sub entry_form {
1.416 raeburn 844: my ($dom,$srch,$forcenewuser,$context,$responsemsg,$crstype,$fixeddom) = @_;
1.229 raeburn 845: my ($usertype,$inexact);
1.214 raeburn 846: if (ref($srch) eq 'HASH') {
847: if (($srch->{'srchin'} eq 'dom') &&
848: ($srch->{'srchby'} eq 'uname') &&
849: ($srch->{'srchtype'} eq 'exact') &&
850: ($srch->{'srchdomain'} ne '') &&
851: ($srch->{'srchterm'} ne '')) {
1.353 raeburn 852: my (%curr_rules,%got_rules);
1.214 raeburn 853: my ($rules,$ruleorder) =
854: &Apache::lonnet::inst_userrules($srch->{'srchdomain'},'username');
1.353 raeburn 855: $usertype = &Apache::lonuserutils::check_usertype($srch->{'srchdomain'},$srch->{'srchterm'},$rules,\%curr_rules,\%got_rules);
1.229 raeburn 856: } else {
857: $inexact = 1;
1.214 raeburn 858: }
1.207 raeburn 859: }
1.438 raeburn 860: my ($cancreate,$noinstd);
861: if ($env{'form.action'} eq 'accesslogs') {
862: $noinstd = 1;
863: } else {
864: $cancreate =
865: &Apache::lonuserutils::can_create_user($dom,$context,$usertype);
866: }
1.412 raeburn 867: my ($userpicker,$cansearch) =
1.179 raeburn 868: &Apache::loncommon::user_picker($dom,$srch,$forcenewuser,
1.438 raeburn 869: 'document.crtuser',$cancreate,$usertype,$context,$fixeddom,$noinstd);
1.160 raeburn 870: my $srchbutton = &mt('Search');
1.229 raeburn 871: if ($env{'form.action'} eq 'singlestudent') {
872: $srchbutton = &mt('Search and Enroll');
1.416 raeburn 873: } elsif ($env{'form.action'} eq 'accesslogs') {
874: $srchbutton = &mt('Search');
1.229 raeburn 875: } elsif ($cancreate && $responsemsg ne '' && $inexact) {
876: $srchbutton = &mt('Search or Add New User');
877: }
1.412 raeburn 878: my $output;
879: if ($cansearch) {
880: $output = <<"ENDBLOCK";
1.160 raeburn 881: <form action="/adm/createuser" method="post" name="crtuser">
1.190 raeburn 882: <input type="hidden" name="action" value="$env{'form.action'}" />
1.160 raeburn 883: <input type="hidden" name="phase" value="get_user_info" />
884: $userpicker
1.179 raeburn 885: <input name="userrole" type="button" value="$srchbutton" onclick="javascript:validateEntry(document.crtuser)" />
1.160 raeburn 886: </form>
1.207 raeburn 887: ENDBLOCK
1.412 raeburn 888: } else {
889: $output = '<p>'.$userpicker.'</p>';
890: }
1.422 raeburn 891: if (($env{'form.phase'} eq '') && ($env{'form.action'} ne 'accesslogs') &&
1.430 raeburn 892: (!(($env{'form.action'} eq 'singleuser') && ($context eq 'domain') &&
1.422 raeburn 893: (!&Apache::lonnet::allowed('mau',$env{'request.role.domain'}))))) {
1.207 raeburn 894: my $defdom=$env{'request.role.domain'};
1.446 raeburn 895: my ($trusted,$untrusted);
1.444 raeburn 896: if ($context eq 'course') {
1.446 raeburn 897: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('enroll',$defdom);
1.444 raeburn 898: } elsif ($context eq 'author') {
1.446 raeburn 899: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('othcoau',$defdom);
1.444 raeburn 900: } elsif ($context eq 'domain') {
1.446 raeburn 901: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('domroles',$defdom);
1.444 raeburn 902: }
1.446 raeburn 903: my $domform = &Apache::loncommon::select_dom_form($defdom,'srchdomain',undef,undef,undef,$trusted,$untrusted);
1.207 raeburn 904: my %lt=&Apache::lonlocal::texthash(
1.229 raeburn 905: 'enro' => 'Enroll one student',
1.318 raeburn 906: 'enrm' => 'Enroll one member',
1.229 raeburn 907: 'admo' => 'Add/modify a single user',
908: 'crea' => 'create new user if required',
909: 'uskn' => "username is known",
1.207 raeburn 910: 'crnu' => 'Create a new user',
911: 'usr' => 'Username',
912: 'dom' => 'in domain',
1.229 raeburn 913: 'enrl' => 'Enroll',
914: 'cram' => 'Create/Modify user',
1.207 raeburn 915: );
1.229 raeburn 916: my $sellink=&Apache::loncommon::selectstudent_link('crtusername','srchterm','srchdomain');
917: my ($title,$buttontext,$showresponse);
1.318 raeburn 918: if ($env{'form.action'} eq 'singlestudent') {
919: if ($crstype eq 'Community') {
920: $title = $lt{'enrm'};
921: } else {
922: $title = $lt{'enro'};
923: }
1.229 raeburn 924: $buttontext = $lt{'enrl'};
925: } else {
926: $title = $lt{'admo'};
927: $buttontext = $lt{'cram'};
928: }
929: if ($cancreate) {
930: $title .= ' <span class="LC_cusr_subheading">('.$lt{'crea'}.')</span>';
931: } else {
932: $title .= ' <span class="LC_cusr_subheading">('.$lt{'uskn'}.')</span>';
933: }
934: if ($env{'form.origform'} eq 'crtusername') {
935: $showresponse = $responsemsg;
936: }
1.207 raeburn 937: $output .= <<"ENDDOCUMENT";
1.229 raeburn 938: <br />
1.207 raeburn 939: <form action="/adm/createuser" method="post" name="crtusername">
940: <input type="hidden" name="action" value="$env{'form.action'}" />
941: <input type="hidden" name="phase" value="createnewuser" />
942: <input type="hidden" name="srchtype" value="exact" />
1.233 raeburn 943: <input type="hidden" name="srchby" value="uname" />
1.207 raeburn 944: <input type="hidden" name="srchin" value="dom" />
945: <input type="hidden" name="forcenewuser" value="1" />
946: <input type="hidden" name="origform" value="crtusername" />
1.229 raeburn 947: <h3>$title</h3>
948: $showresponse
1.207 raeburn 949: <table>
950: <tr>
951: <td>$lt{'usr'}:</td>
952: <td><input type="text" size="15" name="srchterm" /></td>
953: <td> $lt{'dom'}:</td><td>$domform</td>
1.229 raeburn 954: <td> $sellink </td>
955: <td> <input name="userrole" type="submit" value="$buttontext" /></td>
1.207 raeburn 956: </tr>
957: </table>
958: </form>
1.160 raeburn 959: ENDDOCUMENT
1.207 raeburn 960: }
1.160 raeburn 961: return $output;
962: }
1.110 albertel 963:
964: sub user_modification_js {
1.113 raeburn 965: my ($pjump_def,$dc_setcourse_code,$nondc_setsection_code,$groupslist)=@_;
966:
1.110 albertel 967: return <<END;
968: <script type="text/javascript" language="Javascript">
1.301 bisitz 969: // <![CDATA[
1.314 raeburn 970:
1.110 albertel 971: $pjump_def
972: $dc_setcourse_code
973:
974: function dateset() {
975: eval("document.cu."+document.cu.pres_marker.value+
976: ".value=document.cu.pres_value.value");
1.359 www 977: modalWindow.close();
1.110 albertel 978: }
979:
1.113 raeburn 980: $nondc_setsection_code
1.301 bisitz 981: // ]]>
1.110 albertel 982: </script>
983: END
1.2 www 984: }
985:
986: # =================================================================== Phase two
1.160 raeburn 987: sub print_user_selection_page {
1.351 raeburn 988: my ($r,$response,$srch,$srch_results,$srcharray,$context,$opener_elements,$crstype,$brcrum) = @_;
1.160 raeburn 989: my @fields = ('username','domain','lastname','firstname','permanentemail');
990: my $sortby = $env{'form.sortby'};
991:
992: if (!grep(/^\Q$sortby\E$/,@fields)) {
993: $sortby = 'lastname';
994: }
995:
996: my ($jsback,$elements) = &crumb_utilities();
997:
998: my $jscript = (<<ENDSCRIPT);
999: <script type="text/javascript">
1.301 bisitz 1000: // <![CDATA[
1.160 raeburn 1001: function pickuser(uname,udom) {
1002: document.usersrchform.seluname.value=uname;
1003: document.usersrchform.seludom.value=udom;
1004: document.usersrchform.phase.value="userpicked";
1005: document.usersrchform.submit();
1006: }
1007:
1008: $jsback
1.301 bisitz 1009: // ]]>
1.160 raeburn 1010: </script>
1011: ENDSCRIPT
1012:
1013: my %lt=&Apache::lonlocal::texthash(
1.179 raeburn 1014: 'usrch' => "User Search to add/modify roles",
1015: 'stusrch' => "User Search to enroll student",
1.318 raeburn 1016: 'memsrch' => "User Search to enroll member",
1.416 raeburn 1017: 'srcva' => "Search for a user and view access log information",
1.422 raeburn 1018: 'usrvu' => "User Search to view user roles",
1.179 raeburn 1019: 'usel' => "Select a user to add/modify roles",
1.422 raeburn 1020: 'suvr' => "Select a user to view roles",
1.318 raeburn 1021: 'stusel' => "Select a user to enroll as a student",
1022: 'memsel' => "Select a user to enroll as a member",
1.416 raeburn 1023: 'vacsel' => "Select a user to view access log",
1.160 raeburn 1024: 'username' => "username",
1025: 'domain' => "domain",
1026: 'lastname' => "last name",
1027: 'firstname' => "first name",
1028: 'permanentemail' => "permanent e-mail",
1029: );
1.302 raeburn 1030: if ($context eq 'requestcrs') {
1031: $r->print('<div>');
1032: } else {
1.422 raeburn 1033: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$srch->{'srchdomain'});
1.351 raeburn 1034: my $helpitem;
1035: if ($env{'form.action'} eq 'singleuser') {
1036: $helpitem = 'Course_Change_Privileges';
1037: } elsif ($env{'form.action'} eq 'singlestudent') {
1038: $helpitem = 'Course_Add_Student';
1.439 raeburn 1039: } elsif ($context eq 'author') {
1040: $helpitem = 'Author_Change_Privileges';
1041: } elsif ($context eq 'domain') {
1042: $helpitem = 'Domain_Change_Privileges';
1.351 raeburn 1043: }
1044: push (@{$brcrum},
1045: {href => "javascript:backPage(document.usersrchform,'','')",
1046: text => $breadcrumb_text{'search'},
1047: faq => 282,
1048: bug => 'Instructor Interface',},
1049: {href => "javascript:backPage(document.usersrchform,'get_user_info','select')",
1050: text => $breadcrumb_text{'userpicked'},
1051: faq => 282,
1052: bug => 'Instructor Interface',
1053: help => $helpitem}
1054: );
1055: $r->print(&Apache::loncommon::start_page('User Management',$jscript,{bread_crumbs => $brcrum}));
1.302 raeburn 1056: if ($env{'form.action'} eq 'singleuser') {
1.422 raeburn 1057: my $readonly;
1058: if (($context eq 'domain') && (!&Apache::lonnet::allowed('mau',$srch->{'srchdomain'}))) {
1059: $readonly = 1;
1060: $r->print("<b>$lt{'usrvu'}</b><br />");
1061: } else {
1062: $r->print("<b>$lt{'usrch'}</b><br />");
1063: }
1.318 raeburn 1064: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,$crstype));
1.422 raeburn 1065: if ($readonly) {
1066: $r->print('<h3>'.$lt{'suvr'}.'</h3>');
1067: } else {
1068: $r->print('<h3>'.$lt{'usel'}.'</h3>');
1069: }
1.302 raeburn 1070: } elsif ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1071: $r->print($jscript."<b>");
1072: if ($crstype eq 'Community') {
1073: $r->print($lt{'memsrch'});
1074: } else {
1075: $r->print($lt{'stusrch'});
1076: }
1077: $r->print("</b><br />");
1078: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,$crstype));
1079: $r->print('</form><h3>');
1080: if ($crstype eq 'Community') {
1081: $r->print($lt{'memsel'});
1082: } else {
1083: $r->print($lt{'stusel'});
1084: }
1085: $r->print('</h3>');
1.416 raeburn 1086: } elsif ($env{'form.action'} eq 'accesslogs') {
1087: $r->print("<b>$lt{'srcva'}</b><br />");
1.438 raeburn 1088: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,undef,1));
1.416 raeburn 1089: $r->print('<h3>'.$lt{'vacsel'}.'</h3>');
1.302 raeburn 1090: }
1.179 raeburn 1091: }
1.380 bisitz 1092: $r->print('<form name="usersrchform" method="post" action="">'.
1.160 raeburn 1093: &Apache::loncommon::start_data_table()."\n".
1094: &Apache::loncommon::start_data_table_header_row()."\n".
1095: ' <th> </th>'."\n");
1096: foreach my $field (@fields) {
1097: $r->print(' <th><a href="javascript:document.usersrchform.sortby.value='.
1098: "'".$field."'".';document.usersrchform.submit();">'.
1099: $lt{$field}.'</a></th>'."\n");
1100: }
1101: $r->print(&Apache::loncommon::end_data_table_header_row());
1102:
1103: my @sorted_users = sort {
1.167 albertel 1104: lc($srch_results->{$a}->{$sortby}) cmp lc($srch_results->{$b}->{$sortby})
1.160 raeburn 1105: ||
1.167 albertel 1106: lc($srch_results->{$a}->{lastname}) cmp lc($srch_results->{$b}->{lastname})
1.160 raeburn 1107: ||
1108: lc($srch_results->{$a}->{firstname}) cmp lc($srch_results->{$b}->{firstname})
1.167 albertel 1109: ||
1110: lc($a) cmp lc($b)
1.160 raeburn 1111: } (keys(%$srch_results));
1112:
1113: foreach my $user (@sorted_users) {
1114: my ($uname,$udom) = split(/:/,$user);
1.302 raeburn 1115: my $onclick;
1116: if ($context eq 'requestcrs') {
1.314 raeburn 1117: $onclick =
1.302 raeburn 1118: 'onclick="javascript:gochoose('."'$uname','$udom',".
1119: "'$srch_results->{$user}->{firstname}',".
1120: "'$srch_results->{$user}->{lastname}',".
1121: "'$srch_results->{$user}->{permanentemail}'".');"';
1122: } else {
1.314 raeburn 1123: $onclick =
1.302 raeburn 1124: ' onclick="javascript:pickuser('."'".$uname."'".','."'".$udom."'".');"';
1125: }
1.160 raeburn 1126: $r->print(&Apache::loncommon::start_data_table_row().
1.302 raeburn 1127: '<td><input type="button" name="seluser" value="'.&mt('Select').'" '.
1128: $onclick.' /></td>'.
1.160 raeburn 1129: '<td><tt>'.$uname.'</tt></td>'.
1130: '<td><tt>'.$udom.'</tt></td>');
1131: foreach my $field ('lastname','firstname','permanentemail') {
1132: $r->print('<td>'.$srch_results->{$user}->{$field}.'</td>');
1133: }
1134: $r->print(&Apache::loncommon::end_data_table_row());
1135: }
1136: $r->print(&Apache::loncommon::end_data_table().'<br /><br />');
1.179 raeburn 1137: if (ref($srcharray) eq 'ARRAY') {
1138: foreach my $item (@{$srcharray}) {
1139: $r->print('<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n");
1140: }
1141: }
1.160 raeburn 1142: $r->print(' <input type="hidden" name="sortby" value="'.$sortby.'" />'."\n".
1143: ' <input type="hidden" name="seluname" value="" />'."\n".
1144: ' <input type="hidden" name="seludom" value="" />'."\n".
1.179 raeburn 1145: ' <input type="hidden" name="currstate" value="select" />'."\n".
1.190 raeburn 1146: ' <input type="hidden" name="phase" value="get_user_info" />'."\n".
1.214 raeburn 1147: ' <input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n");
1.302 raeburn 1148: if ($context eq 'requestcrs') {
1149: $r->print($opener_elements.'</form></div>');
1150: } else {
1.351 raeburn 1151: $r->print($response.'</form>');
1.302 raeburn 1152: }
1.160 raeburn 1153: }
1154:
1155: sub print_user_query_page {
1.351 raeburn 1156: my ($r,$caller,$brcrum) = @_;
1.160 raeburn 1157: # FIXME - this is for a network-wide name search (similar to catalog search)
1158: # To use frames with similar behavior to catalog/portfolio search.
1159: # To be implemented.
1160: return;
1161: }
1162:
1.42 matthew 1163: sub print_user_modification_page {
1.375 raeburn 1164: my ($r,$ccuname,$ccdomain,$srch,$response,$context,$permission,$crstype,
1165: $brcrum,$showcredits) = @_;
1.185 raeburn 1166: if (($ccuname eq '') || ($ccdomain eq '')) {
1.215 raeburn 1167: my $usermsg = &mt('No username and/or domain provided.');
1168: $env{'form.phase'} = '';
1.439 raeburn 1169: &print_username_entry_form($r,$context,$usermsg,'','',$crstype,$brcrum,
1170: $permission);
1.58 www 1171: return;
1172: }
1.213 raeburn 1173: my ($form,$formname);
1174: if ($env{'form.action'} eq 'singlestudent') {
1175: $form = 'document.enrollstudent';
1176: $formname = 'enrollstudent';
1177: } else {
1178: $form = 'document.cu';
1179: $formname = 'cu';
1180: }
1.188 raeburn 1181: my %abv_auth = &auth_abbrev();
1.227 raeburn 1182: my (%rulematch,%inst_results,$newuser,%alerts,%curr_rules,%got_rules);
1.185 raeburn 1183: my $uhome=&Apache::lonnet::homeserver($ccuname,$ccdomain);
1184: if ($uhome eq 'no_host') {
1.215 raeburn 1185: my $usertype;
1186: my ($rules,$ruleorder) =
1187: &Apache::lonnet::inst_userrules($ccdomain,'username');
1188: $usertype =
1.353 raeburn 1189: &Apache::lonuserutils::check_usertype($ccdomain,$ccuname,$rules,
1.362 raeburn 1190: \%curr_rules,\%got_rules);
1.215 raeburn 1191: my $cancreate =
1192: &Apache::lonuserutils::can_create_user($ccdomain,$context,
1193: $usertype);
1194: if (!$cancreate) {
1.292 bisitz 1195: my $helplink = 'javascript:helpMenu('."'display'".')';
1.215 raeburn 1196: my %usertypetext = (
1197: official => 'institutional',
1198: unofficial => 'non-institutional',
1199: );
1200: my $response;
1201: if ($env{'form.origform'} eq 'crtusername') {
1.362 raeburn 1202: $response = '<span class="LC_warning">'.
1203: &mt('No match found for the username [_1] in LON-CAPA domain: [_2]',
1204: '<b>'.$ccuname.'</b>',$ccdomain).
1.215 raeburn 1205: '</span><br />';
1206: }
1.292 bisitz 1207: $response .= '<p class="LC_warning">'
1208: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
1.418 raeburn 1209: .' ';
1210: if ($context eq 'domain') {
1211: $response .= &mt('Please contact a [_1] for assistance.',
1212: &Apache::lonnet::plaintext('dc'));
1213: } else {
1214: $response .= &mt('Please contact the [_1]helpdesk[_2] for assistance.'
1215: ,'<a href="'.$helplink.'">','</a>');
1216: }
1217: $response .= '</p><br />';
1.215 raeburn 1218: $env{'form.phase'} = '';
1.439 raeburn 1219: &print_username_entry_form($r,$context,$response,undef,undef,$crstype,$brcrum,
1220: $permission);
1.215 raeburn 1221: return;
1222: }
1.188 raeburn 1223: $newuser = 1;
1.193 raeburn 1224: my $checkhash;
1225: my $checks = { 'username' => 1 };
1.196 raeburn 1226: $checkhash->{$ccuname.':'.$ccdomain} = { 'newuser' => $newuser };
1.193 raeburn 1227: &Apache::loncommon::user_rule_check($checkhash,$checks,
1.196 raeburn 1228: \%alerts,\%rulematch,\%inst_results,\%curr_rules,\%got_rules);
1229: if (ref($alerts{'username'}) eq 'HASH') {
1230: if (ref($alerts{'username'}{$ccdomain}) eq 'HASH') {
1231: my $domdesc =
1.193 raeburn 1232: &Apache::lonnet::domain($ccdomain,'description');
1.196 raeburn 1233: if ($alerts{'username'}{$ccdomain}{$ccuname}) {
1234: my $userchkmsg;
1235: if (ref($curr_rules{$ccdomain}) eq 'HASH') {
1236: $userchkmsg =
1237: &Apache::loncommon::instrule_disallow_msg('username',
1.193 raeburn 1238: $domdesc,1).
1239: &Apache::loncommon::user_rule_formats($ccdomain,
1240: $domdesc,$curr_rules{$ccdomain}{'username'},
1241: 'username');
1.196 raeburn 1242: }
1.215 raeburn 1243: $env{'form.phase'} = '';
1.439 raeburn 1244: &print_username_entry_form($r,$context,$userchkmsg,undef,undef,$crstype,$brcrum,
1245: $permission);
1.196 raeburn 1246: return;
1.215 raeburn 1247: }
1.193 raeburn 1248: }
1.185 raeburn 1249: }
1.187 raeburn 1250: } else {
1.188 raeburn 1251: $newuser = 0;
1.185 raeburn 1252: }
1.160 raeburn 1253: if ($response) {
1.215 raeburn 1254: $response = '<br />'.$response;
1.160 raeburn 1255: }
1.149 raeburn 1256:
1.52 matthew 1257: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
1.88 raeburn 1258: my $dc_setcourse_code = '';
1.119 raeburn 1259: my $nondc_setsection_code = '';
1.112 albertel 1260: my %loaditem;
1.114 albertel 1261:
1.216 raeburn 1262: my $groupslist = &Apache::lonuserutils::get_groupslist();
1.88 raeburn 1263:
1.375 raeburn 1264: my $js = &validation_javascript($context,$ccdomain,$pjump_def,$crstype,
1.216 raeburn 1265: $groupslist,$newuser,$formname,\%loaditem);
1.422 raeburn 1266: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$ccdomain);
1.224 raeburn 1267: my $helpitem = 'Course_Change_Privileges';
1268: if ($env{'form.action'} eq 'singlestudent') {
1269: $helpitem = 'Course_Add_Student';
1.439 raeburn 1270: } elsif ($context eq 'author') {
1271: $helpitem = 'Author_Change_Privileges';
1272: } elsif ($context eq 'domain') {
1273: $helpitem = 'Domain_Change_Privileges';
1.224 raeburn 1274: }
1.351 raeburn 1275: push (@{$brcrum},
1276: {href => "javascript:backPage($form)",
1277: text => $breadcrumb_text{'search'},
1278: faq => 282,
1279: bug => 'Instructor Interface',});
1280: if ($env{'form.phase'} eq 'userpicked') {
1281: push(@{$brcrum},
1282: {href => "javascript:backPage($form,'get_user_info','select')",
1283: text => $breadcrumb_text{'userpicked'},
1284: faq => 282,
1285: bug => 'Instructor Interface',});
1286: }
1287: push(@{$brcrum},
1288: {href => "javascript:backPage($form,'$env{'form.phase'}','modify')",
1289: text => $breadcrumb_text{'modify'},
1290: faq => 282,
1291: bug => 'Instructor Interface',
1292: help => $helpitem});
1293: my $args = {'add_entries' => \%loaditem,
1294: 'bread_crumbs' => $brcrum,
1295: 'bread_crumbs_component' => 'User Management'};
1296: if ($env{'form.popup'}) {
1297: $args->{'no_nav_bar'} = 1;
1298: }
1299: my $start_page =
1300: &Apache::loncommon::start_page('User Management',$js,$args);
1.3 www 1301:
1.25 matthew 1302: my $forminfo =<<"ENDFORMINFO";
1.216 raeburn 1303: <form action="/adm/createuser" method="post" name="$formname">
1.190 raeburn 1304: <input type="hidden" name="phase" value="update_user_data" />
1.188 raeburn 1305: <input type="hidden" name="ccuname" value="$ccuname" />
1306: <input type="hidden" name="ccdomain" value="$ccdomain" />
1.157 albertel 1307: <input type="hidden" name="pres_value" value="" />
1308: <input type="hidden" name="pres_type" value="" />
1309: <input type="hidden" name="pres_marker" value="" />
1.25 matthew 1310: ENDFORMINFO
1.375 raeburn 1311: my (%inccourses,$roledom,$defaultcredits);
1.329 raeburn 1312: if ($context eq 'course') {
1313: $inccourses{$env{'request.course.id'}}=1;
1314: $roledom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1.375 raeburn 1315: if ($showcredits) {
1316: $defaultcredits = &Apache::lonuserutils::get_defaultcredits();
1317: }
1.329 raeburn 1318: } elsif ($context eq 'author') {
1319: $roledom = $env{'request.role.domain'};
1320: } elsif ($context eq 'domain') {
1321: foreach my $key (keys(%env)) {
1322: $roledom = $env{'request.role.domain'};
1323: if ($key=~/^user\.priv\.cm\.\/($roledom)\/($match_username)/) {
1324: $inccourses{$1.'_'.$2}=1;
1325: }
1326: }
1327: } else {
1328: foreach my $key (keys(%env)) {
1329: if ($key=~/^user\.priv\.cm\.\/($match_domain)\/($match_username)/) {
1330: $inccourses{$1.'_'.$2}=1;
1331: }
1.2 www 1332: }
1.24 matthew 1333: }
1.389 bisitz 1334: my $title = '';
1.216 raeburn 1335: if ($newuser) {
1.427 raeburn 1336: my ($portfolioform,$domroleform);
1.267 raeburn 1337: if ((&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) ||
1338: (&Apache::lonnet::allowed('mut',$env{'request.role.domain'}))) {
1339: # Current user has quota or user tools modification privileges
1.378 raeburn 1340: $portfolioform = '<br />'.&user_quotas($ccuname,$ccdomain);
1.134 raeburn 1341: }
1.383 raeburn 1342: if ((&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) &&
1343: ($ccdomain eq $env{'request.role.domain'})) {
1.362 raeburn 1344: $domroleform = '<br />'.&domainrole_req($ccuname,$ccdomain);
1345: }
1.227 raeburn 1346: &initialize_authen_forms($ccdomain,$formname);
1.188 raeburn 1347: my %lt=&Apache::lonlocal::texthash(
1348: 'lg' => 'Login Data',
1.190 raeburn 1349: 'hs' => "Home Server",
1.188 raeburn 1350: );
1.185 raeburn 1351: $r->print(<<ENDTITLE);
1.110 albertel 1352: $start_page
1.160 raeburn 1353: $response
1.25 matthew 1354: $forminfo
1.31 matthew 1355: <script type="text/javascript" language="Javascript">
1.301 bisitz 1356: // <![CDATA[
1.20 harris41 1357: $loginscript
1.301 bisitz 1358: // ]]>
1.31 matthew 1359: </script>
1.20 harris41 1360: <input type='hidden' name='makeuser' value='1' />
1.185 raeburn 1361: ENDTITLE
1.213 raeburn 1362: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1363: if ($crstype eq 'Community') {
1.389 bisitz 1364: $title = &mt('Create New User [_1] in domain [_2] as a member',
1365: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1366: } else {
1.389 bisitz 1367: $title = &mt('Create New User [_1] in domain [_2] as a student',
1368: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1369: }
1.389 bisitz 1370: } else {
1371: $title = &mt('Create New User [_1] in domain [_2]',
1372: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.213 raeburn 1373: }
1.389 bisitz 1374: $r->print('<h2>'.$title.'</h2>'."\n");
1375: $r->print('<div class="LC_left_float">');
1.393 raeburn 1376: $r->print(&personal_data_display($ccuname,$ccdomain,$newuser,$context,
1377: $inst_results{$ccuname.':'.$ccdomain}));
1378: # Option to disable student/employee ID conflict checking not offerred for new users.
1.187 raeburn 1379: my ($home_server_pick,$numlib) =
1380: &Apache::loncommon::home_server_form_item($ccdomain,'hserver',
1381: 'default','hide');
1382: if ($numlib > 1) {
1383: $r->print("
1.185 raeburn 1384: <br />
1.187 raeburn 1385: $lt{'hs'}: $home_server_pick
1386: <br />");
1387: } else {
1388: $r->print($home_server_pick);
1389: }
1.304 raeburn 1390: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.362 raeburn 1391: $r->print('<br /><h3>'.
1392: &mt('User Can Request Creation of Courses/Communities in this Domain?').'</h3>'.
1.304 raeburn 1393: &Apache::loncommon::start_data_table().
1394: &build_tools_display($ccuname,$ccdomain,
1395: 'requestcourses').
1396: &Apache::loncommon::end_data_table());
1397: }
1.188 raeburn 1398: $r->print('</div>'."\n".'<div class="LC_left_float"><h3>'.
1399: $lt{'lg'}.'</h3>');
1.185 raeburn 1400: my ($fixedauth,$varauth,$authmsg);
1.193 raeburn 1401: if (ref($rulematch{$ccuname.':'.$ccdomain}) eq 'HASH') {
1402: my $matchedrule = $rulematch{$ccuname.':'.$ccdomain}{'username'};
1403: my ($rules,$ruleorder) =
1404: &Apache::lonnet::inst_userrules($ccdomain,'username');
1.185 raeburn 1405: if (ref($rules) eq 'HASH') {
1.193 raeburn 1406: if (ref($rules->{$matchedrule}) eq 'HASH') {
1407: my $authtype = $rules->{$matchedrule}{'authtype'};
1.185 raeburn 1408: if ($authtype !~ /^(krb4|krb5|int|fsys|loc)$/) {
1.190 raeburn 1409: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.275 raeburn 1410: } else {
1.193 raeburn 1411: my $authparm = $rules->{$matchedrule}{'authparm'};
1.273 raeburn 1412: $authmsg = $rules->{$matchedrule}{'authmsg'};
1.185 raeburn 1413: if ($authtype =~ /^krb(4|5)$/) {
1414: my $ver = $1;
1415: if ($authparm ne '') {
1416: $fixedauth = <<"KERB";
1417: <input type="hidden" name="login" value="krb" />
1418: <input type="hidden" name="krbver" value="$ver" />
1419: <input type="hidden" name="krbarg" value="$authparm" />
1420: KERB
1421: }
1422: } else {
1423: $fixedauth =
1424: '<input type="hidden" name="login" value="'.$authtype.'" />'."\n";
1.193 raeburn 1425: if ($rules->{$matchedrule}{'authparmfixed'}) {
1.185 raeburn 1426: $fixedauth .=
1427: '<input type="hidden" name="'.$authtype.'arg" value="'.$authparm.'" />'."\n";
1428: } else {
1.273 raeburn 1429: if ($authtype eq 'int') {
1430: $varauth = '<br />'.
1.301 bisitz 1431: &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 1432: } elsif ($authtype eq 'loc') {
1433: $varauth = '<br />'.
1434: &mt('[_1] Local Authentication with argument [_2]','','<input type="text" name="'.$authtype.'arg" value="" />')."\n";
1435: } else {
1436: $varauth =
1.185 raeburn 1437: '<input type="text" name="'.$authtype.'arg" value="" />'."\n";
1.273 raeburn 1438: }
1.185 raeburn 1439: }
1440: }
1441: }
1442: } else {
1.190 raeburn 1443: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.185 raeburn 1444: }
1445: }
1446: if ($authmsg) {
1447: $r->print(<<ENDAUTH);
1448: $fixedauth
1449: $authmsg
1450: $varauth
1451: ENDAUTH
1452: }
1453: } else {
1.190 raeburn 1454: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.187 raeburn 1455: }
1.427 raeburn 1456: $r->print($portfolioform.$domroleform);
1.215 raeburn 1457: if ($env{'form.action'} eq 'singlestudent') {
1458: $r->print(&date_sections_select($context,$newuser,$formname,
1.375 raeburn 1459: $permission,$crstype,$ccuname,
1460: $ccdomain,$showcredits));
1.215 raeburn 1461: }
1462: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.216 raeburn 1463: } else { # user already exists
1.389 bisitz 1464: $r->print($start_page.$forminfo);
1.213 raeburn 1465: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1466: if ($crstype eq 'Community') {
1.389 bisitz 1467: $title = &mt('Enroll one member: [_1] in domain [_2]',
1468: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1469: } else {
1.389 bisitz 1470: $title = &mt('Enroll one student: [_1] in domain [_2]',
1471: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1472: }
1.213 raeburn 1473: } else {
1.418 raeburn 1474: if ($permission->{'cusr'}) {
1475: $title = &mt('Modify existing user: [_1] in domain [_2]',
1476: '"'.$ccuname.'"','"'.$ccdomain.'"');
1477: } else {
1478: $title = &mt('Existing user: [_1] in domain [_2]',
1.389 bisitz 1479: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.418 raeburn 1480: }
1.213 raeburn 1481: }
1.389 bisitz 1482: $r->print('<h2>'.$title.'</h2>'."\n");
1483: $r->print('<div class="LC_left_float">');
1.393 raeburn 1484: $r->print(&personal_data_display($ccuname,$ccdomain,$newuser,$context,
1485: $inst_results{$ccuname.':'.$ccdomain}));
1.430 raeburn 1486: if ((&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) ||
1.418 raeburn 1487: (&Apache::lonnet::allowed('udp',$env{'request.role.domain'}))) {
1.450 raeburn 1488: $r->print('<br /><h3>'.&mt('User Can Request Creation of Courses/Communities in this Domain?').'</h3>'."\n");
1489: if (($env{'request.role.domain'} eq $ccdomain) ||
1490: (&Apache::lonnet::will_trust('reqcrs',$ccdomain,$env{'request.role.domain'}))) {
1491: $r->print(&Apache::loncommon::start_data_table());
1492: if ($env{'request.role.domain'} eq $ccdomain) {
1493: $r->print(&build_tools_display($ccuname,$ccdomain,'requestcourses'));
1494: } else {
1.444 raeburn 1495: $r->print(&coursereq_externaluser($ccuname,$ccdomain,
1496: $env{'request.role.domain'}));
1497: }
1.450 raeburn 1498: $r->print(&Apache::loncommon::end_data_table());
1499: } else {
1500: $r->print(&mt('Domain configuration for this domain prohibits course creation by users from domain: "[_1]"',
1501: &Apache::lonnet::domain($ccdomain,'description')));
1.300 raeburn 1502: }
1.275 raeburn 1503: }
1.199 raeburn 1504: $r->print('</div>');
1.427 raeburn 1505: my @order = ('auth','quota','tools','requestauthor');
1.362 raeburn 1506: my %user_text;
1507: my ($isadv,$isauthor) =
1.418 raeburn 1508: &Apache::lonnet::is_advanced_user($ccdomain,$ccuname);
1.362 raeburn 1509: if ((!$isauthor) &&
1.418 raeburn 1510: ((&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) ||
1511: (&Apache::lonnet::allowed('udp',$env{'request.role.domain'}))) &&
1.430 raeburn 1512: ($env{'request.role.domain'} eq $ccdomain)) {
1.362 raeburn 1513: $user_text{'requestauthor'} = &domainrole_req($ccuname,$ccdomain);
1514: }
1.451 raeburn 1515: $user_text{'auth'} = &user_authentication($ccuname,$ccdomain,$formname,$crstype,$permission);
1.267 raeburn 1516: if ((&Apache::lonnet::allowed('mpq',$ccdomain)) ||
1.418 raeburn 1517: (&Apache::lonnet::allowed('mut',$ccdomain)) ||
1518: (&Apache::lonnet::allowed('udp',$ccdomain))) {
1.188 raeburn 1519: # Current user has quota modification privileges
1.378 raeburn 1520: $user_text{'quota'} = &user_quotas($ccuname,$ccdomain);
1.267 raeburn 1521: }
1522: if (!&Apache::lonnet::allowed('mpq',$ccdomain)) {
1523: if (&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) {
1524: my %lt=&Apache::lonlocal::texthash(
1.385 bisitz 1525: 'dska' => "Disk quotas for user's portfolio and Authoring Space",
1526: 'youd' => "You do not have privileges to modify the portfolio and/or Authoring Space quotas for this user.",
1.267 raeburn 1527: 'ichr' => "If a change is required, contact a domain coordinator for the domain",
1528: );
1.362 raeburn 1529: $user_text{'quota'} = <<ENDNOPORTPRIV;
1.188 raeburn 1530: <h3>$lt{'dska'}</h3>
1531: $lt{'youd'} $lt{'ichr'}: $ccdomain
1532: ENDNOPORTPRIV
1.267 raeburn 1533: }
1534: }
1535: if (!&Apache::lonnet::allowed('mut',$ccdomain)) {
1536: if (&Apache::lonnet::allowed('mut',$env{'request.role.domain'})) {
1537: my %lt=&Apache::lonlocal::texthash(
1538: 'utav' => "User Tools Availability",
1.361 raeburn 1539: 'yodo' => "You do not have privileges to modify Portfolio, Blog, WebDAV, or Personal Information Page settings for this user.",
1.267 raeburn 1540: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
1541: );
1.362 raeburn 1542: $user_text{'tools'} = <<ENDNOTOOLSPRIV;
1.267 raeburn 1543: <h3>$lt{'utav'}</h3>
1544: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1545: ENDNOTOOLSPRIV
1546: }
1.188 raeburn 1547: }
1.362 raeburn 1548: my $gotdiv = 0;
1549: foreach my $item (@order) {
1550: if ($user_text{$item} ne '') {
1551: unless ($gotdiv) {
1552: $r->print('<div class="LC_left_float">');
1553: $gotdiv = 1;
1554: }
1555: $r->print('<br />'.$user_text{$item});
1556: }
1557: }
1558: if ($env{'form.action'} eq 'singlestudent') {
1559: unless ($gotdiv) {
1560: $r->print('<div class="LC_left_float">');
1.213 raeburn 1561: }
1.375 raeburn 1562: my $credits;
1563: if ($showcredits) {
1564: $credits = &get_user_credits($ccuname,$ccdomain,$defaultcredits);
1565: if ($credits eq '') {
1566: $credits = $defaultcredits;
1567: }
1568: }
1.374 raeburn 1569: $r->print(&date_sections_select($context,$newuser,$formname,
1.375 raeburn 1570: $permission,$crstype,$ccuname,
1571: $ccdomain,$showcredits));
1.374 raeburn 1572: }
1.362 raeburn 1573: if ($gotdiv) {
1574: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.188 raeburn 1575: }
1.418 raeburn 1576: my $statuses;
1577: if (($context eq 'domain') && (&Apache::lonnet::allowed('udp',$ccdomain)) &&
1578: (!&Apache::lonnet::allowed('mau',$ccdomain))) {
1579: $statuses = ['active'];
1580: } elsif (($context eq 'course') && ((&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) ||
1581: ($env{'request.course.sec'} &&
1582: &Apache::lonnet::allowed('vcl',$env{'request.course.id'}.'/'.$env{'request.course.sec'})))) {
1.430 raeburn 1583: $statuses = ['active'];
1.418 raeburn 1584: }
1.217 raeburn 1585: if ($env{'form.action'} ne 'singlestudent') {
1.329 raeburn 1586: &display_existing_roles($r,$ccuname,$ccdomain,\%inccourses,$context,
1.418 raeburn 1587: $roledom,$crstype,$showcredits,$statuses);
1.217 raeburn 1588: }
1.25 matthew 1589: } ## End of new user/old user logic
1.218 raeburn 1590: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1591: my $btntxt;
1592: if ($crstype eq 'Community') {
1593: $btntxt = &mt('Enroll Member');
1594: } else {
1595: $btntxt = &mt('Enroll Student');
1596: }
1597: $r->print('<br /><input type="button" value="'.$btntxt.'" onclick="setSections(this.form)" />'."\n");
1.418 raeburn 1598: } elsif ($permission->{'cusr'}) {
1.393 raeburn 1599: $r->print('<div class="LC_left_float">'.
1600: '<fieldset><legend>'.&mt('Add Roles').'</legend>');
1.218 raeburn 1601: my $addrolesdisplay = 0;
1602: if ($context eq 'domain' || $context eq 'author') {
1603: $addrolesdisplay = &new_coauthor_roles($r,$ccuname,$ccdomain);
1604: }
1605: if ($context eq 'domain') {
1.357 raeburn 1606: my $add_domainroles = &new_domain_roles($r,$ccdomain);
1.218 raeburn 1607: if (!$addrolesdisplay) {
1608: $addrolesdisplay = $add_domainroles;
1.2 www 1609: }
1.375 raeburn 1610: $r->print(&course_level_dc($env{'request.role.domain'},$showcredits));
1.393 raeburn 1611: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1612: '<br /><input type="button" value="'.&mt('Save').'" onclick="setCourse()" />'."\n");
1.218 raeburn 1613: } elsif ($context eq 'author') {
1614: if ($addrolesdisplay) {
1.393 raeburn 1615: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1616: '<br /><input type="button" value="'.&mt('Save').'"');
1.218 raeburn 1617: if ($newuser) {
1.301 bisitz 1618: $r->print(' onclick="auth_check()" \>'."\n");
1.218 raeburn 1619: } else {
1.301 bisitz 1620: $r->print('onclick="this.form.submit()" \>'."\n");
1.218 raeburn 1621: }
1.188 raeburn 1622: } else {
1.393 raeburn 1623: $r->print('</fieldset></div>'.
1624: '<div class="LC_clear_float_footer"></div>'.
1625: '<br /><a href="javascript:backPage(document.cu)">'.
1.218 raeburn 1626: &mt('Back to previous page').'</a>');
1.188 raeburn 1627: }
1628: } else {
1.375 raeburn 1629: $r->print(&course_level_table(\%inccourses,$showcredits,$defaultcredits));
1.393 raeburn 1630: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1631: '<br /><input type="button" value="'.&mt('Save').'" onclick="setSections(this.form)" />'."\n");
1.188 raeburn 1632: }
1.88 raeburn 1633: }
1.188 raeburn 1634: $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','userrole','ccdomain','prevphase','currstate','ccuname','ccdomain']));
1.179 raeburn 1635: $r->print('<input type="hidden" name="currstate" value="" />');
1.393 raeburn 1636: $r->print('<input type="hidden" name="prevphase" value="'.$env{'form.phase'}.'" /></form><br /><br />');
1.218 raeburn 1637: return;
1.2 www 1638: }
1.1 www 1639:
1.213 raeburn 1640: sub singleuser_breadcrumb {
1.422 raeburn 1641: my ($crstype,$context,$domain) = @_;
1.213 raeburn 1642: my %breadcrumb_text;
1643: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1644: if ($crstype eq 'Community') {
1645: $breadcrumb_text{'search'} = 'Enroll a member';
1646: } else {
1647: $breadcrumb_text{'search'} = 'Enroll a student';
1648: }
1.422 raeburn 1649: $breadcrumb_text{'userpicked'} = 'Select a user';
1650: $breadcrumb_text{'modify'} = 'Set section/dates';
1.416 raeburn 1651: } elsif ($env{'form.action'} eq 'accesslogs') {
1652: $breadcrumb_text{'search'} = 'View access logs for a user';
1.422 raeburn 1653: $breadcrumb_text{'userpicked'} = 'Select a user';
1654: $breadcrumb_text{'activity'} = 'Activity';
1655: } elsif (($env{'form.action'} eq 'singleuser') && ($context eq 'domain') &&
1656: (!&Apache::lonnet::allowed('mau',$domain))) {
1657: $breadcrumb_text{'search'} = "View user's roles";
1658: $breadcrumb_text{'userpicked'} = 'Select a user';
1659: $breadcrumb_text{'modify'} = 'User roles';
1.213 raeburn 1660: } else {
1.229 raeburn 1661: $breadcrumb_text{'search'} = 'Create/modify a user';
1.422 raeburn 1662: $breadcrumb_text{'userpicked'} = 'Select a user';
1663: $breadcrumb_text{'modify'} = 'Set user role';
1.213 raeburn 1664: }
1665: return %breadcrumb_text;
1666: }
1667:
1668: sub date_sections_select {
1.375 raeburn 1669: my ($context,$newuser,$formname,$permission,$crstype,$ccuname,$ccdomain,
1670: $showcredits) = @_;
1671: my $credits;
1672: if ($showcredits) {
1673: my $defaultcredits = &Apache::lonuserutils::get_defaultcredits();
1674: $credits = &get_user_credits($ccuname,$ccdomain,$defaultcredits);
1675: if ($credits eq '') {
1676: $credits = $defaultcredits;
1677: }
1678: }
1.213 raeburn 1679: my $cid = $env{'request.course.id'};
1680: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity($cid);
1681: my $date_table = '<h3>'.&mt('Starting and Ending Dates').'</h3>'."\n".
1682: &Apache::lonuserutils::date_setting_table(undef,undef,$context,
1683: undef,$formname,$permission);
1684: my $rowtitle = 'Section';
1.375 raeburn 1685: my $secbox = '<h3>'.&mt('Section and Credits').'</h3>'."\n".
1.213 raeburn 1686: &Apache::lonuserutils::section_picker($cdom,$cnum,'st',$rowtitle,
1.375 raeburn 1687: $permission,$context,'',$crstype,
1688: $showcredits,$credits);
1.213 raeburn 1689: my $output = $date_table.$secbox;
1690: return $output;
1691: }
1692:
1.216 raeburn 1693: sub validation_javascript {
1.375 raeburn 1694: my ($context,$ccdomain,$pjump_def,$crstype,$groupslist,$newuser,$formname,
1.216 raeburn 1695: $loaditem) = @_;
1696: my $dc_setcourse_code = '';
1697: my $nondc_setsection_code = '';
1698: if ($context eq 'domain') {
1699: my $dcdom = $env{'request.role.domain'};
1700: $loaditem->{'onload'} = "document.cu.coursedesc.value='';";
1.227 raeburn 1701: $dc_setcourse_code =
1702: &Apache::lonuserutils::dc_setcourse_js('cu','singleuser',$context);
1.216 raeburn 1703: } else {
1.227 raeburn 1704: my $checkauth;
1705: if (($newuser) || (&Apache::lonnet::allowed('mau',$ccdomain))) {
1706: $checkauth = 1;
1707: }
1708: if ($context eq 'course') {
1709: $nondc_setsection_code =
1710: &Apache::lonuserutils::setsections_javascript($formname,$groupslist,
1.375 raeburn 1711: undef,$checkauth,
1712: $crstype);
1.227 raeburn 1713: }
1714: if ($checkauth) {
1715: $nondc_setsection_code .=
1716: &Apache::lonuserutils::verify_authen($formname,$context);
1717: }
1.216 raeburn 1718: }
1719: my $js = &user_modification_js($pjump_def,$dc_setcourse_code,
1720: $nondc_setsection_code,$groupslist);
1721: my ($jsback,$elements) = &crumb_utilities();
1722: $js .= "\n".
1.301 bisitz 1723: '<script type="text/javascript">'."\n".
1724: '// <![CDATA['."\n".
1725: $jsback."\n".
1726: '// ]]>'."\n".
1727: '</script>'."\n";
1.216 raeburn 1728: return $js;
1729: }
1730:
1.217 raeburn 1731: sub display_existing_roles {
1.375 raeburn 1732: my ($r,$ccuname,$ccdomain,$inccourses,$context,$roledom,$crstype,
1.418 raeburn 1733: $showcredits,$statuses) = @_;
1.329 raeburn 1734: my $now=time;
1.418 raeburn 1735: my $showall = 1;
1736: my ($showexpired,$showactive);
1737: if ((ref($statuses) eq 'ARRAY') && (@{$statuses} > 0)) {
1738: $showall = 0;
1739: if (grep(/^expired$/,@{$statuses})) {
1740: $showexpired = 1;
1741: }
1742: if (grep(/^active$/,@{$statuses})) {
1743: $showactive = 1;
1744: }
1745: if ($showexpired && $showactive) {
1746: $showall = 1;
1747: }
1748: }
1.329 raeburn 1749: my %lt=&Apache::lonlocal::texthash(
1.217 raeburn 1750: 'rer' => "Existing Roles",
1751: 'rev' => "Revoke",
1752: 'del' => "Delete",
1753: 'ren' => "Re-Enable",
1754: 'rol' => "Role",
1755: 'ext' => "Extent",
1.375 raeburn 1756: 'crd' => "Credits",
1.217 raeburn 1757: 'sta' => "Start",
1758: 'end' => "End",
1759: );
1.329 raeburn 1760: my (%rolesdump,%roletext,%sortrole,%roleclass,%rolepriv);
1761: if ($context eq 'course' || $context eq 'author') {
1762: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
1763: my %roleshash =
1764: &Apache::lonnet::get_my_roles($ccuname,$ccdomain,'userroles',
1765: ['active','previous','future'],\@roles,$roledom,1);
1766: foreach my $key (keys(%roleshash)) {
1767: my ($start,$end) = split(':',$roleshash{$key});
1768: next if ($start eq '-1' || $end eq '-1');
1769: my ($rnum,$rdom,$role,$sec) = split(':',$key);
1770: if ($context eq 'course') {
1771: next unless (($rnum eq $env{'course.'.$env{'request.course.id'}.'.num'})
1772: && ($rdom eq $env{'course.'.$env{'request.course.id'}.'.domain'}));
1773: } elsif ($context eq 'author') {
1774: next unless (($rnum eq $env{'user.name'}) && ($rdom eq $env{'request.role.domain'}));
1775: }
1776: my ($newkey,$newvalue,$newrole);
1777: $newkey = '/'.$rdom.'/'.$rnum;
1778: if ($sec ne '') {
1779: $newkey .= '/'.$sec;
1780: }
1781: $newvalue = $role;
1782: if ($role =~ /^cr/) {
1783: $newrole = 'cr';
1784: } else {
1785: $newrole = $role;
1786: }
1787: $newkey .= '_'.$newrole;
1788: if ($start ne '' && $end ne '') {
1789: $newvalue .= '_'.$end.'_'.$start;
1.335 raeburn 1790: } elsif ($end ne '') {
1791: $newvalue .= '_'.$end;
1.329 raeburn 1792: }
1793: $rolesdump{$newkey} = $newvalue;
1794: }
1795: } else {
1.360 raeburn 1796: %rolesdump=&Apache::lonnet::dump('roles',$ccdomain,$ccuname);
1.329 raeburn 1797: }
1798: # Build up table of user roles to allow revocation and re-enabling of roles.
1799: my ($tmp) = keys(%rolesdump);
1800: return if ($tmp =~ /^(con_lost|error)/i);
1801: foreach my $area (sort { my $a1=join('_',(split('_',$a))[1,0]);
1802: my $b1=join('_',(split('_',$b))[1,0]);
1803: return $a1 cmp $b1;
1804: } keys(%rolesdump)) {
1805: next if ($area =~ /^rolesdef/);
1806: my $envkey=$area;
1807: my $role = $rolesdump{$area};
1808: my $thisrole=$area;
1809: $area =~ s/\_\w\w$//;
1810: my ($role_code,$role_end_time,$role_start_time) =
1811: split(/_/,$role);
1.418 raeburn 1812: my $active=1;
1813: $active=0 if (($role_end_time) && ($now>$role_end_time));
1814: if ($active) {
1815: next unless($showall || $showactive);
1816: } else {
1.430 raeburn 1817: next unless($showall || $showexpired);
1.418 raeburn 1818: }
1.217 raeburn 1819: # Is this a custom role? Get role owner and title.
1.329 raeburn 1820: my ($croleudom,$croleuname,$croletitle)=
1821: ($role_code=~m{^cr/($match_domain)/($match_username)/(\w+)$});
1822: my $allowed=0;
1823: my $delallowed=0;
1824: my $sortkey=$role_code;
1825: my $class='Unknown';
1.375 raeburn 1826: my $credits='';
1.418 raeburn 1827: my $csec;
1.421 raeburn 1828: if ($area =~ m{^/($match_domain)/($match_courseid)}) {
1.329 raeburn 1829: $class='Course';
1830: my ($coursedom,$coursedir) = ($1,$2);
1831: my $cid = $1.'_'.$2;
1832: # $1.'_'.$2 is the course id (eg. 103_12345abcef103l3).
1.421 raeburn 1833: next if ($envkey =~ m{^/$match_domain/$match_courseid/[A-Za-z0-9]+_gr$});
1.329 raeburn 1834: my %coursedata=
1835: &Apache::lonnet::coursedescription($cid);
1836: if ($coursedir =~ /^$match_community$/) {
1837: $class='Community';
1838: }
1839: $sortkey.="\0$coursedom";
1840: my $carea;
1841: if (defined($coursedata{'description'})) {
1842: $carea=$coursedata{'description'}.
1843: '<br />'.&mt('Domain').': '.$coursedom.(' 'x8).
1844: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$coursedir,$coursedom);
1845: $sortkey.="\0".$coursedata{'description'};
1846: } else {
1847: if ($class eq 'Community') {
1848: $carea=&mt('Unavailable community').': '.$area;
1849: $sortkey.="\0".&mt('Unavailable community').': '.$area;
1.217 raeburn 1850: } else {
1851: $carea=&mt('Unavailable course').': '.$area;
1852: $sortkey.="\0".&mt('Unavailable course').': '.$area;
1853: }
1.329 raeburn 1854: }
1855: $sortkey.="\0$coursedir";
1856: $inccourses->{$cid}=1;
1.375 raeburn 1857: if (($showcredits) && ($class eq 'Course') && ($role_code eq 'st')) {
1858: my $defaultcredits = $coursedata{'internal.defaultcredits'};
1859: $credits =
1860: &get_user_credits($ccuname,$ccdomain,$defaultcredits,
1861: $coursedom,$coursedir);
1862: if ($credits eq '') {
1863: $credits = $defaultcredits;
1864: }
1865: }
1.329 raeburn 1866: if ((&Apache::lonnet::allowed('c'.$role_code,$coursedom.'/'.$coursedir)) ||
1867: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
1868: $allowed=1;
1869: }
1870: unless ($allowed) {
1.365 raeburn 1871: my $isowner = &Apache::lonuserutils::is_courseowner($cid,$coursedata{'internal.courseowner'});
1.329 raeburn 1872: if ($isowner) {
1873: if (($role_code eq 'co') && ($class eq 'Community')) {
1874: $allowed = 1;
1875: } elsif (($role_code eq 'cc') && ($class eq 'Course')) {
1876: $allowed = 1;
1877: }
1.217 raeburn 1878: }
1.329 raeburn 1879: }
1880: if ((&Apache::lonnet::allowed('dro',$coursedom)) ||
1881: (&Apache::lonnet::allowed('dro',$ccdomain))) {
1882: $delallowed=1;
1883: }
1.217 raeburn 1884: # - custom role. Needs more info, too
1.329 raeburn 1885: if ($croletitle) {
1886: if (&Apache::lonnet::allowed('ccr',$coursedom.'/'.$coursedir)) {
1887: $allowed=1;
1888: $thisrole.='.'.$role_code;
1.217 raeburn 1889: }
1.329 raeburn 1890: }
1.418 raeburn 1891: if ($area=~m{^/($match_domain/$match_courseid/(\w+))}) {
1892: $csec = $2;
1893: $carea.='<br />'.&mt('Section: [_1]',$csec);
1894: $sortkey.="\0$csec";
1.329 raeburn 1895: if (!$allowed) {
1.418 raeburn 1896: if ($env{'request.course.sec'} eq $csec) {
1897: if (&Apache::lonnet::allowed('c'.$role_code,$1)) {
1.329 raeburn 1898: $allowed = 1;
1.217 raeburn 1899: }
1900: }
1901: }
1.329 raeburn 1902: }
1903: $area=$carea;
1904: } else {
1905: $sortkey.="\0".$area;
1906: # Determine if current user is able to revoke privileges
1907: if ($area=~m{^/($match_domain)/}) {
1908: if ((&Apache::lonnet::allowed('c'.$role_code,$1)) ||
1909: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
1910: $allowed=1;
1.217 raeburn 1911: }
1.329 raeburn 1912: if (((&Apache::lonnet::allowed('dro',$1)) ||
1913: (&Apache::lonnet::allowed('dro',$ccdomain))) &&
1914: ($role_code ne 'dc')) {
1915: $delallowed=1;
1.217 raeburn 1916: }
1.329 raeburn 1917: } else {
1918: if (&Apache::lonnet::allowed('c'.$role_code,'/')) {
1.217 raeburn 1919: $allowed=1;
1920: }
1921: }
1.363 raeburn 1922: if ($role_code eq 'ca' || $role_code eq 'au' || $role_code eq 'aa') {
1.377 raeburn 1923: $class='Authoring Space';
1.329 raeburn 1924: } elsif ($role_code eq 'su') {
1925: $class='System';
1.217 raeburn 1926: } else {
1.329 raeburn 1927: $class='Domain';
1.217 raeburn 1928: }
1.329 raeburn 1929: }
1930: if (($role_code eq 'ca') || ($role_code eq 'aa')) {
1931: $area=~m{/($match_domain)/($match_username)};
1932: if (&Apache::lonuserutils::authorpriv($2,$1)) {
1933: $allowed=1;
1.217 raeburn 1934: } else {
1.329 raeburn 1935: $allowed=0;
1.217 raeburn 1936: }
1.329 raeburn 1937: }
1938: my $row = '';
1.418 raeburn 1939: if ($showall) {
1940: $row.= '<td>';
1941: if (($active) && ($allowed)) {
1942: $row.= '<input type="checkbox" name="rev:'.$thisrole.'" />';
1943: } else {
1944: if ($active) {
1945: $row.=' ';
1946: } else {
1947: $row.=&mt('expired or revoked');
1948: }
1949: }
1950: $row.='</td><td>';
1951: if ($allowed && !$active) {
1952: $row.= '<input type="checkbox" name="ren:'.$thisrole.'" />';
1953: } else {
1954: $row.=' ';
1955: }
1956: $row.='</td><td>';
1957: if ($delallowed) {
1958: $row.= '<input type="checkbox" name="del:'.$thisrole.'" />';
1.217 raeburn 1959: } else {
1.418 raeburn 1960: $row.=' ';
1.217 raeburn 1961: }
1.430 raeburn 1962: $row.= '</td>';
1.329 raeburn 1963: }
1964: my $plaintext='';
1965: if (!$croletitle) {
1.375 raeburn 1966: $plaintext=&Apache::lonnet::plaintext($role_code,$class);
1967: if (($showcredits) && ($credits ne '')) {
1968: $plaintext .= '<br/ ><span class="LC_nobreak">'.
1969: '<span class="LC_fontsize_small">'.
1970: &mt('Credits: [_1]',$credits).
1971: '</span></span>';
1972: }
1.329 raeburn 1973: } else {
1974: $plaintext=
1.395 bisitz 1975: &mt('Custom role [_1][_2]defined by [_3]',
1.346 bisitz 1976: '"'.$croletitle.'"',
1977: '<br />',
1978: $croleuname.':'.$croleudom);
1.329 raeburn 1979: }
1.418 raeburn 1980: $row.= '<td>'.$plaintext.'</td>'.
1981: '<td>'.$area.'</td>'.
1982: '<td>'.($role_start_time?&Apache::lonlocal::locallocaltime($role_start_time)
1983: : ' ' ).'</td>'.
1984: '<td>'.($role_end_time ?&Apache::lonlocal::locallocaltime($role_end_time)
1985: : ' ' ).'</td>';
1.329 raeburn 1986: $sortrole{$sortkey}=$envkey;
1987: $roletext{$envkey}=$row;
1988: $roleclass{$envkey}=$class;
1.418 raeburn 1989: if ($allowed) {
1990: $rolepriv{$envkey}='edit';
1991: } else {
1992: if ($context eq 'domain') {
1.420 raeburn 1993: if ((&Apache::lonnet::allowed('vur',$ccdomain)) &&
1.421 raeburn 1994: ($envkey=~m{^/$ccdomain/})) {
1.418 raeburn 1995: $rolepriv{$envkey}='view';
1996: }
1997: } elsif ($context eq 'course') {
1998: if ((&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) ||
1999: ($env{'request.course.sec'} && ($env{'request.course.sec'} eq $csec) &&
2000: &Apache::lonnet::allowed('vcl',$env{'request.course.id'}.'/'.$env{'request.course.sec'}))) {
2001: $rolepriv{$envkey}='view';
2002: }
2003: }
2004: }
1.329 raeburn 2005: } # end of foreach (table building loop)
2006:
2007: my $rolesdisplay = 0;
2008: my %output = ();
1.377 raeburn 2009: foreach my $type ('Authoring Space','Course','Community','Domain','System','Unknown') {
1.329 raeburn 2010: $output{$type} = '';
2011: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
2012: if ( ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/ ) && ($rolepriv{$sortrole{$which}}) ) {
2013: $output{$type}.=
2014: &Apache::loncommon::start_data_table_row().
2015: $roletext{$sortrole{$which}}.
2016: &Apache::loncommon::end_data_table_row();
1.217 raeburn 2017: }
1.329 raeburn 2018: }
2019: unless($output{$type} eq '') {
2020: $output{$type} = '<tr class="LC_info_row">'.
2021: "<td align='center' colspan='7'>".&mt($type)."</td></tr>".
2022: $output{$type};
2023: $rolesdisplay = 1;
2024: }
2025: }
2026: if ($rolesdisplay == 1) {
2027: my $contextrole='';
2028: if ($env{'request.course.id'}) {
2029: if (&Apache::loncommon::course_type() eq 'Community') {
2030: $contextrole = &mt('Existing Roles in this Community');
1.290 bisitz 2031: } else {
1.329 raeburn 2032: $contextrole = &mt('Existing Roles in this Course');
1.290 bisitz 2033: }
1.329 raeburn 2034: } elsif ($env{'request.role'} =~ /^au\./) {
1.377 raeburn 2035: $contextrole = &mt('Existing Co-Author Roles in your Authoring Space');
1.329 raeburn 2036: } else {
1.418 raeburn 2037: if ($showall) {
2038: $contextrole = &mt('Existing Roles in this Domain');
2039: } elsif ($showactive) {
2040: $contextrole = &mt('Unexpired Roles in this Domain');
2041: } elsif ($showexpired) {
2042: $contextrole = &mt('Expired or Revoked Roles in this Domain');
2043: }
1.329 raeburn 2044: }
1.393 raeburn 2045: $r->print('<div class="LC_left_float">'.
1.375 raeburn 2046: '<fieldset><legend>'.$contextrole.'</legend>'.
1.217 raeburn 2047: &Apache::loncommon::start_data_table("LC_createuser").
1.418 raeburn 2048: &Apache::loncommon::start_data_table_header_row());
2049: if ($showall) {
2050: $r->print(
1.419 raeburn 2051: '<th>'.$lt{'rev'}.'</th><th>'.$lt{'ren'}.'</th><th>'.$lt{'del'}.'</th>'
1.418 raeburn 2052: );
2053: } elsif ($showexpired) {
2054: $r->print('<th>'.$lt{'rev'}.'</th>');
2055: }
2056: $r->print(
1.419 raeburn 2057: '<th>'.$lt{'rol'}.'</th><th>'.$lt{'ext'}.'</th>'.
2058: '<th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
1.217 raeburn 2059: &Apache::loncommon::end_data_table_header_row());
1.377 raeburn 2060: foreach my $type ('Authoring Space','Course','Community','Domain','System','Unknown') {
1.329 raeburn 2061: if ($output{$type}) {
2062: $r->print($output{$type}."\n");
1.217 raeburn 2063: }
2064: }
1.375 raeburn 2065: $r->print(&Apache::loncommon::end_data_table().
2066: '</fieldset></div>');
1.329 raeburn 2067: }
1.217 raeburn 2068: return;
2069: }
2070:
1.218 raeburn 2071: sub new_coauthor_roles {
2072: my ($r,$ccuname,$ccdomain) = @_;
2073: my $addrolesdisplay = 0;
2074: #
2075: # Co-Author
2076: #
2077: if (&Apache::lonuserutils::authorpriv($env{'user.name'},
2078: $env{'request.role.domain'}) &&
2079: ($env{'user.name'} ne $ccuname || $env{'user.domain'} ne $ccdomain)) {
2080: # No sense in assigning co-author role to yourself
2081: $addrolesdisplay = 1;
2082: my $cuname=$env{'user.name'};
2083: my $cudom=$env{'request.role.domain'};
2084: my %lt=&Apache::lonlocal::texthash(
1.377 raeburn 2085: 'cs' => "Authoring Space",
1.218 raeburn 2086: 'act' => "Activate",
2087: 'rol' => "Role",
2088: 'ext' => "Extent",
2089: 'sta' => "Start",
2090: 'end' => "End",
2091: 'cau' => "Co-Author",
2092: 'caa' => "Assistant Co-Author",
2093: 'ssd' => "Set Start Date",
2094: 'sed' => "Set End Date"
2095: );
2096: $r->print('<h4>'.$lt{'cs'}.'</h4>'."\n".
2097: &Apache::loncommon::start_data_table()."\n".
2098: &Apache::loncommon::start_data_table_header_row()."\n".
2099: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'.
2100: '<th>'.$lt{'ext'}.'</th><th>'.$lt{'sta'}.'</th>'.
2101: '<th>'.$lt{'end'}.'</th>'."\n".
2102: &Apache::loncommon::end_data_table_header_row()."\n".
2103: &Apache::loncommon::start_data_table_row().'
2104: <td>
1.291 bisitz 2105: <input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_ca" />
1.218 raeburn 2106: </td>
2107: <td>'.$lt{'cau'}.'</td>
2108: <td>'.$cudom.'_'.$cuname.'</td>
2109: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_ca" value="" />
2110: <a href=
2111: "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>
2112: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_ca" value="" />
2113: <a href=
2114: "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".
2115: &Apache::loncommon::end_data_table_row()."\n".
2116: &Apache::loncommon::start_data_table_row()."\n".
1.291 bisitz 2117: '<td><input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_aa" /></td>
1.218 raeburn 2118: <td>'.$lt{'caa'}.'</td>
2119: <td>'.$cudom.'_'.$cuname.'</td>
2120: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_aa" value="" />
2121: <a href=
2122: "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>
2123: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_aa" value="" />
2124: <a href=
2125: "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".
2126: &Apache::loncommon::end_data_table_row()."\n".
2127: &Apache::loncommon::end_data_table());
2128: } elsif ($env{'request.role'} =~ /^au\./) {
2129: if (!(&Apache::lonuserutils::authorpriv($env{'user.name'},
2130: $env{'request.role.domain'}))) {
2131: $r->print('<span class="LC_error">'.
2132: &mt('You do not have privileges to assign co-author roles.').
2133: '</span>');
2134: } elsif (($env{'user.name'} eq $ccuname) &&
2135: ($env{'user.domain'} eq $ccdomain)) {
1.377 raeburn 2136: $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 2137: }
2138: }
2139: return $addrolesdisplay;;
2140: }
2141:
2142: sub new_domain_roles {
1.357 raeburn 2143: my ($r,$ccdomain) = @_;
1.218 raeburn 2144: my $addrolesdisplay = 0;
2145: #
2146: # Domain level
2147: #
2148: my $num_domain_level = 0;
2149: my $domaintext =
2150: '<h4>'.&mt('Domain Level').'</h4>'.
2151: &Apache::loncommon::start_data_table().
2152: &Apache::loncommon::start_data_table_header_row().
2153: '<th>'.&mt('Activate').'</th><th>'.&mt('Role').'</th><th>'.
2154: &mt('Extent').'</th>'.
2155: '<th>'.&mt('Start').'</th><th>'.&mt('End').'</th>'.
2156: &Apache::loncommon::end_data_table_header_row();
1.312 raeburn 2157: my @allroles = &Apache::lonuserutils::roles_by_context('domain');
1.445 raeburn 2158: my $uprimary = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
2159: my $uintdom = &Apache::lonnet::internet_dom($uprimary);
1.218 raeburn 2160: foreach my $thisdomain (sort(&Apache::lonnet::all_domains())) {
1.312 raeburn 2161: foreach my $role (@allroles) {
2162: next if ($role eq 'ad');
1.357 raeburn 2163: next if (($role eq 'au') && ($ccdomain ne $thisdomain));
1.218 raeburn 2164: if (&Apache::lonnet::allowed('c'.$role,$thisdomain)) {
1.445 raeburn 2165: if ($role eq 'dc') {
2166: unless ($thisdomain eq $env{'request.role.domain'}) {
2167: my $domprim = &Apache::lonnet::domain($thisdomain,'primary');
2168: my $intdom = &Apache::lonnet::internet_dom($domprim);
2169: next unless ($uintdom eq $intdom);
2170: }
2171: }
1.218 raeburn 2172: my $plrole=&Apache::lonnet::plaintext($role);
2173: my %lt=&Apache::lonlocal::texthash(
2174: 'ssd' => "Set Start Date",
2175: 'sed' => "Set End Date"
2176: );
2177: $num_domain_level ++;
2178: $domaintext .=
2179: &Apache::loncommon::start_data_table_row().
1.291 bisitz 2180: '<td><input type="checkbox" name="act_'.$thisdomain.'_'.$role.'" /></td>
1.218 raeburn 2181: <td>'.$plrole.'</td>
2182: <td>'.$thisdomain.'</td>
2183: <td><input type="hidden" name="start_'.$thisdomain.'_'.$role.'" value="" />
2184: <a href=
2185: "javascript:pjump('."'date_start','Start Date $plrole',document.cu.start_$thisdomain\_$role.value,'start_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'ssd'}.'</a></td>
2186: <td><input type="hidden" name="end_'.$thisdomain.'_'.$role.'" value="" />
2187: <a href=
2188: "javascript:pjump('."'date_end','End Date $plrole',document.cu.end_$thisdomain\_$role.value,'end_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'sed'}.'</a></td>'.
2189: &Apache::loncommon::end_data_table_row();
2190: }
2191: }
2192: }
2193: $domaintext.= &Apache::loncommon::end_data_table();
2194: if ($num_domain_level > 0) {
2195: $r->print($domaintext);
2196: $addrolesdisplay = 1;
2197: }
2198: return $addrolesdisplay;
2199: }
2200:
1.188 raeburn 2201: sub user_authentication {
1.451 raeburn 2202: my ($ccuname,$ccdomain,$formname,$crstype,$permission) = @_;
1.188 raeburn 2203: my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
1.227 raeburn 2204: my $outcome;
1.418 raeburn 2205: my %lt=&Apache::lonlocal::texthash(
2206: 'err' => "ERROR",
2207: 'uuas' => "This user has an unrecognized authentication scheme",
2208: 'adcs' => "Please alert a domain coordinator of this situation",
2209: 'sldb' => "Please specify login data below",
2210: 'ld' => "Login Data"
2211: );
1.188 raeburn 2212: # Check for a bad authentication type
1.449 raeburn 2213: if ($currentauth !~ /^(krb4|krb5|unix|internal|localauth|lti):/) {
1.188 raeburn 2214: # bad authentication scheme
2215: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
1.227 raeburn 2216: &initialize_authen_forms($ccdomain,$formname);
2217:
1.190 raeburn 2218: my $choices = &Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc);
1.188 raeburn 2219: $outcome = <<ENDBADAUTH;
2220: <script type="text/javascript" language="Javascript">
1.301 bisitz 2221: // <![CDATA[
1.188 raeburn 2222: $loginscript
1.301 bisitz 2223: // ]]>
1.188 raeburn 2224: </script>
2225: <span class="LC_error">$lt{'err'}:
2226: $lt{'uuas'} ($currentauth). $lt{'sldb'}.</span>
2227: <h3>$lt{'ld'}</h3>
2228: $choices
2229: ENDBADAUTH
2230: } else {
2231: # This user is not allowed to modify the user's
2232: # authentication scheme, so just notify them of the problem
2233: $outcome = <<ENDBADAUTH;
2234: <span class="LC_error"> $lt{'err'}:
2235: $lt{'uuas'} ($currentauth). $lt{'adcs'}.
2236: </span>
2237: ENDBADAUTH
2238: }
2239: } else { # Authentication type is valid
1.418 raeburn 2240:
1.227 raeburn 2241: &initialize_authen_forms($ccdomain,$formname,$currentauth,'modifyuser');
1.205 raeburn 2242: my ($authformcurrent,$can_modify,@authform_others) =
1.188 raeburn 2243: &modify_login_block($ccdomain,$currentauth);
2244: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
2245: # Current user has login modification privileges
2246: $outcome =
2247: '<script type="text/javascript" language="Javascript">'."\n".
1.301 bisitz 2248: '// <![CDATA['."\n".
1.188 raeburn 2249: $loginscript."\n".
1.301 bisitz 2250: '// ]]>'."\n".
1.188 raeburn 2251: '</script>'."\n".
2252: '<h3>'.$lt{'ld'}.'</h3>'.
2253: &Apache::loncommon::start_data_table().
1.205 raeburn 2254: &Apache::loncommon::start_data_table_row().
1.188 raeburn 2255: '<td>'.$authformnop;
1.418 raeburn 2256: if (($can_modify) && (&Apache::lonnet::allowed('mau',$ccdomain))) {
1.188 raeburn 2257: $outcome .= '</td>'."\n".
2258: &Apache::loncommon::end_data_table_row().
2259: &Apache::loncommon::start_data_table_row().
2260: '<td>'.$authformcurrent.'</td>'.
2261: &Apache::loncommon::end_data_table_row()."\n";
2262: } else {
1.200 raeburn 2263: $outcome .= ' ('.$authformcurrent.')</td>'.
2264: &Apache::loncommon::end_data_table_row()."\n";
1.188 raeburn 2265: }
1.418 raeburn 2266: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
2267: foreach my $item (@authform_others) {
2268: $outcome .= &Apache::loncommon::start_data_table_row().
2269: '<td>'.$item.'</td>'.
2270: &Apache::loncommon::end_data_table_row()."\n";
2271: }
1.188 raeburn 2272: }
1.205 raeburn 2273: $outcome .= &Apache::loncommon::end_data_table();
1.188 raeburn 2274: } else {
1.451 raeburn 2275: if (($currentauth =~ /^internal:/) &&
2276: (&Apache::lonuserutils::can_change_internalpass($ccuname,$ccdomain,$crstype,$permission))) {
2277: $outcome = <<"ENDJS";
2278: <script type="text/javascript">
2279: // <![CDATA[
2280: function togglePwd(form) {
2281: if (form.newintpwd.length) {
2282: if (document.getElementById('LC_ownersetpwd')) {
2283: for (var i=0; i<form.newintpwd.length; i++) {
2284: if (form.newintpwd[i].checked) {
2285: if (form.newintpwd[i].value == 1) {
2286: document.getElementById('LC_ownersetpwd').style.display = 'inline-block';
2287: } else {
2288: document.getElementById('LC_ownersetpwd').style.display = 'none';
2289: }
2290: }
2291: }
2292: }
2293: }
2294: }
2295: // ]]>
2296: </script>
2297: ENDJS
2298:
2299: $outcome .= '<h3>'.$lt{'ld'}.'</h3>'.
2300: &Apache::loncommon::start_data_table().
2301: &Apache::loncommon::start_data_table_row().
2302: '<td>'.&mt('Internally authenticated').'<br />'.&mt("Change user's password?").
2303: '<label><input type="radio" name="newintpwd" value="0" checked="checked" onclick="togglePwd(this.form);" />'.
2304: &mt('No').'</label>'.(' 'x2).
2305: '<label><input type="radio" name="newintpwd" value="1" onclick="togglePwd(this.form);" />'.&mt('Yes').'</label>'.
2306: '<div id="LC_ownersetpwd" style="display:none">'.
2307: ' '.&mt('Password').' <input type="password" size="15" name="intarg" value="" />'.
2308: '<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>'.
2309: &Apache::loncommon::end_data_table_row().
2310: &Apache::loncommon::end_data_table();
2311: }
1.418 raeburn 2312: if (&Apache::lonnet::allowed('udp',$ccdomain)) {
2313: # Current user has rights to view domain preferences for user's domain
2314: my $result;
2315: if ($currentauth =~ /^krb(4|5):([^:]*)$/) {
2316: my ($krbver,$krbrealm) = ($1,$2);
2317: if ($krbrealm eq '') {
2318: $result = &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2319: } else {
2320: $result = &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
1.426 raeburn 2321: $krbrealm,$krbver);
1.418 raeburn 2322: }
2323: } elsif ($currentauth =~ /^internal:/) {
2324: $result = &mt('Currently internally authenticated.');
2325: } elsif ($currentauth =~ /^localauth:/) {
2326: $result = &mt('Currently using local (institutional) authentication.');
2327: } elsif ($currentauth =~ /^unix:/) {
2328: $result = &mt('Currently Filesystem Authenticated.');
1.449 raeburn 2329: } elsif ($currentauth =~ /^lti:/) {
1.451 raeburn 2330: $result = &mt('Currently LTI authenticated.');
1.418 raeburn 2331: }
2332: $outcome = '<h3>'.$lt{'ld'}.'</h3>'.
2333: &Apache::loncommon::start_data_table().
2334: &Apache::loncommon::start_data_table_row().
2335: '<td>'.$result.'</td>'.
2336: &Apache::loncommon::end_data_table_row()."\n".
2337: &Apache::loncommon::end_data_table();
2338: } elsif (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
1.188 raeburn 2339: my %lt=&Apache::lonlocal::texthash(
2340: 'ccld' => "Change Current Login Data",
2341: 'yodo' => "You do not have privileges to modify the authentication configuration for this user.",
2342: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
2343: );
2344: $outcome .= <<ENDNOPRIV;
2345: <h3>$lt{'ccld'}</h3>
2346: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1.235 raeburn 2347: <input type="hidden" name="login" value="nochange" />
1.188 raeburn 2348: ENDNOPRIV
2349: }
2350: }
2351: } ## End of "check for bad authentication type" logic
2352: return $outcome;
2353: }
2354:
1.187 raeburn 2355: sub modify_login_block {
2356: my ($dom,$currentauth) = @_;
2357: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2358: my ($authnum,%can_assign) =
2359: &Apache::loncommon::get_assignable_auth($dom);
1.205 raeburn 2360: my ($authformcurrent,@authform_others,$show_override_msg);
1.187 raeburn 2361: if ($currentauth=~/^krb(4|5):/) {
2362: $authformcurrent=$authformkrb;
2363: if ($can_assign{'int'}) {
1.205 raeburn 2364: push(@authform_others,$authformint);
1.187 raeburn 2365: }
2366: if ($can_assign{'loc'}) {
1.205 raeburn 2367: push(@authform_others,$authformloc);
1.187 raeburn 2368: }
1.449 raeburn 2369: if ($can_assign{'lti'}) {
2370: push(@authform_others,$authformlti);
2371: }
1.187 raeburn 2372: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
2373: $show_override_msg = 1;
2374: }
2375: } elsif ($currentauth=~/^internal:/) {
2376: $authformcurrent=$authformint;
2377: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2378: push(@authform_others,$authformkrb);
1.187 raeburn 2379: }
2380: if ($can_assign{'loc'}) {
1.205 raeburn 2381: push(@authform_others,$authformloc);
1.187 raeburn 2382: }
1.449 raeburn 2383: if ($can_assign{'lti'}) {
2384: push(@authform_others,$authformlti);
2385: }
1.187 raeburn 2386: if ($can_assign{'int'}) {
2387: $show_override_msg = 1;
2388: }
2389: } elsif ($currentauth=~/^unix:/) {
2390: $authformcurrent=$authformfsys;
2391: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2392: push(@authform_others,$authformkrb);
1.187 raeburn 2393: }
2394: if ($can_assign{'int'}) {
1.205 raeburn 2395: push(@authform_others,$authformint);
1.187 raeburn 2396: }
2397: if ($can_assign{'loc'}) {
1.205 raeburn 2398: push(@authform_others,$authformloc);
1.187 raeburn 2399: }
1.449 raeburn 2400: if ($can_assign{'lti'}) {
2401: push(@authform_others,$authformlti);
2402: }
1.187 raeburn 2403: if ($can_assign{'fsys'}) {
2404: $show_override_msg = 1;
2405: }
2406: } elsif ($currentauth=~/^localauth:/) {
2407: $authformcurrent=$authformloc;
2408: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2409: push(@authform_others,$authformkrb);
1.187 raeburn 2410: }
2411: if ($can_assign{'int'}) {
1.205 raeburn 2412: push(@authform_others,$authformint);
1.187 raeburn 2413: }
1.449 raeburn 2414: if ($can_assign{'lti'}) {
2415: push(@authform_others,$authformlti);
2416: }
1.187 raeburn 2417: if ($can_assign{'loc'}) {
2418: $show_override_msg = 1;
2419: }
1.449 raeburn 2420: } elsif ($currentauth=~/^lti:/) {
2421: $authformcurrent=$authformlti;
2422: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
2423: push(@authform_others,$authformkrb);
2424: }
2425: if ($can_assign{'int'}) {
2426: push(@authform_others,$authformint);
2427: }
2428: if ($can_assign{'loc'}) {
2429: push(@authform_others,$authformloc);
2430: }
1.187 raeburn 2431: }
2432: if ($show_override_msg) {
1.205 raeburn 2433: $authformcurrent = '<table><tr><td colspan="3">'.$authformcurrent.
2434: '</td></tr>'."\n".
2435: '<tr><td> </td>'.
2436: '<td><b>'.&mt('Currently in use').'</b></td>'.
2437: '<td align="right"><span class="LC_cusr_emph">'.
1.187 raeburn 2438: &mt('will override current values').
1.205 raeburn 2439: '</span></td></tr></table>';
1.187 raeburn 2440: }
1.205 raeburn 2441: return ($authformcurrent,$show_override_msg,@authform_others);
1.187 raeburn 2442: }
2443:
1.188 raeburn 2444: sub personal_data_display {
1.456 ! raeburn 2445: my ($ccuname,$ccdomain,$newuser,$context,$inst_results,$rolesarray,$now,
! 2446: $captchaform,$emailusername,$usertype,$usernameset,$condition,$excluded,$showsubmit) = @_;
1.388 bisitz 2447: my ($output,%userenv,%canmodify,%canmodify_status);
1.219 raeburn 2448: my @userinfo = ('firstname','middlename','lastname','generation',
2449: 'permanentemail','id');
1.252 raeburn 2450: my $rowcount = 0;
2451: my $editable = 0;
1.391 raeburn 2452: my %textboxsize = (
2453: firstname => '15',
2454: middlename => '15',
2455: lastname => '15',
2456: generation => '5',
2457: permanentemail => '25',
2458: id => '15',
2459: );
2460:
2461: my %lt=&Apache::lonlocal::texthash(
2462: 'pd' => "Personal Data",
2463: 'firstname' => "First Name",
2464: 'middlename' => "Middle Name",
2465: 'lastname' => "Last Name",
2466: 'generation' => "Generation",
2467: 'permanentemail' => "Permanent e-mail address",
2468: 'id' => "Student/Employee ID",
2469: 'lg' => "Login Data",
2470: 'inststatus' => "Affiliation",
2471: 'email' => 'E-mail address',
2472: 'valid' => 'Validation',
1.442 raeburn 2473: 'username' => 'Username',
1.391 raeburn 2474: );
2475:
2476: %canmodify_status =
1.286 raeburn 2477: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
2478: ['inststatus'],$rolesarray);
1.253 raeburn 2479: if (!$newuser) {
1.188 raeburn 2480: # Get the users information
2481: %userenv = &Apache::lonnet::get('environment',
2482: ['firstname','middlename','lastname','generation',
1.286 raeburn 2483: 'permanentemail','id','inststatus'],$ccdomain,$ccuname);
1.219 raeburn 2484: %canmodify =
2485: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
1.252 raeburn 2486: \@userinfo,$rolesarray);
1.257 raeburn 2487: } elsif ($context eq 'selfcreate') {
1.391 raeburn 2488: if ($newuser eq 'email') {
1.396 raeburn 2489: if (ref($emailusername) eq 'HASH') {
2490: if (ref($emailusername->{$usertype}) eq 'HASH') {
2491: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.442 raeburn 2492: @userinfo = ();
1.396 raeburn 2493: if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
2494: foreach my $field (@{$infofields}) {
2495: if ($emailusername->{$usertype}->{$field}) {
2496: push(@userinfo,$field);
2497: $canmodify{$field} = 1;
2498: unless ($textboxsize{$field}) {
2499: $textboxsize{$field} = 25;
2500: }
2501: unless ($lt{$field}) {
2502: $lt{$field} = $infotitles->{$field};
2503: }
2504: if ($emailusername->{$usertype}->{$field} eq 'required') {
2505: $lt{$field} .= '<b>*</b>';
2506: }
1.391 raeburn 2507: }
2508: }
2509: }
2510: }
2511: }
2512: } else {
2513: %canmodify = &selfcreate_canmodify($context,$ccdomain,\@userinfo,
2514: $inst_results,$rolesarray);
2515: }
1.188 raeburn 2516: }
1.391 raeburn 2517:
1.188 raeburn 2518: my $genhelp=&Apache::loncommon::help_open_topic('Generation');
2519: $output = '<h3>'.$lt{'pd'}.'</h3>'.
2520: &Apache::lonhtmlcommon::start_pick_box();
1.391 raeburn 2521: if (($context eq 'selfcreate') && ($newuser eq 'email')) {
1.443 raeburn 2522: my $size = 25;
1.442 raeburn 2523: if ($condition) {
1.443 raeburn 2524: if ($condition =~ /^\@[^\@]+$/) {
2525: $size = 10;
1.442 raeburn 2526: } else {
2527: undef($condition);
2528: }
1.443 raeburn 2529: }
2530: if ($excluded) {
2531: unless ($excluded =~ /^\@[^\@]+$/) {
2532: undef($condition);
2533: }
1.442 raeburn 2534: }
1.396 raeburn 2535: $output .= &Apache::lonhtmlcommon::row_title($lt{'email'}.'<b>*</b>',undef,
1.391 raeburn 2536: 'LC_oddrow_value')."\n".
1.443 raeburn 2537: '<input type="text" name="uname" size="'.$size.'" value="" autocomplete="off" />';
2538: if ($condition) {
2539: $output .= $condition;
2540: } elsif ($excluded) {
2541: $output .= '<br /><span style="font-size: smaller">'.&mt('You must use an e-mail address that does not end with [_1]',
2542: $excluded).'</span>';
2543: }
2544: if ($usernameset eq 'first') {
2545: $output .= '<br /><span style="font-size: smaller">';
2546: if ($condition) {
2547: $output .= &mt('Your username in LON-CAPA will be the part of your e-mail address before [_1]',
2548: $condition);
2549: } else {
2550: $output .= &mt('Your username in LON-CAPA will be the part of your e-mail address before the @');
2551: }
2552: $output .= '</span>';
2553: }
1.391 raeburn 2554: $rowcount ++;
2555: $output .= &Apache::lonhtmlcommon::row_closure(1);
1.408 raeburn 2556: my $upassone = '<input type="password" name="upass'.$now.'" size="20" autocomplete="off" />';
2557: my $upasstwo = '<input type="password" name="upasscheck'.$now.'" size="20" autocomplete="off" />';
1.396 raeburn 2558: $output .= &Apache::lonhtmlcommon::row_title(&mt('Password').'<b>*</b>',
1.391 raeburn 2559: 'LC_pick_box_title',
2560: 'LC_oddrow_value')."\n".
2561: $upassone."\n".
2562: &Apache::lonhtmlcommon::row_closure(1)."\n".
1.396 raeburn 2563: &Apache::lonhtmlcommon::row_title(&mt('Confirm password').'<b>*</b>',
1.391 raeburn 2564: 'LC_pick_box_title',
2565: 'LC_oddrow_value')."\n".
2566: $upasstwo.
2567: &Apache::lonhtmlcommon::row_closure()."\n";
1.443 raeburn 2568: if ($usernameset eq 'free') {
2569: my $onclick = "toggleUsernameDisp(this,'selfcreateusername');";
1.442 raeburn 2570: $output .= &Apache::lonhtmlcommon::row_title($lt{'username'},undef,'LC_oddrow_value')."\n".
1.455 raeburn 2571: '<span class="LC_nobreak">'.&mt('Use e-mail address: ').
2572: '<label><input type="radio" name="emailused" value="1" checked="checked" onclick="'.$onclick.'" />'.
2573: &mt('Yes').'</label>'.(' 'x2).
2574: '<label><input type="radio" name="emailused" value="0" onclick="'.$onclick.'" />'.
2575: &mt('No').'</label></span>'."\n".
1.442 raeburn 2576: '<div id="selfcreateusername" style="display: none; font-size: smaller">'.
2577: '<br /><span class="LC_nobreak">'.&mt('Preferred username').
2578: ' <input type="text" name="username" value="" size="20" autocomplete="off"/>'.
2579: '</span></div>'."\n".&Apache::lonhtmlcommon::row_closure(1);
2580: $rowcount ++;
2581: }
1.391 raeburn 2582: }
1.188 raeburn 2583: foreach my $item (@userinfo) {
2584: my $rowtitle = $lt{$item};
1.252 raeburn 2585: my $hiderow = 0;
1.188 raeburn 2586: if ($item eq 'generation') {
2587: $rowtitle = $genhelp.$rowtitle;
2588: }
1.252 raeburn 2589: my $row = &Apache::lonhtmlcommon::row_title($rowtitle,undef,'LC_oddrow_value')."\n";
1.188 raeburn 2590: if ($newuser) {
1.210 raeburn 2591: if (ref($inst_results) eq 'HASH') {
2592: if ($inst_results->{$item} ne '') {
1.252 raeburn 2593: $row .= '<input type="hidden" name="c'.$item.'" value="'.$inst_results->{$item}.'" />'.$inst_results->{$item};
1.210 raeburn 2594: } else {
1.252 raeburn 2595: if ($context eq 'selfcreate') {
1.391 raeburn 2596: if ($canmodify{$item}) {
1.394 raeburn 2597: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.252 raeburn 2598: $editable ++;
2599: } else {
2600: $hiderow = 1;
2601: }
1.253 raeburn 2602: } else {
2603: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1.252 raeburn 2604: }
1.210 raeburn 2605: }
1.188 raeburn 2606: } else {
1.252 raeburn 2607: if ($context eq 'selfcreate') {
1.401 raeburn 2608: if ($canmodify{$item}) {
2609: if ($newuser eq 'email') {
2610: $row .= '<input type="text" name="'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.287 raeburn 2611: } else {
1.401 raeburn 2612: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.287 raeburn 2613: }
1.401 raeburn 2614: $editable ++;
2615: } else {
2616: $hiderow = 1;
1.252 raeburn 2617: }
1.253 raeburn 2618: } else {
2619: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1.252 raeburn 2620: }
1.188 raeburn 2621: }
2622: } else {
1.219 raeburn 2623: if ($canmodify{$item}) {
1.252 raeburn 2624: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="'.$userenv{$item}.'" />';
1.393 raeburn 2625: if (($item eq 'id') && (!$newuser)) {
2626: $row .= '<br />'.&Apache::lonuserutils::forceid_change($context);
2627: }
1.188 raeburn 2628: } else {
1.252 raeburn 2629: $row .= $userenv{$item};
1.188 raeburn 2630: }
2631: }
1.252 raeburn 2632: $row .= &Apache::lonhtmlcommon::row_closure(1);
2633: if (!$hiderow) {
2634: $output .= $row;
2635: $rowcount ++;
2636: }
1.188 raeburn 2637: }
1.286 raeburn 2638: if (($canmodify_status{'inststatus'}) || ($context ne 'selfcreate')) {
2639: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($ccdomain);
2640: if (ref($types) eq 'ARRAY') {
2641: if (@{$types} > 0) {
2642: my ($hiderow,$shown);
2643: if ($canmodify_status{'inststatus'}) {
2644: $shown = &pick_inst_statuses($userenv{'inststatus'},$usertypes,$types);
2645: } else {
2646: if ($userenv{'inststatus'} eq '') {
2647: $hiderow = 1;
1.334 raeburn 2648: } else {
2649: my @showitems;
2650: foreach my $item ( map { &unescape($_); } split(':',$userenv{'inststatus'})) {
2651: if (exists($usertypes->{$item})) {
2652: push(@showitems,$usertypes->{$item});
2653: } else {
2654: push(@showitems,$item);
2655: }
2656: }
2657: if (@showitems) {
2658: $shown = join(', ',@showitems);
2659: } else {
2660: $hiderow = 1;
2661: }
1.286 raeburn 2662: }
2663: }
2664: if (!$hiderow) {
1.389 bisitz 2665: my $row = &Apache::lonhtmlcommon::row_title(&mt('Affiliations'),undef,'LC_oddrow_value')."\n".
1.286 raeburn 2666: $shown.&Apache::lonhtmlcommon::row_closure(1);
2667: if ($context eq 'selfcreate') {
2668: $rowcount ++;
2669: }
2670: $output .= $row;
2671: }
2672: }
2673: }
2674: }
1.391 raeburn 2675: if (($context eq 'selfcreate') && ($newuser eq 'email')) {
2676: if ($captchaform) {
1.410 raeburn 2677: $output .= &Apache::lonhtmlcommon::row_title($lt{'valid'}.'*',
2678: 'LC_pick_box_title')."\n".
1.456 ! raeburn 2679: $captchaform."\n".'<br /><br />'.
1.391 raeburn 2680: &Apache::lonhtmlcommon::row_closure(1);
2681: $rowcount ++;
2682: }
1.456 ! raeburn 2683: if ($showsubmit) {
! 2684: my $submit_text = &mt('Create account');
! 2685: $output .= &Apache::lonhtmlcommon::row_title()."\n".
! 2686: '<br /><input type="submit" name="createaccount" value="'.
! 2687: $submit_text.'" />';
! 2688: if ($usertype ne '') {
! 2689: $output .= '<input type="hidden" name="type" value="'.
! 2690: &HTML::Entities::encode($usertype,'\'<>"&').'" />';
! 2691: }
! 2692: $output .= &Apache::lonhtmlcommon::row_closure(1);
! 2693: }
1.391 raeburn 2694: }
1.188 raeburn 2695: $output .= &Apache::lonhtmlcommon::end_pick_box();
1.206 raeburn 2696: if (wantarray) {
1.252 raeburn 2697: if ($context eq 'selfcreate') {
2698: return($output,$rowcount,$editable);
2699: } else {
1.388 bisitz 2700: return $output;
1.252 raeburn 2701: }
1.206 raeburn 2702: } else {
2703: return $output;
2704: }
1.188 raeburn 2705: }
2706:
1.286 raeburn 2707: sub pick_inst_statuses {
2708: my ($curr,$usertypes,$types) = @_;
2709: my ($output,$rem,@currtypes);
2710: if ($curr ne '') {
2711: @currtypes = map { &unescape($_); } split(/:/,$curr);
2712: }
2713: my $numinrow = 2;
2714: if (ref($types) eq 'ARRAY') {
2715: $output = '<table>';
2716: my $lastcolspan;
2717: for (my $i=0; $i<@{$types}; $i++) {
2718: if (defined($usertypes->{$types->[$i]})) {
2719: my $rem = $i%($numinrow);
2720: if ($rem == 0) {
2721: if ($i<@{$types}-1) {
2722: if ($i > 0) {
2723: $output .= '</tr>';
2724: }
2725: $output .= '<tr>';
2726: }
2727: } elsif ($i==@{$types}-1) {
2728: my $colsleft = $numinrow - $rem;
2729: if ($colsleft > 1) {
2730: $lastcolspan = ' colspan="'.$colsleft.'"';
2731: }
2732: }
2733: my $check = ' ';
2734: if (grep(/^\Q$types->[$i]\E$/,@currtypes)) {
2735: $check = ' checked="checked" ';
2736: }
2737: $output .= '<td class="LC_left_item"'.$lastcolspan.'>'.
2738: '<span class="LC_nobreak"><label>'.
2739: '<input type="checkbox" name="inststatus" '.
2740: 'value="'.$types->[$i].'"'.$check.'/>'.
2741: $usertypes->{$types->[$i]}.'</label></span></td>';
2742: }
2743: }
2744: $output .= '</tr></table>';
2745: }
2746: return $output;
2747: }
2748:
1.257 raeburn 2749: sub selfcreate_canmodify {
2750: my ($context,$dom,$userinfo,$inst_results,$rolesarray) = @_;
2751: if (ref($inst_results) eq 'HASH') {
2752: my @inststatuses = &get_inststatuses($inst_results);
2753: if (@inststatuses == 0) {
2754: @inststatuses = ('default');
2755: }
2756: $rolesarray = \@inststatuses;
2757: }
2758: my %canmodify =
2759: &Apache::lonuserutils::can_modify_userinfo($context,$dom,$userinfo,
2760: $rolesarray);
2761: return %canmodify;
2762: }
2763:
1.252 raeburn 2764: sub get_inststatuses {
2765: my ($insthashref) = @_;
2766: my @inststatuses = ();
2767: if (ref($insthashref) eq 'HASH') {
2768: if (ref($insthashref->{'inststatus'}) eq 'ARRAY') {
2769: @inststatuses = @{$insthashref->{'inststatus'}};
2770: }
2771: }
2772: return @inststatuses;
2773: }
2774:
1.4 www 2775: # ================================================================= Phase Three
1.42 matthew 2776: sub update_user_data {
1.451 raeburn 2777: my ($r,$context,$crstype,$brcrum,$showcredits,$permission) = @_;
1.101 albertel 2778: my $uhome=&Apache::lonnet::homeserver($env{'form.ccuname'},
2779: $env{'form.ccdomain'});
1.27 matthew 2780: # Error messages
1.188 raeburn 2781: my $error = '<span class="LC_error">'.&mt('Error').': ';
1.193 raeburn 2782: my $end = '</span><br /><br />';
2783: my $rtnlink = '<a href="javascript:backPage(document.userupdate,'.
1.188 raeburn 2784: "'$env{'form.prevphase'}','modify')".'" />'.
1.219 raeburn 2785: &mt('Return to previous page').'</a>'.
2786: &Apache::loncommon::end_page();
2787: my $now = time;
1.40 www 2788: my $title;
1.101 albertel 2789: if (exists($env{'form.makeuser'})) {
1.40 www 2790: $title='Set Privileges for New User';
2791: } else {
2792: $title='Modify User Privileges';
2793: }
1.213 raeburn 2794: my $newuser = 0;
1.160 raeburn 2795: my ($jsback,$elements) = &crumb_utilities();
2796: my $jscript = '<script type="text/javascript">'."\n".
1.301 bisitz 2797: '// <![CDATA['."\n".
2798: $jsback."\n".
2799: '// ]]>'."\n".
2800: '</script>'."\n";
1.422 raeburn 2801: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$env{'form.ccdomain'});
1.351 raeburn 2802: push (@{$brcrum},
2803: {href => "javascript:backPage(document.userupdate)",
2804: text => $breadcrumb_text{'search'},
2805: faq => 282,
2806: bug => 'Instructor Interface',}
2807: );
2808: if ($env{'form.prevphase'} eq 'userpicked') {
2809: push(@{$brcrum},
2810: {href => "javascript:backPage(document.userupdate,'get_user_info','select')",
2811: text => $breadcrumb_text{'userpicked'},
2812: faq => 282,
2813: bug => 'Instructor Interface',});
1.233 raeburn 2814: }
1.224 raeburn 2815: my $helpitem = 'Course_Change_Privileges';
2816: if ($env{'form.action'} eq 'singlestudent') {
2817: $helpitem = 'Course_Add_Student';
1.439 raeburn 2818: } elsif ($context eq 'author') {
2819: $helpitem = 'Author_Change_Privileges';
2820: } elsif ($context eq 'domain') {
2821: $helpitem = 'Domain_Change_Privileges';
1.224 raeburn 2822: }
1.351 raeburn 2823: push(@{$brcrum},
2824: {href => "javascript:backPage(document.userupdate,'$env{'form.prevphase'}','modify')",
2825: text => $breadcrumb_text{'modify'},
2826: faq => 282,
2827: bug => 'Instructor Interface',},
2828: {href => "/adm/createuser",
2829: text => "Result",
2830: faq => 282,
2831: bug => 'Instructor Interface',
2832: help => $helpitem});
2833: my $args = {bread_crumbs => $brcrum,
2834: bread_crumbs_component => 'User Management'};
2835: if ($env{'form.popup'}) {
2836: $args->{'no_nav_bar'} = 1;
2837: }
2838: $r->print(&Apache::loncommon::start_page($title,$jscript,$args));
1.188 raeburn 2839: $r->print(&update_result_form($uhome));
1.27 matthew 2840: # Check Inputs
1.101 albertel 2841: if (! $env{'form.ccuname'} ) {
1.193 raeburn 2842: $r->print($error.&mt('No login name specified').'.'.$end.$rtnlink);
1.27 matthew 2843: return;
2844: }
1.138 albertel 2845: if ( $env{'form.ccuname'} ne
2846: &LONCAPA::clean_username($env{'form.ccuname'}) ) {
1.281 bisitz 2847: $r->print($error.&mt('Invalid login name.').' '.
2848: &mt('Only letters, numbers, periods, dashes, @, and underscores are valid.').
1.193 raeburn 2849: $end.$rtnlink);
1.27 matthew 2850: return;
2851: }
1.101 albertel 2852: if (! $env{'form.ccdomain'} ) {
1.193 raeburn 2853: $r->print($error.&mt('No domain specified').'.'.$end.$rtnlink);
1.27 matthew 2854: return;
2855: }
1.138 albertel 2856: if ( $env{'form.ccdomain'} ne
2857: &LONCAPA::clean_domain($env{'form.ccdomain'}) ) {
1.281 bisitz 2858: $r->print($error.&mt('Invalid domain name.').' '.
2859: &mt('Only letters, numbers, periods, dashes, and underscores are valid.').
1.193 raeburn 2860: $end.$rtnlink);
1.27 matthew 2861: return;
2862: }
1.219 raeburn 2863: if ($uhome eq 'no_host') {
2864: $newuser = 1;
2865: }
1.101 albertel 2866: if (! exists($env{'form.makeuser'})) {
1.29 matthew 2867: # Modifying an existing user, so check the validity of the name
2868: if ($uhome eq 'no_host') {
1.389 bisitz 2869: $r->print(
2870: $error
2871: .'<p class="LC_error">'
2872: .&mt('Unable to determine home server for [_1] in domain [_2].',
2873: '"'.$env{'form.ccuname'}.'"','"'.$env{'form.ccdomain'}.'"')
2874: .'</p>');
1.29 matthew 2875: return;
2876: }
2877: }
1.27 matthew 2878: # Determine authentication method and password for the user being modified
2879: my $amode='';
2880: my $genpwd='';
1.101 albertel 2881: if ($env{'form.login'} eq 'krb') {
1.41 albertel 2882: $amode='krb';
1.101 albertel 2883: $amode.=$env{'form.krbver'};
2884: $genpwd=$env{'form.krbarg'};
2885: } elsif ($env{'form.login'} eq 'int') {
1.27 matthew 2886: $amode='internal';
1.101 albertel 2887: $genpwd=$env{'form.intarg'};
2888: } elsif ($env{'form.login'} eq 'fsys') {
1.27 matthew 2889: $amode='unix';
1.101 albertel 2890: $genpwd=$env{'form.fsysarg'};
2891: } elsif ($env{'form.login'} eq 'loc') {
1.27 matthew 2892: $amode='localauth';
1.101 albertel 2893: $genpwd=$env{'form.locarg'};
1.27 matthew 2894: $genpwd=" " if (!$genpwd);
1.449 raeburn 2895: } elsif ($env{'form.login'} eq 'lti') {
2896: $amode='lti';
2897: $genpwd=" ";
1.101 albertel 2898: } elsif (($env{'form.login'} eq 'nochange') ||
2899: ($env{'form.login'} eq '' )) {
1.34 matthew 2900: # There is no need to tell the user we did not change what they
2901: # did not ask us to change.
1.35 matthew 2902: # If they are creating a new user but have not specified login
2903: # information this will be caught below.
1.30 matthew 2904: } else {
1.367 golterma 2905: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
2906: return;
1.27 matthew 2907: }
1.164 albertel 2908:
1.188 raeburn 2909: $r->print('<h3>'.&mt('User [_1] in domain [_2]',
1.367 golterma 2910: $env{'form.ccuname'}.' ('.&Apache::loncommon::plainname($env{'form.ccuname'},
2911: $env{'form.ccdomain'}).')', $env{'form.ccdomain'}).'</h3>');
2912: my %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($r,2);
1.344 bisitz 2913:
1.193 raeburn 2914: my (%alerts,%rulematch,%inst_results,%curr_rules);
1.334 raeburn 2915: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
1.361 raeburn 2916: my @usertools = ('aboutme','blog','webdav','portfolio');
1.449 raeburn 2917: my @requestcourses = ('official','unofficial','community','textbook','placement','lti');
1.362 raeburn 2918: my @requestauthor = ('requestauthor');
1.286 raeburn 2919: my ($othertitle,$usertypes,$types) =
2920: &Apache::loncommon::sorted_inst_types($env{'form.ccdomain'});
1.334 raeburn 2921: my %canmodify_status =
2922: &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},
2923: ['inststatus']);
1.101 albertel 2924: if ($env{'form.makeuser'}) {
1.164 albertel 2925: $r->print('<h3>'.&mt('Creating new account.').'</h3>');
1.27 matthew 2926: # Check for the authentication mode and password
2927: if (! $amode || ! $genpwd) {
1.193 raeburn 2928: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
1.27 matthew 2929: return;
1.18 albertel 2930: }
1.29 matthew 2931: # Determine desired host
1.101 albertel 2932: my $desiredhost = $env{'form.hserver'};
1.29 matthew 2933: if (lc($desiredhost) eq 'default') {
2934: $desiredhost = undef;
2935: } else {
1.147 albertel 2936: my %home_servers =
2937: &Apache::lonnet::get_servers($env{'form.ccdomain'},'library');
1.29 matthew 2938: if (! exists($home_servers{$desiredhost})) {
1.193 raeburn 2939: $r->print($error.&mt('Invalid home server specified').$end.$rtnlink);
2940: return;
2941: }
2942: }
2943: # Check ID format
2944: my %checkhash;
2945: my %checks = ('id' => 1);
2946: %{$checkhash{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}}} = (
1.219 raeburn 2947: 'newuser' => $newuser,
1.196 raeburn 2948: 'id' => $env{'form.cid'},
1.193 raeburn 2949: );
1.196 raeburn 2950: if ($env{'form.cid'} ne '') {
2951: &Apache::loncommon::user_rule_check(\%checkhash,\%checks,\%alerts,
2952: \%rulematch,\%inst_results,\%curr_rules);
2953: if (ref($alerts{'id'}) eq 'HASH') {
2954: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
2955: my $domdesc =
2956: &Apache::lonnet::domain($env{'form.ccdomain'},'description');
2957: if ($alerts{'id'}{$env{'form.ccdomain'}}{$env{'form.cid'}}) {
2958: my $userchkmsg;
2959: if (ref($curr_rules{$env{'form.ccdomain'}}) eq 'HASH') {
2960: $userchkmsg =
2961: &Apache::loncommon::instrule_disallow_msg('id',
2962: $domdesc,1).
2963: &Apache::loncommon::user_rule_formats($env{'form.ccdomain'},
2964: $domdesc,$curr_rules{$env{'form.ccdomain'}}{'id'},'id');
2965: }
2966: $r->print($error.&mt('Invalid ID format').$end.
2967: $userchkmsg.$rtnlink);
2968: return;
2969: }
2970: }
1.29 matthew 2971: }
2972: }
1.367 golterma 2973: &Apache::lonhtmlcommon::Increment_PrgWin($r, \%prog_state);
1.27 matthew 2974: # Call modifyuser
2975: my $result = &Apache::lonnet::modifyuser
1.193 raeburn 2976: ($env{'form.ccdomain'},$env{'form.ccuname'},$env{'form.cid'},
1.188 raeburn 2977: $amode,$genpwd,$env{'form.cfirstname'},
2978: $env{'form.cmiddlename'},$env{'form.clastname'},
2979: $env{'form.cgeneration'},undef,$desiredhost,
2980: $env{'form.cpermanentemail'});
1.77 www 2981: $r->print(&mt('Generating user').': '.$result);
1.219 raeburn 2982: $uhome = &Apache::lonnet::homeserver($env{'form.ccuname'},
1.101 albertel 2983: $env{'form.ccdomain'});
1.334 raeburn 2984: my (%changeHash,%newcustom,%changed,%changedinfo);
1.267 raeburn 2985: if ($uhome ne 'no_host') {
1.334 raeburn 2986: if ($context eq 'domain') {
1.378 raeburn 2987: foreach my $name ('portfolio','author') {
2988: if ($env{'form.custom_'.$name.'quota'} == 1) {
2989: if ($env{'form.'.$name.'quota'} eq '') {
2990: $newcustom{$name.'quota'} = 0;
2991: } else {
2992: $newcustom{$name.'quota'} = $env{'form.'.$name.'quota'};
2993: $newcustom{$name.'quota'} =~ s/[^\d\.]//g;
2994: }
2995: if ("a_admin($newcustom{$name.'quota'},\%changeHash,$name)) {
2996: $changed{$name.'quota'} = 1;
2997: }
1.334 raeburn 2998: }
2999: }
3000: foreach my $item (@usertools) {
3001: if ($env{'form.custom'.$item} == 1) {
3002: $newcustom{$item} = $env{'form.tools_'.$item};
3003: $changed{$item} = &tool_admin($item,$newcustom{$item},
3004: \%changeHash,'tools');
3005: }
1.267 raeburn 3006: }
1.334 raeburn 3007: foreach my $item (@requestcourses) {
1.341 raeburn 3008: if ($env{'form.custom'.$item} == 1) {
3009: $newcustom{$item} = $env{'form.crsreq_'.$item};
3010: if ($env{'form.crsreq_'.$item} eq 'autolimit') {
3011: $newcustom{$item} .= '=';
1.383 raeburn 3012: $env{'form.crsreq_'.$item.'_limit'} =~ s/\D+//g;
3013: if ($env{'form.crsreq_'.$item.'_limit'}) {
1.341 raeburn 3014: $newcustom{$item} .= $env{'form.crsreq_'.$item.'_limit'};
3015: }
1.334 raeburn 3016: }
1.341 raeburn 3017: $changed{$item} = &tool_admin($item,$newcustom{$item},
3018: \%changeHash,'requestcourses');
1.334 raeburn 3019: }
1.275 raeburn 3020: }
1.362 raeburn 3021: if ($env{'form.customrequestauthor'} == 1) {
3022: $newcustom{'requestauthor'} = $env{'form.requestauthor'};
3023: $changed{'requestauthor'} = &tool_admin('requestauthor',
3024: $newcustom{'requestauthor'},
3025: \%changeHash,'requestauthor');
3026: }
1.275 raeburn 3027: }
1.334 raeburn 3028: if ($canmodify_status{'inststatus'}) {
3029: if (exists($env{'form.inststatus'})) {
3030: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
3031: if (@inststatuses > 0) {
3032: $changeHash{'inststatus'} = join(',',@inststatuses);
3033: $changed{'inststatus'} = $changeHash{'inststatus'};
1.306 raeburn 3034: }
3035: }
1.232 raeburn 3036: }
1.334 raeburn 3037: if (keys(%changed)) {
3038: foreach my $item (@userinfo) {
3039: $changeHash{$item} = $env{'form.c'.$item};
1.286 raeburn 3040: }
1.267 raeburn 3041: my $chgresult =
3042: &Apache::lonnet::put('environment',\%changeHash,
3043: $env{'form.ccdomain'},$env{'form.ccuname'});
3044: }
1.232 raeburn 3045: }
1.454 raeburn 3046: $r->print('<br />'.&mt('Home Server').': '.$uhome.' '.
1.219 raeburn 3047: &Apache::lonnet::hostname($uhome));
1.101 albertel 3048: } elsif (($env{'form.login'} ne 'nochange') &&
3049: ($env{'form.login'} ne '' )) {
1.27 matthew 3050: # Modify user privileges
3051: if (! $amode || ! $genpwd) {
1.193 raeburn 3052: $r->print($error.'Invalid login mode or password'.$end.$rtnlink);
1.27 matthew 3053: return;
1.20 harris41 3054: }
1.395 bisitz 3055: # Only allow authentication modification if the person has authority
1.101 albertel 3056: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.20 harris41 3057: $r->print('Modifying authentication: '.
1.31 matthew 3058: &Apache::lonnet::modifyuserauth(
1.101 albertel 3059: $env{'form.ccdomain'},$env{'form.ccuname'},
1.21 harris41 3060: $amode,$genpwd));
1.454 raeburn 3061: $r->print('<br />'.&mt('Home Server').': '.&Apache::lonnet::homeserver
1.101 albertel 3062: ($env{'form.ccuname'},$env{'form.ccdomain'}));
1.4 www 3063: } else {
1.27 matthew 3064: # Okay, this is a non-fatal error.
1.452 raeburn 3065: $r->print($error.&mt('You do not have privileges to modify the authentication configuration for this user.').$end);
1.27 matthew 3066: }
1.451 raeburn 3067: } elsif (($env{'form.intarg'} ne '') &&
3068: (&Apache::lonnet::queryauthenticate($env{'form.ccuname'},$env{'form.ccdomain'}) =~ /^internal:/) &&
3069: (&Apache::lonuserutils::can_change_internalpass($env{'form.ccuname'},$env{'form.ccdomain'},$crstype,$permission))) {
3070: $r->print('Modifying authentication: '.
3071: &Apache::lonnet::modifyuserauth(
3072: $env{'form.ccdomain'},$env{'form.ccuname'},
3073: 'internal',$env{'form.intarg'}));
1.28 matthew 3074: }
1.344 bisitz 3075: $r->rflush(); # Finish display of header before time consuming actions start
1.367 golterma 3076: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state);
1.28 matthew 3077: ##
1.375 raeburn 3078: my (@userroles,%userupdate,$cnum,$cdom,$defaultcredits,%namechanged);
1.213 raeburn 3079: if ($context eq 'course') {
1.375 raeburn 3080: ($cnum,$cdom) =
3081: &Apache::lonuserutils::get_course_identity();
1.318 raeburn 3082: $crstype = &Apache::loncommon::course_type($cdom.'_'.$cnum);
1.375 raeburn 3083: if ($showcredits) {
3084: $defaultcredits = &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
3085: }
1.213 raeburn 3086: }
1.101 albertel 3087: if (! $env{'form.makeuser'} ) {
1.28 matthew 3088: # Check for need to change
3089: my %userenv = &Apache::lonnet::get
1.134 raeburn 3090: ('environment',['firstname','middlename','lastname','generation',
1.378 raeburn 3091: 'id','permanentemail','portfolioquota','authorquota','inststatus',
3092: 'tools.aboutme','tools.blog','tools.webdav','tools.portfolio',
1.361 raeburn 3093: 'requestcourses.official','requestcourses.unofficial',
1.384 raeburn 3094: 'requestcourses.community','requestcourses.textbook',
3095: 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
3096: 'reqcrsotherdom.community','reqcrsotherdom.textbook',
1.427 raeburn 3097: 'reqcrsotherdom.placement','requestauthor'],
1.160 raeburn 3098: $env{'form.ccdomain'},$env{'form.ccuname'});
1.28 matthew 3099: my ($tmp) = keys(%userenv);
3100: if ($tmp =~ /^(con_lost|error)/i) {
3101: %userenv = ();
3102: }
1.206 raeburn 3103: my $no_forceid_alert;
3104: # Check to see if user information can be changed
3105: my %domconfig =
3106: &Apache::lonnet::get_dom('configuration',['usermodification'],
3107: $env{'form.ccdomain'});
1.213 raeburn 3108: my @statuses = ('active','future');
3109: my %roles = &Apache::lonnet::get_my_roles($env{'form.ccuname'},$env{'form.ccdomain'},'userroles',\@statuses,undef,$env{'request.role.domain'});
3110: my ($auname,$audom);
1.220 raeburn 3111: if ($context eq 'author') {
1.206 raeburn 3112: $auname = $env{'user.name'};
3113: $audom = $env{'user.domain'};
3114: }
3115: foreach my $item (keys(%roles)) {
1.220 raeburn 3116: my ($rolenum,$roledom,$role) = split(/:/,$item,-1);
1.206 raeburn 3117: if ($context eq 'course') {
3118: if ($cnum ne '' && $cdom ne '') {
3119: if ($rolenum eq $cnum && $roledom eq $cdom) {
3120: if (!grep(/^\Q$role\E$/,@userroles)) {
3121: push(@userroles,$role);
3122: }
3123: }
3124: }
3125: } elsif ($context eq 'author') {
3126: if ($rolenum eq $auname && $roledom eq $audom) {
3127: if (!grep(/^\Q$role\E$/,@userroles)) {
3128: push(@userroles,$role);
3129: }
3130: }
3131: }
3132: }
1.220 raeburn 3133: if ($env{'form.action'} eq 'singlestudent') {
3134: if (!grep(/^st$/,@userroles)) {
3135: push(@userroles,'st');
3136: }
3137: } else {
3138: # Check for course or co-author roles being activated or re-enabled
3139: if ($context eq 'author' || $context eq 'course') {
3140: foreach my $key (keys(%env)) {
3141: if ($context eq 'author') {
3142: if ($key=~/^form\.act_\Q$audom\E_\Q$auname\E_([^_]+)/) {
3143: if (!grep(/^\Q$1\E$/,@userroles)) {
3144: push(@userroles,$1);
3145: }
3146: } elsif ($key =~/^form\.ren\:\Q$audom\E\/\Q$auname\E_([^_]+)/) {
3147: if (!grep(/^\Q$1\E$/,@userroles)) {
3148: push(@userroles,$1);
3149: }
1.206 raeburn 3150: }
1.220 raeburn 3151: } elsif ($context eq 'course') {
3152: if ($key=~/^form\.act_\Q$cdom\E_\Q$cnum\E_([^_]+)/) {
3153: if (!grep(/^\Q$1\E$/,@userroles)) {
3154: push(@userroles,$1);
3155: }
3156: } elsif ($key =~/^form\.ren\:\Q$cdom\E\/\Q$cnum\E(\/?\w*)_([^_]+)/) {
3157: if (!grep(/^\Q$1\E$/,@userroles)) {
3158: push(@userroles,$1);
3159: }
1.206 raeburn 3160: }
3161: }
3162: }
3163: }
3164: }
3165: #Check to see if we can change personal data for the user
3166: my (@mod_disallowed,@longroles);
3167: foreach my $role (@userroles) {
3168: if ($role eq 'cr') {
3169: push(@longroles,'Custom');
3170: } else {
1.318 raeburn 3171: push(@longroles,&Apache::lonnet::plaintext($role,$crstype));
1.206 raeburn 3172: }
3173: }
1.219 raeburn 3174: my %canmodify = &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},\@userinfo,\@userroles);
3175: foreach my $item (@userinfo) {
1.28 matthew 3176: # Strip leading and trailing whitespace
1.203 raeburn 3177: $env{'form.c'.$item} =~ s/(\s+$|^\s+)//g;
1.219 raeburn 3178: if (!$canmodify{$item}) {
1.207 raeburn 3179: if (defined($env{'form.c'.$item})) {
3180: if ($env{'form.c'.$item} ne $userenv{$item}) {
3181: push(@mod_disallowed,$item);
3182: }
1.206 raeburn 3183: }
3184: $env{'form.c'.$item} = $userenv{$item};
3185: }
1.28 matthew 3186: }
1.259 bisitz 3187: # Check to see if we can change the Student/Employee ID
1.196 raeburn 3188: my $forceid = $env{'form.forceid'};
3189: my $recurseid = $env{'form.recurseid'};
3190: my (%alerts,%rulematch,%idinst_results,%curr_rules,%got_rules);
1.203 raeburn 3191: my %uidhash = &Apache::lonnet::idrget($env{'form.ccdomain'},
3192: $env{'form.ccuname'});
3193: if (($uidhash{$env{'form.ccuname'}}) &&
3194: ($uidhash{$env{'form.ccuname'}}!~/error\:/) &&
3195: (!$forceid)) {
3196: if ($env{'form.cid'} ne $uidhash{$env{'form.ccuname'}}) {
3197: $env{'form.cid'} = $userenv{'id'};
1.293 bisitz 3198: $no_forceid_alert = &mt('New student/employee ID does not match existing ID for this user.')
1.259 bisitz 3199: .'<br />'
3200: .&mt("Change is not permitted without checking the 'Force ID change' checkbox on the previous page.")
3201: .'<br />'."\n";
1.203 raeburn 3202: }
3203: }
3204: if ($env{'form.cid'} ne $userenv{'id'}) {
1.196 raeburn 3205: my $checkhash;
3206: my $checks = { 'id' => 1 };
3207: $checkhash->{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}} =
3208: { 'newuser' => $newuser,
3209: 'id' => $env{'form.cid'},
3210: };
3211: &Apache::loncommon::user_rule_check($checkhash,$checks,
3212: \%alerts,\%rulematch,\%idinst_results,\%curr_rules,\%got_rules);
3213: if (ref($alerts{'id'}) eq 'HASH') {
3214: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
1.203 raeburn 3215: $env{'form.cid'} = $userenv{'id'};
1.196 raeburn 3216: }
3217: }
3218: }
1.378 raeburn 3219: my (%quotachanged,%oldquota,%newquota,%olddefquota,%newdefquota,
3220: $oldinststatus,$newinststatus,%oldisdefault,%newisdefault,%oldsettings,
1.339 raeburn 3221: %oldsettingstext,%newsettings,%newsettingstext,@disporder,
1.378 raeburn 3222: %oldsettingstatus,%newsettingstatus);
1.334 raeburn 3223: @disporder = ('inststatus');
3224: if ($env{'request.role.domain'} eq $env{'form.ccdomain'}) {
1.362 raeburn 3225: push(@disporder,'requestcourses','requestauthor');
1.334 raeburn 3226: } else {
3227: push(@disporder,'reqcrsotherdom');
3228: }
3229: push(@disporder,('quota','tools'));
1.338 raeburn 3230: $oldinststatus = $userenv{'inststatus'};
1.378 raeburn 3231: foreach my $name ('portfolio','author') {
3232: ($olddefquota{$name},$oldsettingstatus{$name}) =
3233: &Apache::loncommon::default_quota($env{'form.ccdomain'},$oldinststatus,$name);
3234: ($newdefquota{$name},$newsettingstatus{$name}) = ($olddefquota{$name},$oldsettingstatus{$name});
3235: }
1.334 raeburn 3236: my %canshow;
1.220 raeburn 3237: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
1.334 raeburn 3238: $canshow{'quota'} = 1;
1.220 raeburn 3239: }
1.267 raeburn 3240: if (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
1.334 raeburn 3241: $canshow{'tools'} = 1;
1.267 raeburn 3242: }
1.275 raeburn 3243: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
1.334 raeburn 3244: $canshow{'requestcourses'} = 1;
1.300 raeburn 3245: } elsif (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.334 raeburn 3246: $canshow{'reqcrsotherdom'} = 1;
1.275 raeburn 3247: }
1.286 raeburn 3248: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.334 raeburn 3249: $canshow{'inststatus'} = 1;
1.286 raeburn 3250: }
1.362 raeburn 3251: if (&Apache::lonnet::allowed('cau',$env{'form.ccdomain'})) {
3252: $canshow{'requestauthor'} = 1;
3253: }
1.267 raeburn 3254: my (%changeHash,%changed);
1.286 raeburn 3255: if ($oldinststatus eq '') {
1.334 raeburn 3256: $oldsettings{'inststatus'} = $othertitle;
1.286 raeburn 3257: } else {
3258: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 3259: $oldsettings{'inststatus'} = join(', ',map{ $usertypes->{ &unescape($_) }; } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 3260: } else {
1.334 raeburn 3261: $oldsettings{'inststatus'} = join(', ',map{ &unescape($_); } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 3262: }
3263: }
3264: $changeHash{'inststatus'} = $userenv{'inststatus'};
1.334 raeburn 3265: if ($canmodify_status{'inststatus'}) {
3266: $canshow{'inststatus'} = 1;
1.286 raeburn 3267: if (exists($env{'form.inststatus'})) {
3268: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
3269: if (@inststatuses > 0) {
3270: $newinststatus = join(':',map { &escape($_); } @inststatuses);
3271: $changeHash{'inststatus'} = $newinststatus;
3272: if ($newinststatus ne $oldinststatus) {
3273: $changed{'inststatus'} = $newinststatus;
1.378 raeburn 3274: foreach my $name ('portfolio','author') {
3275: ($newdefquota{$name},$newsettingstatus{$name}) =
3276: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
3277: }
1.286 raeburn 3278: }
3279: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 3280: $newsettings{'inststatus'} = join(', ',map{ $usertypes->{$_}; } (@inststatuses));
1.286 raeburn 3281: } else {
1.337 raeburn 3282: $newsettings{'inststatus'} = join(', ',@inststatuses);
1.286 raeburn 3283: }
1.334 raeburn 3284: }
3285: } else {
3286: $newinststatus = '';
3287: $changeHash{'inststatus'} = $newinststatus;
3288: $newsettings{'inststatus'} = $othertitle;
3289: if ($newinststatus ne $oldinststatus) {
3290: $changed{'inststatus'} = $changeHash{'inststatus'};
1.378 raeburn 3291: foreach my $name ('portfolio','author') {
3292: ($newdefquota{$name},$newsettingstatus{$name}) =
3293: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
3294: }
1.286 raeburn 3295: }
3296: }
1.334 raeburn 3297: } elsif ($context ne 'selfcreate') {
3298: $canshow{'inststatus'} = 1;
1.337 raeburn 3299: $newsettings{'inststatus'} = $oldsettings{'inststatus'};
1.286 raeburn 3300: }
1.378 raeburn 3301: foreach my $name ('portfolio','author') {
3302: $changeHash{$name.'quota'} = $userenv{$name.'quota'};
3303: }
1.334 raeburn 3304: if ($context eq 'domain') {
1.378 raeburn 3305: foreach my $name ('portfolio','author') {
3306: if ($userenv{$name.'quota'} ne '') {
3307: $oldquota{$name} = $userenv{$name.'quota'};
3308: if ($env{'form.custom_'.$name.'quota'} == 1) {
3309: if ($env{'form.'.$name.'quota'} eq '') {
3310: $newquota{$name} = 0;
3311: } else {
3312: $newquota{$name} = $env{'form.'.$name.'quota'};
3313: $newquota{$name} =~ s/[^\d\.]//g;
3314: }
3315: if ($newquota{$name} != $oldquota{$name}) {
3316: if ("a_admin($newquota{$name},\%changeHash,$name)) {
3317: $changed{$name.'quota'} = 1;
3318: }
3319: }
1.334 raeburn 3320: } else {
1.378 raeburn 3321: if ("a_admin('',\%changeHash,$name)) {
3322: $changed{$name.'quota'} = 1;
3323: $newquota{$name} = $newdefquota{$name};
3324: $newisdefault{$name} = 1;
3325: }
1.334 raeburn 3326: }
1.149 raeburn 3327: } else {
1.378 raeburn 3328: $oldisdefault{$name} = 1;
3329: $oldquota{$name} = $olddefquota{$name};
3330: if ($env{'form.custom_'.$name.'quota'} == 1) {
3331: if ($env{'form.'.$name.'quota'} eq '') {
3332: $newquota{$name} = 0;
3333: } else {
3334: $newquota{$name} = $env{'form.'.$name.'quota'};
3335: $newquota{$name} =~ s/[^\d\.]//g;
3336: }
3337: if ("a_admin($newquota{$name},\%changeHash,$name)) {
3338: $changed{$name.'quota'} = 1;
3339: }
1.334 raeburn 3340: } else {
1.378 raeburn 3341: $newquota{$name} = $newdefquota{$name};
3342: $newisdefault{$name} = 1;
1.334 raeburn 3343: }
1.378 raeburn 3344: }
3345: if ($oldisdefault{$name}) {
3346: $oldsettingstext{'quota'}{$name} = &get_defaultquota_text($oldsettingstatus{$name});
1.383 raeburn 3347: } else {
3348: $oldsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$oldquota{$name});
1.378 raeburn 3349: }
3350: if ($newisdefault{$name}) {
3351: $newsettingstext{'quota'}{$name} = &get_defaultquota_text($newsettingstatus{$name});
1.383 raeburn 3352: } else {
3353: $newsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$newquota{$name});
1.134 raeburn 3354: }
3355: }
1.334 raeburn 3356: &tool_changes('tools',\@usertools,\%oldsettings,\%oldsettingstext,\%userenv,
3357: \%changeHash,\%changed,\%newsettings,\%newsettingstext);
3358: if ($env{'form.ccdomain'} eq $env{'request.role.domain'}) {
3359: &tool_changes('requestcourses',\@requestcourses,\%oldsettings,\%oldsettingstext,
3360: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.384 raeburn 3361: &tool_changes('requestauthor',\@requestauthor,\%oldsettings,\%oldsettingstext,
3362: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 3363: } else {
1.334 raeburn 3364: &tool_changes('reqcrsotherdom',\@requestcourses,\%oldsettings,\%oldsettingstext,
3365: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 3366: }
3367: }
1.334 raeburn 3368: foreach my $item (@userinfo) {
3369: if ($env{'form.c'.$item} ne $userenv{$item}) {
3370: $namechanged{$item} = 1;
3371: }
1.204 raeburn 3372: }
1.378 raeburn 3373: foreach my $name ('portfolio','author') {
1.390 bisitz 3374: $oldsettings{'quota'}{$name} = &mt('[_1] MB',$oldquota{$name});
3375: $newsettings{'quota'}{$name} = &mt('[_1] MB',$newquota{$name});
1.378 raeburn 3376: }
1.334 raeburn 3377: if ((keys(%namechanged) > 0) || (keys(%changed) > 0)) {
1.267 raeburn 3378: my ($chgresult,$namechgresult);
3379: if (keys(%changed) > 0) {
3380: $chgresult =
1.204 raeburn 3381: &Apache::lonnet::put('environment',\%changeHash,
3382: $env{'form.ccdomain'},$env{'form.ccuname'});
1.267 raeburn 3383: if ($chgresult eq 'ok') {
3384: if (($env{'user.name'} eq $env{'form.ccuname'}) &&
3385: ($env{'user.domain'} eq $env{'form.ccdomain'})) {
1.270 raeburn 3386: my %newenvhash;
3387: foreach my $key (keys(%changed)) {
1.411 raeburn 3388: if (($key eq 'official') || ($key eq 'unofficial') ||
3389: ($key eq 'community') || ($key eq 'textbook') ||
1.449 raeburn 3390: ($key eq 'placement') || ($key eq 'lti')) {
1.279 raeburn 3391: $newenvhash{'environment.requestcourses.'.$key} =
3392: $changeHash{'requestcourses.'.$key};
1.362 raeburn 3393: if ($changeHash{'requestcourses.'.$key}) {
1.332 raeburn 3394: $newenvhash{'environment.canrequest.'.$key} = 1;
1.279 raeburn 3395: } else {
3396: $newenvhash{'environment.canrequest.'.$key} =
3397: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3398: $key,'reload','requestcourses');
3399: }
1.362 raeburn 3400: } elsif ($key eq 'requestauthor') {
3401: $newenvhash{'environment.'.$key} = $changeHash{$key};
3402: if ($changeHash{$key}) {
3403: $newenvhash{'environment.canrequest.author'} = 1;
3404: } else {
3405: $newenvhash{'environment.canrequest.author'} =
3406: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3407: $key,'reload','requestauthor');
3408: }
1.275 raeburn 3409: } elsif ($key ne 'quota') {
1.270 raeburn 3410: $newenvhash{'environment.tools.'.$key} =
3411: $changeHash{'tools.'.$key};
1.279 raeburn 3412: if ($changeHash{'tools.'.$key} ne '') {
3413: $newenvhash{'environment.availabletools.'.$key} =
3414: $changeHash{'tools.'.$key};
3415: } else {
3416: $newenvhash{'environment.availabletools.'.$key} =
1.367 golterma 3417: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3418: $key,'reload','tools');
1.279 raeburn 3419: }
1.270 raeburn 3420: }
3421: }
1.271 raeburn 3422: if (keys(%newenvhash)) {
3423: &Apache::lonnet::appenv(\%newenvhash);
3424: }
1.267 raeburn 3425: }
3426: }
1.204 raeburn 3427: }
1.334 raeburn 3428: if (keys(%namechanged) > 0) {
1.337 raeburn 3429: foreach my $field (@userinfo) {
3430: $changeHash{$field} = $env{'form.c'.$field};
3431: }
3432: # Make the change
1.204 raeburn 3433: $namechgresult =
3434: &Apache::lonnet::modifyuser($env{'form.ccdomain'},
3435: $env{'form.ccuname'},$changeHash{'id'},undef,undef,
3436: $changeHash{'firstname'},$changeHash{'middlename'},
3437: $changeHash{'lastname'},$changeHash{'generation'},
1.337 raeburn 3438: $changeHash{'id'},undef,$changeHash{'permanentemail'},undef,\@userinfo);
1.220 raeburn 3439: %userupdate = (
3440: lastname => $env{'form.clastname'},
3441: middlename => $env{'form.cmiddlename'},
3442: firstname => $env{'form.cfirstname'},
3443: generation => $env{'form.cgeneration'},
3444: id => $env{'form.cid'},
3445: );
1.204 raeburn 3446: }
1.334 raeburn 3447: if (((keys(%namechanged) > 0) && $namechgresult eq 'ok') ||
1.267 raeburn 3448: ((keys(%changed) > 0) && $chgresult eq 'ok')) {
1.28 matthew 3449: # Tell the user we changed the name
1.334 raeburn 3450: &display_userinfo($r,1,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 3451: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,
1.334 raeburn 3452: \%oldsettings, \%oldsettingstext,\%newsettings,
3453: \%newsettingstext);
1.203 raeburn 3454: if ($env{'form.cid'} ne $userenv{'id'}) {
3455: &Apache::lonnet::idput($env{'form.ccdomain'},
1.407 raeburn 3456: {$env{'form.ccuname'} => $env{'form.cid'}},$uhome,'ids');
1.203 raeburn 3457: if (($recurseid) &&
3458: (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}))) {
3459: my $idresult =
3460: &Apache::lonuserutils::propagate_id_change(
3461: $env{'form.ccuname'},$env{'form.ccdomain'},
3462: \%userupdate);
3463: $r->print('<br />'.$idresult.'<br />');
3464: }
1.196 raeburn 3465: }
1.149 raeburn 3466: if (($env{'form.ccdomain'} eq $env{'user.domain'}) &&
3467: ($env{'form.ccuname'} eq $env{'user.name'})) {
3468: my %newenvhash;
3469: foreach my $key (keys(%changeHash)) {
3470: $newenvhash{'environment.'.$key} = $changeHash{$key};
3471: }
1.238 raeburn 3472: &Apache::lonnet::appenv(\%newenvhash);
1.149 raeburn 3473: }
1.28 matthew 3474: } else { # error occurred
1.389 bisitz 3475: $r->print(
3476: '<p class="LC_error">'
3477: .&mt('Unable to successfully change environment for [_1] in domain [_2].',
3478: '"'.$env{'form.ccuname'}.'"',
3479: '"'.$env{'form.ccdomain'}.'"')
3480: .'</p>');
1.28 matthew 3481: }
1.334 raeburn 3482: } else { # End of if ($env ... ) logic
1.275 raeburn 3483: # They did not want to change the users name, quota, tool availability,
3484: # or ability to request creation of courses,
1.267 raeburn 3485: # but we can still tell them what the name and quota and availabilities are
1.334 raeburn 3486: &display_userinfo($r,undef,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 3487: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,\%oldsettings,
1.334 raeburn 3488: \%oldsettingstext,\%newsettings,\%newsettingstext);
1.28 matthew 3489: }
1.206 raeburn 3490: if (@mod_disallowed) {
3491: my ($rolestr,$contextname);
3492: if (@longroles > 0) {
3493: $rolestr = join(', ',@longroles);
3494: } else {
3495: $rolestr = &mt('No roles');
3496: }
3497: if ($context eq 'course') {
1.399 bisitz 3498: $contextname = 'course';
1.206 raeburn 3499: } elsif ($context eq 'author') {
1.399 bisitz 3500: $contextname = 'co-author';
1.206 raeburn 3501: }
3502: $r->print(&mt('The following fields were not updated: ').'<ul>');
3503: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
3504: foreach my $field (@mod_disallowed) {
3505: $r->print('<li>'.$fieldtitles{$field}.'</li>'."\n");
3506: }
1.207 raeburn 3507: $r->print('</ul>');
3508: if (@mod_disallowed == 1) {
1.399 bisitz 3509: $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 3510: } else {
1.399 bisitz 3511: $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 3512: }
1.292 bisitz 3513: my $helplink = 'javascript:helpMenu('."'display'".')';
3514: $r->print('<span class="LC_cusr_emph">'.$rolestr.'</span><br />'
3515: .&mt('Please contact your [_1]helpdesk[_2] for more information.'
3516: ,'<a href="'.$helplink.'">','</a>')
3517: .'<br />');
1.206 raeburn 3518: }
1.259 bisitz 3519: $r->print('<span class="LC_warning">'
3520: .$no_forceid_alert
3521: .&Apache::lonuserutils::print_namespacing_alerts($env{'form.ccdomain'},\%alerts,\%curr_rules)
3522: .'</span>');
1.4 www 3523: }
1.367 golterma 3524: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1.220 raeburn 3525: if ($env{'form.action'} eq 'singlestudent') {
1.375 raeburn 3526: &enroll_single_student($r,$uhome,$amode,$genpwd,$now,$newuser,$context,
3527: $crstype,$showcredits,$defaultcredits);
1.386 bisitz 3528: my $linktext = ($crstype eq 'Community' ?
3529: &mt('Enroll Another Member') : &mt('Enroll Another Student'));
3530: $r->print(
3531: &Apache::lonhtmlcommon::actionbox([
3532: '<a href="javascript:backPage(document.userupdate)">'
3533: .($crstype eq 'Community' ?
3534: &mt('Enroll Another Member') : &mt('Enroll Another Student'))
3535: .'</a>']));
1.220 raeburn 3536: } else {
1.375 raeburn 3537: my @rolechanges = &update_roles($r,$context,$showcredits);
1.334 raeburn 3538: if (keys(%namechanged) > 0) {
1.220 raeburn 3539: if ($context eq 'course') {
3540: if (@userroles > 0) {
1.225 raeburn 3541: if ((@rolechanges == 0) ||
3542: (!(grep(/^st$/,@rolechanges)))) {
3543: if (grep(/^st$/,@userroles)) {
3544: my $classlistupdated =
3545: &Apache::lonuserutils::update_classlist($cdom,
1.220 raeburn 3546: $cnum,$env{'form.ccdomain'},
3547: $env{'form.ccuname'},\%userupdate);
1.225 raeburn 3548: }
1.220 raeburn 3549: }
3550: }
3551: }
3552: }
1.226 raeburn 3553: my $userinfo = &Apache::loncommon::plainname($env{'form.ccuname'},
1.233 raeburn 3554: $env{'form.ccdomain'});
3555: if ($env{'form.popup'}) {
3556: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
3557: } else {
1.367 golterma 3558: $r->print('<br />'.&Apache::lonhtmlcommon::actionbox(['<a href="javascript:backPage(document.userupdate,'."'$env{'form.prevphase'}','modify'".')">'
3559: .&mt('Modify this user: [_1]','<span class="LC_cusr_emph">'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.' ('.$userinfo.')</span>').'</a>',
3560: '<a href="javascript:backPage(document.userupdate)">'.&mt('Create/Modify Another User').'</a>']));
1.233 raeburn 3561: }
1.220 raeburn 3562: }
3563: }
3564:
1.334 raeburn 3565: sub display_userinfo {
1.362 raeburn 3566: my ($r,$changed,$order,$canshow,$requestcourses,$usertools,$requestauthor,
3567: $userenv,$changedhash,$namechangedhash,$oldsetting,$oldsettingtext,
1.334 raeburn 3568: $newsetting,$newsettingtext) = @_;
3569: return unless (ref($order) eq 'ARRAY' &&
3570: ref($canshow) eq 'HASH' &&
3571: ref($requestcourses) eq 'ARRAY' &&
1.362 raeburn 3572: ref($requestauthor) eq 'ARRAY' &&
1.334 raeburn 3573: ref($usertools) eq 'ARRAY' &&
3574: ref($userenv) eq 'HASH' &&
3575: ref($changedhash) eq 'HASH' &&
3576: ref($oldsetting) eq 'HASH' &&
3577: ref($oldsettingtext) eq 'HASH' &&
3578: ref($newsetting) eq 'HASH' &&
3579: ref($newsettingtext) eq 'HASH');
3580: my %lt=&Apache::lonlocal::texthash(
1.372 raeburn 3581: 'ui' => 'User Information',
1.334 raeburn 3582: 'uic' => 'User Information Changed',
3583: 'firstname' => 'First Name',
3584: 'middlename' => 'Middle Name',
3585: 'lastname' => 'Last Name',
3586: 'generation' => 'Generation',
3587: 'id' => 'Student/Employee ID',
3588: 'permanentemail' => 'Permanent e-mail address',
1.378 raeburn 3589: 'portfolioquota' => 'Disk space allocated to portfolio files',
1.385 bisitz 3590: 'authorquota' => 'Disk space allocated to Authoring Space',
1.334 raeburn 3591: 'blog' => 'Blog Availability',
1.361 raeburn 3592: 'webdav' => 'WebDAV Availability',
1.334 raeburn 3593: 'aboutme' => 'Personal Information Page Availability',
3594: 'portfolio' => 'Portfolio Availability',
3595: 'official' => 'Can Request Official Courses',
3596: 'unofficial' => 'Can Request Unofficial Courses',
3597: 'community' => 'Can Request Communities',
1.384 raeburn 3598: 'textbook' => 'Can Request Textbook Courses',
1.411 raeburn 3599: 'placement' => 'Can Request Placement Tests',
1.449 raeburn 3600: 'lti' => 'Can Request LTI Courses',
1.362 raeburn 3601: 'requestauthor' => 'Can Request Author Role',
1.334 raeburn 3602: 'inststatus' => "Affiliation",
3603: 'prvs' => 'Previous Value:',
3604: 'chto' => 'Changed To:'
3605: );
3606: if ($changed) {
1.372 raeburn 3607: $r->print('<h3>'.$lt{'uic'}.'</h3>'.
1.367 golterma 3608: &Apache::loncommon::start_data_table().
3609: &Apache::loncommon::start_data_table_header_row());
1.334 raeburn 3610: $r->print("<th> </th>\n");
1.367 golterma 3611: $r->print('<th><b>'.$lt{'prvs'}.'</b></th>');
3612: $r->print('<th><span class="LC_nobreak"><b>'.$lt{'chto'}.'</b></span></th>');
3613: $r->print(&Apache::loncommon::end_data_table_header_row());
3614: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
3615:
1.334 raeburn 3616: foreach my $item (@userinfo) {
3617: my $value = $env{'form.c'.$item};
1.367 golterma 3618: #show changes only:
1.383 raeburn 3619: unless ($value eq $userenv->{$item}){
1.367 golterma 3620: $r->print(&Apache::loncommon::start_data_table_row());
3621: $r->print("<td>$lt{$item}</td>\n");
1.383 raeburn 3622: $r->print("<td>".$userenv->{$item}."</td>\n");
1.367 golterma 3623: $r->print("<td>$value </td>\n");
3624: $r->print(&Apache::loncommon::end_data_table_row());
1.334 raeburn 3625: }
3626: }
3627: foreach my $entry (@{$order}) {
1.383 raeburn 3628: if ($canshow->{$entry}) {
3629: if (($entry eq 'requestcourses') || ($entry eq 'reqcrsotherdom') || ($entry eq 'requestauthor')) {
3630: my @items;
3631: if ($entry eq 'requestauthor') {
3632: @items = ($entry);
3633: } else {
3634: @items = @{$requestcourses};
1.384 raeburn 3635: }
1.383 raeburn 3636: foreach my $item (@items) {
3637: if (($newsetting->{$item} ne $oldsetting->{$item}) ||
3638: ($newsettingtext->{$item} ne $oldsettingtext->{$item})) {
3639: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3640: $r->print("<td>$lt{$item}</td>\n");
3641: $r->print("<td>".$oldsetting->{$item});
3642: if ($oldsettingtext->{$item}) {
3643: if ($oldsetting->{$item}) {
3644: $r->print(' -- ');
3645: }
3646: $r->print($oldsettingtext->{$item});
3647: }
3648: $r->print("</td>\n");
3649: $r->print("<td>".$newsetting->{$item});
3650: if ($newsettingtext->{$item}) {
3651: if ($newsetting->{$item}) {
3652: $r->print(' -- ');
3653: }
3654: $r->print($newsettingtext->{$item});
3655: }
3656: $r->print("</td>\n");
3657: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3658: }
3659: }
3660: } elsif ($entry eq 'tools') {
3661: foreach my $item (@{$usertools}) {
1.383 raeburn 3662: if ($newsetting->{$item} ne $oldsetting->{$item}) {
3663: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3664: $r->print("<td>$lt{$item}</td>\n");
3665: $r->print("<td>".$oldsetting->{$item}.' '.$oldsettingtext->{$item}."</td>\n");
3666: $r->print("<td>".$newsetting->{$item}.' '.$newsettingtext->{$item}."</td>\n");
3667: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3668: }
3669: }
1.378 raeburn 3670: } elsif ($entry eq 'quota') {
3671: if ((ref($oldsetting->{$entry}) eq 'HASH') && (ref($oldsettingtext->{$entry}) eq 'HASH') &&
3672: (ref($newsetting->{$entry}) eq 'HASH') && (ref($newsettingtext->{$entry}) eq 'HASH')) {
3673: foreach my $name ('portfolio','author') {
1.383 raeburn 3674: if ($newsetting->{$entry}->{$name} ne $oldsetting->{$entry}->{$name}) {
3675: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3676: $r->print("<td>$lt{$name.$entry}</td>\n");
3677: $r->print("<td>".$oldsettingtext->{$entry}->{$name}."</td>\n");
3678: $r->print("<td>".$newsettingtext->{$entry}->{$name}."</td>\n");
3679: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.378 raeburn 3680: }
3681: }
3682: }
1.334 raeburn 3683: } else {
1.383 raeburn 3684: if ($newsetting->{$entry} ne $oldsetting->{$entry}) {
3685: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3686: $r->print("<td>$lt{$entry}</td>\n");
3687: $r->print("<td>".$oldsetting->{$entry}.' '.$oldsettingtext->{$entry}."</td>\n");
3688: $r->print("<td>".$newsetting->{$entry}.' '.$newsettingtext->{$entry}."</td>\n");
3689: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3690: }
3691: }
3692: }
3693: }
1.367 golterma 3694: $r->print(&Apache::loncommon::end_data_table().'<br />');
1.372 raeburn 3695: } else {
3696: $r->print('<h3>'.$lt{'ui'}.'</h3>'.
3697: '<p>'.&mt('No changes made to user information').'</p>');
1.334 raeburn 3698: }
3699: return;
3700: }
3701:
1.275 raeburn 3702: sub tool_changes {
3703: my ($context,$usertools,$oldaccess,$oldaccesstext,$userenv,$changeHash,
3704: $changed,$newaccess,$newaccesstext) = @_;
3705: if (!((ref($usertools) eq 'ARRAY') && (ref($oldaccess) eq 'HASH') &&
3706: (ref($oldaccesstext) eq 'HASH') && (ref($userenv) eq 'HASH') &&
3707: (ref($changeHash) eq 'HASH') && (ref($changed) eq 'HASH') &&
3708: (ref($newaccess) eq 'HASH') && (ref($newaccesstext) eq 'HASH'))) {
3709: return;
3710: }
1.383 raeburn 3711: my %reqdisplay = &requestchange_display();
1.300 raeburn 3712: if ($context eq 'reqcrsotherdom') {
1.309 raeburn 3713: my @options = ('approval','validate','autolimit');
1.306 raeburn 3714: my $optregex = join('|',@options);
1.300 raeburn 3715: my $cdom = $env{'request.role.domain'};
3716: foreach my $tool (@{$usertools}) {
1.383 raeburn 3717: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
1.314 raeburn 3718: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
1.300 raeburn 3719: $changeHash->{$context.'.'.$tool} = $userenv->{$context.'.'.$tool};
1.383 raeburn 3720: my ($newop,$limit);
1.314 raeburn 3721: if ($env{'form.'.$context.'_'.$tool}) {
3722: $newop = $env{'form.'.$context.'_'.$tool};
3723: if ($newop eq 'autolimit') {
1.383 raeburn 3724: $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
1.314 raeburn 3725: $limit =~ s/\D+//g;
3726: $newop .= '='.$limit;
3727: }
3728: }
1.300 raeburn 3729: if ($userenv->{$context.'.'.$tool} eq '') {
1.314 raeburn 3730: if ($newop) {
3731: $changed->{$tool}=&tool_admin($tool,$cdom.':'.$newop,
1.300 raeburn 3732: $changeHash,$context);
3733: if ($changed->{$tool}) {
1.383 raeburn 3734: if ($newop =~ /^autolimit/) {
3735: if ($limit) {
3736: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3737: } else {
3738: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3739: }
3740: } else {
3741: $newaccesstext->{$tool} = $reqdisplay{$newop};
3742: }
1.300 raeburn 3743: } else {
3744: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3745: }
3746: }
3747: } else {
3748: my @curr = split(',',$userenv->{$context.'.'.$tool});
3749: my @new;
3750: my $changedoms;
1.314 raeburn 3751: foreach my $req (@curr) {
3752: if ($req =~ /^\Q$cdom\E\:($optregex\=?\d*)$/) {
3753: my $oldop = $1;
1.383 raeburn 3754: if ($oldop =~ /^autolimit=(\d*)/) {
3755: my $limit = $1;
3756: if ($limit) {
3757: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3758: } else {
3759: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3760: }
3761: } else {
3762: $oldaccesstext->{$tool} = $reqdisplay{$oldop};
3763: }
1.314 raeburn 3764: if ($oldop ne $newop) {
3765: $changedoms = 1;
3766: foreach my $item (@curr) {
3767: my ($reqdom,$option) = split(':',$item);
3768: unless ($reqdom eq $cdom) {
3769: push(@new,$item);
3770: }
3771: }
3772: if ($newop) {
3773: push(@new,$cdom.':'.$newop);
1.300 raeburn 3774: }
1.314 raeburn 3775: @new = sort(@new);
1.300 raeburn 3776: }
1.314 raeburn 3777: last;
1.300 raeburn 3778: }
1.314 raeburn 3779: }
3780: if ((!$changedoms) && ($newop)) {
1.300 raeburn 3781: $changedoms = 1;
1.306 raeburn 3782: @new = sort(@curr,$cdom.':'.$newop);
1.300 raeburn 3783: }
3784: if ($changedoms) {
1.314 raeburn 3785: my $newdomstr;
1.300 raeburn 3786: if (@new) {
3787: $newdomstr = join(',',@new);
3788: }
3789: $changed->{$tool}=&tool_admin($tool,$newdomstr,$changeHash,
3790: $context);
3791: if ($changed->{$tool}) {
3792: if ($env{'form.'.$context.'_'.$tool}) {
1.306 raeburn 3793: if ($env{'form.'.$context.'_'.$tool} eq 'autolimit') {
1.314 raeburn 3794: my $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
3795: $limit =~ s/\D+//g;
3796: if ($limit) {
1.383 raeburn 3797: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
1.314 raeburn 3798: } else {
1.383 raeburn 3799: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
1.306 raeburn 3800: }
1.314 raeburn 3801: } else {
1.306 raeburn 3802: $newaccesstext->{$tool} = $reqdisplay{$env{'form.'.$context.'_'.$tool}};
3803: }
1.300 raeburn 3804: } else {
1.383 raeburn 3805: $newaccesstext->{$tool} = &mt("availability set to 'off'");
1.300 raeburn 3806: }
3807: }
3808: }
3809: }
3810: }
3811: return;
3812: }
1.275 raeburn 3813: foreach my $tool (@{$usertools}) {
1.383 raeburn 3814: my ($newval,$limit,$envkey);
1.362 raeburn 3815: $envkey = $context.'.'.$tool;
1.306 raeburn 3816: if ($context eq 'requestcourses') {
3817: $newval = $env{'form.crsreq_'.$tool};
3818: if ($newval eq 'autolimit') {
1.383 raeburn 3819: $limit = $env{'form.crsreq_'.$tool.'_limit'};
3820: $limit =~ s/\D+//g;
3821: $newval .= '='.$limit;
1.306 raeburn 3822: }
1.362 raeburn 3823: } elsif ($context eq 'requestauthor') {
3824: $newval = $env{'form.'.$context};
3825: $envkey = $context;
1.314 raeburn 3826: } else {
1.306 raeburn 3827: $newval = $env{'form.'.$context.'_'.$tool};
3828: }
1.362 raeburn 3829: if ($userenv->{$envkey} ne '') {
1.275 raeburn 3830: $oldaccess->{$tool} = &mt('custom');
1.383 raeburn 3831: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3832: if ($userenv->{$envkey} =~ /^autolimit=(\d*)$/) {
3833: my $currlimit = $1;
3834: if ($currlimit eq '') {
3835: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3836: } else {
3837: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$currlimit);
3838: }
3839: } elsif ($userenv->{$envkey}) {
3840: $oldaccesstext->{$tool} = $reqdisplay{$userenv->{$envkey}};
3841: } else {
3842: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
3843: }
1.275 raeburn 3844: } else {
1.383 raeburn 3845: if ($userenv->{$envkey}) {
3846: $oldaccesstext->{$tool} = &mt("availability set to 'on'");
3847: } else {
3848: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
3849: }
1.275 raeburn 3850: }
1.362 raeburn 3851: $changeHash->{$envkey} = $userenv->{$envkey};
1.275 raeburn 3852: if ($env{'form.custom'.$tool} == 1) {
1.362 raeburn 3853: if ($newval ne $userenv->{$envkey}) {
1.306 raeburn 3854: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
3855: $context);
1.275 raeburn 3856: if ($changed->{$tool}) {
3857: $newaccess->{$tool} = &mt('custom');
1.383 raeburn 3858: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3859: if ($newval =~ /^autolimit/) {
3860: if ($limit) {
3861: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3862: } else {
3863: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3864: }
3865: } elsif ($newval) {
3866: $newaccesstext->{$tool} = $reqdisplay{$newval};
3867: } else {
3868: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3869: }
1.275 raeburn 3870: } else {
1.383 raeburn 3871: if ($newval) {
3872: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3873: } else {
3874: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3875: }
1.275 raeburn 3876: }
3877: } else {
3878: $newaccess->{$tool} = $oldaccess->{$tool};
1.383 raeburn 3879: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3880: if ($newval =~ /^autolimit/) {
3881: if ($limit) {
3882: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3883: } else {
3884: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3885: }
3886: } elsif ($newval) {
3887: $newaccesstext->{$tool} = $reqdisplay{$newval};
3888: } else {
3889: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3890: }
1.275 raeburn 3891: } else {
1.383 raeburn 3892: if ($userenv->{$context.'.'.$tool}) {
3893: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3894: } else {
3895: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3896: }
1.275 raeburn 3897: }
3898: }
3899: } else {
3900: $newaccess->{$tool} = $oldaccess->{$tool};
3901: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3902: }
3903: } else {
3904: $changed->{$tool} = &tool_admin($tool,'',$changeHash,$context);
3905: if ($changed->{$tool}) {
3906: $newaccess->{$tool} = &mt('default');
3907: } else {
3908: $newaccess->{$tool} = $oldaccess->{$tool};
1.383 raeburn 3909: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3910: if ($newval =~ /^autolimit/) {
3911: if ($limit) {
3912: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3913: } else {
3914: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3915: }
3916: } elsif ($newval) {
3917: $newaccesstext->{$tool} = $reqdisplay{$newval};
3918: } else {
3919: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3920: }
1.275 raeburn 3921: } else {
1.383 raeburn 3922: if ($userenv->{$context.'.'.$tool}) {
3923: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3924: } else {
3925: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3926: }
1.275 raeburn 3927: }
3928: }
3929: }
3930: } else {
3931: $oldaccess->{$tool} = &mt('default');
3932: if ($env{'form.custom'.$tool} == 1) {
1.306 raeburn 3933: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
3934: $context);
1.275 raeburn 3935: if ($changed->{$tool}) {
3936: $newaccess->{$tool} = &mt('custom');
1.383 raeburn 3937: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3938: if ($newval =~ /^autolimit/) {
3939: if ($limit) {
3940: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3941: } else {
3942: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3943: }
3944: } elsif ($newval) {
3945: $newaccesstext->{$tool} = $reqdisplay{$newval};
3946: } else {
3947: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3948: }
1.275 raeburn 3949: } else {
1.383 raeburn 3950: if ($newval) {
3951: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3952: } else {
3953: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3954: }
1.275 raeburn 3955: }
3956: } else {
3957: $newaccess->{$tool} = $oldaccess->{$tool};
3958: }
3959: } else {
3960: $newaccess->{$tool} = $oldaccess->{$tool};
3961: }
3962: }
3963: }
3964: return;
3965: }
3966:
1.220 raeburn 3967: sub update_roles {
1.375 raeburn 3968: my ($r,$context,$showcredits) = @_;
1.4 www 3969: my $now=time;
1.225 raeburn 3970: my @rolechanges;
1.220 raeburn 3971: my %disallowed;
1.73 sakharuk 3972: $r->print('<h3>'.&mt('Modifying Roles').'</h3>');
1.404 raeburn 3973: foreach my $key (keys(%env)) {
1.135 raeburn 3974: next if (! $env{$key});
1.190 raeburn 3975: next if ($key eq 'form.action');
1.27 matthew 3976: # Revoke roles
1.135 raeburn 3977: if ($key=~/^form\.rev/) {
3978: if ($key=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) {
1.64 www 3979: # Revoke standard role
1.170 albertel 3980: my ($scope,$role) = ($1,$2);
3981: my $result =
3982: &Apache::lonnet::revokerole($env{'form.ccdomain'},
3983: $env{'form.ccuname'},
1.239 raeburn 3984: $scope,$role,'','',$context);
1.367 golterma 3985: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 3986: &mt('Revoking [_1] in [_2]',
3987: &Apache::lonnet::plaintext($role),
1.372 raeburn 3988: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 3989: $result ne "ok").'<br />');
3990: if ($result ne "ok") {
3991: $r->print(&mt('Error: [_1]',$result).'<br />');
3992: }
1.170 albertel 3993: if ($role eq 'st') {
1.202 raeburn 3994: my $result =
1.198 raeburn 3995: &Apache::lonuserutils::classlist_drop($scope,
3996: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 3997: $now);
1.367 golterma 3998: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.53 www 3999: }
1.225 raeburn 4000: if (!grep(/^\Q$role\E$/,@rolechanges)) {
4001: push(@rolechanges,$role);
4002: }
1.196 raeburn 4003: }
1.195 raeburn 4004: if ($key=~m{^form\.rev\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}s) {
1.64 www 4005: # Revoke custom role
1.369 bisitz 4006: my $result = &Apache::lonnet::revokecustomrole(
4007: $env{'form.ccdomain'},$env{'form.ccuname'},$1,$2,$3,$4,'','',$context);
1.367 golterma 4008: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 4009: &mt('Revoking custom role [_1] by [_2] in [_3]',
1.372 raeburn 4010: $4,$3.':'.$2,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 4011: $result ne 'ok').'<br />');
4012: if ($result ne "ok") {
4013: $r->print(&mt('Error: [_1]',$result).'<br />');
4014: }
1.225 raeburn 4015: if (!grep(/^cr$/,@rolechanges)) {
4016: push(@rolechanges,'cr');
4017: }
1.64 www 4018: }
1.135 raeburn 4019: } elsif ($key=~/^form\.del/) {
4020: if ($key=~/^form\.del\:([^\_]+)\_([^\_\.]+)$/) {
1.116 raeburn 4021: # Delete standard role
1.170 albertel 4022: my ($scope,$role) = ($1,$2);
4023: my $result =
4024: &Apache::lonnet::assignrole($env{'form.ccdomain'},
4025: $env{'form.ccuname'},
1.239 raeburn 4026: $scope,$role,$now,0,1,'',
4027: $context);
1.367 golterma 4028: $r->print(&Apache::lonhtmlcommon::confirm_success(
4029: &mt('Deleting [_1] in [_2]',
1.369 bisitz 4030: &Apache::lonnet::plaintext($role),
1.372 raeburn 4031: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 4032: $result ne 'ok').'<br />');
4033: if ($result ne "ok") {
4034: $r->print(&mt('Error: [_1]',$result).'<br />');
4035: }
1.367 golterma 4036:
1.170 albertel 4037: if ($role eq 'st') {
1.202 raeburn 4038: my $result =
1.198 raeburn 4039: &Apache::lonuserutils::classlist_drop($scope,
4040: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 4041: $now);
1.369 bisitz 4042: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.81 albertel 4043: }
1.225 raeburn 4044: if (!grep(/^\Q$role\E$/,@rolechanges)) {
4045: push(@rolechanges,$role);
4046: }
1.116 raeburn 4047: }
1.139 albertel 4048: if ($key=~m{^form\.del\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 4049: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
4050: # Delete custom role
1.369 bisitz 4051: my $result =
4052: &Apache::lonnet::assigncustomrole($env{'form.ccdomain'},
4053: $env{'form.ccuname'},$url,$rdom,$rnam,$rolename,$now,
4054: 0,1,$context);
4055: $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('Deleting custom role [_1] by [_2] in [_3]',
1.372 raeburn 4056: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 4057: $result ne "ok").'<br />');
4058: if ($result ne "ok") {
4059: $r->print(&mt('Error: [_1]',$result).'<br />');
4060: }
1.367 golterma 4061:
1.225 raeburn 4062: if (!grep(/^cr$/,@rolechanges)) {
4063: push(@rolechanges,'cr');
4064: }
1.116 raeburn 4065: }
1.135 raeburn 4066: } elsif ($key=~/^form\.ren/) {
1.101 albertel 4067: my $udom = $env{'form.ccdomain'};
4068: my $uname = $env{'form.ccuname'};
1.116 raeburn 4069: # Re-enable standard role
1.135 raeburn 4070: if ($key=~/^form\.ren\:([^\_]+)\_([^\_\.]+)$/) {
1.89 raeburn 4071: my $url = $1;
4072: my $role = $2;
4073: my $logmsg;
4074: my $output;
4075: if ($role eq 'st') {
1.141 albertel 4076: if ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
1.374 raeburn 4077: my ($cdom,$cnum,$csec) = ($1,$2,$3);
1.375 raeburn 4078: my $credits;
4079: if ($showcredits) {
4080: my $defaultcredits =
4081: &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
4082: $credits = &get_user_credits($defaultcredits,$cdom,$cnum);
4083: }
4084: my $result = &Apache::loncommon::commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$cdom,$cnum,$csec,$context,$credits);
1.220 raeburn 4085: if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course') || ($result eq 'refused')) {
1.223 raeburn 4086: if ($result eq 'refused' && $logmsg) {
4087: $output = $logmsg;
4088: } else {
1.369 bisitz 4089: $output = &mt('Error: [_1]',$result)."\n";
1.223 raeburn 4090: }
1.89 raeburn 4091: } else {
1.372 raeburn 4092: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Assigning [_1] in [_2] starting [_3]',
4093: &Apache::lonnet::plaintext($role),
4094: &Apache::loncommon::show_role_extent($url,$context,'st'),
4095: &Apache::lonlocal::locallocaltime($now))).'<br />'.$logmsg.'<br />';
1.89 raeburn 4096: }
4097: }
4098: } else {
1.101 albertel 4099: my $result=&Apache::lonnet::assignrole($env{'form.ccdomain'},
1.239 raeburn 4100: $env{'form.ccuname'},$url,$role,0,$now,'','',
4101: $context);
1.367 golterma 4102: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Re-enabling [_1] in [_2]',
1.372 raeburn 4103: &Apache::lonnet::plaintext($role),
4104: &Apache::loncommon::show_role_extent($url,$context,$role)),$result ne "ok").'<br />';
1.369 bisitz 4105: if ($result ne "ok") {
4106: $output .= &mt('Error: [_1]',$result).'<br />';
4107: }
4108: }
1.89 raeburn 4109: $r->print($output);
1.225 raeburn 4110: if (!grep(/^\Q$role\E$/,@rolechanges)) {
4111: push(@rolechanges,$role);
4112: }
1.113 raeburn 4113: }
1.116 raeburn 4114: # Re-enable custom role
1.139 albertel 4115: if ($key=~m{^form\.ren\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 4116: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
4117: my $result = &Apache::lonnet::assigncustomrole(
4118: $env{'form.ccdomain'}, $env{'form.ccuname'},
1.240 raeburn 4119: $url,$rdom,$rnam,$rolename,0,$now,undef,$context);
1.369 bisitz 4120: $r->print(&Apache::lonhtmlcommon::confirm_success(
4121: &mt('Re-enabling custom role [_1] by [_2] in [_3]',
1.372 raeburn 4122: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 4123: $result ne "ok").'<br />');
4124: if ($result ne "ok") {
4125: $r->print(&mt('Error: [_1]',$result).'<br />');
4126: }
1.225 raeburn 4127: if (!grep(/^cr$/,@rolechanges)) {
4128: push(@rolechanges,'cr');
4129: }
1.116 raeburn 4130: }
1.135 raeburn 4131: } elsif ($key=~/^form\.act/) {
1.101 albertel 4132: my $udom = $env{'form.ccdomain'};
4133: my $uname = $env{'form.ccuname'};
1.141 albertel 4134: if ($key=~/^form\.act\_($match_domain)\_($match_courseid)\_cr_cr_($match_domain)_($match_username)_([^\_]+)$/) {
1.65 www 4135: # Activate a custom role
1.83 albertel 4136: my ($one,$two,$three,$four,$five)=($1,$2,$3,$4,$5);
4137: my $url='/'.$one.'/'.$two;
4138: my $full=$one.'_'.$two.'_cr_cr_'.$three.'_'.$four.'_'.$five;
1.65 www 4139:
1.101 albertel 4140: my $start = ( $env{'form.start_'.$full} ?
4141: $env{'form.start_'.$full} :
1.88 raeburn 4142: $now );
1.101 albertel 4143: my $end = ( $env{'form.end_'.$full} ?
4144: $env{'form.end_'.$full} :
1.88 raeburn 4145: 0 );
4146:
4147: # split multiple sections
4148: my %sections = ();
1.101 albertel 4149: my $num_sections = &build_roles($env{'form.sec_'.$full},\%sections,$5);
1.88 raeburn 4150: if ($num_sections == 0) {
1.240 raeburn 4151: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end,$context));
1.88 raeburn 4152: } else {
1.114 albertel 4153: my %curr_groups =
1.117 raeburn 4154: &Apache::longroup::coursegroups($one,$two);
1.404 raeburn 4155: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.113 raeburn 4156: if (($sec eq 'none') || ($sec eq 'all') ||
4157: exists($curr_groups{$sec})) {
4158: $disallowed{$sec} = $url;
4159: next;
4160: }
4161: my $securl = $url.'/'.$sec;
1.240 raeburn 4162: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end,$context));
1.88 raeburn 4163: }
4164: }
1.225 raeburn 4165: if (!grep(/^cr$/,@rolechanges)) {
4166: push(@rolechanges,'cr');
4167: }
1.142 raeburn 4168: } elsif ($key=~/^form\.act\_($match_domain)\_($match_name)\_([^\_]+)$/) {
1.27 matthew 4169: # Activate roles for sections with 3 id numbers
4170: # set start, end times, and the url for the class
1.83 albertel 4171: my ($one,$two,$three)=($1,$2,$3);
1.101 albertel 4172: my $start = ( $env{'form.start_'.$one.'_'.$two.'_'.$three} ?
4173: $env{'form.start_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 4174: $now );
1.101 albertel 4175: my $end = ( $env{'form.end_'.$one.'_'.$two.'_'.$three} ?
4176: $env{'form.end_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 4177: 0 );
1.83 albertel 4178: my $url='/'.$one.'/'.$two;
1.88 raeburn 4179: my $type = 'three';
4180: # split multiple sections
4181: my %sections = ();
1.101 albertel 4182: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections,$three);
1.375 raeburn 4183: my $credits;
4184: if ($three eq 'st') {
4185: if ($showcredits) {
4186: my $defaultcredits =
4187: &Apache::lonuserutils::get_defaultcredits($one,$two);
4188: $credits = $env{'form.credits_'.$one.'_'.$two.'_'.$three};
4189: $credits =~ s/[^\d\.]//g;
4190: if ($credits eq $defaultcredits) {
4191: undef($credits);
4192: }
4193: }
4194: }
1.88 raeburn 4195: if ($num_sections == 0) {
1.375 raeburn 4196: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 4197: } else {
1.114 albertel 4198: my %curr_groups =
1.117 raeburn 4199: &Apache::longroup::coursegroups($one,$two);
1.88 raeburn 4200: my $emptysec = 0;
1.404 raeburn 4201: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.88 raeburn 4202: $sec =~ s/\W//g;
1.113 raeburn 4203: if ($sec ne '') {
4204: if (($sec eq 'none') || ($sec eq 'all') ||
4205: exists($curr_groups{$sec})) {
4206: $disallowed{$sec} = $url;
4207: next;
4208: }
1.88 raeburn 4209: my $securl = $url.'/'.$sec;
1.375 raeburn 4210: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec,$context,$credits));
1.88 raeburn 4211: } else {
4212: $emptysec = 1;
4213: }
4214: }
4215: if ($emptysec) {
1.375 raeburn 4216: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 4217: }
1.225 raeburn 4218: }
4219: if (!grep(/^\Q$three\E$/,@rolechanges)) {
4220: push(@rolechanges,$three);
4221: }
1.135 raeburn 4222: } elsif ($key=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
1.27 matthew 4223: # Activate roles for sections with two id numbers
4224: # set start, end times, and the url for the class
1.101 albertel 4225: my $start = ( $env{'form.start_'.$1.'_'.$2} ?
4226: $env{'form.start_'.$1.'_'.$2} :
1.27 matthew 4227: $now );
1.101 albertel 4228: my $end = ( $env{'form.end_'.$1.'_'.$2} ?
4229: $env{'form.end_'.$1.'_'.$2} :
1.27 matthew 4230: 0 );
1.225 raeburn 4231: my $one = $1;
4232: my $two = $2;
4233: my $url='/'.$one.'/';
1.88 raeburn 4234: # split multiple sections
4235: my %sections = ();
1.225 raeburn 4236: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two},\%sections,$two);
1.88 raeburn 4237: if ($num_sections == 0) {
1.240 raeburn 4238: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 4239: } else {
4240: my $emptysec = 0;
1.404 raeburn 4241: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.88 raeburn 4242: if ($sec ne '') {
4243: my $securl = $url.'/'.$sec;
1.240 raeburn 4244: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$two,$start,$end,$one,undef,$sec,$context));
1.88 raeburn 4245: } else {
4246: $emptysec = 1;
4247: }
4248: }
4249: if ($emptysec) {
1.240 raeburn 4250: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 4251: }
4252: }
1.225 raeburn 4253: if (!grep(/^\Q$two\E$/,@rolechanges)) {
4254: push(@rolechanges,$two);
4255: }
1.64 www 4256: } else {
1.190 raeburn 4257: $r->print('<p><span class="LC_error">'.&mt('ERROR').': '.&mt('Unknown command').' <tt>'.$key.'</tt></span></p><br />');
1.64 www 4258: }
1.113 raeburn 4259: foreach my $key (sort(keys(%disallowed))) {
1.274 bisitz 4260: $r->print('<p class="LC_warning">');
1.113 raeburn 4261: if (($key eq 'none') || ($key eq 'all')) {
1.274 bisitz 4262: $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 4263: } else {
1.274 bisitz 4264: $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 4265: }
1.274 bisitz 4266: $r->print('</p><p>'
4267: .&mt('Please [_1]go back[_2] and choose a different section name.'
4268: ,'<a href="javascript:history.go(-1)'
4269: ,'</a>')
4270: .'</p><br />'
4271: );
1.113 raeburn 4272: }
4273: }
1.101 albertel 4274: } # End of foreach (keys(%env))
1.75 www 4275: # Flush the course logs so reverse user roles immediately updated
1.349 raeburn 4276: $r->register_cleanup(\&Apache::lonnet::flushcourselogs);
1.225 raeburn 4277: if (@rolechanges == 0) {
1.372 raeburn 4278: $r->print('<p>'.&mt('No roles to modify').'</p>');
1.193 raeburn 4279: }
1.225 raeburn 4280: return @rolechanges;
1.220 raeburn 4281: }
4282:
1.375 raeburn 4283: sub get_user_credits {
4284: my ($uname,$udom,$defaultcredits,$cdom,$cnum) = @_;
4285: if ($cdom eq '' || $cnum eq '') {
4286: return unless ($env{'request.course.id'});
4287: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4288: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
4289: }
4290: my $credits;
4291: my %currhash =
4292: &Apache::lonnet::get('classlist',[$uname.':'.$udom],$cdom,$cnum);
4293: if (keys(%currhash) > 0) {
4294: my @items = split(/:/,$currhash{$uname.':'.$udom});
4295: my $crdidx = &Apache::loncoursedata::CL_CREDITS() - 3;
4296: $credits = $items[$crdidx];
4297: $credits =~ s/[^\d\.]//g;
4298: }
4299: if ($credits eq $defaultcredits) {
4300: undef($credits);
4301: }
4302: return $credits;
4303: }
4304:
1.220 raeburn 4305: sub enroll_single_student {
1.375 raeburn 4306: my ($r,$uhome,$amode,$genpwd,$now,$newuser,$context,$crstype,
4307: $showcredits,$defaultcredits) = @_;
1.318 raeburn 4308: $r->print('<h3>');
4309: if ($crstype eq 'Community') {
4310: $r->print(&mt('Enrolling Member'));
4311: } else {
4312: $r->print(&mt('Enrolling Student'));
4313: }
4314: $r->print('</h3>');
1.220 raeburn 4315:
4316: # Remove non alphanumeric values from section
4317: $env{'form.sections'}=~s/\W//g;
4318:
1.375 raeburn 4319: my $credits;
4320: if (($showcredits) && ($env{'form.credits'} ne '')) {
4321: $credits = $env{'form.credits'};
4322: $credits =~ s/[^\d\.]//g;
4323: if ($credits ne '') {
4324: if ($credits eq $defaultcredits) {
4325: undef($credits);
4326: }
4327: }
4328: }
4329:
1.220 raeburn 4330: # Clean out any old student roles the user has in this class.
4331: &Apache::lonuserutils::modifystudent($env{'form.ccdomain'},
4332: $env{'form.ccuname'},$env{'request.course.id'},undef,$uhome);
4333: my ($startdate,$enddate) = &Apache::lonuserutils::get_dates_from_form();
4334: my $enroll_result =
4335: &Apache::lonnet::modify_student_enrollment($env{'form.ccdomain'},
4336: $env{'form.ccuname'},$env{'form.cid'},$env{'form.cfirstname'},
4337: $env{'form.cmiddlename'},$env{'form.clastname'},
4338: $env{'form.generation'},$env{'form.sections'},$enddate,
1.375 raeburn 4339: $startdate,'manual',undef,$env{'request.course.id'},'',$context,
4340: $credits);
1.220 raeburn 4341: if ($enroll_result =~ /^ok/) {
1.381 bisitz 4342: $r->print(&mt('[_1] enrolled','<b>'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.'</b>'));
1.220 raeburn 4343: if ($env{'form.sections'} ne '') {
4344: $r->print(' '.&mt('in section [_1]',$env{'form.sections'}));
4345: }
4346: my ($showstart,$showend);
4347: if ($startdate <= $now) {
4348: $showstart = &mt('Access starts immediately');
4349: } else {
4350: $showstart = &mt('Access starts: ').&Apache::lonlocal::locallocaltime($startdate);
4351: }
4352: if ($enddate == 0) {
4353: $showend = &mt('ends: no ending date');
4354: } else {
4355: $showend = &mt('ends: ').&Apache::lonlocal::locallocaltime($enddate);
4356: }
4357: $r->print('.<br />'.$showstart.'; '.$showend);
4358: if ($startdate <= $now && !$newuser) {
1.386 bisitz 4359: $r->print('<p class="LC_info">');
1.318 raeburn 4360: if ($crstype eq 'Community') {
1.392 raeburn 4361: $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 4362: } else {
1.392 raeburn 4363: $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 4364: }
4365: $r->print('</p>');
1.220 raeburn 4366: }
4367: } else {
4368: $r->print(&mt('unable to enroll').": ".$enroll_result);
4369: }
4370: return;
1.188 raeburn 4371: }
4372:
1.204 raeburn 4373: sub get_defaultquota_text {
4374: my ($settingstatus) = @_;
4375: my $defquotatext;
4376: if ($settingstatus eq '') {
1.383 raeburn 4377: $defquotatext = &mt('default');
1.204 raeburn 4378: } else {
4379: my ($usertypes,$order) =
4380: &Apache::lonnet::retrieve_inst_usertypes($env{'form.ccdomain'});
4381: if ($usertypes->{$settingstatus} eq '') {
1.383 raeburn 4382: $defquotatext = &mt('default');
1.204 raeburn 4383: } else {
1.383 raeburn 4384: $defquotatext = &mt('default for [_1]',$usertypes->{$settingstatus});
1.204 raeburn 4385: }
4386: }
4387: return $defquotatext;
4388: }
4389:
1.188 raeburn 4390: sub update_result_form {
4391: my ($uhome) = @_;
4392: my $outcome =
1.367 golterma 4393: '<form name="userupdate" method="post" action="">'."\n";
1.160 raeburn 4394: foreach my $item ('srchby','srchin','srchtype','srchterm','srchdomain','ccuname','ccdomain') {
1.188 raeburn 4395: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 4396: }
1.207 raeburn 4397: if ($env{'form.origname'} ne '') {
4398: $outcome .= '<input type="hidden" name="origname" value="'.$env{'form.origname'}.'" />'."\n";
4399: }
1.160 raeburn 4400: foreach my $item ('sortby','seluname','seludom') {
4401: if (exists($env{'form.'.$item})) {
1.188 raeburn 4402: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 4403: }
4404: }
1.188 raeburn 4405: if ($uhome eq 'no_host') {
4406: $outcome .= '<input type="hidden" name="forcenewuser" value="1" />'."\n";
4407: }
4408: $outcome .= '<input type="hidden" name="phase" value="" />'."\n".
1.383 raeburn 4409: '<input type="hidden" name="currstate" value="" />'."\n".
4410: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
1.188 raeburn 4411: '</form>';
4412: return $outcome;
1.4 www 4413: }
4414:
1.149 raeburn 4415: sub quota_admin {
1.378 raeburn 4416: my ($setquota,$changeHash,$name) = @_;
1.149 raeburn 4417: my $quotachanged;
4418: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
4419: # Current user has quota modification privileges
1.267 raeburn 4420: if (ref($changeHash) eq 'HASH') {
4421: $quotachanged = 1;
1.378 raeburn 4422: $changeHash->{$name.'quota'} = $setquota;
1.267 raeburn 4423: }
1.149 raeburn 4424: }
4425: return $quotachanged;
4426: }
4427:
1.267 raeburn 4428: sub tool_admin {
1.275 raeburn 4429: my ($tool,$settool,$changeHash,$context) = @_;
4430: my $canchange = 0;
1.279 raeburn 4431: if ($context eq 'requestcourses') {
1.275 raeburn 4432: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
4433: $canchange = 1;
4434: }
1.300 raeburn 4435: } elsif ($context eq 'reqcrsotherdom') {
4436: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
4437: $canchange = 1;
4438: }
1.362 raeburn 4439: } elsif ($context eq 'requestauthor') {
4440: if (&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) {
4441: $canchange = 1;
4442: }
1.275 raeburn 4443: } elsif (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
4444: # Current user has quota modification privileges
4445: $canchange = 1;
4446: }
1.267 raeburn 4447: my $toolchanged;
1.275 raeburn 4448: if ($canchange) {
1.267 raeburn 4449: if (ref($changeHash) eq 'HASH') {
4450: $toolchanged = 1;
1.362 raeburn 4451: if ($tool eq 'requestauthor') {
4452: $changeHash->{$context} = $settool;
4453: } else {
4454: $changeHash->{$context.'.'.$tool} = $settool;
4455: }
1.267 raeburn 4456: }
4457: }
4458: return $toolchanged;
4459: }
4460:
1.88 raeburn 4461: sub build_roles {
1.89 raeburn 4462: my ($sectionstr,$sections,$role) = @_;
1.88 raeburn 4463: my $num_sections = 0;
4464: if ($sectionstr=~ /,/) {
4465: my @secnums = split/,/,$sectionstr;
1.89 raeburn 4466: if ($role eq 'st') {
4467: $secnums[0] =~ s/\W//g;
4468: $$sections{$secnums[0]} = 1;
4469: $num_sections = 1;
4470: } else {
4471: foreach my $sec (@secnums) {
4472: $sec =~ ~s/\W//g;
1.150 banghart 4473: if (!($sec eq "")) {
1.89 raeburn 4474: if (exists($$sections{$sec})) {
4475: $$sections{$sec} ++;
4476: } else {
4477: $$sections{$sec} = 1;
4478: $num_sections ++;
4479: }
1.88 raeburn 4480: }
4481: }
4482: }
4483: } else {
4484: $sectionstr=~s/\W//g;
4485: unless ($sectionstr eq '') {
4486: $$sections{$sectionstr} = 1;
4487: $num_sections ++;
4488: }
4489: }
1.129 albertel 4490:
1.88 raeburn 4491: return $num_sections;
4492: }
4493:
1.58 www 4494: # ========================================================== Custom Role Editor
4495:
4496: sub custom_role_editor {
1.439 raeburn 4497: my ($r,$context,$brcrum,$prefix,$permission) = @_;
1.324 raeburn 4498: my $action = $env{'form.customroleaction'};
1.439 raeburn 4499: my ($rolename,$helpitem);
1.324 raeburn 4500: if ($action eq 'new') {
4501: $rolename=$env{'form.newrolename'};
4502: } else {
4503: $rolename=$env{'form.rolename'};
1.59 www 4504: }
4505:
1.324 raeburn 4506: my ($crstype,$context);
4507: if ($env{'request.course.id'}) {
4508: $crstype = &Apache::loncommon::course_type();
4509: $context = 'course';
1.439 raeburn 4510: $helpitem = 'Course_Editing_Custom_Roles';
1.324 raeburn 4511: } else {
4512: $context = 'domain';
1.414 raeburn 4513: $crstype = 'course';
1.439 raeburn 4514: $helpitem = 'Domain_Editing_Custom_Roles';
1.324 raeburn 4515: }
1.351 raeburn 4516:
4517: $rolename=~s/[^A-Za-z0-9]//gs;
4518: if (!$rolename || $env{'form.phase'} eq 'pickrole') {
1.439 raeburn 4519: &print_username_entry_form($r,$context,undef,undef,undef,$crstype,$brcrum,
4520: $permission);
1.351 raeburn 4521: return;
4522: }
4523:
1.414 raeburn 4524: my $formname = 'form1';
4525: my %privs=();
4526: my $body_top = '<h2>';
4527: # ------------------------------------------------------- Does this role exist?
1.59 www 4528: my ($rdummy,$roledef)=
4529: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
4530: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.414 raeburn 4531: $body_top .= &mt('Existing Role').' "';
1.61 www 4532: # ------------------------------------------------- Get current role privileges
1.414 raeburn 4533: ($privs{'system'},$privs{'domain'},$privs{'course'})=split(/\_/,$roledef);
4534: if ($privs{'system'} =~ /bre\&S/) {
4535: if ($context eq 'domain') {
1.417 raeburn 4536: $crstype = 'Course';
1.414 raeburn 4537: } elsif ($crstype eq 'Community') {
4538: $privs{'system'} =~ s/bre\&S//;
4539: }
4540: } elsif ($context eq 'domain') {
4541: $crstype = 'Course';
1.324 raeburn 4542: }
1.59 www 4543: } else {
1.414 raeburn 4544: $body_top .= &mt('New Role').' "';
4545: $roledef='';
1.59 www 4546: }
1.153 banghart 4547: $body_top .= $rolename.'"</h2>';
1.414 raeburn 4548:
4549: # ------------------------------------------------------- What can be assigned?
4550: my %full=();
1.417 raeburn 4551: my %levels=(
1.414 raeburn 4552: course => {},
4553: domain => {},
4554: system => {},
4555: );
4556: my %levelscurrent=(
4557: course => {},
4558: domain => {},
4559: system => {},
4560: );
4561: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
1.160 raeburn 4562: my ($jsback,$elements) = &crumb_utilities();
1.414 raeburn 4563: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.417 raeburn 4564: my $head_script =
1.414 raeburn 4565: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,
4566: \%full,\@templateroles,$jsback);
1.351 raeburn 4567: push (@{$brcrum},
1.414 raeburn 4568: {href => "javascript:backPage(document.$formname,'pickrole','')",
1.351 raeburn 4569: text => "Pick custom role",
4570: faq => 282,bug=>'Instructor Interface',},
1.414 raeburn 4571: {href => "javascript:backPage(document.$formname,'','')",
1.351 raeburn 4572: text => "Edit custom role",
4573: faq => 282,
4574: bug => 'Instructor Interface',
1.439 raeburn 4575: help => $helpitem}
1.351 raeburn 4576: );
4577: my $args = { bread_crumbs => $brcrum,
4578: bread_crumbs_component => 'User Management'};
4579: $r->print(&Apache::loncommon::start_page('Custom Role Editor',
4580: $head_script,$args).
4581: $body_top);
1.414 raeburn 4582: $r->print('<form name="'.$formname.'" method="post" action="">'."\n".
4583: &Apache::lonuserutils::custom_role_header($context,$crstype,
4584: \@templateroles,$prefix));
1.264 bisitz 4585:
1.61 www 4586: $r->print(<<ENDCCF);
4587: <input type="hidden" name="phase" value="set_custom_roles" />
4588: <input type="hidden" name="rolename" value="$rolename" />
4589: ENDCCF
1.414 raeburn 4590: $r->print(&Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
4591: \%levelscurrent,$prefix));
1.135 raeburn 4592: $r->print(&Apache::loncommon::end_data_table().
1.190 raeburn 4593: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
1.160 raeburn 4594: '<input type="hidden" name="startrolename" value="'.$env{'form.rolename'}.
1.417 raeburn 4595: '" />'."\n".'<input type="hidden" name="currstate" value="" />'."\n".
1.160 raeburn 4596: '<input type="reset" value="'.&mt("Reset").'" />'."\n".
1.351 raeburn 4597: '<input type="submit" value="'.&mt('Save').'" /></form>');
1.61 www 4598: }
1.414 raeburn 4599:
1.61 www 4600: # ---------------------------------------------------------- Call to definerole
4601: sub set_custom_role {
1.439 raeburn 4602: my ($r,$context,$brcrum,$prefix,$permission) = @_;
1.101 albertel 4603: my $rolename=$env{'form.rolename'};
1.63 www 4604: $rolename=~s/[^A-Za-z0-9]//gs;
1.150 banghart 4605: if (!$rolename) {
1.439 raeburn 4606: &custom_role_editor($r,$context,$brcrum,$prefix,$permission);
1.61 www 4607: return;
4608: }
1.160 raeburn 4609: my ($jsback,$elements) = &crumb_utilities();
1.301 bisitz 4610: my $jscript = '<script type="text/javascript">'
4611: .'// <![CDATA['."\n"
4612: .$jsback."\n"
4613: .'// ]]>'."\n"
4614: .'</script>'."\n";
1.439 raeburn 4615: my $helpitem = 'Course_Editing_Custom_Roles';
4616: if ($context eq 'domain') {
4617: $helpitem = 'Domain_Editing_Custom_Roles';
4618: }
1.352 raeburn 4619: push(@{$brcrum},
4620: {href => "javascript:backPage(document.customresult,'pickrole','')",
4621: text => "Pick custom role",
4622: faq => 282,
4623: bug => 'Instructor Interface',},
4624: {href => "javascript:backPage(document.customresult,'selected_custom_edit','')",
4625: text => "Edit custom role",
4626: faq => 282,
4627: bug => 'Instructor Interface',},
4628: {href => "javascript:backPage(document.customresult,'set_custom_roles','')",
4629: text => "Result",
4630: faq => 282,
4631: bug => 'Instructor Interface',
1.439 raeburn 4632: help => $helpitem,}
1.352 raeburn 4633: );
4634: my $args = { bread_crumbs => $brcrum,
1.414 raeburn 4635: bread_crumbs_component => 'User Management'};
1.351 raeburn 4636: $r->print(&Apache::loncommon::start_page('Save Custom Role',$jscript,$args));
1.160 raeburn 4637:
1.393 raeburn 4638: my $newrole;
1.61 www 4639: my ($rdummy,$roledef)=
1.110 albertel 4640: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
4641:
1.61 www 4642: # ------------------------------------------------------- Does this role exist?
1.188 raeburn 4643: $r->print('<h3>');
1.61 www 4644: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.73 sakharuk 4645: $r->print(&mt('Existing Role').' "');
1.61 www 4646: } else {
1.73 sakharuk 4647: $r->print(&mt('New Role').' "');
1.61 www 4648: $roledef='';
1.393 raeburn 4649: $newrole = 1;
1.61 www 4650: }
1.188 raeburn 4651: $r->print($rolename.'"</h3>');
1.414 raeburn 4652: # ------------------------------------------------- Assign role and show result
1.61 www 4653:
1.387 bisitz 4654: my $errmsg;
1.414 raeburn 4655: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$prefix);
4656: # Assign role and return result
4657: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
4658: $newprivs{'c'});
1.387 bisitz 4659: if ($result ne 'ok') {
4660: $errmsg = ': '.$result;
4661: }
4662: my $message =
4663: &Apache::lonhtmlcommon::confirm_success(
4664: &mt('Defining Role').$errmsg, ($result eq 'ok' ? 0 : 1));
1.101 albertel 4665: if ($env{'request.course.id'}) {
4666: my $url='/'.$env{'request.course.id'};
1.63 www 4667: $url=~s/\_/\//g;
1.387 bisitz 4668: $result =
4669: &Apache::lonnet::assigncustomrole(
4670: $env{'user.domain'},$env{'user.name'},
4671: $url,
4672: $env{'user.domain'},$env{'user.name'},
4673: $rolename,undef,undef,undef,$context);
4674: if ($result ne 'ok') {
4675: $errmsg = ': '.$result;
4676: }
4677: $message .=
4678: '<br />'
4679: .&Apache::lonhtmlcommon::confirm_success(
4680: &mt('Assigning Role to Self').$errmsg, ($result eq 'ok' ? 0 : 1));
1.63 www 4681: }
1.380 bisitz 4682: $r->print(
1.387 bisitz 4683: &Apache::loncommon::confirmwrapper($message)
4684: .'<br />'
4685: .&Apache::lonhtmlcommon::actionbox([
4686: '<a href="javascript:backPage(document.customresult,'."'pickrole'".')">'
4687: .&mt('Create or edit another custom role')
4688: .'</a>'])
1.380 bisitz 4689: .'<form name="customresult" method="post" action="">'
1.387 bisitz 4690: .&Apache::lonhtmlcommon::echo_form_input([])
4691: .'</form>'
1.380 bisitz 4692: );
1.58 www 4693: }
4694:
1.2 www 4695: # ================================================================ Main Handler
4696: sub handler {
4697: my $r = shift;
4698: if ($r->header_only) {
1.68 www 4699: &Apache::loncommon::content_type($r,'text/html');
1.2 www 4700: $r->send_http_header;
4701: return OK;
4702: }
1.439 raeburn 4703: my ($context,$crstype,$cid,$cnum,$cdom,$allhelpitems);
4704:
1.190 raeburn 4705: if ($env{'request.course.id'}) {
4706: $context = 'course';
1.318 raeburn 4707: $crstype = &Apache::loncommon::course_type();
1.190 raeburn 4708: } elsif ($env{'request.role'} =~ /^au\./) {
1.206 raeburn 4709: $context = 'author';
1.190 raeburn 4710: } else {
4711: $context = 'domain';
4712: }
1.375 raeburn 4713:
1.439 raeburn 4714: my ($permission,$allowed) =
4715: &Apache::lonuserutils::get_permission($context,$crstype);
4716:
4717: if ($allowed) {
4718: my @allhelp;
4719: if ($context eq 'course') {
4720: $cid = $env{'request.course.id'};
4721: $cdom = $env{'course.'.$cid.'.domain'};
4722: $cnum = $env{'course.'.$cid.'.num'};
4723:
4724: if ($permission->{'cusr'}) {
4725: push(@allhelp,'Course_Create_Class_List');
4726: }
4727: if ($permission->{'view'} || $permission->{'cusr'}) {
4728: push(@allhelp,('Course_Change_Privileges','Course_View_Class_List'));
4729: }
4730: if ($permission->{'custom'}) {
4731: push(@allhelp,'Course_Editing_Custom_Roles');
4732: }
4733: if ($permission->{'cusr'}) {
4734: push(@allhelp,('Course_Add_Student','Course_Drop_Student'));
4735: }
4736: unless ($permission->{'cusr_section'}) {
4737: if (&Apache::lonnet::auto_run($cnum,$cdom) && (($permission->{'cusr'}) || ($permission->{'view'}))) {
4738: push(@allhelp,'Course_Automated_Enrollment');
4739: }
4740: if ($permission->{'selfenrolladmin'}) {
4741: push(@allhelp,'Course_Approve_Selfenroll');
4742: }
4743: }
4744: if ($permission->{'grp_manage'}) {
4745: push(@allhelp,'Course_Manage_Group');
4746: }
4747: if ($permission->{'view'} || $permission->{'cusr'}) {
4748: push(@allhelp,'Course_User_Logs');
4749: }
4750: } elsif ($context eq 'author') {
4751: push(@allhelp,('Author_Change_Privileges','Author_Create_Coauthor_List',
4752: 'Author_View_Coauthor_List','Author_User_Logs'));
4753: } else {
4754: if ($permission->{'cusr'}) {
4755: push(@allhelp,'Domain_Change_Privileges');
4756: if ($permission->{'activity'}) {
4757: push(@allhelp,'Domain_User_Access_Logs');
4758: }
4759: push(@allhelp,('Domain_Create_Users','Domain_View_Users_List'));
4760: if ($permission->{'custom'}) {
4761: push(@allhelp,'Domain_Editing_Custom_Roles');
4762: }
4763: push(@allhelp,('Domain_Role_Approvals','Domain_Username_Approvals','Domain_Change_Logs'));
4764: } elsif ($permission->{'view'}) {
4765: push(@allhelp,'Domain_View_Privileges');
4766: if ($permission->{'activity'}) {
4767: push(@allhelp,'Domain_User_Access_Logs');
4768: }
4769: push(@allhelp,('Domain_View_Users_List','Domain_Change_Logs'));
4770: }
4771: }
4772: if (@allhelp) {
4773: $allhelpitems = join(',',@allhelp);
4774: }
4775: }
4776:
1.190 raeburn 4777: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.233 raeburn 4778: ['action','state','callingform','roletype','showrole','bulkaction','popup','phase',
1.391 raeburn 4779: 'username','domain','srchterm','srchdomain','srchin','srchby','srchtype','queue']);
1.190 raeburn 4780: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.351 raeburn 4781: my $args;
4782: my $brcrum = [];
4783: my $bread_crumbs_component = 'User Management';
1.391 raeburn 4784: if (($env{'form.action'} ne 'dateselect') && ($env{'form.action'} ne 'displayuserreq')) {
1.351 raeburn 4785: $brcrum = [{href=>"/adm/createuser",
4786: text=>"User Management",
1.439 raeburn 4787: help=>$allhelpitems}
1.351 raeburn 4788: ];
1.202 raeburn 4789: }
1.190 raeburn 4790: if (!$allowed) {
1.358 raeburn 4791: if ($context eq 'course') {
4792: $r->internal_redirect('/adm/viewclasslist');
4793: return OK;
4794: }
1.190 raeburn 4795: $env{'user.error.msg'}=
4796: "/adm/createuser:cst:0:0:Cannot create/modify user data ".
4797: "or view user status.";
4798: return HTTP_NOT_ACCEPTABLE;
4799: }
4800:
4801: &Apache::loncommon::content_type($r,'text/html');
4802: $r->send_http_header;
4803:
1.375 raeburn 4804: my $showcredits;
4805: if ((($context eq 'course') && ($crstype eq 'Course')) ||
4806: ($context eq 'domain')) {
4807: my %domdefaults =
4808: &Apache::lonnet::get_domain_defaults($env{'request.role.domain'});
4809: if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'}) {
4810: $showcredits = 1;
4811: }
4812: }
4813:
1.190 raeburn 4814: # Main switch on form.action and form.state, as appropriate
4815: if (! exists($env{'form.action'})) {
1.351 raeburn 4816: $args = {bread_crumbs => $brcrum,
4817: bread_crumbs_component => $bread_crumbs_component};
4818: $r->print(&header(undef,$args));
1.318 raeburn 4819: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 4820: } elsif ($env{'form.action'} eq 'upload' && $permission->{'cusr'}) {
1.439 raeburn 4821: my $helpitem = 'Course_Create_Class_List';
4822: if ($context eq 'author') {
4823: $helpitem = 'Author_Create_Coauthor_List';
4824: } elsif ($context eq 'domain') {
4825: $helpitem = 'Domain_Create_Users';
4826: }
1.351 raeburn 4827: push(@{$brcrum},
4828: { href => '/adm/createuser?action=upload&state=',
4829: text => 'Upload Users List',
1.439 raeburn 4830: help => $helpitem,
1.351 raeburn 4831: });
4832: $bread_crumbs_component = 'Upload Users List';
4833: $args = {bread_crumbs => $brcrum,
4834: bread_crumbs_component => $bread_crumbs_component};
4835: $r->print(&header(undef,$args));
1.190 raeburn 4836: $r->print('<form name="studentform" method="post" '.
4837: 'enctype="multipart/form-data" '.
4838: ' action="/adm/createuser">'."\n");
4839: if (! exists($env{'form.state'})) {
4840: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4841: } elsif ($env{'form.state'} eq 'got_file') {
1.448 raeburn 4842: my $result =
4843: &Apache::lonuserutils::print_upload_manager_form($r,$context,
4844: $permission,
4845: $crstype,$showcredits);
4846: if ($result eq 'missingdata') {
4847: delete($env{'form.state'});
4848: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4849: }
1.190 raeburn 4850: } elsif ($env{'form.state'} eq 'enrolling') {
4851: if ($env{'form.datatoken'}) {
1.448 raeburn 4852: my $result = &Apache::lonuserutils::upfile_drop_add($r,$context,
4853: $permission,
4854: $showcredits);
4855: if ($result eq 'missingdata') {
4856: delete($env{'form.state'});
4857: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4858: } elsif ($result eq 'invalidhome') {
4859: $env{'form.state'} = 'got_file';
4860: delete($env{'form.lcserver'});
4861: my $result =
4862: &Apache::lonuserutils::print_upload_manager_form($r,$context,$permission,
4863: $crstype,$showcredits);
4864: if ($result eq 'missingdata') {
4865: delete($env{'form.state'});
4866: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4867: }
4868: }
4869: } else {
4870: delete($env{'form.state'});
4871: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
1.190 raeburn 4872: }
4873: } else {
4874: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4875: }
1.447 raeburn 4876: $r->print('</form>');
1.416 raeburn 4877: } elsif (((($env{'form.action'} eq 'singleuser') || ($env{'form.action'}
4878: eq 'singlestudent')) && ($permission->{'cusr'})) ||
1.418 raeburn 4879: (($env{'form.action'} eq 'singleuser') && ($permission->{'view'})) ||
1.416 raeburn 4880: (($env{'form.action'} eq 'accesslogs') && ($permission->{'activity'}))) {
1.190 raeburn 4881: my $phase = $env{'form.phase'};
4882: my @search = ('srchterm','srchby','srchin','srchtype','srchdomain');
1.192 albertel 4883: &Apache::loncreateuser::restore_prev_selections();
4884: my $srch;
4885: foreach my $item (@search) {
4886: $srch->{$item} = $env{'form.'.$item};
4887: }
1.207 raeburn 4888: if (($phase eq 'get_user_info') || ($phase eq 'userpicked') ||
1.416 raeburn 4889: ($phase eq 'createnewuser') || ($phase eq 'activity')) {
1.207 raeburn 4890: if ($env{'form.phase'} eq 'createnewuser') {
4891: my $response;
4892: if ($env{'form.srchterm'} !~ /^$match_username$/) {
1.366 bisitz 4893: my $response =
4894: '<span class="LC_warning">'
4895: .&mt('You must specify a valid username. Only the following are allowed:'
4896: .' letters numbers - . @')
4897: .'</span>';
1.221 raeburn 4898: $env{'form.phase'} = '';
1.375 raeburn 4899: &print_username_entry_form($r,$context,$response,$srch,undef,
1.439 raeburn 4900: $crstype,$brcrum,$permission);
1.207 raeburn 4901: } else {
4902: my $ccuname =&LONCAPA::clean_username($srch->{'srchterm'});
4903: my $ccdomain=&LONCAPA::clean_domain($srch->{'srchdomain'});
4904: &print_user_modification_page($r,$ccuname,$ccdomain,
1.221 raeburn 4905: $srch,$response,$context,
1.375 raeburn 4906: $permission,$crstype,$brcrum,
4907: $showcredits);
1.207 raeburn 4908: }
4909: } elsif ($env{'form.phase'} eq 'get_user_info') {
1.190 raeburn 4910: my ($currstate,$response,$forcenewuser,$results) =
1.221 raeburn 4911: &user_search_result($context,$srch);
1.190 raeburn 4912: if ($env{'form.currstate'} eq 'modify') {
4913: $currstate = $env{'form.currstate'};
4914: }
4915: if ($currstate eq 'select') {
4916: &print_user_selection_page($r,$response,$srch,$results,
1.351 raeburn 4917: \@search,$context,undef,$crstype,
4918: $brcrum);
1.416 raeburn 4919: } elsif (($currstate eq 'modify') || ($env{'form.action'} eq 'accesslogs')) {
4920: my ($ccuname,$ccdomain,$uhome);
1.190 raeburn 4921: if (($srch->{'srchby'} eq 'uname') &&
4922: ($srch->{'srchtype'} eq 'exact')) {
4923: $ccuname = $srch->{'srchterm'};
4924: $ccdomain= $srch->{'srchdomain'};
4925: } else {
4926: my @matchedunames = keys(%{$results});
4927: ($ccuname,$ccdomain) = split(/:/,$matchedunames[0]);
4928: }
4929: $ccuname =&LONCAPA::clean_username($ccuname);
4930: $ccdomain=&LONCAPA::clean_domain($ccdomain);
1.416 raeburn 4931: if ($env{'form.action'} eq 'accesslogs') {
4932: my $uhome;
4933: if (($ccuname ne '') && ($ccdomain ne '')) {
4934: $uhome = &Apache::lonnet::homeserver($ccuname,$ccdomain);
4935: }
4936: if (($uhome eq '') || ($uhome eq 'no_host')) {
4937: $env{'form.phase'} = '';
4938: undef($forcenewuser);
4939: #if ($response) {
4940: # unless ($response =~ m{\Q<br /><br />\E$}) {
4941: # $response .= '<br /><br />';
4942: # }
4943: #}
4944: &print_username_entry_form($r,$context,$response,$srch,
1.439 raeburn 4945: $forcenewuser,$crstype,$brcrum,
4946: $permission);
1.416 raeburn 4947: } else {
4948: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
4949: }
4950: } else {
4951: if ($env{'form.forcenewuser'}) {
4952: $response = '';
4953: }
4954: &print_user_modification_page($r,$ccuname,$ccdomain,
4955: $srch,$response,$context,
4956: $permission,$crstype,$brcrum);
1.190 raeburn 4957: }
4958: } elsif ($currstate eq 'query') {
1.351 raeburn 4959: &print_user_query_page($r,'createuser',$brcrum);
1.190 raeburn 4960: } else {
1.229 raeburn 4961: $env{'form.phase'} = '';
1.207 raeburn 4962: &print_username_entry_form($r,$context,$response,$srch,
1.439 raeburn 4963: $forcenewuser,$crstype,$brcrum,
4964: $permission);
1.190 raeburn 4965: }
4966: } elsif ($env{'form.phase'} eq 'userpicked') {
4967: my $ccuname = &LONCAPA::clean_username($env{'form.seluname'});
4968: my $ccdomain = &LONCAPA::clean_domain($env{'form.seludom'});
1.416 raeburn 4969: if ($env{'form.action'} eq 'accesslogs') {
4970: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
4971: } else {
4972: &print_user_modification_page($r,$ccuname,$ccdomain,$srch,'',
4973: $context,$permission,$crstype,
4974: $brcrum);
4975: }
4976: } elsif ($env{'form.action'} eq 'accesslogs') {
4977: my $ccuname = &LONCAPA::clean_username($env{'form.accessuname'});
4978: my $ccdomain = &LONCAPA::clean_domain($env{'form.accessudom'});
4979: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
1.190 raeburn 4980: }
4981: } elsif ($env{'form.phase'} eq 'update_user_data') {
1.451 raeburn 4982: &update_user_data($r,$context,$crstype,$brcrum,$showcredits,$permission);
1.190 raeburn 4983: } else {
1.351 raeburn 4984: &print_username_entry_form($r,$context,undef,$srch,undef,$crstype,
1.439 raeburn 4985: $brcrum,$permission);
1.190 raeburn 4986: }
4987: } elsif ($env{'form.action'} eq 'custom' && $permission->{'custom'}) {
1.414 raeburn 4988: my $prefix;
1.190 raeburn 4989: if ($env{'form.phase'} eq 'set_custom_roles') {
1.439 raeburn 4990: &set_custom_role($r,$context,$brcrum,$prefix,$permission);
1.190 raeburn 4991: } else {
1.439 raeburn 4992: &custom_role_editor($r,$context,$brcrum,$prefix,$permission);
1.190 raeburn 4993: }
1.362 raeburn 4994: } elsif (($env{'form.action'} eq 'processauthorreq') &&
4995: ($permission->{'cusr'}) &&
4996: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
4997: push(@{$brcrum},
4998: {href => '/adm/createuser?action=processauthorreq',
1.385 bisitz 4999: text => 'Authoring Space requests',
1.362 raeburn 5000: help => 'Domain_Role_Approvals'});
5001: $bread_crumbs_component = 'Authoring requests';
5002: if ($env{'form.state'} eq 'done') {
5003: push(@{$brcrum},
5004: {href => '/adm/createuser?action=authorreqqueue',
5005: text => 'Result',
5006: help => 'Domain_Role_Approvals'});
5007: $bread_crumbs_component = 'Authoring request result';
5008: }
5009: $args = { bread_crumbs => $brcrum,
5010: bread_crumbs_component => $bread_crumbs_component};
1.391 raeburn 5011: my $js = &usernamerequest_javascript();
5012: $r->print(&header(&add_script($js),$args));
1.362 raeburn 5013: if (!exists($env{'form.state'})) {
5014: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestauthor',
5015: $env{'request.role.domain'}));
5016: } elsif ($env{'form.state'} eq 'done') {
5017: $r->print('<h3>'.&mt('Authoring request processing').'</h3>'."\n");
5018: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestauthor',
5019: $env{'request.role.domain'}));
5020: }
1.391 raeburn 5021: } elsif (($env{'form.action'} eq 'processusernamereq') &&
5022: ($permission->{'cusr'}) &&
5023: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
5024: push(@{$brcrum},
5025: {href => '/adm/createuser?action=processusernamereq',
5026: text => 'LON-CAPA account requests',
5027: help => 'Domain_Username_Approvals'});
5028: $bread_crumbs_component = 'Account requests';
5029: if ($env{'form.state'} eq 'done') {
5030: push(@{$brcrum},
5031: {href => '/adm/createuser?action=usernamereqqueue',
5032: text => 'Result',
5033: help => 'Domain_Username_Approvals'});
5034: $bread_crumbs_component = 'LON-CAPA account request result';
5035: }
5036: $args = { bread_crumbs => $brcrum,
5037: bread_crumbs_component => $bread_crumbs_component};
5038: my $js = &usernamerequest_javascript();
5039: $r->print(&header(&add_script($js),$args));
5040: if (!exists($env{'form.state'})) {
5041: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestusername',
5042: $env{'request.role.domain'}));
5043: } elsif ($env{'form.state'} eq 'done') {
5044: $r->print('<h3>'.&mt('LON-CAPA account request processing').'</h3>'."\n");
5045: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestusername',
5046: $env{'request.role.domain'}));
5047: }
5048: } elsif (($env{'form.action'} eq 'displayuserreq') &&
5049: ($permission->{'cusr'})) {
5050: my $dom = $env{'form.domain'};
5051: my $uname = $env{'form.username'};
5052: my $warning;
5053: if (($dom =~ /^$match_domain$/) && (&Apache::lonnet::domain($dom) ne '')) {
5054: if (($dom eq $env{'request.role.domain'}) && (&Apache::lonnet::allowed('ccc',$dom))) {
5055: if (($uname =~ /^$match_username$/) && ($env{'form.queue'} eq 'approval')) {
5056: my $uhome = &Apache::lonnet::homeserver($uname,$dom);
5057: if ($uhome eq 'no_host') {
5058: my $queue = $env{'form.queue'};
5059: my $reqkey = &escape($uname).'_'.$queue;
5060: my $namespace = 'usernamequeue';
5061: my $domconfig = &Apache::lonnet::get_domainconfiguser($dom);
5062: my %queued =
5063: &Apache::lonnet::get($namespace,[$reqkey],$dom,$domconfig);
5064: unless ($queued{$reqkey}) {
5065: $warning = &mt('No information was found for this LON-CAPA account request.');
5066: }
5067: } else {
5068: $warning = &mt('A LON-CAPA account already exists for the requested username and domain.');
5069: }
5070: } else {
5071: $warning = &mt('LON-CAPA account request status check is for an invalid username.');
5072: }
5073: } else {
5074: $warning = &mt('You do not have rights to view LON-CAPA account requests in the domain specified.');
5075: }
5076: } else {
5077: $warning = &mt('LON-CAPA account request status check is for an invalid domain.');
5078: }
5079: my $args = { only_body => 1 };
5080: $r->print(&header(undef,$args).
5081: '<h3>'.&mt('LON-CAPA Account Request Details').'</h3>');
5082: if ($warning ne '') {
5083: $r->print('<div class="LC_warning">'.$warning.'</div>');
5084: } else {
5085: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
5086: my $domconfiguser = &Apache::lonnet::get_domainconfiguser($dom);
5087: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
5088: if (ref($domconfig{'usercreation'}) eq 'HASH') {
5089: if (ref($domconfig{'usercreation'}{'cancreate'}) eq 'HASH') {
5090: if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}) eq 'HASH') {
5091: my %info =
5092: &Apache::lonnet::get('nohist_requestedusernames',[$uname],$dom,$domconfiguser);
5093: if (ref($info{$uname}) eq 'HASH') {
1.396 raeburn 5094: my $usertype = $info{$uname}{'inststatus'};
5095: unless ($usertype) {
5096: $usertype = 'default';
5097: }
1.442 raeburn 5098: my ($showstatus,$showemail,$pickstart);
5099: my $numextras = 0;
5100: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.443 raeburn 5101: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
5102: if (ref($usertypes) eq 'HASH') {
5103: if ($usertypes->{$usertype}) {
5104: $showstatus = $usertypes->{$usertype};
5105: } else {
5106: $showstatus = $othertitle;
5107: }
5108: if ($showstatus) {
5109: $numextras ++;
5110: }
1.442 raeburn 5111: }
5112: }
5113: if (($info{$uname}{'email'} ne '') && ($info{$uname}{'email'} ne $uname)) {
5114: $showemail = $info{$uname}{'email'};
5115: $numextras ++;
5116: }
1.396 raeburn 5117: if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}) eq 'HASH') {
5118: if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
1.442 raeburn 5119: $pickstart = 1;
1.396 raeburn 5120: $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box());
1.442 raeburn 5121: my ($num,$count);
1.396 raeburn 5122: $count = scalar(keys(%{$domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}}));
1.442 raeburn 5123: $count += $numextras;
1.396 raeburn 5124: foreach my $field (@{$infofields}) {
5125: next unless ($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}{$field});
5126: next unless ($infotitles->{$field});
5127: $r->print(&Apache::lonhtmlcommon::row_title($infotitles->{$field}).
5128: $info{$uname}{$field});
5129: $num ++;
1.442 raeburn 5130: unless ($count == $num) {
1.396 raeburn 5131: $r->print(&Apache::lonhtmlcommon::row_closure());
5132: }
5133: }
1.442 raeburn 5134: }
5135: }
5136: if ($numextras) {
5137: unless ($pickstart) {
5138: $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box());
5139: $pickstart = 1;
5140: }
5141: if ($showemail) {
5142: my $closure = '';
5143: unless ($showstatus) {
5144: $closure = 1;
1.391 raeburn 5145: }
1.442 raeburn 5146: $r->print(&Apache::lonhtmlcommon::row_title(&mt('E-mail address')).
5147: $showemail.
5148: &Apache::lonhtmlcommon::row_closure($closure));
1.391 raeburn 5149: }
1.442 raeburn 5150: if ($showstatus) {
5151: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Status type[_1](self-reported)','<br />')).
5152: $showstatus.
5153: &Apache::lonhtmlcommon::row_closure(1));
5154: }
5155: }
5156: if ($pickstart) {
5157: $r->print(&Apache::lonhtmlcommon::end_pick_box().'</div>');
5158: } else {
5159: $r->print('<div>'.&mt('No information to display for this account request.').'</div>');
1.391 raeburn 5160: }
1.442 raeburn 5161: } else {
5162: $r->print('<div>'.&mt('No information available for this account request.').'</div>');
1.391 raeburn 5163: }
5164: }
5165: }
5166: }
5167: }
1.442 raeburn 5168: $r->print(&close_popup_form());
1.207 raeburn 5169: } elsif (($env{'form.action'} eq 'listusers') &&
5170: ($permission->{'view'} || $permission->{'cusr'})) {
1.439 raeburn 5171: my $helpitem = 'Course_View_Class_List';
5172: if ($context eq 'author') {
5173: $helpitem = 'Author_View_Coauthor_List';
5174: } elsif ($context eq 'domain') {
5175: $helpitem = 'Domain_View_Users_List';
5176: }
1.202 raeburn 5177: if ($env{'form.phase'} eq 'bulkchange') {
1.351 raeburn 5178: push(@{$brcrum},
5179: {href => '/adm/createuser?action=listusers',
5180: text => "List Users"},
5181: {href => "/adm/createuser",
5182: text => "Result",
1.439 raeburn 5183: help => $helpitem});
1.351 raeburn 5184: $bread_crumbs_component = 'Update Users';
5185: $args = {bread_crumbs => $brcrum,
5186: bread_crumbs_component => $bread_crumbs_component};
5187: $r->print(&header(undef,$args));
1.202 raeburn 5188: my $setting = $env{'form.roletype'};
5189: my $choice = $env{'form.bulkaction'};
5190: if ($permission->{'cusr'}) {
1.336 raeburn 5191: &Apache::lonuserutils::update_user_list($r,$context,$setting,$choice,$crstype);
1.221 raeburn 5192: } else {
5193: $r->print(&mt('You are not authorized to make bulk changes to user roles'));
1.223 raeburn 5194: $r->print('<p><a href="/adm/createuser?action=listusers">'.&mt('Display User Lists').'</a>');
1.202 raeburn 5195: }
5196: } else {
1.351 raeburn 5197: push(@{$brcrum},
5198: {href => '/adm/createuser?action=listusers',
5199: text => "List Users",
1.439 raeburn 5200: help => $helpitem});
1.351 raeburn 5201: $bread_crumbs_component = 'List Users';
5202: $args = {bread_crumbs => $brcrum,
5203: bread_crumbs_component => $bread_crumbs_component};
1.202 raeburn 5204: my ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles);
5205: my $formname = 'studentform';
1.364 raeburn 5206: my $hidecall = "hide_searching();";
1.321 raeburn 5207: if (($context eq 'domain') && (($env{'form.roletype'} eq 'course') ||
5208: ($env{'form.roletype'} eq 'community'))) {
5209: if ($env{'form.roletype'} eq 'course') {
5210: ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles) =
5211: &Apache::lonuserutils::courses_selector($env{'request.role.domain'},
5212: $formname);
5213: } elsif ($env{'form.roletype'} eq 'community') {
5214: $cb_jscript =
5215: &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
5216: my %elements = (
5217: coursepick => 'radio',
5218: coursetotal => 'text',
5219: courselist => 'text',
5220: );
5221: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements);
5222: }
1.364 raeburn 5223: $jscript .= &verify_user_display($context)."\n".
5224: &Apache::loncommon::check_uncheck_jscript();
1.202 raeburn 5225: my $js = &add_script($jscript).$cb_jscript;
5226: my $loadcode =
5227: &Apache::lonuserutils::course_selector_loadcode($formname);
5228: if ($loadcode ne '') {
1.364 raeburn 5229: $args->{add_entries} = {onload => "$loadcode;$hidecall"};
5230: } else {
5231: $args->{add_entries} = {onload => $hidecall};
1.202 raeburn 5232: }
1.351 raeburn 5233: $r->print(&header($js,$args));
1.191 raeburn 5234: } else {
1.364 raeburn 5235: $args->{add_entries} = {onload => $hidecall};
5236: $jscript = &verify_user_display($context).
5237: &Apache::loncommon::check_uncheck_jscript();
5238: $r->print(&header(&add_script($jscript),$args));
1.191 raeburn 5239: }
1.202 raeburn 5240: &Apache::lonuserutils::print_userlist($r,undef,$permission,$context,
1.375 raeburn 5241: $formname,$totcodes,$codetitles,$idlist,$idlist_titles,
5242: $showcredits);
1.191 raeburn 5243: }
1.213 raeburn 5244: } elsif ($env{'form.action'} eq 'drop' && $permission->{'cusr'}) {
1.318 raeburn 5245: my $brtext;
5246: if ($crstype eq 'Community') {
5247: $brtext = 'Drop Members';
5248: } else {
5249: $brtext = 'Drop Students';
5250: }
1.351 raeburn 5251: push(@{$brcrum},
5252: {href => '/adm/createuser?action=drop',
5253: text => $brtext,
5254: help => 'Course_Drop_Student'});
5255: if ($env{'form.state'} eq 'done') {
5256: push(@{$brcrum},
5257: {href=>'/adm/createuser?action=drop',
5258: text=>"Result"});
5259: }
5260: $bread_crumbs_component = $brtext;
5261: $args = {bread_crumbs => $brcrum,
5262: bread_crumbs_component => $bread_crumbs_component};
5263: $r->print(&header(undef,$args));
1.213 raeburn 5264: if (!exists($env{'form.state'})) {
1.318 raeburn 5265: &Apache::lonuserutils::print_drop_menu($r,$context,$permission,$crstype);
1.213 raeburn 5266: } elsif ($env{'form.state'} eq 'done') {
5267: &Apache::lonuserutils::update_user_list($r,$context,undef,
5268: $env{'form.action'});
5269: }
1.202 raeburn 5270: } elsif ($env{'form.action'} eq 'dateselect') {
5271: if ($permission->{'cusr'}) {
1.351 raeburn 5272: $r->print(&header(undef,{'no_nav_bar' => 1}).
1.375 raeburn 5273: &Apache::lonuserutils::date_section_selector($context,$permission,
5274: $crstype,$showcredits));
1.202 raeburn 5275: } else {
1.351 raeburn 5276: $r->print(&header(undef,{'no_nav_bar' => 1}).
5277: '<span class="LC_error">'.&mt('You do not have permission to modify dates or sections for users').'</span>');
1.202 raeburn 5278: }
1.237 raeburn 5279: } elsif ($env{'form.action'} eq 'selfenroll') {
1.398 raeburn 5280: if ($permission->{selfenrolladmin}) {
5281: my %currsettings = (
5282: selfenroll_types => $env{'course.'.$cid.'.internal.selfenroll_types'},
5283: selfenroll_registered => $env{'course.'.$cid.'.internal.selfenroll_registered'},
5284: selfenroll_section => $env{'course.'.$cid.'.internal.selfenroll_section'},
5285: selfenroll_notifylist => $env{'course.'.$cid.'.internal.selfenroll_notifylist'},
5286: selfenroll_approval => $env{'course.'.$cid.'.internal.selfenroll_approval'},
5287: selfenroll_limit => $env{'course.'.$cid.'.internal.selfenroll_limit'},
5288: selfenroll_cap => $env{'course.'.$cid.'.internal.selfenroll_cap'},
5289: selfenroll_start_date => $env{'course.'.$cid.'.internal.selfenroll_start_date'},
5290: selfenroll_end_date => $env{'course.'.$cid.'.internal.selfenroll_end_date'},
5291: selfenroll_start_access => $env{'course.'.$cid.'.internal.selfenroll_start_access'},
5292: selfenroll_end_access => $env{'course.'.$cid.'.internal.selfenroll_end_access'},
5293: default_enrollment_start_date => $env{'course.'.$cid.'.default_enrollment_start_date'},
5294: default_enrollment_end_date => $env{'course.'.$cid.'.default_enrollment_end_date'},
1.400 raeburn 5295: uniquecode => $env{'course.'.$cid.'.internal.uniquecode'},
1.398 raeburn 5296: );
5297: push(@{$brcrum},
5298: {href => '/adm/createuser?action=selfenroll',
5299: text => "Configure Self-enrollment",
5300: help => 'Course_Self_Enrollment'});
5301: if (!exists($env{'form.state'})) {
5302: $args = { bread_crumbs => $brcrum,
5303: bread_crumbs_component => 'Configure Self-enrollment'};
5304: $r->print(&header(undef,$args));
5305: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
5306: &print_selfenroll_menu($r,'course',$cid,$cdom,$cnum,\%currsettings);
5307: } elsif ($env{'form.state'} eq 'done') {
5308: push (@{$brcrum},
5309: {href=>'/adm/createuser?action=selfenroll',
5310: text=>"Result"});
5311: $args = { bread_crumbs => $brcrum,
5312: bread_crumbs_component => 'Self-enrollment result'};
5313: $r->print(&header(undef,$args));
5314: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
1.400 raeburn 5315: &update_selfenroll_config($r,$cid,$cdom,$cnum,$context,$crstype,\%currsettings);
1.398 raeburn 5316: }
5317: } else {
5318: $r->print(&header(undef,{'no_nav_bar' => 1}).
5319: '<span class="LC_error">'.&mt('You do not have permission to configure self-enrollment').'</span>');
1.237 raeburn 5320: }
1.277 raeburn 5321: } elsif ($env{'form.action'} eq 'selfenrollqueue') {
1.418 raeburn 5322: if ($permission->{selfenrolladmin}) {
1.351 raeburn 5323: push(@{$brcrum},
5324: {href => '/adm/createuser?action=selfenrollqueue',
1.418 raeburn 5325: text => 'Enrollment requests',
1.439 raeburn 5326: help => 'Course_Approve_Selfenroll'});
1.418 raeburn 5327: $bread_crumbs_component = 'Enrollment requests';
5328: if ($env{'form.state'} eq 'done') {
5329: push(@{$brcrum},
5330: {href => '/adm/createuser?action=selfenrollqueue',
5331: text => 'Result',
1.439 raeburn 5332: help => 'Course_Approve_Selfenroll'});
1.418 raeburn 5333: $bread_crumbs_component = 'Enrollment result';
5334: }
5335: $args = { bread_crumbs => $brcrum,
5336: bread_crumbs_component => $bread_crumbs_component};
5337: $r->print(&header(undef,$args));
5338: my $coursedesc = $env{'course.'.$cid.'.description'};
5339: if (!exists($env{'form.state'})) {
5340: $r->print('<h3>'.&mt('Pending enrollment requests').'</h3>'."\n");
5341: $r->print(&Apache::loncoursequeueadmin::display_queued_requests($context,
5342: $cdom,$cnum));
5343: } elsif ($env{'form.state'} eq 'done') {
5344: $r->print('<h3>'.&mt('Enrollment request processing').'</h3>'."\n");
5345: $r->print(&Apache::loncoursequeueadmin::update_request_queue($context,
1.430 raeburn 5346: $cdom,$cnum,$coursedesc));
1.418 raeburn 5347: }
5348: } else {
5349: $r->print(&header(undef,{'no_nav_bar' => 1}).
5350: '<span class="LC_error">'.&mt('You do not have permission to manage self-enrollment').'</span>');
1.351 raeburn 5351: }
1.418 raeburn 5352: } elsif ($env{'form.action'} eq 'changelogs') {
5353: if ($permission->{cusr} || $permission->{view}) {
5354: &print_userchangelogs_display($r,$context,$permission,$brcrum);
5355: } else {
5356: $r->print(&header(undef,{'no_nav_bar' => 1}).
5357: '<span class="LC_error">'.&mt('You do not have permission to view change logs').'</span>');
1.277 raeburn 5358: }
1.428 raeburn 5359: } elsif ($env{'form.action'} eq 'helpdesk') {
5360: if (($permission->{'owner'}) || ($permission->{'co-owner'})) {
5361: if ($env{'form.state'} eq 'process') {
5362: if ($permission->{'owner'}) {
5363: &update_helpdeskaccess($r,$permission,$brcrum);
5364: } else {
5365: &print_helpdeskaccess_display($r,$permission,$brcrum);
1.430 raeburn 5366: }
1.428 raeburn 5367: } else {
5368: &print_helpdeskaccess_display($r,$permission,$brcrum);
5369: }
5370: } else {
5371: $r->print(&header(undef,{'no_nav_bar' => 1}).
5372: '<span class="LC_error">'.&mt('You do not have permission to view helpdesk access').'</span>');
5373: }
1.190 raeburn 5374: } else {
1.351 raeburn 5375: $bread_crumbs_component = 'User Management';
5376: $args = { bread_crumbs => $brcrum,
5377: bread_crumbs_component => $bread_crumbs_component};
5378: $r->print(&header(undef,$args));
1.318 raeburn 5379: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 5380: }
1.351 raeburn 5381: $r->print(&Apache::loncommon::end_page());
1.190 raeburn 5382: return OK;
5383: }
5384:
5385: sub header {
1.351 raeburn 5386: my ($jscript,$args) = @_;
1.190 raeburn 5387: my $start_page;
1.351 raeburn 5388: if (ref($args) eq 'HASH') {
5389: $start_page=&Apache::loncommon::start_page('User Management',$jscript,$args);
1.190 raeburn 5390: } else {
1.351 raeburn 5391: $start_page=&Apache::loncommon::start_page('User Management',$jscript);
1.190 raeburn 5392: }
5393: return $start_page;
5394: }
1.2 www 5395:
1.191 raeburn 5396: sub add_script {
5397: my ($js) = @_;
1.301 bisitz 5398: return '<script type="text/javascript">'."\n"
5399: .'// <![CDATA['."\n"
5400: .$js."\n"
5401: .'// ]]>'."\n"
5402: .'</script>'."\n";
1.191 raeburn 5403: }
5404:
1.391 raeburn 5405: sub usernamerequest_javascript {
5406: my $js = <<ENDJS;
5407:
5408: function openusernamereqdisplay(dom,uname,queue) {
5409: var url = '/adm/createuser?action=displayuserreq';
5410: url += '&domain='+dom+'&username='+uname+'&queue='+queue;
5411: var title = 'Account_Request_Browser';
5412: var options = 'scrollbars=1,resizable=1,menubar=0';
5413: options += ',width=700,height=600';
5414: var stdeditbrowser = open(url,title,options,'1');
5415: stdeditbrowser.focus();
5416: return;
5417: }
5418:
5419: ENDJS
5420: }
5421:
5422: sub close_popup_form {
5423: my $close= &mt('Close Window');
5424: return << "END";
5425: <p><form name="displayreq" action="" method="post">
5426: <input type="button" name="closeme" value="$close" onclick="javascript:self.close();" />
5427: </form></p>
5428: END
5429: }
5430:
1.202 raeburn 5431: sub verify_user_display {
1.364 raeburn 5432: my ($context) = @_;
1.374 raeburn 5433: my %lt = &Apache::lonlocal::texthash (
5434: course => 'course(s): description, section(s), status',
5435: community => 'community(s): description, section(s), status',
5436: author => 'author',
5437: );
1.364 raeburn 5438: my $photos;
5439: if (($context eq 'course') && $env{'request.course.id'}) {
5440: $photos = $env{'course.'.$env{'request.course.id'}.'.internal.showphoto'};
5441: }
1.202 raeburn 5442: my $output = <<"END";
5443:
1.364 raeburn 5444: function hide_searching() {
5445: if (document.getElementById('searching')) {
5446: document.getElementById('searching').style.display = 'none';
5447: }
5448: return;
5449: }
5450:
1.202 raeburn 5451: function display_update() {
5452: document.studentform.action.value = 'listusers';
5453: document.studentform.phase.value = 'display';
5454: document.studentform.submit();
5455: }
5456:
1.364 raeburn 5457: function updateCols(caller) {
5458: var context = '$context';
5459: var photos = '$photos';
5460: if (caller == 'Status') {
1.374 raeburn 5461: if ((context == 'domain') &&
5462: ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
5463: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community'))) {
1.364 raeburn 5464: document.getElementById('showcolstatus').checked = false;
5465: document.getElementById('showcolstatus').disabled = 'disabled';
5466: document.getElementById('showcolstart').checked = false;
5467: document.getElementById('showcolend').checked = false;
1.374 raeburn 5468: } else {
5469: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
5470: document.getElementById('showcolstatus').checked = true;
5471: document.getElementById('showcolstatus').disabled = '';
5472: document.getElementById('showcolstart').checked = true;
5473: document.getElementById('showcolend').checked = true;
5474: } else {
5475: document.getElementById('showcolstatus').checked = false;
5476: document.getElementById('showcolstatus').disabled = 'disabled';
5477: document.getElementById('showcolstart').checked = false;
5478: document.getElementById('showcolend').checked = false;
5479: }
1.364 raeburn 5480: }
5481: }
5482: if (caller == 'output') {
5483: if (photos == 1) {
5484: if (document.getElementById('showcolphoto')) {
5485: var photoitem = document.getElementById('showcolphoto');
5486: if (document.studentform.output.options[document.studentform.output.selectedIndex].value == 'html') {
5487: photoitem.checked = true;
5488: photoitem.disabled = '';
5489: } else {
5490: photoitem.checked = false;
5491: photoitem.disabled = 'disabled';
5492: }
5493: }
5494: }
5495: }
5496: if (caller == 'showrole') {
1.371 raeburn 5497: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any') ||
5498: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'cr')) {
1.364 raeburn 5499: document.getElementById('showcolrole').checked = true;
5500: document.getElementById('showcolrole').disabled = '';
5501: } else {
5502: document.getElementById('showcolrole').checked = false;
5503: document.getElementById('showcolrole').disabled = 'disabled';
5504: }
1.374 raeburn 5505: if (context == 'domain') {
1.382 raeburn 5506: var quotausageshow = 0;
1.374 raeburn 5507: if ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
5508: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community')) {
5509: document.getElementById('showcolstatus').checked = false;
5510: document.getElementById('showcolstatus').disabled = 'disabled';
5511: document.getElementById('showcolstart').checked = false;
5512: document.getElementById('showcolend').checked = false;
5513: } else {
5514: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
5515: document.getElementById('showcolstatus').checked = true;
5516: document.getElementById('showcolstatus').disabled = '';
5517: document.getElementById('showcolstart').checked = true;
5518: document.getElementById('showcolend').checked = true;
5519: }
5520: }
5521: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'domain') {
5522: document.getElementById('showcolextent').disabled = 'disabled';
5523: document.getElementById('showcolextent').checked = 'false';
5524: document.getElementById('showextent').style.display='none';
5525: document.getElementById('showcoltextextent').innerHTML = '';
1.382 raeburn 5526: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'au') ||
5527: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any')) {
5528: if (document.getElementById('showcolauthorusage')) {
5529: document.getElementById('showcolauthorusage').disabled = '';
5530: }
5531: if (document.getElementById('showcolauthorquota')) {
5532: document.getElementById('showcolauthorquota').disabled = '';
5533: }
5534: quotausageshow = 1;
5535: }
1.374 raeburn 5536: } else {
5537: document.getElementById('showextent').style.display='block';
5538: document.getElementById('showextent').style.textAlign='left';
5539: document.getElementById('showextent').style.textFace='normal';
5540: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'author') {
5541: document.getElementById('showcolextent').disabled = '';
5542: document.getElementById('showcolextent').checked = 'true';
5543: document.getElementById('showcoltextextent').innerHTML="$lt{'author'}";
5544: } else {
5545: document.getElementById('showcolextent').disabled = '';
5546: document.getElementById('showcolextent').checked = 'true';
5547: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community') {
5548: document.getElementById('showcoltextextent').innerHTML="$lt{'community'}";
5549: } else {
5550: document.getElementById('showcoltextextent').innerHTML="$lt{'course'}";
5551: }
5552: }
5553: }
1.382 raeburn 5554: if (quotausageshow == 0) {
5555: if (document.getElementById('showcolauthorusage')) {
5556: document.getElementById('showcolauthorusage').checked = false;
5557: document.getElementById('showcolauthorusage').disabled = 'disabled';
5558: }
5559: if (document.getElementById('showcolauthorquota')) {
5560: document.getElementById('showcolauthorquota').checked = false;
5561: document.getElementById('showcolauthorquota').disabled = 'disabled';
5562: }
5563: }
1.374 raeburn 5564: }
1.364 raeburn 5565: }
5566: return;
5567: }
5568:
1.202 raeburn 5569: END
5570: return $output;
5571:
5572: }
5573:
1.190 raeburn 5574: ###############################################################
5575: ###############################################################
5576: # Menu Phase One
5577: sub print_main_menu {
1.318 raeburn 5578: my ($permission,$context,$crstype) = @_;
5579: my $linkcontext = $context;
5580: my $stuterm = lc(&Apache::lonnet::plaintext('st',$crstype));
5581: if (($context eq 'course') && ($crstype eq 'Community')) {
5582: $linkcontext = lc($crstype);
5583: $stuterm = 'Members';
5584: }
1.208 raeburn 5585: my %links = (
1.298 droeschl 5586: domain => {
5587: upload => 'Upload a File of Users',
5588: singleuser => 'Add/Modify a User',
5589: listusers => 'Manage Users',
5590: },
5591: author => {
5592: upload => 'Upload a File of Co-authors',
5593: singleuser => 'Add/Modify a Co-author',
5594: listusers => 'Manage Co-authors',
5595: },
5596: course => {
5597: upload => 'Upload a File of Course Users',
5598: singleuser => 'Add/Modify a Course User',
1.354 www 5599: listusers => 'List and Modify Multiple Course Users',
1.298 droeschl 5600: },
1.318 raeburn 5601: community => {
5602: upload => 'Upload a File of Community Users',
5603: singleuser => 'Add/Modify a Community User',
1.354 www 5604: listusers => 'List and Modify Multiple Community Users',
1.318 raeburn 5605: },
5606: );
5607: my %linktitles = (
5608: domain => {
5609: singleuser => 'Add a user to the domain, and/or a course or community in the domain.',
5610: listusers => 'Show and manage users in this domain.',
5611: },
5612: author => {
5613: singleuser => 'Add a user with a co- or assistant author role.',
5614: listusers => 'Show and manage co- or assistant authors.',
5615: },
5616: course => {
5617: singleuser => 'Add a user with a certain role to this course.',
5618: listusers => 'Show and manage users in this course.',
5619: },
5620: community => {
5621: singleuser => 'Add a user with a certain role to this community.',
5622: listusers => 'Show and manage users in this community.',
5623: },
1.298 droeschl 5624: );
1.418 raeburn 5625: if ($linkcontext eq 'domain') {
5626: unless ($permission->{'cusr'}) {
1.430 raeburn 5627: $links{'domain'}{'singleuser'} = 'View a User';
1.418 raeburn 5628: $linktitles{'domain'}{'singleuser'} = 'View information about a user in the domain';
5629: }
5630: } elsif ($linkcontext eq 'course') {
5631: unless ($permission->{'cusr'}) {
5632: $links{'course'}{'singleuser'} = 'View a Course User';
5633: $linktitles{'course'}{'singleuser'} = 'View information about a user in this course';
5634: $links{'course'}{'listusers'} = 'List Course Users';
5635: $linktitles{'course'}{'listusers'} = 'Show information about users in this course';
5636: }
5637: } elsif ($linkcontext eq 'community') {
5638: unless ($permission->{'cusr'}) {
5639: $links{'community'}{'singleuser'} = 'View a Community User';
5640: $linktitles{'community'}{'singleuser'} = 'View information about a user in this community';
5641: $links{'community'}{'listusers'} = 'List Community Users';
5642: $linktitles{'community'}{'listusers'} = 'Show information about users in this community';
5643: }
5644: }
1.298 droeschl 5645: my @menu = ( {categorytitle => 'Single Users',
5646: items =>
5647: [
5648: {
1.318 raeburn 5649: linktext => $links{$linkcontext}{'singleuser'},
1.298 droeschl 5650: icon => 'edit-redo.png',
5651: #help => 'Course_Change_Privileges',
5652: url => '/adm/createuser?action=singleuser',
1.418 raeburn 5653: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.318 raeburn 5654: linktitle => $linktitles{$linkcontext}{'singleuser'},
1.298 droeschl 5655: },
5656: ]},
5657:
5658: {categorytitle => 'Multiple Users',
5659: items =>
5660: [
5661: {
1.318 raeburn 5662: linktext => $links{$linkcontext}{'upload'},
1.340 wenzelju 5663: icon => 'uplusr.png',
1.298 droeschl 5664: #help => 'Course_Create_Class_List',
5665: url => '/adm/createuser?action=upload',
5666: permission => $permission->{'cusr'},
5667: linktitle => 'Upload a CSV or a text file containing users.',
5668: },
5669: {
1.318 raeburn 5670: linktext => $links{$linkcontext}{'listusers'},
1.340 wenzelju 5671: icon => 'mngcu.png',
1.298 droeschl 5672: #help => 'Course_View_Class_List',
5673: url => '/adm/createuser?action=listusers',
5674: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.318 raeburn 5675: linktitle => $linktitles{$linkcontext}{'listusers'},
1.298 droeschl 5676: },
5677:
5678: ]},
5679:
5680: {categorytitle => 'Administration',
5681: items => [ ]},
5682: );
1.415 raeburn 5683:
1.265 mielkec 5684: if ($context eq 'domain'){
1.416 raeburn 5685: push(@{ $menu[0]->{items} }, # Single Users
5686: {
5687: linktext => 'User Access Log',
1.417 raeburn 5688: icon => 'document-properties.png',
1.425 raeburn 5689: #help => 'Domain_User_Access_Logs',
1.416 raeburn 5690: url => '/adm/createuser?action=accesslogs',
5691: permission => $permission->{'activity'},
5692: linktitle => 'View user access log.',
5693: }
5694: );
1.298 droeschl 5695:
5696: push(@{ $menu[2]->{items} }, #Category: Administration
5697: {
5698: linktext => 'Custom Roles',
5699: icon => 'emblem-photos.png',
5700: #help => 'Course_Editing_Custom_Roles',
5701: url => '/adm/createuser?action=custom',
5702: permission => $permission->{'custom'},
5703: linktitle => 'Configure a custom role.',
5704: },
1.362 raeburn 5705: {
5706: linktext => 'Authoring Space Requests',
5707: icon => 'selfenrl-queue.png',
5708: #help => 'Domain_Role_Approvals',
5709: url => '/adm/createuser?action=processauthorreq',
5710: permission => $permission->{'cusr'},
5711: linktitle => 'Approve or reject author role requests',
5712: },
1.363 raeburn 5713: {
1.391 raeburn 5714: linktext => 'LON-CAPA Account Requests',
5715: icon => 'list-add.png',
5716: #help => 'Domain_Username_Approvals',
5717: url => '/adm/createuser?action=processusernamereq',
5718: permission => $permission->{'cusr'},
5719: linktitle => 'Approve or reject LON-CAPA account requests',
5720: },
5721: {
1.363 raeburn 5722: linktext => 'Change Log',
5723: icon => 'document-properties.png',
5724: #help => 'Course_User_Logs',
5725: url => '/adm/createuser?action=changelogs',
1.418 raeburn 5726: permission => ($permission->{'cusr'} || $permission->{'view'}),
1.363 raeburn 5727: linktitle => 'View change log.',
5728: },
1.298 droeschl 5729: );
5730:
1.265 mielkec 5731: }elsif ($context eq 'course'){
1.298 droeschl 5732: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity();
1.318 raeburn 5733:
5734: my %linktext = (
5735: 'Course' => {
5736: single => 'Add/Modify a Student',
5737: drop => 'Drop Students',
5738: groups => 'Course Groups',
5739: },
5740: 'Community' => {
5741: single => 'Add/Modify a Member',
5742: drop => 'Drop Members',
5743: groups => 'Community Groups',
5744: },
5745: );
1.411 raeburn 5746: $linktext{'Placement'} = $linktext{'Course'};
1.318 raeburn 5747:
5748: my %linktitle = (
5749: 'Course' => {
5750: single => 'Add a user with the role of student to this course',
5751: drop => 'Remove a student from this course.',
5752: groups => 'Manage course groups',
5753: },
5754: 'Community' => {
5755: single => 'Add a user with the role of member to this community',
5756: drop => 'Remove a member from this community.',
5757: groups => 'Manage community groups',
5758: },
5759: );
5760:
1.411 raeburn 5761: $linktitle{'Placement'} = $linktitle{'Course'};
5762:
1.298 droeschl 5763: push(@{ $menu[0]->{items} }, #Category: Single Users
5764: {
1.318 raeburn 5765: linktext => $linktext{$crstype}{'single'},
1.298 droeschl 5766: #help => 'Course_Add_Student',
5767: icon => 'list-add.png',
5768: url => '/adm/createuser?action=singlestudent',
5769: permission => $permission->{'cusr'},
1.318 raeburn 5770: linktitle => $linktitle{$crstype}{'single'},
1.298 droeschl 5771: },
5772: );
5773:
5774: push(@{ $menu[1]->{items} }, #Category: Multiple Users
5775: {
1.318 raeburn 5776: linktext => $linktext{$crstype}{'drop'},
1.298 droeschl 5777: icon => 'edit-undo.png',
5778: #help => 'Course_Drop_Student',
5779: url => '/adm/createuser?action=drop',
5780: permission => $permission->{'cusr'},
1.318 raeburn 5781: linktitle => $linktitle{$crstype}{'drop'},
1.298 droeschl 5782: },
5783: );
5784: push(@{ $menu[2]->{items} }, #Category: Administration
1.428 raeburn 5785: {
5786: linktext => 'Helpdesk Access',
5787: icon => 'helpdesk-access.png',
5788: #help => 'Course_Helpdesk_Access',
5789: url => '/adm/createuser?action=helpdesk',
5790: permission => ($permission->{'owner'} || $permission->{'co-owner'}),
5791: linktitle => 'Helpdesk access options',
5792: },
5793: {
1.298 droeschl 5794: linktext => 'Custom Roles',
5795: icon => 'emblem-photos.png',
5796: #help => 'Course_Editing_Custom_Roles',
5797: url => '/adm/createuser?action=custom',
5798: permission => $permission->{'custom'},
5799: linktitle => 'Configure a custom role.',
5800: },
5801: {
1.318 raeburn 5802: linktext => $linktext{$crstype}{'groups'},
1.333 wenzelju 5803: icon => 'grps.png',
1.298 droeschl 5804: #help => 'Course_Manage_Group',
5805: url => '/adm/coursegroups?refpage=cusr',
5806: permission => $permission->{'grp_manage'},
1.318 raeburn 5807: linktitle => $linktitle{$crstype}{'groups'},
1.298 droeschl 5808: },
5809: {
1.328 wenzelju 5810: linktext => 'Change Log',
1.298 droeschl 5811: icon => 'document-properties.png',
5812: #help => 'Course_User_Logs',
5813: url => '/adm/createuser?action=changelogs',
1.418 raeburn 5814: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.298 droeschl 5815: linktitle => 'View change log.',
5816: },
5817: );
1.277 raeburn 5818: if ($env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'}) {
1.298 droeschl 5819: push(@{ $menu[2]->{items} },
1.398 raeburn 5820: {
1.298 droeschl 5821: linktext => 'Enrollment Requests',
5822: icon => 'selfenrl-queue.png',
5823: #help => 'Course_Approve_Selfenroll',
5824: url => '/adm/createuser?action=selfenrollqueue',
1.398 raeburn 5825: permission => $permission->{'selfenrolladmin'},
1.298 droeschl 5826: linktitle =>'Approve or reject enrollment requests.',
5827: },
5828: );
1.277 raeburn 5829: }
1.298 droeschl 5830:
1.265 mielkec 5831: if (!exists($permission->{'cusr_section'})){
1.320 raeburn 5832: if ($crstype ne 'Community') {
5833: push(@{ $menu[2]->{items} },
5834: {
5835: linktext => 'Automated Enrollment',
5836: icon => 'roles.png',
5837: #help => 'Course_Automated_Enrollment',
5838: permission => (&Apache::lonnet::auto_run($cnum,$cdom)
1.418 raeburn 5839: && (($permission->{'cusr'}) ||
5840: ($permission->{'view'}))),
1.320 raeburn 5841: url => '/adm/populate',
5842: linktitle => 'Automated enrollment manager.',
5843: }
5844: );
5845: }
5846: push(@{ $menu[2]->{items} },
1.298 droeschl 5847: {
5848: linktext => 'User Self-Enrollment',
1.342 wenzelju 5849: icon => 'self_enroll.png',
1.298 droeschl 5850: #help => 'Course_Self_Enrollment',
5851: url => '/adm/createuser?action=selfenroll',
1.398 raeburn 5852: permission => $permission->{'selfenrolladmin'},
1.317 bisitz 5853: linktitle => 'Configure user self-enrollment.',
1.298 droeschl 5854: },
5855: );
5856: }
1.363 raeburn 5857: } elsif ($context eq 'author') {
1.370 raeburn 5858: push(@{ $menu[2]->{items} }, #Category: Administration
1.363 raeburn 5859: {
5860: linktext => 'Change Log',
5861: icon => 'document-properties.png',
5862: #help => 'Course_User_Logs',
5863: url => '/adm/createuser?action=changelogs',
5864: permission => $permission->{'cusr'},
5865: linktitle => 'View change log.',
5866: },
1.370 raeburn 5867: );
1.363 raeburn 5868: }
5869: return Apache::lonhtmlcommon::generate_menu(@menu);
1.250 raeburn 5870: # { text => 'View Log-in History',
5871: # help => 'Course_User_Logins',
5872: # action => 'logins',
5873: # permission => $permission->{'cusr'},
5874: # });
1.190 raeburn 5875: }
5876:
1.189 albertel 5877: sub restore_prev_selections {
5878: my %saveable_parameters = ('srchby' => 'scalar',
5879: 'srchin' => 'scalar',
5880: 'srchtype' => 'scalar',
5881: );
5882: &Apache::loncommon::store_settings('user','user_picker',
5883: \%saveable_parameters);
5884: &Apache::loncommon::restore_settings('user','user_picker',
5885: \%saveable_parameters);
5886: }
5887:
1.237 raeburn 5888: sub print_selfenroll_menu {
1.418 raeburn 5889: my ($r,$context,$cid,$cdom,$cnum,$currsettings,$additional,$readonly) = @_;
1.322 raeburn 5890: my $crstype = &Apache::loncommon::course_type();
1.398 raeburn 5891: my $formname = 'selfenroll';
1.237 raeburn 5892: my $nolink = 1;
1.398 raeburn 5893: my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles();
1.237 raeburn 5894: my $groupslist = &Apache::lonuserutils::get_groupslist();
5895: my $setsec_js =
5896: &Apache::lonuserutils::setsections_javascript($formname,$groupslist);
1.249 raeburn 5897: my %alerts = &Apache::lonlocal::texthash(
5898: acto => 'Activation of self-enrollment was selected for the following domain(s)',
5899: butn => 'but no user types have been checked.',
5900: wilf => "Please uncheck 'activate' or check at least one type.",
5901: );
1.418 raeburn 5902: my $disabled;
5903: if ($readonly) {
5904: $disabled = ' disabled="disabled"';
5905: }
1.405 damieng 5906: &js_escape(\%alerts);
1.249 raeburn 5907: my $selfenroll_js = <<"ENDSCRIPT";
5908: function update_types(caller,num) {
5909: var delidx = getIndexByName('selfenroll_delete');
5910: var actidx = getIndexByName('selfenroll_activate');
5911: if (caller == 'selfenroll_all') {
5912: var selall;
5913: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5914: if (document.$formname.selfenroll_all[i].checked) {
5915: selall = document.$formname.selfenroll_all[i].value;
5916: }
5917: }
5918: if (selall == 1) {
5919: if (delidx != -1) {
5920: if (document.$formname.selfenroll_delete.length) {
5921: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
5922: document.$formname.selfenroll_delete[j].checked = true;
5923: }
5924: } else {
5925: document.$formname.elements[delidx].checked = true;
5926: }
5927: }
5928: if (actidx != -1) {
5929: if (document.$formname.selfenroll_activate.length) {
5930: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5931: document.$formname.selfenroll_activate[j].checked = false;
5932: }
5933: } else {
5934: document.$formname.elements[actidx].checked = false;
5935: }
5936: }
5937: document.$formname.selfenroll_newdom.selectedIndex = 0;
5938: }
5939: }
5940: if (caller == 'selfenroll_activate') {
5941: if (document.$formname.selfenroll_activate.length) {
5942: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5943: if (document.$formname.selfenroll_activate[j].value == num) {
5944: if (document.$formname.selfenroll_activate[j].checked) {
5945: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5946: if (document.$formname.selfenroll_all[i].value == '1') {
5947: document.$formname.selfenroll_all[i].checked = false;
5948: }
5949: if (document.$formname.selfenroll_all[i].value == '0') {
5950: document.$formname.selfenroll_all[i].checked = true;
5951: }
5952: }
5953: }
5954: }
5955: }
5956: } else {
5957: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5958: if (document.$formname.selfenroll_all[i].value == '1') {
5959: document.$formname.selfenroll_all[i].checked = false;
5960: }
5961: if (document.$formname.selfenroll_all[i].value == '0') {
5962: document.$formname.selfenroll_all[i].checked = true;
5963: }
5964: }
5965: }
5966: }
5967: if (caller == 'selfenroll_delete') {
5968: if (document.$formname.selfenroll_delete.length) {
5969: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
5970: if (document.$formname.selfenroll_delete[j].value == num) {
5971: if (document.$formname.selfenroll_delete[j].checked) {
5972: var delindex = getIndexByName('selfenroll_types_'+num);
5973: if (delindex != -1) {
5974: if (document.$formname.elements[delindex].length) {
5975: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
5976: document.$formname.elements[delindex][k].checked = false;
5977: }
5978: } else {
5979: document.$formname.elements[delindex].checked = false;
5980: }
5981: }
5982: }
5983: }
5984: }
5985: } else {
5986: if (document.$formname.selfenroll_delete.checked) {
5987: var delindex = getIndexByName('selfenroll_types_'+num);
5988: if (delindex != -1) {
5989: if (document.$formname.elements[delindex].length) {
5990: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
5991: document.$formname.elements[delindex][k].checked = false;
5992: }
5993: } else {
5994: document.$formname.elements[delindex].checked = false;
5995: }
5996: }
5997: }
5998: }
5999: }
6000: return;
6001: }
6002:
6003: function validate_types(form) {
6004: var needaction = new Array();
6005: var countfail = 0;
6006: var actidx = getIndexByName('selfenroll_activate');
6007: if (actidx != -1) {
6008: if (document.$formname.selfenroll_activate.length) {
6009: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
6010: var num = document.$formname.selfenroll_activate[j].value;
6011: if (document.$formname.selfenroll_activate[j].checked) {
6012: countfail = check_types(num,countfail,needaction)
6013: }
6014: }
6015: } else {
6016: if (document.$formname.selfenroll_activate.checked) {
1.398 raeburn 6017: var num = document.$formname.selfenroll_activate.value;
1.249 raeburn 6018: countfail = check_types(num,countfail,needaction)
6019: }
6020: }
6021: }
6022: if (countfail > 0) {
6023: var msg = "$alerts{'acto'}\\n";
6024: var loopend = needaction.length -1;
6025: if (loopend > 0) {
6026: for (var m=0; m<loopend; m++) {
6027: msg += needaction[m]+", ";
6028: }
6029: }
6030: msg += needaction[loopend]+"\\n$alerts{'butn'}\\n$alerts{'wilf'}";
6031: alert(msg);
6032: return;
6033: }
6034: setSections(form);
6035: }
6036:
6037: function check_types(num,countfail,needaction) {
1.441 raeburn 6038: var boxname = 'selfenroll_types_'+num;
6039: var typeidx = getIndexByName(boxname);
1.249 raeburn 6040: var count = 0;
6041: if (typeidx != -1) {
1.441 raeburn 6042: if (document.$formname.elements[boxname].length) {
6043: for (var k=0; k<document.$formname.elements[boxname].length; k++) {
6044: if (document.$formname.elements[boxname][k].checked) {
1.249 raeburn 6045: count ++;
6046: }
6047: }
6048: } else {
6049: if (document.$formname.elements[typeidx].checked) {
6050: count ++;
6051: }
6052: }
6053: if (count == 0) {
6054: var domidx = getIndexByName('selfenroll_dom_'+num);
6055: if (domidx != -1) {
6056: var domname = document.$formname.elements[domidx].value;
6057: needaction[countfail] = domname;
6058: countfail ++;
6059: }
6060: }
6061: }
6062: return countfail;
6063: }
6064:
1.398 raeburn 6065: function toggleNotify() {
6066: var selfenrollApproval = 0;
6067: if (document.$formname.selfenroll_approval.length) {
6068: for (var i=0; i<document.$formname.selfenroll_approval.length; i++) {
6069: if (document.$formname.selfenroll_approval[i].checked) {
6070: selfenrollApproval = document.$formname.selfenroll_approval[i].value;
6071: break;
6072: }
6073: }
6074: }
6075: if (document.getElementById('notified')) {
6076: if (selfenrollApproval == 0) {
6077: document.getElementById('notified').style.display='none';
6078: } else {
6079: document.getElementById('notified').style.display='block';
6080: }
6081: }
6082: return;
6083: }
6084:
1.249 raeburn 6085: function getIndexByName(item) {
6086: for (var i=0;i<document.$formname.elements.length;i++) {
6087: if (document.$formname.elements[i].name == item) {
6088: return i;
6089: }
6090: }
6091: return -1;
6092: }
6093: ENDSCRIPT
1.256 raeburn 6094:
1.237 raeburn 6095: my $output = '<script type="text/javascript">'."\n".
1.301 bisitz 6096: '// <![CDATA['."\n".
1.249 raeburn 6097: $setsec_js."\n".$selfenroll_js."\n".
1.301 bisitz 6098: '// ]]>'."\n".
1.237 raeburn 6099: '</script>'."\n".
1.256 raeburn 6100: '<h3>'.$lt->{'selfenroll'}.'</h3>'."\n";
1.400 raeburn 6101:
6102: my $visactions = &cat_visibility();
6103: my ($cathash,%cattype);
6104: my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
6105: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
6106: $cathash = $domconfig{'coursecategories'}{'cats'};
6107: $cattype{'auth'} = $domconfig{'coursecategories'}{'auth'};
6108: $cattype{'unauth'} = $domconfig{'coursecategories'}{'unauth'};
1.406 raeburn 6109: if ($cattype{'auth'} eq '') {
6110: $cattype{'auth'} = 'std';
6111: }
6112: if ($cattype{'unauth'} eq '') {
6113: $cattype{'unauth'} = 'std';
6114: }
1.400 raeburn 6115: } else {
6116: $cathash = {};
6117: $cattype{'auth'} = 'std';
6118: $cattype{'unauth'} = 'std';
6119: }
6120: if (($cattype{'auth'} eq 'none') && ($cattype{'unauth'} eq 'none')) {
6121: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
6122: '<br />'.
6123: '<br />'.$visactions->{'take'}.'<ul>'.
6124: '<li>'.$visactions->{'dc_chgconf'}.'</li>'.
6125: '</ul>');
6126: } elsif (($cattype{'auth'} !~ /^(std|domonly)$/) && ($cattype{'unauth'} !~ /^(std|domonly)$/)) {
6127: if ($currsettings->{'uniquecode'}) {
6128: $r->print('<span class="LC_info">'.$visactions->{'vis'}.'</span>');
6129: } else {
6130: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
6131: '<br />'.
6132: '<br />'.$visactions->{'take'}.'<ul>'.
6133: '<li>'.$visactions->{'dc_setcode'}.'</li>'.
6134: '</ul><br />');
6135: }
6136: } else {
6137: my ($visible,$cansetvis,$vismsgs) = &visible_in_stdcat($cdom,$cnum,\%domconfig);
6138: if (ref($visactions) eq 'HASH') {
6139: if ($visible) {
6140: $output .= '<p class="LC_info">'.$visactions->{'vis'}.'</p>';
6141: } else {
6142: $output .= '<p class="LC_warning">'.$visactions->{'miss'}.'</p>'
6143: .$visactions->{'yous'}.
6144: '<p>'.$visactions->{'gen'}.'<br />'.$visactions->{'coca'};
6145: if (ref($vismsgs) eq 'ARRAY') {
6146: $output .= '<br />'.$visactions->{'make'}.'<ul>';
6147: foreach my $item (@{$vismsgs}) {
6148: $output .= '<li>'.$visactions->{$item}.'</li>';
6149: }
6150: $output .= '</ul>';
1.256 raeburn 6151: }
1.400 raeburn 6152: $output .= '</p>';
1.256 raeburn 6153: }
6154: }
6155: }
1.398 raeburn 6156: my $actionhref = '/adm/createuser';
6157: if ($context eq 'domain') {
6158: $actionhref = '/adm/modifycourse';
6159: }
1.400 raeburn 6160:
6161: my %noedit;
6162: unless ($context eq 'domain') {
6163: %noedit = &get_noedit_fields($cdom,$cnum,$crstype,$row);
6164: }
1.398 raeburn 6165: $output .= '<form name="'.$formname.'" method="post" action="'.$actionhref.'">'."\n".
1.256 raeburn 6166: &Apache::lonhtmlcommon::start_pick_box();
1.237 raeburn 6167: if (ref($row) eq 'ARRAY') {
6168: foreach my $item (@{$row}) {
6169: my $title = $item;
6170: if (ref($lt) eq 'HASH') {
6171: $title = $lt->{$item};
6172: }
1.297 bisitz 6173: $output .= &Apache::lonhtmlcommon::row_title($title);
1.237 raeburn 6174: if ($item eq 'types') {
1.398 raeburn 6175: my $curr_types;
6176: if (ref($currsettings) eq 'HASH') {
6177: $curr_types = $currsettings->{'selfenroll_types'};
6178: }
1.400 raeburn 6179: if ($noedit{$item}) {
6180: if ($curr_types eq '*') {
6181: $output .= &mt('Any user in any domain');
6182: } else {
6183: my @entries = split(/;/,$curr_types);
6184: if (@entries > 0) {
6185: $output .= '<ul>';
6186: foreach my $entry (@entries) {
6187: my ($currdom,$typestr) = split(/:/,$entry);
6188: next if ($typestr eq '');
6189: my $domdesc = &Apache::lonnet::domain($currdom);
6190: my @currinsttypes = split(',',$typestr);
6191: my ($othertitle,$usertypes,$types) =
6192: &Apache::loncommon::sorted_inst_types($currdom);
6193: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
6194: $usertypes->{'any'} = &mt('any user');
6195: if (keys(%{$usertypes}) > 0) {
6196: $usertypes->{'other'} = &mt('other users');
6197: }
6198: my @longinsttypes = map { $usertypes->{$_}; } @currinsttypes;
6199: $output .= '<li>'.$domdesc.':'.join(', ',@longinsttypes).'</li>';
6200: }
6201: }
6202: $output .= '</ul>';
6203: } else {
6204: $output .= &mt('None');
6205: }
6206: }
6207: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6208: next;
6209: }
1.241 raeburn 6210: my $showdomdesc = 1;
6211: my $includeempty = 1;
6212: my $num = 0;
6213: $output .= &Apache::loncommon::start_data_table().
6214: &Apache::loncommon::start_data_table_row()
6215: .'<td colspan="2"><span class="LC_nobreak"><label>'
6216: .&mt('Any user in any domain:')
6217: .' <input type="radio" name="selfenroll_all" value="1" ';
6218: if ($curr_types eq '*') {
6219: $output .= ' checked="checked" ';
6220: }
1.249 raeburn 6221: $output .= 'onchange="javascript:update_types('.
1.418 raeburn 6222: "'selfenroll_all'".');"'.$disabled.' />'.&mt('Yes').'</label>'.
1.249 raeburn 6223: ' <input type="radio" name="selfenroll_all" value="0" ';
1.241 raeburn 6224: if ($curr_types ne '*') {
6225: $output .= ' checked="checked" ';
6226: }
1.249 raeburn 6227: $output .= ' onchange="javascript:update_types('.
1.418 raeburn 6228: "'selfenroll_all'".');"'.$disabled.' />'.&mt('No').'</label></td>'.
1.249 raeburn 6229: &Apache::loncommon::end_data_table_row().
6230: &Apache::loncommon::end_data_table().
6231: &mt('Or').'<br />'.
6232: &Apache::loncommon::start_data_table();
1.241 raeburn 6233: my %currdoms;
1.249 raeburn 6234: if ($curr_types eq '') {
1.241 raeburn 6235: $output .= &new_selfenroll_dom_row($cdom,'0');
6236: } elsif ($curr_types ne '*') {
6237: my @entries = split(/;/,$curr_types);
6238: if (@entries > 0) {
6239: foreach my $entry (@entries) {
6240: my ($currdom,$typestr) = split(/:/,$entry);
6241: $currdoms{$currdom} = 1;
6242: my $domdesc = &Apache::lonnet::domain($currdom);
1.249 raeburn 6243: my @currinsttypes = split(',',$typestr);
1.241 raeburn 6244: $output .= &Apache::loncommon::start_data_table_row()
6245: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').'<b>'
6246: .' '.$domdesc.' ('.$currdom.')'
6247: .'</b><input type="hidden" name="selfenroll_dom_'.$num
6248: .'" value="'.$currdom.'" /></span><br />'
6249: .'<span class="LC_nobreak"><label><input type="checkbox" '
1.418 raeburn 6250: .'name="selfenroll_delete" value="'.$num.'" onchange="javascript:update_types('."'selfenroll_delete','$num'".');"'.$disabled.' />'
1.241 raeburn 6251: .&mt('Delete').'</label></span></td>';
1.249 raeburn 6252: $output .= '<td valign="top"> '.&mt('User types:').'<br />'
1.418 raeburn 6253: .&selfenroll_inst_types($num,$currdom,\@currinsttypes,$readonly).'</td>'
1.241 raeburn 6254: .&Apache::loncommon::end_data_table_row();
6255: $num ++;
6256: }
6257: }
6258: }
1.249 raeburn 6259: my $add_domtitle = &mt('Users in additional domain:');
1.241 raeburn 6260: if ($curr_types eq '*') {
1.249 raeburn 6261: $add_domtitle = &mt('Users in specific domain:');
1.241 raeburn 6262: } elsif ($curr_types eq '') {
1.249 raeburn 6263: $add_domtitle = &mt('Users in other domain:');
1.241 raeburn 6264: }
1.446 raeburn 6265: my ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('enroll',$cdom);
1.241 raeburn 6266: $output .= &Apache::loncommon::start_data_table_row()
6267: .'<td colspan="2"><span class="LC_nobreak">'.$add_domtitle.'</span><br />'
6268: .&Apache::loncommon::select_dom_form('','selfenroll_newdom',
1.446 raeburn 6269: $includeempty,$showdomdesc,'',$trusted,$untrusted,$readonly)
1.241 raeburn 6270: .'<input type="hidden" name="selfenroll_types_total" value="'.$num.'" />'
6271: .'</td>'.&Apache::loncommon::end_data_table_row()
6272: .&Apache::loncommon::end_data_table();
1.237 raeburn 6273: } elsif ($item eq 'registered') {
6274: my ($regon,$regoff);
1.398 raeburn 6275: my $registered;
6276: if (ref($currsettings) eq 'HASH') {
6277: $registered = $currsettings->{'selfenroll_registered'};
6278: }
1.400 raeburn 6279: if ($noedit{$item}) {
6280: if ($registered) {
6281: $output .= &mt('Must be registered in course');
6282: } else {
6283: $output .= &mt('No requirement');
6284: }
6285: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6286: next;
6287: }
1.398 raeburn 6288: if ($registered) {
1.237 raeburn 6289: $regon = ' checked="checked" ';
1.419 raeburn 6290: $regoff = '';
1.237 raeburn 6291: } else {
1.419 raeburn 6292: $regon = '';
1.237 raeburn 6293: $regoff = ' checked="checked" ';
6294: }
6295: $output .= '<label>'.
1.419 raeburn 6296: '<input type="radio" name="selfenroll_registered" value="1"'.$regon.$disabled.' />'.
1.244 bisitz 6297: &mt('Yes').'</label> <label>'.
1.419 raeburn 6298: '<input type="radio" name="selfenroll_registered" value="0"'.$regoff.$disabled.' />'.
1.244 bisitz 6299: &mt('No').'</label>';
1.237 raeburn 6300: } elsif ($item eq 'enroll_dates') {
1.398 raeburn 6301: my ($starttime,$endtime);
6302: if (ref($currsettings) eq 'HASH') {
6303: $starttime = $currsettings->{'selfenroll_start_date'};
6304: $endtime = $currsettings->{'selfenroll_end_date'};
6305: if ($starttime eq '') {
6306: $starttime = $currsettings->{'default_enrollment_start_date'};
6307: }
6308: if ($endtime eq '') {
6309: $endtime = $currsettings->{'default_enrollment_end_date'};
6310: }
1.237 raeburn 6311: }
1.400 raeburn 6312: if ($noedit{$item}) {
6313: $output .= &mt('From: [_1], to: [_2]',&Apache::lonlocal::locallocaltime($starttime),
6314: &Apache::lonlocal::locallocaltime($endtime));
6315: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6316: next;
6317: }
1.237 raeburn 6318: my $startform =
6319: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_date',$starttime,
1.418 raeburn 6320: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6321: my $endform =
6322: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_date',$endtime,
1.418 raeburn 6323: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6324: $output .= &selfenroll_date_forms($startform,$endform);
6325: } elsif ($item eq 'access_dates') {
1.398 raeburn 6326: my ($starttime,$endtime);
6327: if (ref($currsettings) eq 'HASH') {
6328: $starttime = $currsettings->{'selfenroll_start_access'};
6329: $endtime = $currsettings->{'selfenroll_end_access'};
6330: if ($starttime eq '') {
6331: $starttime = $currsettings->{'default_enrollment_start_date'};
6332: }
6333: if ($endtime eq '') {
6334: $endtime = $currsettings->{'default_enrollment_end_date'};
6335: }
1.237 raeburn 6336: }
1.400 raeburn 6337: if ($noedit{$item}) {
6338: $output .= &mt('From: [_1], to: [_2]',&Apache::lonlocal::locallocaltime($starttime),
6339: &Apache::lonlocal::locallocaltime($endtime));
6340: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6341: next;
6342: }
1.237 raeburn 6343: my $startform =
6344: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_access',$starttime,
1.418 raeburn 6345: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6346: my $endform =
6347: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_access',$endtime,
1.418 raeburn 6348: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6349: $output .= &selfenroll_date_forms($startform,$endform);
6350: } elsif ($item eq 'section') {
1.398 raeburn 6351: my $currsec;
6352: if (ref($currsettings) eq 'HASH') {
6353: $currsec = $currsettings->{'selfenroll_section'};
6354: }
1.237 raeburn 6355: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
6356: my $newsecval;
6357: if ($currsec ne 'none' && $currsec ne '') {
6358: if (!defined($sections_count{$currsec})) {
6359: $newsecval = $currsec;
6360: }
6361: }
1.400 raeburn 6362: if ($noedit{$item}) {
6363: if ($currsec ne '') {
6364: $output .= $currsec;
6365: } else {
6366: $output .= &mt('No specific section');
6367: }
6368: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6369: next;
6370: }
1.237 raeburn 6371: my $sections_select =
1.418 raeburn 6372: &Apache::lonuserutils::course_sections(\%sections_count,'st',$currsec,$disabled);
1.237 raeburn 6373: $output .= '<table class="LC_createuser">'."\n".
6374: '<tr class="LC_section_row">'."\n".
6375: '<td align="center">'.&mt('Existing sections')."\n".
6376: '<br />'.$sections_select.'</td><td align="center">'.
6377: &mt('New section').'<br />'."\n".
1.418 raeburn 6378: '<input type="text" name="newsec" size="15" value="'.$newsecval.'"'.$disabled.' />'."\n".
1.237 raeburn 6379: '<input type="hidden" name="sections" value="" />'."\n".
6380: '</td></tr></table>'."\n";
1.276 raeburn 6381: } elsif ($item eq 'approval') {
1.398 raeburn 6382: my ($currnotified,$currapproval,%appchecked);
6383: my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs();
1.430 raeburn 6384: if (ref($currsettings) eq 'HASH') {
1.398 raeburn 6385: $currnotified = $currsettings->{'selfenroll_notifylist'};
6386: $currapproval = $currsettings->{'selfenroll_approval'};
6387: }
6388: if ($currapproval !~ /^[012]$/) {
6389: $currapproval = 0;
6390: }
1.400 raeburn 6391: if ($noedit{$item}) {
6392: $output .= $selfdescs{'approval'}{$currapproval}.
6393: '<br />'.&mt('(Set by Domain Coordinator)');
6394: next;
6395: }
1.398 raeburn 6396: $appchecked{$currapproval} = ' checked="checked"';
6397: for my $i (0..2) {
6398: $output .= '<label>'.
6399: '<input type="radio" name="selfenroll_approval" value="'.$i.'"'.
1.418 raeburn 6400: $appchecked{$i}.' onclick="toggleNotify();"'.$disabled.' />'.
6401: $selfdescs{'approval'}{$i}.'</label>'.(' 'x2);
1.276 raeburn 6402: }
6403: my %advhash = &Apache::lonnet::get_course_adv_roles($cid,1);
6404: my (@ccs,%notified);
1.322 raeburn 6405: my $ccrole = 'cc';
6406: if ($crstype eq 'Community') {
6407: $ccrole = 'co';
6408: }
6409: if ($advhash{$ccrole}) {
6410: @ccs = split(/,/,$advhash{$ccrole});
1.276 raeburn 6411: }
6412: if ($currnotified) {
6413: foreach my $current (split(/,/,$currnotified)) {
6414: $notified{$current} = 1;
6415: if (!grep(/^\Q$current\E$/,@ccs)) {
6416: push(@ccs,$current);
6417: }
6418: }
6419: }
6420: if (@ccs) {
1.398 raeburn 6421: my $style;
6422: unless ($currapproval) {
6423: $style = ' style="display: none;"';
6424: }
6425: $output .= '<br /><div id="notified"'.$style.'>'.
6426: &mt('Personnel to be notified when an enrollment request needs approval, or has been approved:').' '.
6427: &Apache::loncommon::start_data_table().
1.276 raeburn 6428: &Apache::loncommon::start_data_table_row();
6429: my $count = 0;
6430: my $numcols = 4;
6431: foreach my $cc (sort(@ccs)) {
6432: my $notifyon;
6433: my ($ccuname,$ccudom) = split(/:/,$cc);
6434: if ($notified{$cc}) {
6435: $notifyon = ' checked="checked" ';
6436: }
6437: if ($count && !$count%$numcols) {
6438: $output .= &Apache::loncommon::end_data_table_row().
6439: &Apache::loncommon::start_data_table_row()
6440: }
6441: $output .= '<td><span class="LC_nobreak"><label>'.
1.418 raeburn 6442: '<input type="checkbox" name="selfenroll_notify"'.$notifyon.' value="'.$cc.'"'.$disabled.' />'.
1.276 raeburn 6443: &Apache::loncommon::plainname($ccuname,$ccudom).
6444: '</label></span></td>';
1.343 raeburn 6445: $count ++;
1.276 raeburn 6446: }
6447: my $rem = $count%$numcols;
6448: if ($rem) {
6449: my $emptycols = $numcols - $rem;
6450: for (my $i=0; $i<$emptycols; $i++) {
6451: $output .= '<td> </td>';
6452: }
6453: }
6454: $output .= &Apache::loncommon::end_data_table_row().
1.398 raeburn 6455: &Apache::loncommon::end_data_table().
6456: '</div>';
1.276 raeburn 6457: }
6458: } elsif ($item eq 'limit') {
1.398 raeburn 6459: my ($crslimit,$selflimit,$nolimit,$currlim,$currcap);
6460: if (ref($currsettings) eq 'HASH') {
6461: $currlim = $currsettings->{'selfenroll_limit'};
6462: $currcap = $currsettings->{'selfenroll_cap'};
6463: }
1.400 raeburn 6464: if ($noedit{$item}) {
6465: if (($currlim eq 'allstudents') || ($currlim eq 'selfenrolled')) {
6466: if ($currlim eq 'allstudents') {
6467: $output .= &mt('Limit by total students');
6468: } elsif ($currlim eq 'selfenrolled') {
6469: $output .= &mt('Limit by total self-enrolled students');
6470: }
6471: $output .= ' '.&mt('Maximum: [_1]',$currcap).
6472: '<br />'.&mt('(Set by Domain Coordinator)');
6473: } else {
6474: $output .= &mt('No limit').'<br />'.&mt('(Set by Domain Coordinator)');
6475: }
6476: next;
6477: }
1.276 raeburn 6478: if ($currlim eq 'allstudents') {
6479: $crslimit = ' checked="checked" ';
6480: $selflimit = ' ';
6481: $nolimit = ' ';
6482: } elsif ($currlim eq 'selfenrolled') {
6483: $crslimit = ' ';
6484: $selflimit = ' checked="checked" ';
6485: $nolimit = ' ';
6486: } else {
6487: $crslimit = ' ';
6488: $selflimit = ' ';
1.398 raeburn 6489: $nolimit = ' checked="checked" ';
1.276 raeburn 6490: }
6491: $output .= '<table><tr><td><label>'.
1.418 raeburn 6492: '<input type="radio" name="selfenroll_limit" value="none"'.$nolimit.$disabled.'/>'.
1.276 raeburn 6493: &mt('No limit').'</label></td><td><label>'.
1.418 raeburn 6494: '<input type="radio" name="selfenroll_limit" value="allstudents"'.$crslimit.$disabled.'/>'.
1.276 raeburn 6495: &mt('Limit by total students').'</label></td><td><label>'.
1.418 raeburn 6496: '<input type="radio" name="selfenroll_limit" value="selfenrolled"'.$selflimit.$disabled.'/>'.
1.276 raeburn 6497: &mt('Limit by total self-enrolled students').
6498: '</td></tr><tr>'.
6499: '<td> </td><td colspan="2"><span class="LC_nobreak">'.
6500: (' 'x3).&mt('Maximum number allowed: ').
1.418 raeburn 6501: '<input type="text" name="selfenroll_cap" size = "5" value="'.$currcap.'"'.$disabled.' /></td></tr></table>';
1.237 raeburn 6502: }
6503: $output .= &Apache::lonhtmlcommon::row_closure(1);
6504: }
6505: }
1.418 raeburn 6506: $output .= &Apache::lonhtmlcommon::end_pick_box().'<br />';
6507: unless ($readonly) {
6508: $output .= '<input type="button" name="selfenrollconf" value="'
6509: .&mt('Save').'" onclick="validate_types(this.form);" />';
6510: }
6511: $output .= '<input type="hidden" name="action" value="selfenroll" />'
6512: .'<input type="hidden" name="state" value="done" />'."\n"
6513: .$additional.'</form>';
1.237 raeburn 6514: $r->print($output);
6515: return;
6516: }
6517:
1.400 raeburn 6518: sub get_noedit_fields {
6519: my ($cdom,$cnum,$crstype,$row) = @_;
6520: my %noedit;
6521: if (ref($row) eq 'ARRAY') {
6522: my %settings = &Apache::lonnet::get('environment',['internal.coursecode','internal.textbook',
6523: 'internal.selfenrollmgrdc',
6524: 'internal.selfenrollmgrcc'],$cdom,$cnum);
6525: my $type = &Apache::lonuserutils::get_extended_type($cdom,$cnum,$crstype,\%settings);
6526: my (%specific_managebydc,%specific_managebycc,%default_managebydc);
6527: map { $specific_managebydc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrdc'}));
6528: map { $specific_managebycc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrcc'}));
6529: my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
6530: map { $default_managebydc{$_} = 1; } (split(/,/,$domdefaults{$type.'selfenrolladmdc'}));
6531:
6532: foreach my $item (@{$row}) {
6533: next if ($specific_managebycc{$item});
6534: if (($specific_managebydc{$item}) || ($default_managebydc{$item})) {
6535: $noedit{$item} = 1;
6536: }
6537: }
6538: }
6539: return %noedit;
6540: }
6541:
6542: sub visible_in_stdcat {
6543: my ($cdom,$cnum,$domconf) = @_;
6544: my ($cathash,%settable,@vismsgs,$cansetvis,$visible);
6545: unless (ref($domconf) eq 'HASH') {
6546: return ($visible,$cansetvis,\@vismsgs);
6547: }
6548: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6549: if ($domconf->{'coursecategories'}{'togglecats'} eq 'crs') {
1.256 raeburn 6550: $settable{'togglecats'} = 1;
6551: }
1.400 raeburn 6552: if ($domconf->{'coursecategories'}{'categorize'} eq 'crs') {
1.256 raeburn 6553: $settable{'categorize'} = 1;
6554: }
1.400 raeburn 6555: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6556: }
1.260 raeburn 6557: if ($settable{'togglecats'} && $settable{'categorize'}) {
1.256 raeburn 6558: $cansetvis = &mt('You are able to both assign a course category and choose to exclude this course from the catalog.');
6559: } elsif ($settable{'togglecats'}) {
6560: $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 6561: } elsif ($settable{'categorize'}) {
1.256 raeburn 6562: $cansetvis = &mt('You may assign a course category, but only a Domain Coordinator may choose to exclude this course from the catalog.');
6563: } else {
6564: $cansetvis = &mt('Only a Domain Coordinator may assign a course category or choose to exclude this course from the catalog.');
6565: }
6566:
6567: my %currsettings =
6568: &Apache::lonnet::get('environment',['hidefromcat','categories','internal.coursecode'],
6569: $cdom,$cnum);
1.400 raeburn 6570: $visible = 0;
1.256 raeburn 6571: if ($currsettings{'internal.coursecode'} ne '') {
1.400 raeburn 6572: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6573: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6574: if (ref($cathash) eq 'HASH') {
6575: if ($cathash->{'instcode::0'} eq '') {
6576: push(@vismsgs,'dc_addinst');
6577: } else {
6578: $visible = 1;
6579: }
6580: } else {
6581: $visible = 1;
6582: }
6583: } else {
6584: $visible = 1;
6585: }
6586: } else {
6587: if (ref($cathash) eq 'HASH') {
6588: if ($cathash->{'instcode::0'} ne '') {
6589: push(@vismsgs,'dc_instcode');
6590: }
6591: } else {
6592: push(@vismsgs,'dc_instcode');
6593: }
6594: }
6595: if ($currsettings{'categories'} ne '') {
6596: my $cathash;
1.400 raeburn 6597: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6598: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6599: if (ref($cathash) eq 'HASH') {
6600: if (keys(%{$cathash}) == 0) {
6601: push(@vismsgs,'dc_catalog');
6602: } elsif ((keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} ne '')) {
6603: push(@vismsgs,'dc_categories');
6604: } else {
6605: my @currcategories = split('&',$currsettings{'categories'});
6606: my $matched = 0;
6607: foreach my $cat (@currcategories) {
6608: if ($cathash->{$cat} ne '') {
6609: $visible = 1;
6610: $matched = 1;
6611: last;
6612: }
6613: }
6614: if (!$matched) {
1.260 raeburn 6615: if ($settable{'categorize'}) {
1.256 raeburn 6616: push(@vismsgs,'chgcat');
6617: } else {
6618: push(@vismsgs,'dc_chgcat');
6619: }
6620: }
6621: }
6622: }
6623: }
6624: } else {
6625: if (ref($cathash) eq 'HASH') {
6626: if ((keys(%{$cathash}) > 1) ||
6627: (keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} eq '')) {
1.260 raeburn 6628: if ($settable{'categorize'}) {
1.256 raeburn 6629: push(@vismsgs,'addcat');
6630: } else {
6631: push(@vismsgs,'dc_addcat');
6632: }
6633: }
6634: }
6635: }
6636: if ($currsettings{'hidefromcat'} eq 'yes') {
6637: $visible = 0;
6638: if ($settable{'togglecats'}) {
6639: unshift(@vismsgs,'unhide');
6640: } else {
6641: unshift(@vismsgs,'dc_unhide')
6642: }
6643: }
1.400 raeburn 6644: return ($visible,$cansetvis,\@vismsgs);
6645: }
6646:
6647: sub cat_visibility {
6648: my %visactions = &Apache::lonlocal::texthash(
6649: vis => 'This course/community currently appears in the Course/Community Catalog for this domain.',
6650: 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.',
6651: miss => 'This course/community does not currently appear in the Course/Community Catalog for this domain.',
6652: none => 'Display of a course catalog is disabled for this domain.',
6653: yous => 'You should remedy this if you plan to allow self-enrollment, otherwise students will have difficulty finding this course.',
6654: 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.',
6655: make => 'Make any changes to self-enrollment settings below, click "Save", then take action to include the course in the Catalog:',
6656: take => 'Take the following action to ensure the course appears in the Catalog:',
6657: dc_chgconf => 'Ask a domain coordinator to change the Catalog type for this domain.',
6658: dc_setcode => 'Ask a domain coordinator to assign a six character code to the course',
6659: dc_unhide => 'Ask a domain coordinator to change the "Exclude from course catalog" setting.',
6660: dc_addinst => 'Ask a domain coordinator to enable display the catalog of "Official courses (with institutional codes)".',
6661: dc_instcode => 'Ask a domain coordinator to assign an institutional code (if this is an official course).',
6662: dc_catalog => 'Ask a domain coordinator to enable or create at least one course category in the domain.',
6663: dc_categories => 'Ask a domain coordinator to create a hierarchy of categories and sub categories for courses in the domain.',
6664: 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',
6665: dc_addcat => 'Ask a domain coordinator to assign a category to the course.',
6666: );
6667: $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>"');
6668: $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>"');
6669: $visactions{'addcat'} = &mt('Use [_1]Categorize course[_2] to assign a category to the course.','"<a href="/adm/courseprefs?phase=display&actions=courseinfo">','</a>"');
6670: return \%visactions;
1.256 raeburn 6671: }
6672:
1.241 raeburn 6673: sub new_selfenroll_dom_row {
6674: my ($newdom,$num) = @_;
6675: my $domdesc = &Apache::lonnet::domain($newdom);
6676: my $output;
6677: if ($domdesc ne '') {
6678: $output .= &Apache::loncommon::start_data_table_row()
6679: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').' <b>'.$domdesc
6680: .' ('.$newdom.')</b><input type="hidden" name="selfenroll_dom_'.$num
1.249 raeburn 6681: .'" value="'.$newdom.'" /></span><br />'
6682: .'<span class="LC_nobreak"><label><input type="checkbox" '
6683: .'name="selfenroll_activate" value="'.$num.'" '
6684: .'onchange="javascript:update_types('
6685: ."'selfenroll_activate','$num'".');" />'
6686: .&mt('Activate').'</label></span></td>';
1.241 raeburn 6687: my @currinsttypes;
6688: $output .= '<td>'.&mt('User types:').'<br />'
6689: .&selfenroll_inst_types($num,$newdom,\@currinsttypes).'</td>'
6690: .&Apache::loncommon::end_data_table_row();
6691: }
6692: return $output;
6693: }
6694:
6695: sub selfenroll_inst_types {
1.418 raeburn 6696: my ($num,$currdom,$currinsttypes,$readonly) = @_;
1.241 raeburn 6697: my $output;
6698: my $numinrow = 4;
6699: my $count = 0;
6700: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($currdom);
1.247 raeburn 6701: my $othervalue = 'any';
1.418 raeburn 6702: my $disabled;
6703: if ($readonly) {
6704: $disabled = ' disabled="disabled"';
6705: }
1.241 raeburn 6706: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
1.251 raeburn 6707: if (keys(%{$usertypes}) > 0) {
1.247 raeburn 6708: $othervalue = 'other';
6709: }
1.241 raeburn 6710: $output .= '<table><tr>';
6711: foreach my $type (@{$types}) {
6712: if (($count > 0) && ($count%$numinrow == 0)) {
6713: $output .= '</tr><tr>';
6714: }
6715: if (defined($usertypes->{$type})) {
1.257 raeburn 6716: my $esc_type = &escape($type);
1.241 raeburn 6717: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.
1.257 raeburn 6718: $esc_type.'" ';
1.241 raeburn 6719: if (ref($currinsttypes) eq 'ARRAY') {
6720: if (@{$currinsttypes} > 0) {
1.249 raeburn 6721: if (grep(/^any$/,@{$currinsttypes})) {
6722: $output .= 'checked="checked"';
1.257 raeburn 6723: } elsif (grep(/^\Q$esc_type\E$/,@{$currinsttypes})) {
1.241 raeburn 6724: $output .= 'checked="checked"';
6725: }
1.249 raeburn 6726: } else {
6727: $output .= 'checked="checked"';
1.241 raeburn 6728: }
6729: }
1.418 raeburn 6730: $output .= ' name="selfenroll_types_'.$num.'"'.$disabled.' />'.$usertypes->{$type}.'</label></span></td>';
1.241 raeburn 6731: }
6732: $count ++;
6733: }
6734: if (($count > 0) && ($count%$numinrow == 0)) {
6735: $output .= '</tr><tr>';
6736: }
1.249 raeburn 6737: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.$othervalue.'"';
1.241 raeburn 6738: if (ref($currinsttypes) eq 'ARRAY') {
6739: if (@{$currinsttypes} > 0) {
1.249 raeburn 6740: if (grep(/^any$/,@{$currinsttypes})) {
6741: $output .= ' checked="checked"';
6742: } elsif ($othervalue eq 'other') {
6743: if (grep(/^\Q$othervalue\E$/,@{$currinsttypes})) {
6744: $output .= ' checked="checked"';
6745: }
1.241 raeburn 6746: }
1.249 raeburn 6747: } else {
6748: $output .= ' checked="checked"';
1.241 raeburn 6749: }
1.249 raeburn 6750: } else {
6751: $output .= ' checked="checked"';
1.241 raeburn 6752: }
1.418 raeburn 6753: $output .= ' name="selfenroll_types_'.$num.'"'.$disabled.' />'.$othertitle.'</label></span></td></tr></table>';
1.241 raeburn 6754: }
6755: return $output;
6756: }
6757:
1.237 raeburn 6758: sub selfenroll_date_forms {
6759: my ($startform,$endform) = @_;
6760: my $output .= &Apache::lonhtmlcommon::start_pick_box()."\n".
1.244 bisitz 6761: &Apache::lonhtmlcommon::row_title(&mt('Start date'),
1.237 raeburn 6762: 'LC_oddrow_value')."\n".
6763: $startform."\n".
6764: &Apache::lonhtmlcommon::row_closure(1).
1.244 bisitz 6765: &Apache::lonhtmlcommon::row_title(&mt('End date'),
1.237 raeburn 6766: 'LC_oddrow_value')."\n".
6767: $endform."\n".
6768: &Apache::lonhtmlcommon::row_closure(1).
6769: &Apache::lonhtmlcommon::end_pick_box();
6770: return $output;
6771: }
6772:
1.239 raeburn 6773: sub print_userchangelogs_display {
1.415 raeburn 6774: my ($r,$context,$permission,$brcrum) = @_;
1.363 raeburn 6775: my $formname = 'rolelog';
1.418 raeburn 6776: my ($username,$domain,$crstype,$viewablesec,%roleslog);
1.363 raeburn 6777: if ($context eq 'domain') {
6778: $domain = $env{'request.role.domain'};
6779: %roleslog=&Apache::lonnet::dump_dom('nohist_rolelog',$domain);
6780: } else {
6781: if ($context eq 'course') {
6782: $domain = $env{'course.'.$env{'request.course.id'}.'.domain'};
6783: $username = $env{'course.'.$env{'request.course.id'}.'.num'};
6784: $crstype = &Apache::loncommon::course_type();
1.418 raeburn 6785: $viewablesec = &Apache::lonuserutils::viewable_section($permission);
1.363 raeburn 6786: my %saveable_parameters = ('show' => 'scalar',);
6787: &Apache::loncommon::store_course_settings('roles_log',
6788: \%saveable_parameters);
6789: &Apache::loncommon::restore_course_settings('roles_log',
6790: \%saveable_parameters);
6791: } elsif ($context eq 'author') {
6792: $domain = $env{'user.domain'};
6793: if ($env{'request.role'} =~ m{^au\./\Q$domain\E/$}) {
6794: $username = $env{'user.name'};
6795: } else {
6796: undef($domain);
6797: }
6798: }
6799: if ($domain ne '' && $username ne '') {
6800: %roleslog=&Apache::lonnet::dump('nohist_rolelog',$domain,$username);
6801: }
6802: }
1.239 raeburn 6803: if ((keys(%roleslog))[0]=~/^error\:/) { undef(%roleslog); }
6804:
1.415 raeburn 6805: my $helpitem;
6806: if ($context eq 'course') {
6807: $helpitem = 'Course_User_Logs';
1.439 raeburn 6808: } elsif ($context eq 'domain') {
6809: $helpitem = 'Domain_Role_Logs';
6810: } elsif ($context eq 'author') {
6811: $helpitem = 'Author_User_Logs';
1.415 raeburn 6812: }
6813: push (@{$brcrum},
6814: {href => '/adm/createuser?action=changelogs',
6815: text => 'User Management Logs',
6816: help => $helpitem});
6817: my $bread_crumbs_component = 'User Changes';
6818: my $args = { bread_crumbs => $brcrum,
6819: bread_crumbs_component => $bread_crumbs_component};
6820:
6821: # Create navigation javascript
6822: my $jsnav = &userlogdisplay_js($formname);
6823:
6824: my $jscript = (<<ENDSCRIPT);
6825: <script type="text/javascript">
6826: // <![CDATA[
6827: $jsnav
6828: // ]]>
6829: </script>
6830: ENDSCRIPT
6831:
6832: # print page header
6833: $r->print(&header($jscript,$args));
6834:
1.239 raeburn 6835: # set defaults
6836: my $now = time();
6837: my $defstart = $now - (7*24*3600); #7 days ago
6838: my %defaults = (
6839: page => '1',
6840: show => '10',
6841: role => 'any',
6842: chgcontext => 'any',
6843: rolelog_start_date => $defstart,
6844: rolelog_end_date => $now,
6845: );
6846: my $more_records = 0;
6847:
6848: # set current
6849: my %curr;
6850: foreach my $item ('show','page','role','chgcontext') {
6851: $curr{$item} = $env{'form.'.$item};
6852: }
6853: my ($startdate,$enddate) =
6854: &Apache::lonuserutils::get_dates_from_form('rolelog_start_date','rolelog_end_date');
6855: $curr{'rolelog_start_date'} = $startdate;
6856: $curr{'rolelog_end_date'} = $enddate;
6857: foreach my $key (keys(%defaults)) {
6858: if ($curr{$key} eq '') {
6859: $curr{$key} = $defaults{$key};
6860: }
6861: }
1.248 raeburn 6862: my (%whodunit,%changed,$version);
6863: ($version) = ($r->dir_config('lonVersion') =~ /^([\d\.]+)\-/);
1.239 raeburn 6864: my ($minshown,$maxshown);
1.255 raeburn 6865: $minshown = 1;
1.239 raeburn 6866: my $count = 0;
1.415 raeburn 6867: if ($curr{'show'} =~ /\D/) {
6868: $curr{'page'} = 1;
6869: } else {
1.239 raeburn 6870: $maxshown = $curr{'page'} * $curr{'show'};
6871: if ($curr{'page'} > 1) {
6872: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
6873: }
6874: }
1.301 bisitz 6875:
1.327 raeburn 6876: # Form Header
6877: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
1.363 raeburn 6878: &role_display_filter($context,$formname,$domain,$username,\%curr,
6879: $version,$crstype));
1.327 raeburn 6880:
6881: my $showntableheader = 0;
6882:
6883: # Table Header
6884: my $tableheader =
6885: &Apache::loncommon::start_data_table_header_row()
6886: .'<th> </th>'
6887: .'<th>'.&mt('When').'</th>'
6888: .'<th>'.&mt('Who made the change').'</th>'
6889: .'<th>'.&mt('Changed User').'</th>'
1.363 raeburn 6890: .'<th>'.&mt('Role').'</th>';
6891:
6892: if ($context eq 'course') {
6893: $tableheader .= '<th>'.&mt('Section').'</th>';
6894: }
6895: $tableheader .=
6896: '<th>'.&mt('Context').'</th>'
1.327 raeburn 6897: .'<th>'.&mt('Start').'</th>'
6898: .'<th>'.&mt('End').'</th>'
6899: .&Apache::loncommon::end_data_table_header_row();
6900:
6901: # Display user change log data
1.239 raeburn 6902: foreach my $id (sort { $roleslog{$b}{'exe_time'}<=>$roleslog{$a}{'exe_time'} } (keys(%roleslog))) {
6903: next if (($roleslog{$id}{'exe_time'} < $curr{'rolelog_start_date'}) ||
6904: ($roleslog{$id}{'exe_time'} > $curr{'rolelog_end_date'}));
1.415 raeburn 6905: if ($curr{'show'} !~ /\D/) {
1.239 raeburn 6906: if ($count >= $curr{'page'} * $curr{'show'}) {
6907: $more_records = 1;
6908: last;
6909: }
6910: }
6911: if ($curr{'role'} ne 'any') {
6912: next if ($roleslog{$id}{'logentry'}{'role'} ne $curr{'role'});
6913: }
6914: if ($curr{'chgcontext'} ne 'any') {
6915: if ($curr{'chgcontext'} eq 'selfenroll') {
6916: next if (!$roleslog{$id}{'logentry'}{'selfenroll'});
6917: } else {
6918: next if ($roleslog{$id}{'logentry'}{'context'} ne $curr{'chgcontext'});
6919: }
6920: }
1.418 raeburn 6921: if (($context eq 'course') && ($viewablesec ne '')) {
1.430 raeburn 6922: next if ($roleslog{$id}{'logentry'}{'section'} ne $viewablesec);
1.418 raeburn 6923: }
1.239 raeburn 6924: $count ++;
6925: next if ($count < $minshown);
1.327 raeburn 6926: unless ($showntableheader) {
1.415 raeburn 6927: $r->print(&Apache::loncommon::start_data_table()
1.327 raeburn 6928: .$tableheader);
6929: $r->rflush();
6930: $showntableheader = 1;
6931: }
1.239 raeburn 6932: if ($whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} eq '') {
6933: $whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} =
6934: &Apache::loncommon::plainname($roleslog{$id}{'exe_uname'},$roleslog{$id}{'exe_udom'});
6935: }
6936: if ($changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} eq '') {
6937: $changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} =
6938: &Apache::loncommon::plainname($roleslog{$id}{'uname'},$roleslog{$id}{'udom'});
6939: }
6940: my $sec = $roleslog{$id}{'logentry'}{'section'};
6941: if ($sec eq '') {
6942: $sec = &mt('None');
6943: }
6944: my ($rolestart,$roleend);
6945: if ($roleslog{$id}{'delflag'}) {
6946: $rolestart = &mt('deleted');
6947: $roleend = &mt('deleted');
6948: } else {
6949: $rolestart = $roleslog{$id}{'logentry'}{'start'};
6950: $roleend = $roleslog{$id}{'logentry'}{'end'};
6951: if ($rolestart eq '' || $rolestart == 0) {
6952: $rolestart = &mt('No start date');
6953: } else {
6954: $rolestart = &Apache::lonlocal::locallocaltime($rolestart);
6955: }
6956: if ($roleend eq '' || $roleend == 0) {
6957: $roleend = &mt('No end date');
6958: } else {
6959: $roleend = &Apache::lonlocal::locallocaltime($roleend);
6960: }
6961: }
6962: my $chgcontext = $roleslog{$id}{'logentry'}{'context'};
6963: if ($roleslog{$id}{'logentry'}{'selfenroll'}) {
6964: $chgcontext = 'selfenroll';
6965: }
1.363 raeburn 6966: my %lt = &rolechg_contexts($context,$crstype);
1.239 raeburn 6967: if ($chgcontext ne '' && $lt{$chgcontext} ne '') {
6968: $chgcontext = $lt{$chgcontext};
6969: }
1.327 raeburn 6970: $r->print(
1.301 bisitz 6971: &Apache::loncommon::start_data_table_row()
6972: .'<td>'.$count.'</td>'
6973: .'<td>'.&Apache::lonlocal::locallocaltime($roleslog{$id}{'exe_time'}).'</td>'
6974: .'<td>'.$whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}}.'</td>'
6975: .'<td>'.$changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}}.'</td>'
1.363 raeburn 6976: .'<td>'.&Apache::lonnet::plaintext($roleslog{$id}{'logentry'}{'role'},$crstype).'</td>');
6977: if ($context eq 'course') {
6978: $r->print('<td>'.$sec.'</td>');
6979: }
6980: $r->print(
6981: '<td>'.$chgcontext.'</td>'
1.301 bisitz 6982: .'<td>'.$rolestart.'</td>'
6983: .'<td>'.$roleend.'</td>'
1.327 raeburn 6984: .&Apache::loncommon::end_data_table_row()."\n");
1.301 bisitz 6985: }
6986:
1.327 raeburn 6987: if ($showntableheader) { # Table footer, if content displayed above
1.415 raeburn 6988: $r->print(&Apache::loncommon::end_data_table().
6989: &userlogdisplay_navlinks(\%curr,$more_records));
1.327 raeburn 6990: } else { # No content displayed above
1.301 bisitz 6991: $r->print('<p class="LC_info">'
6992: .&mt('There are no records to display.')
6993: .'</p>'
6994: );
1.239 raeburn 6995: }
1.301 bisitz 6996:
1.327 raeburn 6997: # Form Footer
6998: $r->print(
6999: '<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
7000: .'<input type="hidden" name="action" value="changelogs" />'
7001: .'</form>');
7002: return;
7003: }
1.301 bisitz 7004:
1.416 raeburn 7005: sub print_useraccesslogs_display {
7006: my ($r,$uname,$udom,$permission,$brcrum) = @_;
7007: my $formname = 'accesslog';
7008: my $form = 'document.accesslog';
7009:
7010: # set breadcrumbs
1.422 raeburn 7011: my %breadcrumb_text = &singleuser_breadcrumb('','domain',$udom);
1.431 raeburn 7012: my $prevphasestr;
7013: if ($env{'form.popup'}) {
7014: $brcrum = [];
7015: } else {
7016: push (@{$brcrum},
7017: {href => "javascript:backPage($form)",
7018: text => $breadcrumb_text{'search'}});
7019: my @prevphases;
7020: if ($env{'form.prevphases'}) {
7021: @prevphases = split(/,/,$env{'form.prevphases'});
7022: $prevphasestr = $env{'form.prevphases'};
7023: }
7024: if (($env{'form.phase'} eq 'userpicked') || (grep(/^userpicked$/,@prevphases))) {
7025: push(@{$brcrum},
7026: {href => "javascript:backPage($form,'get_user_info','select')",
7027: text => $breadcrumb_text{'userpicked'}});
7028: if ($env{'form.phase'} eq 'userpicked') {
7029: $prevphasestr = 'userpicked';
7030: }
1.416 raeburn 7031: }
7032: }
7033: push(@{$brcrum},
7034: {href => '/adm/createuser?action=accesslogs',
7035: text => 'User access logs',
1.424 raeburn 7036: help => 'Domain_User_Access_Logs'});
1.416 raeburn 7037: my $bread_crumbs_component = 'User Access Logs';
7038: my $args = { bread_crumbs => $brcrum,
7039: bread_crumbs_component => 'User Management'};
1.423 raeburn 7040: if ($env{'form.popup'}) {
7041: $args->{'no_nav_bar'} = 1;
1.431 raeburn 7042: $args->{'bread_crumbs_nomenu'} = 1;
1.423 raeburn 7043: }
1.416 raeburn 7044:
1.417 raeburn 7045: # set javascript
1.416 raeburn 7046: my ($jsback,$elements) = &crumb_utilities();
7047: my $jsnav = &userlogdisplay_js($formname);
7048:
7049: my $jscript = (<<ENDSCRIPT);
7050: <script type="text/javascript">
7051: // <![CDATA[
7052:
7053: $jsback
7054: $jsnav
7055:
7056: // ]]>
7057: </script>
7058:
7059: ENDSCRIPT
7060:
1.417 raeburn 7061: # print page header
1.416 raeburn 7062: $r->print(&header($jscript,$args));
7063:
7064: # early out unless log data can be displayed.
7065: unless ($permission->{'activity'}) {
7066: $r->print('<p class="LC_warning">'
7067: .&mt('You do not have rights to display user access logs.')
1.431 raeburn 7068: .'</p>');
7069: if ($env{'form.popup'}) {
7070: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
7071: } else {
7072: $r->print(&earlyout_accesslog_form($formname,$prevphasestr,$udom));
7073: }
1.416 raeburn 7074: return;
7075: }
7076:
7077: unless ($udom eq $env{'request.role.domain'}) {
7078: $r->print('<p class="LC_warning">'
7079: .&mt("User's domain must match role's domain")
7080: .'</p>'
7081: .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
1.417 raeburn 7082: return;
1.416 raeburn 7083: }
7084:
7085: if (($uname eq '') || ($udom eq '')) {
7086: $r->print('<p class="LC_warning">'
7087: .&mt('Invalid username or domain')
7088: .'</p>'
7089: .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
7090: return;
7091: }
7092:
1.437 raeburn 7093: if (&Apache::lonnet::privileged($uname,$udom,
7094: [$env{'request.role.domain'}],['dc','su'])) {
7095: unless (&Apache::lonnet::privileged($env{'user.name'},$env{'user.domain'},
7096: [$env{'request.role.domain'}],['dc','su'])) {
7097: $r->print('<p class="LC_warning">'
7098: .&mt('You need to be a privileged user to display user access logs for [_1]',
7099: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),
7100: $uname,$udom))
7101: .'</p>');
7102: if ($env{'form.popup'}) {
7103: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
7104: } else {
7105: $r->print(&earlyout_accesslog_form($formname,$prevphasestr,$udom));
7106: }
7107: return;
7108: }
7109: }
7110:
1.416 raeburn 7111: # set defaults
7112: my $now = time();
7113: my $defstart = $now - (7*24*3600);
7114: my %defaults = (
7115: page => '1',
7116: show => '10',
7117: activity => 'any',
7118: accesslog_start_date => $defstart,
7119: accesslog_end_date => $now,
7120: );
7121: my $more_records = 0;
7122:
7123: # set current
7124: my %curr;
7125: foreach my $item ('show','page','activity') {
7126: $curr{$item} = $env{'form.'.$item};
7127: }
7128: my ($startdate,$enddate) =
7129: &Apache::lonuserutils::get_dates_from_form('accesslog_start_date','accesslog_end_date');
7130: $curr{'accesslog_start_date'} = $startdate;
7131: $curr{'accesslog_end_date'} = $enddate;
7132: foreach my $key (keys(%defaults)) {
7133: if ($curr{$key} eq '') {
7134: $curr{$key} = $defaults{$key};
7135: }
7136: }
7137: my ($minshown,$maxshown);
7138: $minshown = 1;
7139: my $count = 0;
7140: if ($curr{'show'} =~ /\D/) {
7141: $curr{'page'} = 1;
7142: } else {
7143: $maxshown = $curr{'page'} * $curr{'show'};
7144: if ($curr{'page'} > 1) {
7145: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
7146: }
7147: }
7148:
7149: # form header
7150: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
7151: &activity_display_filter($formname,\%curr));
7152:
7153: my $showntableheader = 0;
7154: my ($nav_script,$nav_links);
7155:
7156: # table header
1.453 raeburn 7157: my $heading = '<h3>'.
1.431 raeburn 7158: &mt('User access logs for: [_1]',
1.453 raeburn 7159: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom)).'</h3>';
7160: my $tableheader = $heading
1.431 raeburn 7161: .&Apache::loncommon::start_data_table_header_row()
1.416 raeburn 7162: .'<th> </th>'
7163: .'<th>'.&mt('When').'</th>'
7164: .'<th>'.&mt('HostID').'</th>'
7165: .'<th>'.&mt('Event').'</th>'
7166: .'<th>'.&mt('Other data').'</th>'
7167: .&Apache::loncommon::end_data_table_header_row();
7168:
7169: my %filters=(
7170: start => $curr{'accesslog_start_date'},
7171: end => $curr{'accesslog_end_date'},
7172: action => $curr{'activity'},
7173: );
7174:
7175: my $reply = &Apache::lonnet::userlog_query($uname,$udom,%filters);
7176: unless ( ($reply =~/^timeout/) || ($reply =~/^error/) ) {
7177: my (%courses,%missing);
7178: my @results = split(/\&/,$reply);
7179: foreach my $item (reverse(@results)) {
7180: my ($timestamp,$host,$event) = split(/:/,$item);
7181: next unless ($event =~ /^(Log|Role)/);
7182: if ($curr{'show'} !~ /\D/) {
7183: if ($count >= $curr{'page'} * $curr{'show'}) {
7184: $more_records = 1;
7185: last;
7186: }
7187: }
7188: $count ++;
7189: next if ($count < $minshown);
7190: unless ($showntableheader) {
7191: $r->print($nav_script
7192: .&Apache::loncommon::start_data_table()
7193: .$tableheader);
7194: $r->rflush();
7195: $showntableheader = 1;
7196: }
1.418 raeburn 7197: my ($shown,$extra);
1.437 raeburn 7198: my ($event,$data) = split(/\s+/,&unescape($event),2);
1.416 raeburn 7199: if ($event eq 'Role') {
7200: my ($rolecode,$extent) = split(/\./,$data,2);
7201: next if ($extent eq '');
7202: my ($crstype,$desc,$info);
1.418 raeburn 7203: if ($extent =~ m{^/($match_domain)/($match_courseid)(?:/(\w+)|)$}) {
7204: my ($cdom,$cnum,$sec) = ($1,$2,$3);
1.416 raeburn 7205: my $cid = $cdom.'_'.$cnum;
7206: if (exists($courses{$cid})) {
7207: $crstype = $courses{$cid}{'type'};
7208: $desc = $courses{$cid}{'description'};
7209: } elsif ($missing{$cid}) {
7210: $crstype = 'Course';
7211: $desc = 'Course/Community';
7212: } else {
7213: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',$cnum,undef,undef,'.');
7214: if (ref($crsinfo{$cdom.'_'.$cnum}) eq 'HASH') {
7215: $courses{$cid} = $crsinfo{$cid};
7216: $crstype = $crsinfo{$cid}{'type'};
7217: $desc = $crsinfo{$cid}{'description'};
7218: } else {
7219: $missing{$cid} = 1;
7220: }
7221: }
7222: $extra = &mt($crstype).': <a href="/public/'.$cdom.'/'.$cnum.'/syllabus">'.$desc.'</a>';
1.418 raeburn 7223: if ($sec ne '') {
7224: $extra .= ' ('.&mt('Section: [_1]',$sec).')';
7225: }
1.416 raeburn 7226: } elsif ($extent =~ m{^/($match_domain)/($match_username|$)}) {
7227: my ($dom,$name) = ($1,$2);
7228: if ($rolecode eq 'au') {
7229: $extra = '';
7230: } elsif ($rolecode =~ /^(ca|aa)$/) {
1.417 raeburn 7231: $extra = &mt('Authoring Space: [_1]',$name.':'.$dom);
1.416 raeburn 7232: } elsif ($rolecode =~ /^(li|dg|dh|dc|sc)$/) {
7233: $extra = &mt('Domain: [_1]',$dom);
7234: }
7235: }
7236: my $rolename;
7237: if ($rolecode =~ m{^cr/($match_domain)/($match_username)/(\w+)}) {
7238: my $role = $3;
1.417 raeburn 7239: my $owner = "($2:$1)";
1.416 raeburn 7240: if ($2 eq $1.'-domainconfig') {
7241: $owner = '(ad hoc)';
1.417 raeburn 7242: }
1.416 raeburn 7243: $rolename = &mt('Custom role: [_1]',$role.' '.$owner);
7244: } else {
7245: $rolename = &Apache::lonnet::plaintext($rolecode,$crstype);
7246: }
7247: $shown = &mt('Role selection: [_1]',$rolename);
7248: } else {
7249: $shown = &mt($event);
1.437 raeburn 7250: if ($data =~ /^webdav/) {
7251: my ($path,$clientip) = split(/\s+/,$data,2);
7252: $path =~ s/^webdav//;
7253: if ($clientip ne '') {
7254: $extra = &mt('Client IP address: [_1]',$clientip);
7255: }
7256: if ($path ne '') {
7257: $shown .= ' '.&mt('(WebDAV access to [_1])',$path);
7258: }
7259: } elsif ($data ne '') {
7260: $extra = &mt('Client IP address: [_1]',$data);
1.416 raeburn 7261: }
7262: }
7263: $r->print(
7264: &Apache::loncommon::start_data_table_row()
7265: .'<td>'.$count.'</td>'
7266: .'<td>'.&Apache::lonlocal::locallocaltime($timestamp).'</td>'
7267: .'<td>'.$host.'</td>'
7268: .'<td>'.$shown.'</td>'
7269: .'<td>'.$extra.'</td>'
7270: .&Apache::loncommon::end_data_table_row()."\n");
7271: }
7272: }
7273:
7274: if ($showntableheader) { # Table footer, if content displayed above
7275: $r->print(&Apache::loncommon::end_data_table().
7276: &userlogdisplay_navlinks(\%curr,$more_records));
7277: } else { # No content displayed above
1.453 raeburn 7278: $r->print($heading.'<p class="LC_info">'
1.416 raeburn 7279: .&mt('There are no records to display.')
7280: .'</p>');
7281: }
7282:
1.423 raeburn 7283: if ($env{'form.popup'} == 1) {
7284: $r->print('<input type="hidden" name="popup" value="1" />'."\n");
7285: }
7286:
1.416 raeburn 7287: # Form Footer
7288: $r->print(
7289: '<input type="hidden" name="currstate" value="" />'
7290: .'<input type="hidden" name="accessuname" value="'.$uname.'" />'
7291: .'<input type="hidden" name="accessudom" value="'.$udom.'" />'
7292: .'<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
7293: .'<input type="hidden" name="prevphases" value="'.$prevphasestr.'" />'
7294: .'<input type="hidden" name="phase" value="activity" />'
7295: .'<input type="hidden" name="action" value="accesslogs" />'
7296: .'<input type="hidden" name="srchdomain" value="'.$udom.'" />'
7297: .'<input type="hidden" name="srchby" value="'.$env{'form.srchby'}.'" />'
7298: .'<input type="hidden" name="srchtype" value="'.$env{'form.srchtype'}.'" />'
7299: .'<input type="hidden" name="srchterm" value="'.&HTML::Entities::encode($env{'form.srchterm'},'<>"&').'" />'
7300: .'<input type="hidden" name="srchin" value="'.$env{'form.srchin'}.'" />'
7301: .'</form>');
7302: return;
7303: }
7304:
7305: sub earlyout_accesslog_form {
7306: my ($formname,$prevphasestr,$udom) = @_;
7307: my $srchterm = &HTML::Entities::encode($env{'form.srchterm'},'<>"&');
7308: return <<"END";
7309: <form action="/adm/createuser" method="post" name="$formname">
7310: <input type="hidden" name="currstate" value="" />
7311: <input type="hidden" name="prevphases" value="$prevphasestr" />
7312: <input type="hidden" name="phase" value="activity" />
7313: <input type="hidden" name="action" value="accesslogs" />
7314: <input type="hidden" name="srchdomain" value="$udom" />
7315: <input type="hidden" name="srchby" value="$env{'form.srchby'}" />
7316: <input type="hidden" name="srchtype" value="$env{'form.srchtype'}" />
7317: <input type="hidden" name="srchterm" value="$srchterm" />
7318: <input type="hidden" name="srchin" value="$env{'form.srchin'}" />
7319: </form>
7320: END
7321: }
7322:
7323: sub activity_display_filter {
7324: my ($formname,$curr) = @_;
7325: my $nolink = 1;
7326: my $output = '<table><tr><td valign="top">'.
7327: '<span class="LC_nobreak"><b>'.&mt('Actions/page:').'</b></span><br />'.
7328: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
7329: (&mt('all'),5,10,20,50,100,1000,10000)).
7330: '</td><td> </td>';
7331: my $startform =
7332: &Apache::lonhtmlcommon::date_setter($formname,'accesslog_start_date',
7333: $curr->{'accesslog_start_date'},undef,
7334: undef,undef,undef,undef,undef,undef,$nolink);
7335: my $endform =
7336: &Apache::lonhtmlcommon::date_setter($formname,'accesslog_end_date',
7337: $curr->{'accesslog_end_date'},undef,
7338: undef,undef,undef,undef,undef,undef,$nolink);
7339: my %lt = &Apache::lonlocal::texthash (
7340: activity => 'Activity',
7341: Role => 'Role selection',
7342: log => 'Log-in or Logout',
7343: );
7344: $output .= '<td valign="top"><b>'.&mt('Window during which actions occurred:').'</b><br />'.
7345: '<table><tr><td>'.&mt('After:').
7346: '</td><td>'.$startform.'</td></tr>'.
7347: '<tr><td>'.&mt('Before:').'</td>'.
7348: '<td>'.$endform.'</td></tr></table>'.
7349: '</td>'.
7350: '<td> </td>'.
7351: '<td valign="top"><b>'.&mt('Activities').'</b><br />'.
7352: '<select name="activity"><option value="any"';
7353: if ($curr->{'activity'} eq 'any') {
7354: $output .= ' selected="selected"';
7355: }
7356: $output .= '>'.&mt('Any').'</option>'."\n";
7357: foreach my $activity ('Role','log') {
7358: my $selstr = '';
7359: if ($activity eq $curr->{'activity'}) {
7360: $selstr = ' selected="selected"';
7361: }
7362: $output .= '<option value="'.$activity.'"'.$selstr.'>'.$lt{$activity}.'</option>';
7363: }
7364: $output .= '</select></td>'.
7365: '</tr></table>';
7366: # Update Display button
7367: $output .= '<p>'
7368: .'<input type="submit" value="'.&mt('Update Display').'" />'
1.431 raeburn 7369: .'</p><hr />';
1.416 raeburn 7370: return $output;
7371: }
7372:
1.415 raeburn 7373: sub userlogdisplay_js {
7374: my ($formname) = @_;
7375: return <<"ENDSCRIPT";
7376:
1.239 raeburn 7377: function chgPage(caller) {
7378: if (caller == 'previous') {
7379: document.$formname.page.value --;
7380: }
7381: if (caller == 'next') {
7382: document.$formname.page.value ++;
7383: }
1.327 raeburn 7384: document.$formname.submit();
1.239 raeburn 7385: return;
7386: }
7387: ENDSCRIPT
1.415 raeburn 7388: }
7389:
7390: sub userlogdisplay_navlinks {
7391: my ($curr,$more_records) = @_;
7392: return unless(ref($curr) eq 'HASH');
7393: # Navigation Buttons
7394: my $nav_links = '<p>';
7395: if (($curr->{'page'} > 1) || ($more_records)) {
7396: if (($curr->{'page'} > 1) && ($curr->{'show'} !~ /\D/)) {
7397: $nav_links .= '<input type="button"'
7398: .' onclick="javascript:chgPage('."'previous'".');"'
7399: .' value="'.&mt('Previous [_1] changes',$curr->{'show'})
7400: .'" /> ';
7401: }
7402: if ($more_records) {
7403: $nav_links .= '<input type="button"'
7404: .' onclick="javascript:chgPage('."'next'".');"'
7405: .' value="'.&mt('Next [_1] changes',$curr->{'show'})
7406: .'" />';
1.301 bisitz 7407: }
7408: }
1.415 raeburn 7409: $nav_links .= '</p>';
7410: return $nav_links;
1.239 raeburn 7411: }
7412:
7413: sub role_display_filter {
1.363 raeburn 7414: my ($context,$formname,$cdom,$cnum,$curr,$version,$crstype) = @_;
7415: my $lctype;
7416: if ($context eq 'course') {
7417: $lctype = lc($crstype);
7418: }
1.239 raeburn 7419: my $nolink = 1;
7420: my $output = '<table><tr><td valign="top">'.
1.301 bisitz 7421: '<span class="LC_nobreak"><b>'.&mt('Changes/page:').'</b></span><br />'.
1.239 raeburn 7422: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
7423: (&mt('all'),5,10,20,50,100,1000,10000)).
7424: '</td><td> </td>';
7425: my $startform =
7426: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_start_date',
7427: $curr->{'rolelog_start_date'},undef,
7428: undef,undef,undef,undef,undef,undef,$nolink);
7429: my $endform =
7430: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_end_date',
7431: $curr->{'rolelog_end_date'},undef,
7432: undef,undef,undef,undef,undef,undef,$nolink);
1.363 raeburn 7433: my %lt = &rolechg_contexts($context,$crstype);
1.301 bisitz 7434: $output .= '<td valign="top"><b>'.&mt('Window during which changes occurred:').'</b><br />'.
7435: '<table><tr><td>'.&mt('After:').
7436: '</td><td>'.$startform.'</td></tr>'.
7437: '<tr><td>'.&mt('Before:').'</td>'.
7438: '<td>'.$endform.'</td></tr></table>'.
7439: '</td>'.
7440: '<td> </td>'.
1.239 raeburn 7441: '<td valign="top"><b>'.&mt('Role:').'</b><br />'.
7442: '<select name="role"><option value="any"';
7443: if ($curr->{'role'} eq 'any') {
7444: $output .= ' selected="selected"';
7445: }
7446: $output .= '>'.&mt('Any').'</option>'."\n";
1.363 raeburn 7447: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
1.239 raeburn 7448: foreach my $role (@roles) {
7449: my $plrole;
7450: if ($role eq 'cr') {
7451: $plrole = &mt('Custom Role');
7452: } else {
1.318 raeburn 7453: $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.239 raeburn 7454: }
7455: my $selstr = '';
7456: if ($role eq $curr->{'role'}) {
7457: $selstr = ' selected="selected"';
7458: }
7459: $output .= ' <option value="'.$role.'"'.$selstr.'>'.$plrole.'</option>';
7460: }
1.301 bisitz 7461: $output .= '</select></td>'.
7462: '<td> </td>'.
7463: '<td valign="top"><b>'.
1.239 raeburn 7464: &mt('Context:').'</b><br /><select name="chgcontext">';
1.363 raeburn 7465: my @posscontexts;
7466: if ($context eq 'course') {
1.376 raeburn 7467: @posscontexts = ('any','automated','updatenow','createcourse','course','domain','selfenroll','requestcourses');
1.363 raeburn 7468: } elsif ($context eq 'domain') {
7469: @posscontexts = ('any','domain','requestauthor','domconfig','server');
7470: } else {
7471: @posscontexts = ('any','author','domain');
7472: }
7473: foreach my $chgtype (@posscontexts) {
1.239 raeburn 7474: my $selstr = '';
7475: if ($curr->{'chgcontext'} eq $chgtype) {
1.301 bisitz 7476: $selstr = ' selected="selected"';
1.239 raeburn 7477: }
1.363 raeburn 7478: if ($context eq 'course') {
1.376 raeburn 7479: if (($chgtype eq 'automated') || ($chgtype eq 'updatenow')) {
1.363 raeburn 7480: next if (!&Apache::lonnet::auto_run($cnum,$cdom));
7481: }
1.239 raeburn 7482: }
7483: $output .= '<option value="'.$chgtype.'"'.$selstr.'>'.$lt{$chgtype}.'</option>'."\n";
1.248 raeburn 7484: }
1.303 bisitz 7485: $output .= '</select></td>'
7486: .'</tr></table>';
7487:
7488: # Update Display button
7489: $output .= '<p>'
7490: .'<input type="submit" value="'.&mt('Update Display').'" />'
7491: .'</p>';
7492:
7493: # Server version info
1.363 raeburn 7494: my $needsrev = '2.11.0';
7495: if ($context eq 'course') {
7496: $needsrev = '2.7.0';
7497: }
7498:
1.303 bisitz 7499: $output .= '<p class="LC_info">'
7500: .&mt('Only changes made from servers running LON-CAPA [_1] or later are displayed.'
1.363 raeburn 7501: ,$needsrev);
1.248 raeburn 7502: if ($version) {
1.303 bisitz 7503: $output .= ' '.&mt('This LON-CAPA server is version [_1]',$version);
7504: }
7505: $output .= '</p><hr />';
1.239 raeburn 7506: return $output;
7507: }
7508:
7509: sub rolechg_contexts {
1.363 raeburn 7510: my ($context,$crstype) = @_;
7511: my %lt;
7512: if ($context eq 'course') {
7513: %lt = &Apache::lonlocal::texthash (
1.239 raeburn 7514: any => 'Any',
1.376 raeburn 7515: automated => 'Automated Enrollment',
1.239 raeburn 7516: updatenow => 'Roster Update',
7517: createcourse => 'Course Creation',
7518: course => 'User Management in course',
7519: domain => 'User Management in domain',
1.313 raeburn 7520: selfenroll => 'Self-enrolled',
1.318 raeburn 7521: requestcourses => 'Course Request',
1.239 raeburn 7522: );
1.363 raeburn 7523: if ($crstype eq 'Community') {
7524: $lt{'createcourse'} = &mt('Community Creation');
7525: $lt{'course'} = &mt('User Management in community');
7526: $lt{'requestcourses'} = &mt('Community Request');
7527: }
7528: } elsif ($context eq 'domain') {
7529: %lt = &Apache::lonlocal::texthash (
7530: any => 'Any',
7531: domain => 'User Management in domain',
7532: requestauthor => 'Authoring Request',
7533: server => 'Command line script (DC role)',
7534: domconfig => 'Self-enrolled',
7535: );
7536: } else {
7537: %lt = &Apache::lonlocal::texthash (
7538: any => 'Any',
7539: domain => 'User Management in domain',
7540: author => 'User Management by author',
7541: );
7542: }
1.239 raeburn 7543: return %lt;
7544: }
7545:
1.428 raeburn 7546: sub print_helpdeskaccess_display {
7547: my ($r,$permission,$brcrum) = @_;
7548: my $formname = 'helpdeskaccess';
7549: my $helpitem = 'Course_Helpdesk_Access';
7550: push (@{$brcrum},
7551: {href => '/adm/createuser?action=helpdesk',
7552: text => 'Helpdesk Access',
7553: help => $helpitem});
7554: my $bread_crumbs_component = 'Helpdesk Staff Access';
7555: my $args = { bread_crumbs => $brcrum,
7556: bread_crumbs_component => $bread_crumbs_component};
7557:
7558: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
7559: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
7560: my $confname = $cdom.'-domainconfig';
7561: my $crstype = &Apache::loncommon::course_type();
7562:
1.434 raeburn 7563: my @accesstypes = ('all','dh','da','none');
1.428 raeburn 7564: my ($numstatustypes,@jsarray);
7565: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($cdom);
7566: if (ref($types) eq 'ARRAY') {
1.430 raeburn 7567: if (@{$types} > 0) {
1.428 raeburn 7568: $numstatustypes = scalar(@{$types});
7569: push(@accesstypes,'status');
7570: @jsarray = ('bystatus');
7571: }
7572: }
7573: my %customroles = &get_domain_customroles($cdom,$confname);
1.432 raeburn 7574: my %domhelpdesk = &Apache::lonnet::get_active_domroles($cdom,['dh','da']);
1.428 raeburn 7575: if (keys(%domhelpdesk)) {
7576: push(@accesstypes,('inc','exc'));
7577: push(@jsarray,('notinc','notexc'));
7578: }
7579: push(@jsarray,'privs');
7580: my $hiddenstr = join("','",@jsarray);
7581: my $rolestr = join("','",sort(keys(%customroles)));
7582:
7583: my $jscript;
7584: my (%settings,%overridden);
7585: if (keys(%customroles)) {
7586: &get_adhocrole_settings($env{'request.course.id'},\@accesstypes,
7587: $types,\%customroles,\%settings,\%overridden);
7588: my %jsfull=();
7589: my %jslevels= (
7590: course => {},
7591: domain => {},
7592: system => {},
7593: );
7594: my %jslevelscurrent=(
7595: course => {},
7596: domain => {},
7597: system => {},
7598: );
7599: my (%privs,%jsprivs);
7600: &Apache::lonuserutils::custom_role_privs(\%privs,\%jsfull,\%jslevels,\%jslevelscurrent);
7601: foreach my $priv (keys(%jsfull)) {
7602: if ($jslevels{'course'}{$priv}) {
7603: $jsprivs{$priv} = 1;
7604: }
7605: }
7606: my (%elements,%stored);
7607: foreach my $role (keys(%customroles)) {
7608: $elements{$role.'_access'} = 'radio';
7609: $elements{$role.'_incrs'} = 'radio';
7610: if ($numstatustypes) {
7611: $elements{$role.'_status'} = 'checkbox';
7612: }
7613: if (keys(%domhelpdesk) > 0) {
7614: $elements{$role.'_staff_inc'} = 'checkbox';
7615: $elements{$role.'_staff_exc'} = 'checkbox';
7616: }
1.430 raeburn 7617: $elements{$role.'_override'} = 'checkbox';
1.428 raeburn 7618: if (ref($settings{$role}) eq 'HASH') {
7619: if ($settings{$role}{'access'} ne '') {
7620: my $curraccess = $settings{$role}{'access'};
7621: $stored{$role.'_access'} = $curraccess;
7622: $stored{$role.'_incrs'} = 1;
7623: if ($curraccess eq 'status') {
7624: if (ref($settings{$role}{'status'}) eq 'ARRAY') {
7625: $stored{$role.'_status'} = $settings{$role}{'status'};
7626: }
7627: } elsif (($curraccess eq 'exc') || ($curraccess eq 'inc')) {
7628: if (ref($settings{$role}{$curraccess}) eq 'ARRAY') {
7629: $stored{$role.'_staff_'.$curraccess} = $settings{$role}{$curraccess};
7630: }
7631: }
7632: } else {
7633: $stored{$role.'_incrs'} = 0;
7634: }
7635: $stored{$role.'_override'} = [];
7636: if ($env{'course.'.$env{'request.course.id'}.'.internal.adhocpriv.'.$role}) {
7637: if (ref($settings{$role}{'off'}) eq 'ARRAY') {
7638: foreach my $priv (@{$settings{$role}{'off'}}) {
7639: push(@{$stored{$role.'_override'}},$priv);
7640: }
7641: }
7642: if (ref($settings{$role}{'on'}) eq 'ARRAY') {
7643: foreach my $priv (@{$settings{$role}{'on'}}) {
7644: unless (grep(/^$priv$/,@{$stored{$role.'_override'}})) {
7645: push(@{$stored{$role.'_override'}},$priv);
7646: }
7647: }
7648: }
7649: }
7650: } else {
7651: $stored{$role.'_incrs'} = 0;
7652: }
7653: }
7654: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements,\%stored);
7655: }
7656:
7657: my $js = <<"ENDJS";
7658: <script type="text/javascript">
7659: // <![CDATA[
7660: $jscript;
7661:
7662: function switchRoleTab(caller,role) {
7663: if (document.getElementById(role+'_maindiv')) {
7664: if (caller.id != 'LC_current_minitab') {
7665: if (document.getElementById('LC_current_minitab')) {
7666: document.getElementById('LC_current_minitab').id=null;
7667: }
7668: var roledivs = Array('$rolestr');
7669: if (roledivs.length > 0) {
7670: for (var i=0; i<roledivs.length; i++) {
7671: if (document.getElementById(roledivs[i]+'_maindiv')) {
7672: document.getElementById(roledivs[i]+'_maindiv').style.display='none';
7673: }
7674: }
7675: }
7676: caller.id = 'LC_current_minitab';
7677: document.getElementById(role+'_maindiv').style.display='block';
7678: }
7679: }
7680: return false;
1.430 raeburn 7681: }
1.428 raeburn 7682:
7683: function helpdeskAccess(role) {
7684: var curraccess = null;
7685: if (document.$formname.elements[role+'_access'].length) {
7686: for (var i=0; i<document.$formname.elements[role+'_access'].length; i++) {
7687: if (document.$formname.elements[role+'_access'][i].checked) {
7688: curraccess = document.$formname.elements[role+'_access'][i].value;
7689: }
7690: }
7691: }
7692: var shown = Array();
7693: var hidden = Array();
7694: if (curraccess == 'none') {
1.430 raeburn 7695: hidden = Array ('$hiddenstr');
1.428 raeburn 7696: } else {
7697: if (curraccess == 'status') {
1.430 raeburn 7698: shown = Array ('bystatus','privs');
7699: hidden = Array ('notinc','notexc');
1.428 raeburn 7700: } else {
7701: if (curraccess == 'exc') {
7702: shown = Array ('notexc','privs');
7703: hidden = Array ('notinc','bystatus');
7704: }
7705: if (curraccess == 'inc') {
7706: shown = Array ('notinc','privs');
7707: hidden = Array ('notexc','bystatus');
7708: }
7709: if (curraccess == 'all') {
7710: shown = Array ('privs');
7711: hidden = Array ('notinc','notexc','bystatus');
7712: }
7713: }
7714: }
7715: if (hidden.length > 0) {
7716: for (var i=0; i<hidden.length; i++) {
7717: if (document.getElementById(role+'_'+hidden[i])) {
1.430 raeburn 7718: document.getElementById(role+'_'+hidden[i]).style.display = 'none';
1.428 raeburn 7719: }
7720: }
7721: }
7722: if (shown.length > 0) {
7723: for (var i=0; i<shown.length; i++) {
7724: if (document.getElementById(role+'_'+shown[i])) {
7725: if (shown[i] == 'privs') {
7726: document.getElementById(role+'_'+shown[i]).style.display = 'block';
7727: } else {
7728: document.getElementById(role+'_'+shown[i]).style.display = 'inline';
7729: }
7730: }
7731: }
7732: }
7733: return;
7734: }
7735:
7736: function toggleAccess(role) {
7737: if ((document.getElementById(role+'_setincrs')) &&
7738: (document.getElementById(role+'_setindom'))) {
7739: for (var i=0; i<document.$formname.elements[role+'_incrs'].length; i++) {
7740: if (document.$formname.elements[role+'_incrs'][i].checked) {
7741: if (document.$formname.elements[role+'_incrs'][i].value == 1) {
7742: document.getElementById(role+'_setindom').style.display = 'none';
1.430 raeburn 7743: document.getElementById(role+'_setincrs').style.display = 'block';
1.428 raeburn 7744: } else {
7745: document.getElementById(role+'_setincrs').style.display = 'none';
7746: document.getElementById(role+'_setindom').style.display = 'block';
7747: }
7748: break;
7749: }
7750: }
7751: }
7752: return;
7753: }
7754:
7755: // ]]>
7756: </script>
7757: ENDJS
7758:
7759: $args->{add_entries} = {onload => "javascript:setFormElements(document.$formname)"};
7760:
7761: # print page header
7762: $r->print(&header($js,$args));
7763: # print form header
7764: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">');
7765:
7766: if (keys(%customroles)) {
7767: my %lt = &Apache::lonlocal::texthash(
7768: 'aco' => 'As course owner you may override the defaults set in the domain for role usage and/or privileges.',
7769: 'rou' => 'Role usage',
7770: 'whi' => 'Which helpdesk personnel may use this role?',
7771: 'udd' => 'Use domain default',
1.433 raeburn 7772: 'all' => 'All with domain helpdesk or helpdesk assistant role',
1.434 raeburn 7773: 'dh' => 'All with domain helpdesk role',
7774: 'da' => 'All with domain helpdesk assistant role',
1.428 raeburn 7775: 'none' => 'None',
7776: 'status' => 'Determined based on institutional status',
1.430 raeburn 7777: 'inc' => 'Include all, but exclude specific personnel',
1.428 raeburn 7778: 'exc' => 'Exclude all, but include specific personnel',
7779: 'hel' => 'Helpdesk',
7780: 'rpr' => 'Role privileges',
7781: );
7782: $lt{'tfh'} = &mt("Custom [_1]ad hoc[_2] course roles available for use by the domain's helpdesk are as follows",'<i>','</i>');
7783: my %domconfig = &Apache::lonnet::get_dom('configuration',['helpsettings'],$cdom);
7784: my (%domcurrent,%ordered,%description,%domusage,$disabled);
7785: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
7786: if (ref($domconfig{'helpsettings'}{'adhoc'}) eq 'HASH') {
7787: %domcurrent = %{$domconfig{'helpsettings'}{'adhoc'}};
7788: }
7789: }
7790: my $count = 0;
7791: foreach my $role (sort(keys(%customroles))) {
7792: my ($order,$desc,$access_in_dom);
7793: if (ref($domcurrent{$role}) eq 'HASH') {
7794: $order = $domcurrent{$role}{'order'};
7795: $desc = $domcurrent{$role}{'desc'};
7796: $access_in_dom = $domcurrent{$role}{'access'};
7797: }
7798: if ($order eq '') {
7799: $order = $count;
7800: }
7801: $ordered{$order} = $role;
7802: if ($desc ne '') {
7803: $description{$role} = $desc;
7804: } else {
7805: $description{$role}= $role;
7806: }
7807: $count++;
7808: }
7809: %domusage = &domain_adhoc_access(\%customroles,\%domcurrent,\@accesstypes,$usertypes,$othertitle);
7810: my @roles_by_num = ();
7811: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
7812: push(@roles_by_num,$ordered{$item});
1.430 raeburn 7813: }
1.429 raeburn 7814: $r->print('<p>'.$lt{'tfh'}.': <i>'.join('</i>, <i>',map { $description{$_}; } @roles_by_num).'</i>.');
1.428 raeburn 7815: if ($permission->{'owner'}) {
7816: $r->print('<br />'.$lt{'aco'}.'</p><p>');
7817: $r->print('<input type="hidden" name="state" value="process" />'.
7818: '<input type="submit" value="'.&mt('Save changes').'" />');
7819: } else {
7820: if ($env{'course.'.$env{'request.course.id'}.'.internal.courseowner'}) {
7821: my ($ownername,$ownerdom) = split(/:/,$env{'course.'.$env{'request.course.id'}.'.internal.courseowner'});
7822: $r->print('<br />'.&mt('The course owner -- [_1] -- can override the default access and/or privileges for these ad hoc roles.',
7823: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($ownername,$ownerdom),$ownername,$ownerdom)));
7824: }
7825: $disabled = ' disabled="disabled"';
7826: }
7827: $r->print('</p>');
7828:
7829: $r->print('<div id="LC_minitab_header"><ul>');
7830: my $count = 0;
7831: my %visibility;
7832: foreach my $role (@roles_by_num) {
7833: my $id;
7834: if ($count == 0) {
7835: $id=' id="LC_current_minitab"';
1.430 raeburn 7836: $visibility{$role} = ' style="display:block"';
1.428 raeburn 7837: } else {
7838: $visibility{$role} = ' style="display:none"';
7839: }
7840: $count ++;
7841: $r->print('<li'.$id.'><a href="#" onclick="javascript:switchRoleTab(this.parentNode,'."'$role'".');">'.$description{$role}.'</a></li>');
7842: }
7843: $r->print('</ul></div>');
7844:
7845: foreach my $role (@roles_by_num) {
7846: my %usecheck = (
7847: all => ' checked="checked"',
7848: );
7849: my %displaydiv = (
7850: status => 'none',
7851: inc => 'none',
7852: exc => 'none',
7853: priv => 'block',
7854: );
7855: my (%selected,$overridden,$incrscheck,$indomcheck,$indomvis,$incrsvis);
1.430 raeburn 7856: if (ref($settings{$role}) eq 'HASH') {
1.428 raeburn 7857: if ($settings{$role}{'access'} ne '') {
7858: $indomvis = ' style="display:none"';
7859: $incrsvis = ' style="display:block"';
1.430 raeburn 7860: $incrscheck = ' checked="checked"';
1.428 raeburn 7861: if ($settings{$role}{'access'} ne 'all') {
7862: $usecheck{$settings{$role}{'access'}} = $usecheck{'all'};
7863: delete($usecheck{'all'});
7864: if ($settings{$role}{'access'} eq 'status') {
7865: my $access = 'status';
7866: $displaydiv{$access} = 'inline';
7867: if (ref($settings{$role}{$access}) eq 'ARRAY') {
7868: $selected{$access} = $settings{$role}{$access};
7869: }
7870: } elsif ($settings{$role}{'access'} =~ /^(inc|exc)$/) {
7871: my $access = $1;
7872: $displaydiv{$access} = 'inline';
7873: if (ref($settings{$role}{$access}) eq 'ARRAY') {
7874: $selected{$access} = $settings{$role}{$access};
7875: }
7876: } elsif ($settings{$role}{'access'} eq 'none') {
7877: $displaydiv{'priv'} = 'none';
7878: }
7879: }
7880: } else {
7881: $indomcheck = ' checked="checked"';
7882: $indomvis = ' style="display:block"';
7883: $incrsvis = ' style="display:none"';
7884: }
7885: } else {
7886: $indomcheck = ' checked="checked"';
1.430 raeburn 7887: $indomvis = ' style="display:block"';
1.428 raeburn 7888: $incrsvis = ' style="display:none"';
7889: }
7890: $r->print('<div class="LC_left_float" id="'.$role.'_maindiv"'.$visibility{$role}.'>'.
7891: '<fieldset><legend>'.$lt{'rou'}.'</legend>'.
7892: '<p>'.$lt{'whi'}.' <span class="LC_nobreak">'.
7893: '<label><input type="radio" name="'.$role.'_incrs" value="1"'.$incrscheck.' onclick="toggleAccess('."'$role'".');"'.$disabled.'>'.
7894: &mt('Set here in [_1]',lc($crstype)).'</label>'.
7895: '<span>'.(' 'x2).
7896: '<label><input type="radio" name="'.$role.'_incrs" value="0"'.$indomcheck.' onclick="toggleAccess('."'$role'".');"'.$disabled.'>'.
7897: $lt{'udd'}.'</label><span></p>'.
7898: '<div id="'.$role.'_setindom"'.$indomvis.'>'.
7899: '<span class="LC_cusr_emph">'.$domusage{$role}.'</span></div>'.
7900: '<div id="'.$role.'_setincrs"'.$incrsvis.'>');
7901: foreach my $access (@accesstypes) {
7902: $r->print('<p><label><input type="radio" name="'.$role.'_access" value="'.$access.'" '.$usecheck{$access}.
7903: ' onclick="helpdeskAccess('."'$role'".');"'.$disabled.' />'.$lt{$access}.'</label>');
7904: if ($access eq 'status') {
7905: $r->print('<div id="'.$role.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
7906: &Apache::lonuserutils::adhoc_status_types($cdom,undef,$role,$selected{$access},
7907: $othertitle,$usertypes,$types,$disabled).
7908: '</div>');
7909: } elsif (($access eq 'inc') && (keys(%domhelpdesk) > 0)) {
7910: $r->print('<div id="'.$role.'_notinc" style="display:'.$displaydiv{$access}.'">'.
7911: &Apache::lonuserutils::adhoc_staff($access,undef,$role,$selected{$access},
7912: \%domhelpdesk,$disabled).
7913: '</div>');
7914: } elsif (($access eq 'exc') && (keys(%domhelpdesk) > 0)) {
7915: $r->print('<div id="'.$role.'_notexc" style="display:'.$displaydiv{$access}.'">'.
7916: &Apache::lonuserutils::adhoc_staff($access,undef,$role,$selected{$access},
7917: \%domhelpdesk,$disabled).
7918: '</div>');
7919: }
7920: $r->print('</p>');
7921: }
7922: $r->print('</div></fieldset>');
7923: my %full=();
7924: my %levels= (
7925: course => {},
7926: domain => {},
7927: system => {},
7928: );
7929: my %levelscurrent=(
7930: course => {},
7931: domain => {},
7932: system => {},
7933: );
7934: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
7935: $r->print('<fieldset id="'.$role.'_privs" style="display:'.$displaydiv{'priv'}.'">'.
7936: '<legend>'.$lt{'rpr'}.'</legend>'.
7937: &role_priv_table($role,$permission,$crstype,\%full,\%levels,\%levelscurrent,$overridden{$role}).
7938: '</fieldset></div><div style="padding:0;clear:both;margin:0;border:0"></div>');
7939: }
1.429 raeburn 7940: if ($permission->{'owner'}) {
7941: $r->print('<p><input type="submit" value="'.&mt('Save changes').'" /></p>');
7942: }
1.428 raeburn 7943: } else {
7944: $r->print(&mt('Helpdesk roles have not yet been created in this domain.'));
7945: }
7946: # Form Footer
7947: $r->print('<input type="hidden" name="action" value="helpdesk" />'
7948: .'</form>');
7949: return;
7950: }
7951:
7952: sub domain_adhoc_access {
7953: my ($roles,$domcurrent,$accesstypes,$usertypes,$othertitle) = @_;
7954: my %domusage;
7955: return unless ((ref($roles) eq 'HASH') && (ref($domcurrent) eq 'HASH') && (ref($accesstypes) eq 'ARRAY'));
7956: foreach my $role (keys(%{$roles})) {
7957: if (ref($domcurrent->{$role}) eq 'HASH') {
7958: my $access = $domcurrent->{$role}{'access'};
7959: if (($access eq '') || (!grep(/^\Q$access\E$/,@{$accesstypes}))) {
7960: $access = 'all';
1.432 raeburn 7961: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',&Apache::lonnet::plaintext('dh'),
7962: &Apache::lonnet::plaintext('da'));
1.428 raeburn 7963: } elsif ($access eq 'status') {
7964: if (ref($domcurrent->{$role}{$access}) eq 'ARRAY') {
7965: my @shown;
7966: foreach my $type (@{$domcurrent->{$role}{$access}}) {
7967: unless ($type eq 'default') {
7968: if ($usertypes->{$type}) {
7969: push(@shown,$usertypes->{$type});
7970: }
7971: }
7972: }
7973: if (grep(/^default$/,@{$domcurrent->{$role}{$access}})) {
7974: push(@shown,$othertitle);
7975: }
7976: if (@shown) {
7977: my $shownstatus = join(' '.&mt('or').' ',@shown);
1.432 raeburn 7978: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role, and institutional status: [_3]',
7979: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$shownstatus);
1.428 raeburn 7980: } else {
7981: $domusage{$role} = &mt('No one in the domain');
7982: }
7983: }
7984: } elsif ($access eq 'inc') {
7985: my @dominc = ();
7986: if (ref($domcurrent->{$role}{'inc'}) eq 'ARRAY') {
7987: foreach my $user (@{$domcurrent->{$role}{'inc'}}) {
7988: my ($uname,$udom) = split(/:/,$user);
7989: push(@dominc,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom));
7990: }
7991: my $showninc = join(', ',@dominc);
7992: if ($showninc ne '') {
1.432 raeburn 7993: $domusage{$role} = &mt('Include any user in domain with active [_1] or [_2] role, except: [_3]',
7994: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$showninc);
1.428 raeburn 7995: } else {
1.432 raeburn 7996: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
7997: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.428 raeburn 7998: }
7999: }
8000: } elsif ($access eq 'exc') {
8001: my @domexc = ();
8002: if (ref($domcurrent->{$role}{'exc'}) eq 'ARRAY') {
8003: foreach my $user (@{$domcurrent->{$role}{'exc'}}) {
8004: my ($uname,$udom) = split(/:/,$user);
8005: push(@domexc,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom));
8006: }
8007: }
8008: my $shownexc = join(', ',@domexc);
8009: if ($shownexc ne '') {
1.432 raeburn 8010: $domusage{$role} = &mt('Only the following in the domain with active [_1] or [_2] role: [_3]',
8011: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$shownexc);
1.428 raeburn 8012: } else {
8013: $domusage{$role} = &mt('No one in the domain');
8014: }
8015: } elsif ($access eq 'none') {
8016: $domusage{$role} = &mt('No one in the domain');
1.434 raeburn 8017: } elsif ($access eq 'dh') {
1.433 raeburn 8018: $domusage{$role} = &mt('Any user in domain with active [_1] role',&Apache::lonnet::plaintext('dh'));
1.434 raeburn 8019: } elsif ($access eq 'da') {
1.433 raeburn 8020: $domusage{$role} = &mt('Any user in domain with active [_1] role',&Apache::lonnet::plaintext('da'));
1.428 raeburn 8021: } elsif ($access eq 'all') {
1.432 raeburn 8022: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
8023: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.428 raeburn 8024: }
8025: } else {
1.432 raeburn 8026: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
8027: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.428 raeburn 8028: }
8029: }
8030: return %domusage;
8031: }
8032:
8033: sub get_domain_customroles {
8034: my ($cdom,$confname) = @_;
8035: my %existing=&Apache::lonnet::dump('roles',$cdom,$confname,'rolesdef_');
8036: my %customroles;
8037: foreach my $key (keys(%existing)) {
8038: if ($key=~/^rolesdef\_(\w+)$/) {
8039: my $rolename = $1;
8040: my %privs;
8041: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
8042: $customroles{$rolename} = \%privs;
8043: }
8044: }
8045: return %customroles;
8046: }
8047:
8048: sub role_priv_table {
8049: my ($role,$permission,$crstype,$full,$levels,$levelscurrent,$overridden) = @_;
8050: return unless ((ref($full) eq 'HASH') && (ref($levels) eq 'HASH') &&
8051: (ref($levelscurrent) eq 'HASH'));
8052: my %lt=&Apache::lonlocal::texthash (
8053: 'crl' => 'Course Level Privilege',
8054: 'def' => 'Domain Defaults',
8055: 'ove' => 'Override in Course',
8056: 'ine' => 'In effect',
8057: 'dis' => 'Disabled',
8058: 'ena' => 'Enabled',
8059: );
8060: if ($crstype eq 'Community') {
8061: $lt{'ove'} = 'Override in Community',
8062: }
8063: my @status = ('Disabled','Enabled');
8064: my (%on,%off);
8065: if (ref($overridden) eq 'HASH') {
8066: if (ref($overridden->{'on'}) eq 'ARRAY') {
8067: map { $on{$_} = 1; } (@{$overridden->{'on'}});
8068: }
8069: if (ref($overridden->{'off'}) eq 'ARRAY') {
8070: map { $off{$_} = 1; } (@{$overridden->{'off'}});
8071: }
8072: }
8073: my $output=&Apache::loncommon::start_data_table().
8074: &Apache::loncommon::start_data_table_header_row().
8075: '<th>'.$lt{'crl'}.'</th><th>'.$lt{'def'}.'</th><th>'.$lt{'ove'}.
8076: '</th><th>'.$lt{'ine'}.'</th>'.
8077: &Apache::loncommon::end_data_table_header_row();
8078: foreach my $priv (sort(keys(%{$full}))) {
8079: next unless ($levels->{'course'}{$priv});
8080: my $privtext = &Apache::lonnet::plaintext($priv,$crstype);
8081: my ($default,$ineffect);
8082: if ($levelscurrent->{'course'}{$priv}) {
8083: $default = '<img src="/adm/lonIcons/navmap.correct.gif" alt="'.$lt{'ena'}.'" />';
8084: $ineffect = $default;
8085: }
8086: my ($customstatus,$checked);
8087: $output .= &Apache::loncommon::start_data_table_row().
8088: '<td>'.$privtext.'</td>'.
8089: '<td>'.$default.'</td><td>';
8090: if (($levelscurrent->{'course'}{$priv}) && ($off{$priv})) {
8091: if ($permission->{'owner'}) {
8092: $checked = ' checked="checked"';
8093: }
8094: $customstatus = '<img src="/adm/lonIcons/navmap.wrong.gif" alt="'.$lt{'dis'}.'" />';
1.430 raeburn 8095: $ineffect = $customstatus;
1.428 raeburn 8096: } elsif ((!$levelscurrent->{'course'}{$priv}) && ($on{$priv})) {
8097: if ($permission->{'owner'}) {
1.430 raeburn 8098: $checked = ' checked="checked"';
1.428 raeburn 8099: }
8100: $customstatus = '<img src="/adm/lonIcons/navmap.correct.gif" alt="'.$lt{'ena'}.'" />';
1.430 raeburn 8101: $ineffect = $customstatus;
1.428 raeburn 8102: }
8103: if ($permission->{'owner'}) {
8104: $output .= '<input type="checkbox" name="'.$role.'_override" value="'.$priv.'"'.$checked.' />';
8105: } else {
8106: $output .= $customstatus;
8107: }
8108: $output .= '</td><td>'.$ineffect.'</td>'.
8109: &Apache::loncommon::end_data_table_row();
8110: }
8111: $output .= &Apache::loncommon::end_data_table();
8112: return $output;
8113: }
8114:
8115: sub get_adhocrole_settings {
1.430 raeburn 8116: my ($cid,$accesstypes,$types,$customroles,$settings,$overridden) = @_;
1.428 raeburn 8117: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($customroles) eq 'HASH') &&
8118: (ref($settings) eq 'HASH') && (ref($overridden) eq 'HASH'));
8119: foreach my $role (split(/,/,$env{'course.'.$cid.'.internal.adhocaccess'})) {
8120: my ($curraccess,$rest) = split(/=/,$env{'course.'.$cid.'.internal.adhoc.'.$role});
8121: if (($curraccess ne '') && (grep(/^\Q$curraccess\E$/,@{$accesstypes}))) {
8122: $settings->{$role}{'access'} = $curraccess;
8123: if (($curraccess eq 'status') && (ref($types) eq 'ARRAY')) {
8124: my @status = split(/,/,$rest);
8125: my @currstatus;
8126: foreach my $type (@status) {
8127: if ($type eq 'default') {
8128: push(@currstatus,$type);
8129: } elsif (grep(/^\Q$type\E$/,@{$types})) {
8130: push(@currstatus,$type);
8131: }
8132: }
8133: if (@currstatus) {
8134: $settings->{$role}{$curraccess} = \@currstatus;
8135: } elsif (($curraccess eq 'exc') || ($curraccess eq 'inc')) {
8136: my @personnel = split(/,/,$rest);
8137: $settings->{$role}{$curraccess} = \@personnel;
8138: }
8139: }
8140: }
8141: }
8142: foreach my $role (keys(%{$customroles})) {
8143: if ($env{'course.'.$cid.'.internal.adhocpriv.'.$role}) {
8144: my %currentprivs;
8145: if (ref($customroles->{$role}) eq 'HASH') {
8146: if (exists($customroles->{$role}{'course'})) {
8147: my %full=();
8148: my %levels= (
8149: course => {},
8150: domain => {},
8151: system => {},
8152: );
8153: my %levelscurrent=(
8154: course => {},
8155: domain => {},
8156: system => {},
8157: );
8158: &Apache::lonuserutils::custom_role_privs($customroles->{$role},\%full,\%levels,\%levelscurrent);
8159: %currentprivs = %{$levelscurrent{'course'}};
8160: }
8161: }
8162: foreach my $item (split(/,/,$env{'course.'.$cid.'.internal.adhocpriv.'.$role})) {
8163: next if ($item eq '');
8164: my ($rule,$rest) = split(/=/,$item);
8165: next unless (($rule eq 'off') || ($rule eq 'on'));
8166: foreach my $priv (split(/:/,$rest)) {
8167: if ($priv ne '') {
8168: if ($rule eq 'off') {
8169: push(@{$overridden->{$role}{'off'}},$priv);
8170: if ($currentprivs{$priv}) {
8171: push(@{$settings->{$role}{'off'}},$priv);
8172: }
8173: } else {
8174: push(@{$overridden->{$role}{'on'}},$priv);
8175: unless ($currentprivs{$priv}) {
8176: push(@{$settings->{$role}{'on'}},$priv);
8177: }
8178: }
8179: }
8180: }
8181: }
8182: }
8183: }
8184: return;
8185: }
8186:
8187: sub update_helpdeskaccess {
8188: my ($r,$permission,$brcrum) = @_;
8189: my $helpitem = 'Course_Helpdesk_Access';
8190: push (@{$brcrum},
8191: {href => '/adm/createuser?action=helpdesk',
8192: text => 'Helpdesk Access',
8193: help => $helpitem},
8194: {href => '/adm/createuser?action=helpdesk',
8195: text => 'Result',
8196: help => $helpitem}
8197: );
8198: my $bread_crumbs_component = 'Helpdesk Staff Access';
8199: my $args = { bread_crumbs => $brcrum,
8200: bread_crumbs_component => $bread_crumbs_component};
8201:
8202: # print page header
8203: $r->print(&header('',$args));
8204: unless ((ref($permission) eq 'HASH') && ($permission->{'owner'})) {
8205: $r->print('<p class="LC_error">'.&mt('You do not have permission to change helpdesk access.').'</p>');
8206: return;
8207: }
1.434 raeburn 8208: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.428 raeburn 8209: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8210: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
8211: my $confname = $cdom.'-domainconfig';
8212: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($cdom);
8213: my $crstype = &Apache::loncommon::course_type();
8214: my %customroles = &get_domain_customroles($cdom,$confname);
8215: my (%settings,%overridden);
8216: &get_adhocrole_settings($env{'request.course.id'},\@accesstypes,
8217: $types,\%customroles,\%settings,\%overridden);
1.432 raeburn 8218: my %domhelpdesk = &Apache::lonnet::get_active_domroles($cdom,['dh','da']);
1.428 raeburn 8219: my (%changed,%storehash,@todelete);
8220:
8221: if (keys(%customroles)) {
8222: my (%newsettings,@incrs);
8223: foreach my $role (keys(%customroles)) {
8224: $newsettings{$role} = {
8225: access => '',
8226: status => '',
8227: exc => '',
8228: inc => '',
8229: on => '',
8230: off => '',
8231: };
8232: my %current;
8233: if (ref($settings{$role}) eq 'HASH') {
8234: %current = %{$settings{$role}};
8235: }
8236: if (ref($overridden{$role}) eq 'HASH') {
8237: $current{'overridden'} = $overridden{$role};
8238: }
8239: if ($env{'form.'.$role.'_incrs'}) {
8240: my $access = $env{'form.'.$role.'_access'};
8241: if (grep(/^\Q$access\E$/,@accesstypes)) {
8242: push(@incrs,$role);
8243: unless ($current{'access'} eq $access) {
8244: $changed{$role}{'access'} = 1;
1.430 raeburn 8245: $storehash{'internal.adhoc.'.$role} = $access;
1.428 raeburn 8246: }
8247: if ($access eq 'status') {
8248: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$role.'_status');
8249: my @stored;
8250: my @shownstatus;
8251: if (ref($types) eq 'ARRAY') {
8252: foreach my $type (sort(@statuses)) {
8253: if ($type eq 'default') {
8254: push(@stored,$type);
8255: } elsif (grep(/^\Q$type\E$/,@{$types})) {
8256: push(@stored,$type);
8257: push(@shownstatus,$usertypes->{$type});
8258: }
8259: }
8260: if (grep(/^default$/,@statuses)) {
8261: push(@shownstatus,$othertitle);
8262: }
8263: $storehash{'internal.adhoc.'.$role} .= '='.join(',',@stored);
8264: }
8265: $newsettings{$role}{'status'} = join(' '.&mt('or').' ',@shownstatus);
8266: if (ref($current{'status'}) eq 'ARRAY') {
8267: my @diffs = &Apache::loncommon::compare_arrays(\@stored,$current{'status'});
8268: if (@diffs) {
8269: $changed{$role}{'status'} = 1;
8270: }
8271: } elsif (@stored) {
8272: $changed{$role}{'status'} = 1;
8273: }
8274: } elsif (($access eq 'inc') || ($access eq 'exc')) {
8275: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$role.'_staff_'.$access);
8276: my @newspecstaff;
8277: my @stored;
8278: my @currstaff;
8279: foreach my $person (sort(@personnel)) {
8280: if ($domhelpdesk{$person}) {
1.430 raeburn 8281: push(@stored,$person);
1.428 raeburn 8282: }
8283: }
8284: if (ref($current{$access}) eq 'ARRAY') {
8285: my @diffs = &Apache::loncommon::compare_arrays(\@stored,$current{$access});
8286: if (@diffs) {
8287: $changed{$role}{$access} = 1;
8288: }
8289: } elsif (@stored) {
8290: $changed{$role}{$access} = 1;
8291: }
8292: $storehash{'internal.adhoc.'.$role} .= '='.join(',',@stored);
8293: foreach my $person (@stored) {
8294: my ($uname,$udom) = split(/:/,$person);
8295: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
8296: }
8297: $newsettings{$role}{$access} = join(', ',sort(@newspecstaff));
8298: }
8299: $newsettings{$role}{'access'} = $access;
8300: }
8301: } else {
8302: if (($current{'access'} ne '') && (grep(/^\Q$current{'access'}\E$/,@accesstypes))) {
8303: $changed{$role}{'access'} = 1;
8304: $newsettings{$role} = {};
8305: push(@todelete,'internal.adhoc.'.$role);
8306: }
8307: }
8308: if (($env{'form.'.$role.'_incrs'}) && ($env{'form.'.$role.'_access'} eq 'none')) {
8309: if (ref($current{'overridden'}) eq 'HASH') {
8310: push(@todelete,'internal.adhocpriv.'.$role);
8311: }
8312: } else {
8313: my %full=();
8314: my %levels= (
8315: course => {},
8316: domain => {},
8317: system => {},
8318: );
8319: my %levelscurrent=(
8320: course => {},
8321: domain => {},
8322: system => {},
8323: );
8324: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
8325: my (@updatedon,@updatedoff,@override);
8326: @override = &Apache::loncommon::get_env_multiple('form.'.$role.'_override');
1.430 raeburn 8327: if (@override) {
1.428 raeburn 8328: foreach my $priv (sort(keys(%full))) {
8329: next unless ($levels{'course'}{$priv});
8330: if (grep(/^\Q$priv\E$/,@override)) {
8331: if ($levelscurrent{'course'}{$priv}) {
8332: push(@updatedoff,$priv);
8333: } else {
8334: push(@updatedon,$priv);
8335: }
8336: }
8337: }
8338: }
8339: if (@updatedon) {
1.430 raeburn 8340: $newsettings{$role}{'on'} = join('</li><li>', map { &Apache::lonnet::plaintext($_,$crstype) } (@updatedon));
1.428 raeburn 8341: }
8342: if (@updatedoff) {
8343: $newsettings{$role}{'off'} = join('</li><li>', map { &Apache::lonnet::plaintext($_,$crstype) } (@updatedoff));
8344: }
8345: if (ref($current{'overridden'}) eq 'HASH') {
8346: if (ref($current{'overridden'}{'on'}) eq 'ARRAY') {
8347: if (@updatedon) {
8348: my @diffs = &Apache::loncommon::compare_arrays(\@updatedon,$current{'overridden'}{'on'});
8349: if (@diffs) {
8350: $changed{$role}{'on'} = 1;
8351: }
8352: } else {
8353: $changed{$role}{'on'} = 1;
8354: }
8355: } elsif (@updatedon) {
8356: $changed{$role}{'on'} = 1;
8357: }
8358: if (ref($current{'overridden'}{'off'}) eq 'ARRAY') {
8359: if (@updatedoff) {
8360: my @diffs = &Apache::loncommon::compare_arrays(\@updatedoff,$current{'overridden'}{'off'});
8361: if (@diffs) {
8362: $changed{$role}{'off'} = 1;
8363: }
8364: } else {
8365: $changed{$role}{'off'} = 1;
8366: }
8367: } elsif (@updatedoff) {
8368: $changed{$role}{'off'} = 1;
8369: }
8370: } else {
8371: if (@updatedon) {
8372: $changed{$role}{'on'} = 1;
8373: }
8374: if (@updatedoff) {
8375: $changed{$role}{'off'} = 1;
8376: }
8377: }
8378: if (ref($changed{$role}) eq 'HASH') {
8379: if (($changed{$role}{'on'} || $changed{$role}{'off'})) {
8380: my $newpriv;
8381: if (@updatedon) {
8382: $newpriv = 'on='.join(':',@updatedon);
8383: }
8384: if (@updatedoff) {
8385: $newpriv .= ($newpriv ? ',' : '' ).'off='.join(':',@updatedoff);
8386: }
8387: if ($newpriv eq '') {
8388: push(@todelete,'internal.adhocpriv.'.$role);
8389: } else {
8390: $storehash{'internal.adhocpriv.'.$role} = $newpriv;
8391: }
8392: }
8393: }
8394: }
8395: }
8396: if (@incrs) {
8397: $storehash{'internal.adhocaccess'} = join(',',@incrs);
8398: } elsif (@todelete) {
8399: push(@todelete,'internal.adhocaccess');
8400: }
8401: if (keys(%changed)) {
8402: my ($putres,$delres);
8403: if (keys(%storehash)) {
8404: $putres = &Apache::lonnet::put('environment',\%storehash,$cdom,$cnum);
8405: my %newenvhash;
8406: foreach my $key (keys(%storehash)) {
8407: $newenvhash{'course.'.$env{'request.course.id'}.'.'.$key} = $storehash{$key};
8408: }
8409: &Apache::lonnet::appenv(\%newenvhash);
8410: }
8411: if (@todelete) {
8412: $delres = &Apache::lonnet::del('environment',\@todelete,$cdom,$cnum);
8413: foreach my $key (@todelete) {
8414: &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.'.$key);
8415: }
8416: }
8417: if (($putres eq 'ok') || ($delres eq 'ok')) {
8418: my %domconfig = &Apache::lonnet::get_dom('configuration',['helpsettings'],$cdom);
8419: my (%domcurrent,%ordered,%description,%domusage);
8420: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
8421: if (ref($domconfig{'helpsettings'}{'adhoc'}) eq 'HASH') {
8422: %domcurrent = %{$domconfig{'helpsettings'}{'adhoc'}};
8423: }
8424: }
8425: my $count = 0;
8426: foreach my $role (sort(keys(%customroles))) {
8427: my ($order,$desc);
8428: if (ref($domcurrent{$role}) eq 'HASH') {
8429: $order = $domcurrent{$role}{'order'};
8430: $desc = $domcurrent{$role}{'desc'};
8431: }
8432: if ($order eq '') {
8433: $order = $count;
8434: }
8435: $ordered{$order} = $role;
8436: if ($desc ne '') {
8437: $description{$role} = $desc;
8438: } else {
8439: $description{$role}= $role;
8440: }
8441: $count++;
8442: }
8443: my @roles_by_num = ();
8444: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
8445: push(@roles_by_num,$ordered{$item});
8446: }
8447: %domusage = &domain_adhoc_access(\%changed,\%domcurrent,\@accesstypes,$usertypes,$othertitle);
1.430 raeburn 8448: $r->print(&mt('Helpdesk access settings have been changed as follows').'<br />');
1.428 raeburn 8449: $r->print('<ul>');
8450: foreach my $role (@roles_by_num) {
8451: next unless (ref($changed{$role}) eq 'HASH');
8452: $r->print('<li>'.&mt('Ad hoc role').': <b>'.$description{$role}.'</b>'.
8453: '<ul>');
1.430 raeburn 8454: if ($changed{$role}{'access'} || $changed{$role}{'status'} || $changed{$role}{'inc'} || $changed{$role}{'exc'}) {
1.428 raeburn 8455: $r->print('<li>');
8456: if ($env{'form.'.$role.'_incrs'}) {
8457: if ($newsettings{$role}{'access'} eq 'all') {
8458: $r->print(&mt('All helpdesk staff can access '.lc($crstype).' with this role.'));
1.434 raeburn 8459: } elsif ($newsettings{$role}{'access'} eq 'dh') {
1.433 raeburn 8460: $r->print(&mt('Helpdesk staff can use this role if they have an active [_1] role',
8461: &Apache::lonnet::plaintext('dh')));
1.434 raeburn 8462: } elsif ($newsettings{$role}{'access'} eq 'da') {
1.433 raeburn 8463: $r->print(&mt('Helpdesk staff can use this role if they have an active [_1] role',
8464: &Apache::lonnet::plaintext('da')));
1.428 raeburn 8465: } elsif ($newsettings{$role}{'access'} eq 'none') {
8466: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
8467: } elsif ($newsettings{$role}{'access'} eq 'status') {
8468: if ($newsettings{$role}{'status'}) {
8469: my ($access,$rest) = split(/=/,$storehash{'internal.adhoc.'.$role});
1.430 raeburn 8470: if (split(/,/,$rest) > 1) {
1.428 raeburn 8471: $r->print(&mt('Helpdesk staff can use this role if their institutional type is one of: [_1].',
8472: $newsettings{$role}{'status'}));
8473: } else {
8474: $r->print(&mt('Helpdesk staff can use this role if their institutional type is: [_1].',
8475: $newsettings{$role}{'status'}));
8476: }
8477: } else {
8478: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
8479: }
8480: } elsif ($newsettings{$role}{'access'} eq 'exc') {
8481: if ($newsettings{$role}{'exc'}) {
8482: $r->print(&mt('Helpdesk staff who can use this role are as follows:').' '.$newsettings{$role}{'exc'}.'.');
8483: } else {
8484: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
8485: }
8486: } elsif ($newsettings{$role}{'access'} eq 'inc') {
8487: if ($newsettings{$role}{'inc'}) {
8488: $r->print(&mt('All helpdesk staff may use this role except the following:').' '.$newsettings{$role}{'inc'}.'.');
8489: } else {
8490: $r->print(&mt('All helpdesk staff may use this role.'));
8491: }
8492: }
8493: } else {
8494: $r->print(&mt('Default access set in the domain now applies.').'<br />'.
8495: '<span class="LC_cusr_emph">'.$domusage{$role}.'</span>');
8496: }
8497: $r->print('</li>');
8498: }
8499: unless ($newsettings{$role}{'access'} eq 'none') {
8500: if ($changed{$role}{'off'}) {
8501: if ($newsettings{$role}{'off'}) {
8502: $r->print('<li>'.&mt('Privileges which are available by default for this ad hoc role, but are disabled for this specific '.lc($crstype).':').
8503: '<ul><li>'.$newsettings{$role}{'off'}.'</li></ul></li>');
8504: } else {
1.430 raeburn 8505: $r->print('<li>'.&mt('All privileges available by default for this ad hoc role are enabled.').'</li>');
1.428 raeburn 8506: }
8507: }
1.430 raeburn 8508: if ($changed{$role}{'on'}) {
1.428 raeburn 8509: if ($newsettings{$role}{'on'}) {
8510: $r->print('<li>'.&mt('Privileges which are not available by default for this ad hoc role, but are enabled for this specific '.lc($crstype).':').
8511: '<ul><li>'.$newsettings{$role}{'on'}.'</li></ul></li>');
8512: } else {
1.430 raeburn 8513: $r->print('<li>'.&mt('None of the privileges unavailable by default for this ad hoc role are enabled.').'</li>');
1.428 raeburn 8514: }
8515: }
8516: }
8517: $r->print('</ul></li>');
8518: }
8519: $r->print('</ul>');
8520: }
8521: } else {
1.430 raeburn 8522: $r->print(&mt('No changes made to helpdesk access settings.'));
1.428 raeburn 8523: }
8524: }
8525: return;
8526: }
8527:
1.27 matthew 8528: #-------------------------------------------------- functions for &phase_two
1.160 raeburn 8529: sub user_search_result {
1.221 raeburn 8530: my ($context,$srch) = @_;
1.160 raeburn 8531: my %allhomes;
8532: my %inst_matches;
8533: my %srch_results;
1.181 raeburn 8534: my ($response,$currstate,$forcenewuser,$dirsrchres);
1.183 raeburn 8535: $srch->{'srchterm'} =~ s/\s+/ /g;
1.176 raeburn 8536: if ($srch->{'srchby'} !~ /^(uname|lastname|lastfirst)$/) {
1.160 raeburn 8537: $response = &mt('Invalid search.');
8538: }
8539: if ($srch->{'srchin'} !~ /^(crs|dom|alc|instd)$/) {
8540: $response = &mt('Invalid search.');
8541: }
1.177 raeburn 8542: if ($srch->{'srchtype'} !~ /^(exact|contains|begins)$/) {
1.160 raeburn 8543: $response = &mt('Invalid search.');
8544: }
8545: if ($srch->{'srchterm'} eq '') {
8546: $response = &mt('You must enter a search term.');
8547: }
1.183 raeburn 8548: if ($srch->{'srchterm'} =~ /^\s+$/) {
8549: $response = &mt('Your search term must contain more than just spaces.');
8550: }
1.160 raeburn 8551: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'instd')) {
8552: if (($srch->{'srchdomain'} eq '') ||
1.163 albertel 8553: ! (&Apache::lonnet::domain($srch->{'srchdomain'}))) {
1.160 raeburn 8554: $response = &mt('You must specify a valid domain when searching in a domain or institutional directory.')
8555: }
8556: }
8557: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs') ||
8558: ($srch->{'srchin'} eq 'alc')) {
1.176 raeburn 8559: if ($srch->{'srchby'} eq 'uname') {
1.243 raeburn 8560: my $unamecheck = $srch->{'srchterm'};
8561: if ($srch->{'srchtype'} eq 'contains') {
8562: if ($unamecheck !~ /^\w/) {
8563: $unamecheck = 'a'.$unamecheck;
8564: }
8565: }
8566: if ($unamecheck !~ /^$match_username$/) {
1.176 raeburn 8567: $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
8568: }
1.160 raeburn 8569: }
8570: }
1.180 raeburn 8571: if ($response ne '') {
1.413 raeburn 8572: $response = '<span class="LC_warning">'.$response.'</span><br />';
1.180 raeburn 8573: }
1.160 raeburn 8574: if ($srch->{'srchin'} eq 'instd') {
1.412 raeburn 8575: my $instd_chk = &instdirectorysrch_check($srch);
1.160 raeburn 8576: if ($instd_chk ne 'ok') {
1.412 raeburn 8577: my $domd_chk = &domdirectorysrch_check($srch);
1.413 raeburn 8578: $response .= '<span class="LC_warning">'.$instd_chk.'</span><br />';
1.412 raeburn 8579: if ($domd_chk eq 'ok') {
1.435 raeburn 8580: $response .= &mt('You may want to search in the LON-CAPA domain instead of in the institutional directory.');
1.412 raeburn 8581: }
1.415 raeburn 8582: $response .= '<br />';
1.412 raeburn 8583: }
8584: } else {
1.417 raeburn 8585: unless (($context eq 'requestcrs') && ($srch->{'srchtype'} eq 'exact')) {
1.412 raeburn 8586: my $domd_chk = &domdirectorysrch_check($srch);
1.438 raeburn 8587: if (($domd_chk ne 'ok') && ($env{'form.action'} ne 'accesslogs')) {
1.412 raeburn 8588: my $instd_chk = &instdirectorysrch_check($srch);
1.413 raeburn 8589: $response .= '<span class="LC_warning">'.$domd_chk.'</span><br />';
1.412 raeburn 8590: if ($instd_chk eq 'ok') {
1.435 raeburn 8591: $response .= &mt('You may want to search in the institutional directory instead of in the LON-CAPA domain.');
1.412 raeburn 8592: }
1.415 raeburn 8593: $response .= '<br />';
1.412 raeburn 8594: }
1.160 raeburn 8595: }
8596: }
8597: if ($response ne '') {
1.180 raeburn 8598: return ($currstate,$response);
1.160 raeburn 8599: }
8600: if ($srch->{'srchby'} eq 'uname') {
8601: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs')) {
8602: if ($env{'form.forcenew'}) {
8603: if ($srch->{'srchdomain'} ne $env{'request.role.domain'}) {
8604: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
8605: if ($uhome eq 'no_host') {
8606: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
1.180 raeburn 8607: my $showdom = &display_domain_info($env{'request.role.domain'});
8608: $response = &mt('New users can only be created in the domain to which your current role belongs - [_1].',$showdom);
1.160 raeburn 8609: } else {
1.179 raeburn 8610: $currstate = 'modify';
1.160 raeburn 8611: }
8612: } else {
1.179 raeburn 8613: $currstate = 'modify';
1.160 raeburn 8614: }
8615: } else {
8616: if ($srch->{'srchin'} eq 'dom') {
1.162 raeburn 8617: if ($srch->{'srchtype'} eq 'exact') {
8618: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
8619: if ($uhome eq 'no_host') {
1.179 raeburn 8620: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8621: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 8622: } else {
1.179 raeburn 8623: $currstate = 'modify';
1.416 raeburn 8624: if ($env{'form.action'} eq 'accesslogs') {
8625: $currstate = 'activity';
8626: }
1.310 raeburn 8627: my $uname = $srch->{'srchterm'};
8628: my $udom = $srch->{'srchdomain'};
8629: $srch_results{$uname.':'.$udom} =
8630: { &Apache::lonnet::get('environment',
8631: ['firstname',
8632: 'lastname',
8633: 'permanentemail'],
8634: $udom,$uname)
8635: };
1.162 raeburn 8636: }
8637: } else {
8638: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 8639: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8640: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8641: }
8642: } else {
1.167 albertel 8643: my $courseusers = &get_courseusers();
1.162 raeburn 8644: if ($srch->{'srchtype'} eq 'exact') {
1.167 albertel 8645: if (exists($courseusers->{$srch->{'srchterm'}.':'.$srch->{'srchdomain'}})) {
1.179 raeburn 8646: $currstate = 'modify';
1.162 raeburn 8647: } else {
1.179 raeburn 8648: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8649: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 8650: }
1.160 raeburn 8651: } else {
1.167 albertel 8652: foreach my $user (keys(%$courseusers)) {
1.162 raeburn 8653: my ($cuname,$cudomain) = split(/:/,$user);
8654: if ($cudomain eq $srch->{'srchdomain'}) {
1.177 raeburn 8655: my $matched = 0;
8656: if ($srch->{'srchtype'} eq 'begins') {
8657: if ($cuname =~ /^\Q$srch->{'srchterm'}\E/i) {
8658: $matched = 1;
8659: }
8660: } else {
8661: if ($cuname =~ /\Q$srch->{'srchterm'}\E/i) {
8662: $matched = 1;
8663: }
8664: }
8665: if ($matched) {
1.167 albertel 8666: $srch_results{$user} =
8667: {&Apache::lonnet::get('environment',
8668: ['firstname',
8669: 'lastname',
1.194 albertel 8670: 'permanentemail'],
8671: $cudomain,$cuname)};
1.162 raeburn 8672: }
8673: }
8674: }
1.179 raeburn 8675: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8676: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8677: }
8678: }
8679: }
8680: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 8681: $currstate = 'query';
1.160 raeburn 8682: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 8683: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
8684: if ($dirsrchres eq 'ok') {
8685: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8686: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 8687: } else {
8688: my $showdom = &display_domain_info($srch->{'srchdomain'});
8689: $response = '<span class="LC_warning">'.
8690: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
8691: '</span><br />'.
1.435 raeburn 8692: &mt('You may want to search in the LON-CAPA domain instead of in the institutional directory.').
1.415 raeburn 8693: '<br />';
1.181 raeburn 8694: }
1.160 raeburn 8695: }
8696: } else {
8697: if ($srch->{'srchin'} eq 'dom') {
8698: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 8699: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8700: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8701: } elsif ($srch->{'srchin'} eq 'crs') {
1.167 albertel 8702: my $courseusers = &get_courseusers();
8703: foreach my $user (keys(%$courseusers)) {
1.160 raeburn 8704: my ($uname,$udom) = split(/:/,$user);
8705: my %names = &Apache::loncommon::getnames($uname,$udom);
8706: my %emails = &Apache::loncommon::getemails($uname,$udom);
8707: if ($srch->{'srchby'} eq 'lastname') {
8708: if ((($srch->{'srchtype'} eq 'exact') &&
8709: ($names{'lastname'} eq $srch->{'srchterm'})) ||
1.177 raeburn 8710: (($srch->{'srchtype'} eq 'begins') &&
8711: ($names{'lastname'} =~ /^\Q$srch->{'srchterm'}\E/i)) ||
1.160 raeburn 8712: (($srch->{'srchtype'} eq 'contains') &&
8713: ($names{'lastname'} =~ /\Q$srch->{'srchterm'}\E/i))) {
8714: $srch_results{$user} = {firstname => $names{'firstname'},
8715: lastname => $names{'lastname'},
8716: permanentemail => $emails{'permanentemail'},
8717: };
8718: }
8719: } elsif ($srch->{'srchby'} eq 'lastfirst') {
8720: my ($srchlast,$srchfirst) = split(/,/,$srch->{'srchterm'});
1.177 raeburn 8721: $srchlast =~ s/\s+$//;
8722: $srchfirst =~ s/^\s+//;
1.160 raeburn 8723: if ($srch->{'srchtype'} eq 'exact') {
8724: if (($names{'lastname'} eq $srchlast) &&
8725: ($names{'firstname'} eq $srchfirst)) {
8726: $srch_results{$user} = {firstname => $names{'firstname'},
8727: lastname => $names{'lastname'},
8728: permanentemail => $emails{'permanentemail'},
8729:
8730: };
8731: }
1.177 raeburn 8732: } elsif ($srch->{'srchtype'} eq 'begins') {
8733: if (($names{'lastname'} =~ /^\Q$srchlast\E/i) &&
8734: ($names{'firstname'} =~ /^\Q$srchfirst\E/i)) {
8735: $srch_results{$user} = {firstname => $names{'firstname'},
8736: lastname => $names{'lastname'},
8737: permanentemail => $emails{'permanentemail'},
8738: };
8739: }
8740: } else {
1.160 raeburn 8741: if (($names{'lastname'} =~ /\Q$srchlast\E/i) &&
8742: ($names{'firstname'} =~ /\Q$srchfirst\E/i)) {
8743: $srch_results{$user} = {firstname => $names{'firstname'},
8744: lastname => $names{'lastname'},
8745: permanentemail => $emails{'permanentemail'},
8746: };
8747: }
8748: }
8749: }
8750: }
1.179 raeburn 8751: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8752: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8753: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 8754: $currstate = 'query';
1.160 raeburn 8755: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 8756: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
8757: if ($dirsrchres eq 'ok') {
8758: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8759: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 8760: } else {
1.412 raeburn 8761: my $showdom = &display_domain_info($srch->{'srchdomain'});
8762: $response = '<span class="LC_warning">'.
1.181 raeburn 8763: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
8764: '</span><br />'.
1.435 raeburn 8765: &mt('You may want to search in the LON-CAPA domain instead of in the institutional directory.').
1.415 raeburn 8766: '<br />';
1.181 raeburn 8767: }
1.160 raeburn 8768: }
8769: }
1.179 raeburn 8770: return ($currstate,$response,$forcenewuser,\%srch_results);
1.160 raeburn 8771: }
8772:
1.412 raeburn 8773: sub domdirectorysrch_check {
8774: my ($srch) = @_;
8775: my $response;
8776: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
8777: ['directorysrch'],$srch->{'srchdomain'});
8778: my $showdom = &display_domain_info($srch->{'srchdomain'});
8779: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
8780: if ($dom_inst_srch{'directorysrch'}{'lcavailable'} eq '0') {
8781: return &mt('LON-CAPA directory search is not available in domain: [_1]',$showdom);
8782: }
8783: if ($dom_inst_srch{'directorysrch'}{'lclocalonly'}) {
8784: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
8785: return &mt('LON-CAPA directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
8786: }
8787: }
8788: }
8789: return 'ok';
8790: }
8791:
8792: sub instdirectorysrch_check {
1.160 raeburn 8793: my ($srch) = @_;
8794: my $can_search = 0;
8795: my $response;
8796: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
8797: ['directorysrch'],$srch->{'srchdomain'});
1.180 raeburn 8798: my $showdom = &display_domain_info($srch->{'srchdomain'});
1.160 raeburn 8799: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
8800: if (!$dom_inst_srch{'directorysrch'}{'available'}) {
1.180 raeburn 8801: return &mt('Institutional directory search is not available in domain: [_1]',$showdom);
1.160 raeburn 8802: }
8803: if ($dom_inst_srch{'directorysrch'}{'localonly'}) {
8804: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
1.180 raeburn 8805: return &mt('Institutional directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
1.160 raeburn 8806: }
8807: my @usertypes = split(/:/,$env{'environment.inststatus'});
8808: if (!@usertypes) {
8809: push(@usertypes,'default');
8810: }
8811: if (ref($dom_inst_srch{'directorysrch'}{'cansearch'}) eq 'ARRAY') {
8812: foreach my $type (@usertypes) {
8813: if (grep(/^\Q$type\E$/,@{$dom_inst_srch{'directorysrch'}{'cansearch'}})) {
8814: $can_search = 1;
8815: last;
8816: }
8817: }
8818: }
8819: if (!$can_search) {
8820: my ($insttypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($srch->{'srchdomain'});
8821: my @longtypes;
8822: foreach my $item (@usertypes) {
1.229 raeburn 8823: if (defined($insttypes->{$item})) {
8824: push (@longtypes,$insttypes->{$item});
8825: } elsif ($item eq 'default') {
8826: push (@longtypes,&mt('other'));
8827: }
1.160 raeburn 8828: }
8829: my $insttype_str = join(', ',@longtypes);
1.180 raeburn 8830: return &mt('Institutional directory search in domain: [_1] is not available to your user type: ',$showdom).$insttype_str;
1.229 raeburn 8831: }
1.160 raeburn 8832: } else {
8833: $can_search = 1;
8834: }
8835: } else {
1.180 raeburn 8836: return &mt('Institutional directory search has not been configured for domain: [_1]',$showdom);
1.160 raeburn 8837: }
8838: my %longtext = &Apache::lonlocal::texthash (
1.167 albertel 8839: uname => 'username',
1.160 raeburn 8840: lastfirst => 'last name, first name',
1.167 albertel 8841: lastname => 'last name',
1.172 raeburn 8842: contains => 'contains',
1.178 raeburn 8843: exact => 'as exact match to',
8844: begins => 'begins with',
1.160 raeburn 8845: );
8846: if ($can_search) {
8847: if (ref($dom_inst_srch{'directorysrch'}{'searchby'}) eq 'ARRAY') {
8848: if (!grep(/^\Q$srch->{'srchby'}\E$/,@{$dom_inst_srch{'directorysrch'}{'searchby'}})) {
1.180 raeburn 8849: return &mt('Institutional directory search in domain: [_1] is not available for searching by "[_2]"',$showdom,$longtext{$srch->{'srchby'}});
1.160 raeburn 8850: }
8851: } else {
1.180 raeburn 8852: return &mt('Institutional directory search in domain: [_1] is not available.', $showdom);
1.160 raeburn 8853: }
8854: }
8855: if ($can_search) {
1.178 raeburn 8856: if (ref($dom_inst_srch{'directorysrch'}{'searchtypes'}) eq 'ARRAY') {
8857: if (grep(/^\Q$srch->{'srchtype'}\E/,@{$dom_inst_srch{'directorysrch'}{'searchtypes'}})) {
8858: return 'ok';
8859: } else {
1.180 raeburn 8860: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 8861: }
8862: } else {
8863: if ((($dom_inst_srch{'directorysrch'}{'searchtypes'} eq 'specify') &&
8864: ($srch->{'srchtype'} eq 'exact' || $srch->{'srchtype'} eq 'contains')) ||
8865: ($dom_inst_srch{'directorysrch'}{'searchtypes'} eq $srch->{'srchtype'})) {
8866: return 'ok';
8867: } else {
1.180 raeburn 8868: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 8869: }
1.160 raeburn 8870: }
8871: }
8872: }
8873:
8874: sub get_courseusers {
8875: my %advhash;
1.167 albertel 8876: my $classlist = &Apache::loncoursedata::get_classlist();
1.160 raeburn 8877: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles();
8878: foreach my $role (sort(keys(%coursepersonnel))) {
8879: foreach my $user (split(/\,/,$coursepersonnel{$role})) {
1.167 albertel 8880: if (!exists($classlist->{$user})) {
8881: $classlist->{$user} = [];
8882: }
1.160 raeburn 8883: }
8884: }
1.167 albertel 8885: return $classlist;
1.160 raeburn 8886: }
8887:
8888: sub build_search_response {
1.221 raeburn 8889: my ($context,$srch,%srch_results) = @_;
1.179 raeburn 8890: my ($currstate,$response,$forcenewuser);
1.160 raeburn 8891: my %names = (
1.330 bisitz 8892: 'uname' => 'username',
8893: 'lastname' => 'last name',
1.160 raeburn 8894: 'lastfirst' => 'last name, first name',
1.330 bisitz 8895: 'crs' => 'this course',
8896: 'dom' => 'LON-CAPA domain',
8897: 'instd' => 'the institutional directory for domain',
1.160 raeburn 8898: );
8899:
8900: my %single = (
1.180 raeburn 8901: begins => 'A match',
1.160 raeburn 8902: contains => 'A match',
1.180 raeburn 8903: exact => 'An exact match',
1.160 raeburn 8904: );
8905: my %nomatch = (
1.180 raeburn 8906: begins => 'No match',
1.160 raeburn 8907: contains => 'No match',
1.180 raeburn 8908: exact => 'No exact match',
1.160 raeburn 8909: );
8910: if (keys(%srch_results) > 1) {
1.179 raeburn 8911: $currstate = 'select';
1.160 raeburn 8912: } else {
8913: if (keys(%srch_results) == 1) {
1.416 raeburn 8914: if ($env{'form.action'} eq 'accesslogs') {
8915: $currstate = 'activity';
8916: } else {
8917: $currstate = 'modify';
8918: }
1.180 raeburn 8919: $response = &mt("$single{$srch->{'srchtype'}} was found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}.",$srch->{'srchterm'});
8920: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 8921: $response .= ': '.&display_domain_info($srch->{'srchdomain'});
1.180 raeburn 8922: }
1.330 bisitz 8923: } else { # Search has nothing found. Prepare message to user.
8924: $response = '<span class="LC_warning">';
1.180 raeburn 8925: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 8926: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}: [_2]",
8927: '<b>'.$srch->{'srchterm'}.'</b>',
8928: &display_domain_info($srch->{'srchdomain'}));
8929: } else {
8930: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}.",
8931: '<b>'.$srch->{'srchterm'}.'</b>');
1.180 raeburn 8932: }
8933: $response .= '</span>';
1.330 bisitz 8934:
1.160 raeburn 8935: if ($srch->{'srchin'} ne 'alc') {
8936: $forcenewuser = 1;
8937: my $cansrchinst = 0;
1.438 raeburn 8938: if (($srch->{'srchdomain'}) && ($env{'form.action'} ne 'accesslogs')) {
1.160 raeburn 8939: my %domconfig = &Apache::lonnet::get_dom('configuration',['directorysrch'],$srch->{'srchdomain'});
8940: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
8941: if ($domconfig{'directorysrch'}{'available'}) {
8942: $cansrchinst = 1;
8943: }
8944: }
8945: }
1.180 raeburn 8946: if ((($srch->{'srchby'} eq 'lastfirst') ||
8947: ($srch->{'srchby'} eq 'lastname')) &&
8948: ($srch->{'srchin'} eq 'dom')) {
8949: if ($cansrchinst) {
8950: $response .= '<br />'.&mt('You may want to broaden your search to a search of the institutional directory for the domain.');
1.160 raeburn 8951: }
8952: }
1.180 raeburn 8953: if ($srch->{'srchin'} eq 'crs') {
8954: $response .= '<br />'.&mt('You may want to broaden your search to the selected LON-CAPA domain.');
8955: }
8956: }
1.305 raeburn 8957: my $createdom = $env{'request.role.domain'};
8958: if ($context eq 'requestcrs') {
8959: if ($env{'form.coursedom'} ne '') {
8960: $createdom = $env{'form.coursedom'};
8961: }
8962: }
1.416 raeburn 8963: unless (($env{'form.action'} eq 'accesslogs') || (($srch->{'srchby'} eq 'uname') && ($srch->{'srchin'} eq 'dom') &&
8964: ($srch->{'srchtype'} eq 'exact') && ($srch->{'srchdomain'} eq $createdom))) {
1.221 raeburn 8965: my $cancreate =
1.305 raeburn 8966: &Apache::lonuserutils::can_create_user($createdom,$context);
8967: my $targetdom = '<span class="LC_cusr_emph">'.$createdom.'</span>';
1.221 raeburn 8968: if ($cancreate) {
1.305 raeburn 8969: my $showdom = &display_domain_info($createdom);
1.266 bisitz 8970: $response .= '<br /><br />'
8971: .'<b>'.&mt('To add a new user:').'</b>'
1.305 raeburn 8972: .'<br />';
8973: if ($context eq 'requestcrs') {
8974: $response .= &mt("(You can only define new users in the new course's domain - [_1])",$targetdom);
8975: } else {
8976: $response .= &mt("(You can only create new users in your current role's domain - [_1])",$targetdom);
8977: }
8978: $response .='<ul><li>'
1.266 bisitz 8979: .&mt("Set 'Domain/institution to search' to: [_1]",'<span class="LC_cusr_emph">'.$showdom.'</span>')
8980: .'</li><li>'
8981: .&mt("Set 'Search criteria' to: [_1]username is ..... in selected LON-CAPA domain[_2]",'<span class="LC_cusr_emph">','</span>')
8982: .'</li><li>'
8983: .&mt('Provide the proposed username')
8984: .'</li><li>'
8985: .&mt("Click 'Search'")
8986: .'</li></ul><br />';
1.221 raeburn 8987: } else {
1.422 raeburn 8988: unless (($context eq 'domain') && ($env{'form.action'} eq 'singleuser')) {
8989: my $helplink = ' href="javascript:helpMenu('."'display'".')"';
8990: $response .= '<br /><br />';
8991: if ($context eq 'requestcrs') {
8992: $response .= &mt("You are not authorized to define new users in the new course's domain - [_1].",$targetdom);
8993: } else {
8994: $response .= &mt("You are not authorized to create new users in your current role's domain - [_1].",$targetdom);
8995: }
8996: $response .= '<br />'
8997: .&mt('Please contact the [_1]helpdesk[_2] if you need to create a new user.'
8998: ,' <a'.$helplink.'>'
8999: ,'</a>')
9000: .'<br />';
1.305 raeburn 9001: }
1.221 raeburn 9002: }
1.160 raeburn 9003: }
9004: }
9005: }
1.179 raeburn 9006: return ($currstate,$response,$forcenewuser);
1.160 raeburn 9007: }
9008:
1.180 raeburn 9009: sub display_domain_info {
9010: my ($dom) = @_;
9011: my $output = $dom;
9012: if ($dom ne '') {
9013: my $domdesc = &Apache::lonnet::domain($dom,'description');
9014: if ($domdesc ne '') {
9015: $output .= ' <span class="LC_cusr_emph">('.$domdesc.')</span>';
9016: }
9017: }
9018: return $output;
9019: }
9020:
1.160 raeburn 9021: sub crumb_utilities {
9022: my %elements = (
9023: crtuser => {
9024: srchterm => 'text',
1.172 raeburn 9025: srchin => 'selectbox',
1.160 raeburn 9026: srchby => 'selectbox',
9027: srchtype => 'selectbox',
9028: srchdomain => 'selectbox',
9029: },
1.207 raeburn 9030: crtusername => {
9031: srchterm => 'text',
9032: srchdomain => 'selectbox',
9033: },
1.160 raeburn 9034: docustom => {
9035: rolename => 'selectbox',
9036: newrolename => 'textbox',
9037: },
1.179 raeburn 9038: studentform => {
9039: srchterm => 'text',
9040: srchin => 'selectbox',
9041: srchby => 'selectbox',
9042: srchtype => 'selectbox',
9043: srchdomain => 'selectbox',
9044: },
1.160 raeburn 9045: );
9046:
9047: my $jsback .= qq|
9048: function backPage(formname,prevphase,prevstate) {
1.211 raeburn 9049: if (typeof prevphase == 'undefined') {
9050: formname.phase.value = '';
9051: }
9052: else {
9053: formname.phase.value = prevphase;
9054: }
9055: if (typeof prevstate == 'undefined') {
9056: formname.currstate.value = '';
9057: }
9058: else {
9059: formname.currstate.value = prevstate;
9060: }
1.160 raeburn 9061: formname.submit();
9062: }
9063: |;
9064: return ($jsback,\%elements);
9065: }
9066:
1.26 matthew 9067: sub course_level_table {
1.375 raeburn 9068: my ($inccourses,$showcredits,$defaultcredits) = @_;
9069: return unless (ref($inccourses) eq 'HASH');
1.26 matthew 9070: my $table = '';
1.62 www 9071: # Custom Roles?
9072:
1.190 raeburn 9073: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.89 raeburn 9074: my %lt=&Apache::lonlocal::texthash(
9075: 'exs' => "Existing sections",
9076: 'new' => "Define new section",
9077: 'ssd' => "Set Start Date",
9078: 'sed' => "Set End Date",
1.131 raeburn 9079: 'crl' => "Course Level",
1.89 raeburn 9080: 'act' => "Activate",
9081: 'rol' => "Role",
9082: 'ext' => "Extent",
1.113 raeburn 9083: 'grs' => "Section",
1.375 raeburn 9084: 'crd' => "Credits",
1.89 raeburn 9085: 'sta' => "Start",
9086: 'end' => "End"
9087: );
1.62 www 9088:
1.375 raeburn 9089: foreach my $protectedcourse (sort(keys(%{$inccourses}))) {
1.135 raeburn 9090: my $thiscourse=$protectedcourse;
1.26 matthew 9091: $thiscourse=~s:_:/:g;
9092: my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
1.365 raeburn 9093: my $isowner = &Apache::lonuserutils::is_courseowner($protectedcourse,$coursedata{'internal.courseowner'});
1.26 matthew 9094: my $area=$coursedata{'description'};
1.321 raeburn 9095: my $crstype=$coursedata{'type'};
1.135 raeburn 9096: if (!defined($area)) { $area=&mt('Unavailable course').': '.$protectedcourse; }
1.89 raeburn 9097: my ($domain,$cnum)=split(/\//,$thiscourse);
1.115 albertel 9098: my %sections_count;
1.101 albertel 9099: if (defined($env{'request.course.id'})) {
9100: if ($env{'request.course.id'} eq $domain.'_'.$cnum) {
1.115 albertel 9101: %sections_count =
9102: &Apache::loncommon::get_sections($domain,$cnum);
1.92 raeburn 9103: }
9104: }
1.321 raeburn 9105: my @roles = &Apache::lonuserutils::roles_by_context('course','',$crstype);
1.213 raeburn 9106: foreach my $role (@roles) {
1.321 raeburn 9107: my $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.329 raeburn 9108: if ((&Apache::lonnet::allowed('c'.$role,$thiscourse)) ||
9109: ((($role eq 'cc') || ($role eq 'co')) && ($isowner))) {
1.221 raeburn 9110: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 9111: $plrole,\%sections_count,\%lt,
1.402 raeburn 9112: $showcredits,$defaultcredits,$crstype);
1.221 raeburn 9113: } elsif ($env{'request.course.sec'} ne '') {
9114: if (&Apache::lonnet::allowed('c'.$role,$thiscourse.'/'.
9115: $env{'request.course.sec'})) {
9116: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 9117: $plrole,\%sections_count,\%lt,
1.402 raeburn 9118: $showcredits,$defaultcredits,$crstype);
1.26 matthew 9119: }
9120: }
9121: }
1.221 raeburn 9122: if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
1.324 raeburn 9123: foreach my $cust (sort(keys(%customroles))) {
9124: next if ($crstype eq 'Community' && $customroles{$cust} =~ /bre\&S/);
1.221 raeburn 9125: my $role = 'cr_cr_'.$env{'user.domain'}.'_'.$env{'user.name'}.'_'.$cust;
9126: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.402 raeburn 9127: $cust,\%sections_count,\%lt,
9128: $showcredits,$defaultcredits,$crstype);
1.221 raeburn 9129: }
1.62 www 9130: }
1.26 matthew 9131: }
9132: return '' if ($table eq ''); # return nothing if there is nothing
9133: # in the table
1.188 raeburn 9134: my $result;
9135: if (!$env{'request.course.id'}) {
9136: $result = '<h4>'.$lt{'crl'}.'</h4>'."\n";
9137: }
9138: $result .=
1.136 raeburn 9139: &Apache::loncommon::start_data_table().
9140: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 9141: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
1.402 raeburn 9142: '<th>'.$lt{'ext'}.'</th><th>'."\n";
9143: if ($showcredits) {
9144: $result .= $lt{'crd'}.'</th>';
9145: }
9146: $result .=
1.375 raeburn 9147: '<th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th>'."\n".
9148: '<th>'.$lt{'end'}.'</th>'.
1.136 raeburn 9149: &Apache::loncommon::end_data_table_header_row().
9150: $table.
9151: &Apache::loncommon::end_data_table();
1.26 matthew 9152: return $result;
9153: }
1.88 raeburn 9154:
1.221 raeburn 9155: sub course_level_row {
1.375 raeburn 9156: my ($protectedcourse,$role,$area,$domain,$plrole,$sections_count,
1.402 raeburn 9157: $lt,$showcredits,$defaultcredits,$crstype) = @_;
1.375 raeburn 9158: my $creditem;
1.222 raeburn 9159: my $row = &Apache::loncommon::start_data_table_row().
9160: ' <td><input type="checkbox" name="act_'.
9161: $protectedcourse.'_'.$role.'" /></td>'."\n".
9162: ' <td>'.$plrole.'</td>'."\n".
9163: ' <td>'.$area.'<br />Domain: '.$domain.'</td>'."\n";
1.402 raeburn 9164: if (($showcredits) && ($role eq 'st') && ($crstype eq 'Course')) {
1.375 raeburn 9165: $row .=
9166: '<td><input type="text" name="credits_'.$protectedcourse.'_'.
9167: $role.'" size="3" value="'.$defaultcredits.'" /></td>';
9168: } else {
9169: $row .= '<td> </td>';
9170: }
1.322 raeburn 9171: if (($role eq 'cc') || ($role eq 'co')) {
1.222 raeburn 9172: $row .= '<td> </td>';
1.221 raeburn 9173: } elsif ($env{'request.course.sec'} ne '') {
1.222 raeburn 9174: $row .= ' <td><input type="hidden" value="'.
9175: $env{'request.course.sec'}.'" '.
9176: 'name="sec_'.$protectedcourse.'_'.$role.'" />'.
9177: $env{'request.course.sec'}.'</td>';
1.221 raeburn 9178: } else {
9179: if (ref($sections_count) eq 'HASH') {
9180: my $currsec =
9181: &Apache::lonuserutils::course_sections($sections_count,
9182: $protectedcourse.'_'.$role);
1.222 raeburn 9183: $row .= '<td><table class="LC_createuser">'."\n".
9184: '<tr class="LC_section_row">'."\n".
9185: ' <td valign="top">'.$lt->{'exs'}.'<br />'.
9186: $currsec.'</td>'."\n".
9187: ' <td> </td>'."\n".
9188: ' <td valign="top"> '.$lt->{'new'}.'<br />'.
1.221 raeburn 9189: '<input type="text" name="newsec_'.$protectedcourse.'_'.$role.
9190: '" value="" />'.
9191: '<input type="hidden" '.
9192: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n".
1.222 raeburn 9193: '</tr></table></td>'."\n";
1.221 raeburn 9194: } else {
1.222 raeburn 9195: $row .= '<td><input type="text" size="10" '.
1.375 raeburn 9196: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n";
1.221 raeburn 9197: }
9198: }
1.222 raeburn 9199: $row .= <<ENDTIMEENTRY;
9200: <td><input type="hidden" name="start_$protectedcourse\_$role" value="" />
1.221 raeburn 9201: <a href=
9202: "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 9203: <td><input type="hidden" name="end_$protectedcourse\_$role" value="" />
1.221 raeburn 9204: <a href=
9205: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$role.value,'end_$protectedcourse\_$role','cu.pres','dateset')">$lt->{'sed'}</a></td>
9206: ENDTIMEENTRY
1.222 raeburn 9207: $row .= &Apache::loncommon::end_data_table_row();
9208: return $row;
1.221 raeburn 9209: }
9210:
1.88 raeburn 9211: sub course_level_dc {
1.375 raeburn 9212: my ($dcdom,$showcredits) = @_;
1.190 raeburn 9213: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.213 raeburn 9214: my @roles = &Apache::lonuserutils::roles_by_context('course');
1.88 raeburn 9215: my $hiddenitems = '<input type="hidden" name="dcdomain" value="'.$dcdom.'" />'.
9216: '<input type="hidden" name="origdom" value="'.$dcdom.'" />'.
1.133 raeburn 9217: '<input type="hidden" name="dccourse" value="" />';
1.355 www 9218: my $courseform=&Apache::loncommon::selectcourse_link
1.356 raeburn 9219: ('cu','dccourse','dcdomain','coursedesc',undef,undef,'Select','crstype');
1.375 raeburn 9220: my $credit_elem;
9221: if ($showcredits) {
9222: $credit_elem = 'credits';
9223: }
9224: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,'currsec','cu','role','Course/Community Browser',$credit_elem);
1.88 raeburn 9225: my %lt=&Apache::lonlocal::texthash(
9226: 'rol' => "Role",
1.113 raeburn 9227: 'grs' => "Section",
1.88 raeburn 9228: 'exs' => "Existing sections",
9229: 'new' => "Define new section",
9230: 'sta' => "Start",
9231: 'end' => "End",
9232: 'ssd' => "Set Start Date",
1.355 www 9233: 'sed' => "Set End Date",
1.375 raeburn 9234: 'scc' => "Course/Community",
9235: 'crd' => "Credits",
1.88 raeburn 9236: );
1.323 raeburn 9237: my $header = '<h4>'.&mt('Course/Community Level').'</h4>'.
1.136 raeburn 9238: &Apache::loncommon::start_data_table().
9239: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 9240: '<th>'.$lt{'scc'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
1.397 bisitz 9241: '<th>'.$lt{'grs'}.'</th>'."\n";
9242: $header .= '<th>'.$lt{'crd'}.'</th>'."\n" if ($showcredits);
9243: $header .= '<th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'."\n".
1.136 raeburn 9244: &Apache::loncommon::end_data_table_header_row();
1.143 raeburn 9245: my $otheritems = &Apache::loncommon::start_data_table_row()."\n".
1.356 raeburn 9246: '<td><br /><span class="LC_nobreak"><input type="text" name="coursedesc" value="" onfocus="this.blur();opencrsbrowser('."'cu','dccourse','dcdomain','coursedesc','','','','crstype'".')" />'.
9247: $courseform.(' ' x4).'</span></td>'."\n".
1.389 bisitz 9248: '<td valign="top"><br /><select name="role">'."\n";
1.213 raeburn 9249: foreach my $role (@roles) {
1.135 raeburn 9250: my $plrole=&Apache::lonnet::plaintext($role);
1.389 bisitz 9251: $otheritems .= ' <option value="'.$role.'">'.$plrole.'</option>';
1.88 raeburn 9252: }
1.404 raeburn 9253: if ( keys(%customroles) > 0) {
9254: foreach my $cust (sort(keys(%customroles))) {
1.101 albertel 9255: my $custrole='cr_cr_'.$env{'user.domain'}.
1.135 raeburn 9256: '_'.$env{'user.name'}.'_'.$cust;
1.389 bisitz 9257: $otheritems .= ' <option value="'.$custrole.'">'.$cust.'</option>';
1.88 raeburn 9258: }
9259: }
9260: $otheritems .= '</select></td><td>'.
9261: '<table border="0" cellspacing="0" cellpadding="0">'.
9262: '<tr><td valign="top"><b>'.$lt{'exs'}.'</b><br /><select name="currsec">'.
1.389 bisitz 9263: ' <option value=""><--'.&mt('Pick course first').'</option></select></td>'.
1.88 raeburn 9264: '<td> </td>'.
9265: '<td valign="top"> <b>'.$lt{'new'}.'</b><br />'.
1.113 raeburn 9266: '<input type="text" name="newsec" value="" />'.
1.237 raeburn 9267: '<input type="hidden" name="section" value="" />'.
1.323 raeburn 9268: '<input type="hidden" name="groups" value="" />'.
9269: '<input type="hidden" name="crstype" value="" /></td>'.
1.375 raeburn 9270: '</tr></table></td>'."\n";
9271: if ($showcredits) {
9272: $otheritems .= '<td><br />'."\n".
1.397 bisitz 9273: '<input type="text" size="3" name="credits" value="" /></td>'."\n";
1.375 raeburn 9274: }
1.88 raeburn 9275: $otheritems .= <<ENDTIMEENTRY;
1.323 raeburn 9276: <td><br /><input type="hidden" name="start" value='' />
1.88 raeburn 9277: <a href=
9278: "javascript:pjump('date_start','Start Date',document.cu.start.value,'start','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.323 raeburn 9279: <td><br /><input type="hidden" name="end" value='' />
1.88 raeburn 9280: <a href=
9281: "javascript:pjump('date_end','End Date',document.cu.end.value,'end','cu.pres','dateset')">$lt{'sed'}</a></td>
9282: ENDTIMEENTRY
1.136 raeburn 9283: $otheritems .= &Apache::loncommon::end_data_table_row().
9284: &Apache::loncommon::end_data_table()."\n";
1.88 raeburn 9285: return $cb_jscript.$header.$hiddenitems.$otheritems;
9286: }
9287:
1.237 raeburn 9288: sub update_selfenroll_config {
1.400 raeburn 9289: my ($r,$cid,$cdom,$cnum,$context,$crstype,$currsettings) = @_;
1.398 raeburn 9290: return unless (ref($currsettings) eq 'HASH');
9291: my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles();
9292: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
1.237 raeburn 9293: my (%changes,%warning);
1.241 raeburn 9294: my $curr_types;
1.400 raeburn 9295: my %noedit;
9296: unless ($context eq 'domain') {
9297: %noedit = &get_noedit_fields($cdom,$cnum,$crstype,$row);
9298: }
1.237 raeburn 9299: if (ref($row) eq 'ARRAY') {
9300: foreach my $item (@{$row}) {
1.400 raeburn 9301: next if ($noedit{$item});
1.237 raeburn 9302: if ($item eq 'enroll_dates') {
9303: my (%currenrolldate,%newenrolldate);
9304: foreach my $type ('start','end') {
1.398 raeburn 9305: $currenrolldate{$type} = $currsettings->{'selfenroll_'.$type.'_date'};
1.237 raeburn 9306: $newenrolldate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_date');
9307: if ($newenrolldate{$type} ne $currenrolldate{$type}) {
9308: $changes{'internal.selfenroll_'.$type.'_date'} = $newenrolldate{$type};
9309: }
9310: }
9311: } elsif ($item eq 'access_dates') {
9312: my (%currdate,%newdate);
9313: foreach my $type ('start','end') {
1.398 raeburn 9314: $currdate{$type} = $currsettings->{'selfenroll_'.$type.'_access'};
1.237 raeburn 9315: $newdate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_access');
9316: if ($newdate{$type} ne $currdate{$type}) {
9317: $changes{'internal.selfenroll_'.$type.'_access'} = $newdate{$type};
9318: }
9319: }
1.241 raeburn 9320: } elsif ($item eq 'types') {
1.398 raeburn 9321: $curr_types = $currsettings->{'selfenroll_'.$item};
1.241 raeburn 9322: if ($env{'form.selfenroll_all'}) {
9323: if ($curr_types ne '*') {
9324: $changes{'internal.selfenroll_types'} = '*';
9325: } else {
9326: next;
9327: }
9328: } else {
1.249 raeburn 9329: my %currdoms;
1.241 raeburn 9330: my @entries = split(/;/,$curr_types);
9331: my @deletedoms = &Apache::loncommon::get_env_multiple('form.selfenroll_delete');
1.249 raeburn 9332: my @activations = &Apache::loncommon::get_env_multiple('form.selfenroll_activate');
1.241 raeburn 9333: my $newnum = 0;
1.249 raeburn 9334: my @latesttypes;
9335: foreach my $num (@activations) {
9336: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$num);
9337: if (@types > 0) {
1.241 raeburn 9338: @types = sort(@types);
9339: my $typestr = join(',',@types);
1.249 raeburn 9340: my $typedom = $env{'form.selfenroll_dom_'.$num};
9341: $latesttypes[$newnum] = $typedom.':'.$typestr;
9342: $currdoms{$typedom} = 1;
1.241 raeburn 9343: $newnum ++;
9344: }
9345: }
1.338 raeburn 9346: for (my $j=0; $j<$env{'form.selfenroll_types_total'}; $j++) {
9347: if ((!grep(/^$j$/,@deletedoms)) && (!grep(/^$j$/,@activations))) {
1.249 raeburn 9348: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$j);
9349: if (@types > 0) {
9350: @types = sort(@types);
9351: my $typestr = join(',',@types);
9352: my $typedom = $env{'form.selfenroll_dom_'.$j};
9353: $latesttypes[$newnum] = $typedom.':'.$typestr;
9354: $currdoms{$typedom} = 1;
9355: $newnum ++;
9356: }
9357: }
9358: }
9359: if ($env{'form.selfenroll_newdom'} ne '') {
9360: my $typedom = $env{'form.selfenroll_newdom'};
9361: if ((!defined($currdoms{$typedom})) &&
9362: (&Apache::lonnet::domain($typedom) ne '')) {
9363: my $typestr;
9364: my ($othertitle,$usertypes,$types) =
9365: &Apache::loncommon::sorted_inst_types($typedom);
9366: my $othervalue = 'any';
9367: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
9368: if (@{$types} > 0) {
1.257 raeburn 9369: my @esc_types = map { &escape($_); } @{$types};
1.249 raeburn 9370: $othervalue = 'other';
1.258 raeburn 9371: $typestr = join(',',(@esc_types,$othervalue));
1.249 raeburn 9372: }
9373: $typestr = $othervalue;
9374: } else {
9375: $typestr = $othervalue;
9376: }
9377: $latesttypes[$newnum] = $typedom.':'.$typestr;
9378: $newnum ++ ;
9379: }
9380: }
1.241 raeburn 9381: my $selfenroll_types = join(';',@latesttypes);
9382: if ($selfenroll_types ne $curr_types) {
9383: $changes{'internal.selfenroll_types'} = $selfenroll_types;
9384: }
9385: }
1.276 raeburn 9386: } elsif ($item eq 'limit') {
9387: my $newlimit = $env{'form.selfenroll_limit'};
9388: my $newcap = $env{'form.selfenroll_cap'};
9389: $newcap =~s/\s+//g;
1.398 raeburn 9390: my $currlimit = $currsettings->{'selfenroll_limit'};
1.276 raeburn 9391: $currlimit = 'none' if ($currlimit eq '');
1.398 raeburn 9392: my $currcap = $currsettings->{'selfenroll_cap'};
1.276 raeburn 9393: if ($newlimit ne $currlimit) {
9394: if ($newlimit ne 'none') {
9395: if ($newcap =~ /^\d+$/) {
9396: if ($newcap ne $currcap) {
9397: $changes{'internal.selfenroll_cap'} = $newcap;
9398: }
9399: $changes{'internal.selfenroll_limit'} = $newlimit;
9400: } else {
1.398 raeburn 9401: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.
9402: &mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
1.276 raeburn 9403: }
9404: } elsif ($currcap ne '') {
9405: $changes{'internal.selfenroll_cap'} = '';
9406: $changes{'internal.selfenroll_limit'} = $newlimit;
9407: }
9408: } elsif ($currlimit ne 'none') {
9409: if ($newcap =~ /^\d+$/) {
9410: if ($newcap ne $currcap) {
9411: $changes{'internal.selfenroll_cap'} = $newcap;
9412: }
9413: } else {
1.398 raeburn 9414: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.
9415: &mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
1.276 raeburn 9416: }
9417: }
9418: } elsif ($item eq 'approval') {
9419: my (@currnotified,@newnotified);
1.398 raeburn 9420: my $currapproval = $currsettings->{'selfenroll_approval'};
9421: my $currnotifylist = $currsettings->{'selfenroll_notifylist'};
1.276 raeburn 9422: if ($currnotifylist ne '') {
9423: @currnotified = split(/,/,$currnotifylist);
9424: @currnotified = sort(@currnotified);
9425: }
9426: my $newapproval = $env{'form.selfenroll_approval'};
9427: @newnotified = &Apache::loncommon::get_env_multiple('form.selfenroll_notify');
9428: @newnotified = sort(@newnotified);
9429: if ($newapproval ne $currapproval) {
9430: $changes{'internal.selfenroll_approval'} = $newapproval;
9431: if (!$newapproval) {
9432: if ($currnotifylist ne '') {
9433: $changes{'internal.selfenroll_notifylist'} = '';
9434: }
9435: } else {
9436: my @differences =
1.295 raeburn 9437: &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 9438: if (@differences > 0) {
9439: if (@newnotified > 0) {
9440: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
9441: } else {
9442: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
9443: }
9444: }
9445: }
9446: } else {
1.295 raeburn 9447: my @differences = &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 9448: if (@differences > 0) {
9449: if (@newnotified > 0) {
9450: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
9451: } else {
9452: $changes{'internal.selfenroll_notifylist'} = '';
9453: }
9454: }
9455: }
1.237 raeburn 9456: } else {
1.398 raeburn 9457: my $curr_val = $currsettings->{'selfenroll_'.$item};
1.237 raeburn 9458: my $newval = $env{'form.selfenroll_'.$item};
9459: if ($item eq 'section') {
9460: $newval = $env{'form.sections'};
1.241 raeburn 9461: if (defined($curr_groups{$newval})) {
1.237 raeburn 9462: $newval = $curr_val;
1.398 raeburn 9463: $warning{$item} = &mt('Section for self-enrolled users unchanged as the proposed section is a group').'<br />'.
9464: &mt('Group names and section names must be distinct');
1.237 raeburn 9465: } elsif ($newval eq 'all') {
9466: $newval = $curr_val;
1.274 bisitz 9467: $warning{$item} = &mt('Section for self-enrolled users unchanged, as "all" is a reserved section name.');
1.237 raeburn 9468: }
9469: if ($newval eq '') {
9470: $newval = 'none';
9471: }
9472: }
9473: if ($newval ne $curr_val) {
9474: $changes{'internal.selfenroll_'.$item} = $newval;
9475: }
1.241 raeburn 9476: }
1.237 raeburn 9477: }
9478: if (keys(%warning) > 0) {
9479: foreach my $item (@{$row}) {
9480: if (exists($warning{$item})) {
9481: $r->print($warning{$item}.'<br />');
9482: }
9483: }
9484: }
9485: if (keys(%changes) > 0) {
9486: my $putresult = &Apache::lonnet::put('environment',\%changes,$cdom,$cnum);
9487: if ($putresult eq 'ok') {
9488: if ((exists($changes{'internal.selfenroll_types'})) ||
9489: (exists($changes{'internal.selfenroll_start_date'})) ||
9490: (exists($changes{'internal.selfenroll_end_date'}))) {
9491: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',
9492: $cnum,undef,undef,'Course');
9493: my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
1.398 raeburn 9494: if (ref($crsinfo{$cid}) eq 'HASH') {
1.237 raeburn 9495: foreach my $item ('selfenroll_types','selfenroll_start_date','selfenroll_end_date') {
9496: if (exists($changes{'internal.'.$item})) {
1.398 raeburn 9497: $crsinfo{$cid}{$item} = $changes{'internal.'.$item};
1.237 raeburn 9498: }
9499: }
9500: my $crsputresult =
9501: &Apache::lonnet::courseidput($cdom,\%crsinfo,
9502: $chome,'notime');
9503: }
9504: }
9505: $r->print(&mt('The following changes were made to self-enrollment settings:').'<ul>');
9506: foreach my $item (@{$row}) {
9507: my $title = $item;
9508: if (ref($lt) eq 'HASH') {
9509: $title = $lt->{$item};
9510: }
9511: if ($item eq 'enroll_dates') {
9512: foreach my $type ('start','end') {
9513: if (exists($changes{'internal.selfenroll_'.$type.'_date'})) {
9514: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_date'});
1.244 bisitz 9515: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 9516: $title,$type,$newdate).'</li>');
9517: }
9518: }
9519: } elsif ($item eq 'access_dates') {
9520: foreach my $type ('start','end') {
9521: if (exists($changes{'internal.selfenroll_'.$type.'_access'})) {
9522: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_access'});
1.244 bisitz 9523: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 9524: $title,$type,$newdate).'</li>');
9525: }
9526: }
1.276 raeburn 9527: } elsif ($item eq 'limit') {
9528: if ((exists($changes{'internal.selfenroll_limit'})) ||
9529: (exists($changes{'internal.selfenroll_cap'}))) {
9530: my ($newval,$newcap);
9531: if ($changes{'internal.selfenroll_cap'} ne '') {
9532: $newcap = $changes{'internal.selfenroll_cap'}
9533: } else {
1.398 raeburn 9534: $newcap = $currsettings->{'selfenroll_cap'};
1.276 raeburn 9535: }
9536: if ($changes{'internal.selfenroll_limit'} eq 'none') {
9537: $newval = &mt('No limit');
9538: } elsif ($changes{'internal.selfenroll_limit'} eq
9539: 'allstudents') {
9540: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
9541: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
9542: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
9543: } else {
1.398 raeburn 9544: my $currlimit = $currsettings->{'selfenroll_limit'};
1.276 raeburn 9545: if ($currlimit eq 'allstudents') {
9546: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
9547: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
1.308 raeburn 9548: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
1.276 raeburn 9549: }
9550: }
9551: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
9552: }
9553: } elsif ($item eq 'approval') {
9554: if ((exists($changes{'internal.selfenroll_approval'})) ||
9555: (exists($changes{'internal.selfenroll_notifylist'}))) {
1.398 raeburn 9556: my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs();
1.276 raeburn 9557: my ($newval,$newnotify);
9558: if (exists($changes{'internal.selfenroll_notifylist'})) {
9559: $newnotify = $changes{'internal.selfenroll_notifylist'};
9560: } else {
1.398 raeburn 9561: $newnotify = $currsettings->{'selfenroll_notifylist'};
1.276 raeburn 9562: }
1.398 raeburn 9563: if (exists($changes{'internal.selfenroll_approval'})) {
9564: if ($changes{'internal.selfenroll_approval'} !~ /^[012]$/) {
9565: $changes{'internal.selfenroll_approval'} = '0';
9566: }
9567: $newval = $selfdescs{'approval'}{$changes{'internal.selfenroll_approval'}};
1.276 raeburn 9568: } else {
1.398 raeburn 9569: my $currapproval = $currsettings->{'selfenroll_approval'};
9570: if ($currapproval !~ /^[012]$/) {
9571: $currapproval = 0;
1.276 raeburn 9572: }
1.398 raeburn 9573: $newval = $selfdescs{'approval'}{$currapproval};
1.276 raeburn 9574: }
9575: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval));
9576: if ($newnotify) {
1.277 raeburn 9577: $r->print('<br />'.&mt('The following will be notified when an enrollment request needs approval, or has been approved: [_1].',$newnotify));
1.276 raeburn 9578: } else {
1.277 raeburn 9579: $r->print('<br />'.&mt('No notifications sent when an enrollment request needs approval, or has been approved.'));
1.276 raeburn 9580: }
9581: $r->print('</li>'."\n");
9582: }
1.237 raeburn 9583: } else {
9584: if (exists($changes{'internal.selfenroll_'.$item})) {
1.241 raeburn 9585: my $newval = $changes{'internal.selfenroll_'.$item};
9586: if ($item eq 'types') {
9587: if ($newval eq '') {
9588: $newval = &mt('None');
9589: } elsif ($newval eq '*') {
9590: $newval = &mt('Any user in any domain');
9591: }
1.245 raeburn 9592: } elsif ($item eq 'registered') {
9593: if ($newval eq '1') {
9594: $newval = &mt('Yes');
9595: } elsif ($newval eq '0') {
9596: $newval = &mt('No');
9597: }
1.241 raeburn 9598: }
1.244 bisitz 9599: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
1.237 raeburn 9600: }
9601: }
9602: }
9603: $r->print('</ul>');
1.398 raeburn 9604: if ($env{'course.'.$cid.'.description'} ne '') {
9605: my %newenvhash;
9606: foreach my $key (keys(%changes)) {
9607: $newenvhash{'course.'.$cid.'.'.$key} = $changes{$key};
9608: }
9609: &Apache::lonnet::appenv(\%newenvhash);
1.237 raeburn 9610: }
9611: } else {
1.398 raeburn 9612: $r->print(&mt('An error occurred when saving changes to self-enrollment settings in this course.').'<br />'.
9613: &mt('The error was: [_1].',$putresult));
1.237 raeburn 9614: }
9615: } else {
1.249 raeburn 9616: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.237 raeburn 9617: }
9618: } else {
1.249 raeburn 9619: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.241 raeburn 9620: }
1.400 raeburn 9621: my $visactions = &cat_visibility();
9622: my ($cathash,%cattype);
9623: my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
9624: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
9625: $cathash = $domconfig{'coursecategories'}{'cats'};
9626: $cattype{'auth'} = $domconfig{'coursecategories'}{'auth'};
9627: $cattype{'unauth'} = $domconfig{'coursecategories'}{'unauth'};
9628: } else {
9629: $cathash = {};
9630: $cattype{'auth'} = 'std';
9631: $cattype{'unauth'} = 'std';
9632: }
9633: if (($cattype{'auth'} eq 'none') && ($cattype{'unauth'} eq 'none')) {
9634: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
9635: '<br />'.
9636: '<br />'.$visactions->{'take'}.'<ul>'.
9637: '<li>'.$visactions->{'dc_chgconf'}.'</li>'.
9638: '</ul>');
9639: } elsif (($cattype{'auth'} !~ /^(std|domonly)$/) && ($cattype{'unauth'} !~ /^(std|domonly)$/)) {
9640: if ($currsettings->{'uniquecode'}) {
9641: $r->print('<span class="LC_info">'.$visactions->{'vis'}.'</span>');
9642: } else {
1.366 bisitz 9643: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
1.400 raeburn 9644: '<br />'.
9645: '<br />'.$visactions->{'take'}.'<ul>'.
9646: '<li>'.$visactions->{'dc_setcode'}.'</li>'.
9647: '</ul><br />');
9648: }
9649: } else {
9650: my ($visible,$cansetvis,$vismsgs) = &visible_in_stdcat($cdom,$cnum,\%domconfig);
9651: if (ref($visactions) eq 'HASH') {
9652: if (!$visible) {
9653: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
9654: '<br />');
9655: if (ref($vismsgs) eq 'ARRAY') {
9656: $r->print('<br />'.$visactions->{'take'}.'<ul>');
9657: foreach my $item (@{$vismsgs}) {
9658: $r->print('<li>'.$visactions->{$item}.'</li>');
9659: }
9660: $r->print('</ul>');
1.256 raeburn 9661: }
1.400 raeburn 9662: $r->print($cansetvis);
1.256 raeburn 9663: }
9664: }
9665: }
1.237 raeburn 9666: return;
9667: }
9668:
1.27 matthew 9669: #---------------------------------------------- end functions for &phase_two
1.29 matthew 9670:
9671: #--------------------------------- functions for &phase_two and &phase_three
9672:
9673: #--------------------------end of functions for &phase_two and &phase_three
1.372 raeburn 9674:
1.1 www 9675: 1;
9676: __END__
1.2 www 9677:
9678:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>