Annotation of loncom/interface/loncreateuser.pm, revision 1.406.2.5
1.20 harris41 1: # The LearningOnline Network with CAPA
1.1 www 2: # Create a user
3: #
1.406.2.5! raeburn 4: # $Id: loncreateuser.pm,v 1.406.2.4 2016/10/22 15:53:55 raeburn Exp $
1.22 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.20 harris41 28: ###
29:
1.1 www 30: package Apache::loncreateuser;
1.66 bowersj2 31:
32: =pod
33:
34: =head1 NAME
35:
1.263 jms 36: Apache::loncreateuser.pm
1.66 bowersj2 37:
38: =head1 SYNOPSIS
39:
1.263 jms 40: Handler to create users and custom roles
41:
42: Provides an Apache handler for creating users,
1.66 bowersj2 43: editing their login parameters, roles, and removing roles, and
44: also creating and assigning custom roles.
45:
46: =head1 OVERVIEW
47:
48: =head2 Custom Roles
49:
50: In LON-CAPA, roles are actually collections of privileges. "Teaching
51: Assistant", "Course Coordinator", and other such roles are really just
52: collection of privileges that are useful in many circumstances.
53:
1.324 raeburn 54: Custom roles can be defined by a Domain Coordinator, Course Coordinator
55: or Community Coordinator via the Manage User functionality.
56: The custom role editor screen will show all privileges which can be
57: assigned to users. For a complete list of privileges, please see
58: C</home/httpd/lonTabs/rolesplain.tab>.
1.66 bowersj2 59:
1.324 raeburn 60: Custom role definitions are stored in the C<roles.db> file of the creator
61: of the role.
1.66 bowersj2 62:
63: =cut
1.1 www 64:
65: use strict;
66: use Apache::Constants qw(:common :http);
67: use Apache::lonnet;
1.54 bowersj2 68: use Apache::loncommon;
1.68 www 69: use Apache::lonlocal;
1.117 raeburn 70: use Apache::longroup;
1.190 raeburn 71: use Apache::lonuserutils;
1.307 raeburn 72: use Apache::loncoursequeueadmin;
1.139 albertel 73: use LONCAPA qw(:DEFAULT :match);
1.1 www 74:
1.20 harris41 75: my $loginscript; # piece of javascript used in two separate instances
76: my $authformnop;
77: my $authformkrb;
78: my $authformint;
79: my $authformfsys;
80: my $authformloc;
81:
1.94 matthew 82: sub initialize_authen_forms {
1.227 raeburn 83: my ($dom,$formname,$curr_authtype,$mode) = @_;
84: my ($krbdef,$krbdefdom) = &Apache::loncommon::get_kerberos_defaults($dom);
85: my %param = ( formname => $formname,
1.187 raeburn 86: kerb_def_dom => $krbdefdom,
1.227 raeburn 87: kerb_def_auth => $krbdef,
1.187 raeburn 88: domain => $dom,
89: );
1.188 raeburn 90: my %abv_auth = &auth_abbrev();
1.227 raeburn 91: if ($curr_authtype =~ /^(krb4|krb5|internal|localauth|unix):(.*)$/) {
1.188 raeburn 92: my $long_auth = $1;
1.227 raeburn 93: my $curr_autharg = $2;
1.188 raeburn 94: my %abv_auth = &auth_abbrev();
95: $param{'curr_authtype'} = $abv_auth{$long_auth};
96: if ($long_auth =~ /^krb(4|5)$/) {
97: $param{'curr_kerb_ver'} = $1;
1.227 raeburn 98: $param{'curr_autharg'} = $curr_autharg;
1.188 raeburn 99: }
1.205 raeburn 100: if ($mode eq 'modifyuser') {
101: $param{'mode'} = $mode;
102: }
1.187 raeburn 103: }
1.227 raeburn 104: $loginscript = &Apache::loncommon::authform_header(%param);
105: $authformkrb = &Apache::loncommon::authform_kerberos(%param);
1.31 matthew 106: $authformnop = &Apache::loncommon::authform_nochange(%param);
107: $authformint = &Apache::loncommon::authform_internal(%param);
108: $authformfsys = &Apache::loncommon::authform_filesystem(%param);
109: $authformloc = &Apache::loncommon::authform_local(%param);
1.20 harris41 110: }
111:
1.188 raeburn 112: sub auth_abbrev {
113: my %abv_auth = (
1.368 raeburn 114: krb5 => 'krb',
115: krb4 => 'krb',
116: internal => 'int',
117: localauth => 'loc',
118: unix => 'fsys',
1.188 raeburn 119: );
120: return %abv_auth;
121: }
1.43 www 122:
1.134 raeburn 123: # ====================================================
124:
1.378 raeburn 125: sub user_quotas {
1.134 raeburn 126: my ($ccuname,$ccdomain) = @_;
127: my %lt = &Apache::lonlocal::texthash(
1.267 raeburn 128: 'usrt' => "User Tools",
129: 'cust' => "Custom quota",
130: 'chqu' => "Change quota",
1.134 raeburn 131: );
1.378 raeburn 132:
1.149 raeburn 133: my $quota_javascript = <<"END_SCRIPT";
134: <script type="text/javascript">
1.301 bisitz 135: // <![CDATA[
1.378 raeburn 136: function quota_changes(caller,context) {
137: var customoff = document.getElementById('custom_'+context+'quota_off');
138: var customon = document.getElementById('custom_'+context+'quota_on');
139: var number = document.getElementById(context+'quota');
1.149 raeburn 140: if (caller == "custom") {
1.378 raeburn 141: if (customoff) {
142: if (customoff.checked) {
143: number.value = "";
144: }
1.149 raeburn 145: }
146: }
147: if (caller == "quota") {
1.378 raeburn 148: if (customon) {
149: customon.checked = true;
150: }
1.149 raeburn 151: }
1.378 raeburn 152: return;
1.149 raeburn 153: }
1.301 bisitz 154: // ]]>
1.149 raeburn 155: </script>
156: END_SCRIPT
1.378 raeburn 157: my $longinsttype;
158: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($ccdomain);
1.267 raeburn 159: my $output = $quota_javascript."\n".
160: '<h3>'.$lt{'usrt'}.'</h3>'."\n".
161: &Apache::loncommon::start_data_table();
162:
163: if (&Apache::lonnet::allowed('mut',$ccdomain)) {
1.275 raeburn 164: $output .= &build_tools_display($ccuname,$ccdomain,'tools');
1.267 raeburn 165: }
1.378 raeburn 166:
167: my %titles = &Apache::lonlocal::texthash (
168: portfolio => "Disk space allocated to user's portfolio files",
1.385 bisitz 169: author => "Disk space allocated to user's Authoring Space (if role assigned)",
1.378 raeburn 170: );
171: foreach my $name ('portfolio','author') {
172: my ($currquota,$quotatype,$inststatus,$defquota) =
173: &Apache::loncommon::get_user_quota($ccuname,$ccdomain,$name);
174: if ($longinsttype eq '') {
175: if ($inststatus ne '') {
176: if ($usertypes->{$inststatus} ne '') {
177: $longinsttype = $usertypes->{$inststatus};
178: }
179: }
180: }
181: my ($showquota,$custom_on,$custom_off,$defaultinfo);
182: $custom_on = ' ';
183: $custom_off = ' checked="checked" ';
184: if ($quotatype eq 'custom') {
185: $custom_on = $custom_off;
186: $custom_off = ' ';
187: $showquota = $currquota;
188: if ($longinsttype eq '') {
189: $defaultinfo = &mt('For this user, the default quota would be [_1]'
1.383 raeburn 190: .' MB.',$defquota);
1.378 raeburn 191: } else {
192: $defaultinfo = &mt("For this user, the default quota would be [_1]".
1.383 raeburn 193: " MB, as determined by the user's institutional".
1.378 raeburn 194: " affiliation ([_2]).",$defquota,$longinsttype);
195: }
196: } else {
197: if ($longinsttype eq '') {
198: $defaultinfo = &mt('For this user, the default quota is [_1]'
1.383 raeburn 199: .' MB.',$defquota);
1.378 raeburn 200: } else {
201: $defaultinfo = &mt("For this user, the default quota of [_1]".
1.383 raeburn 202: " MB, is determined by the user's institutional".
1.378 raeburn 203: " affiliation ([_2]).",$defquota,$longinsttype);
204: }
205: }
206:
207: if (&Apache::lonnet::allowed('mpq',$ccdomain)) {
208: $output .= '<tr class="LC_info_row">'."\n".
209: ' <td>'.$titles{$name}.'</td>'."\n".
210: ' </tr>'."\n".
211: &Apache::loncommon::start_data_table_row()."\n".
1.390 bisitz 212: ' <td><span class="LC_nobreak">'.
213: &mt('Current quota: [_1] MB',$currquota).'</span> '.
1.378 raeburn 214: $defaultinfo.'</td>'."\n".
215: &Apache::loncommon::end_data_table_row()."\n".
216: &Apache::loncommon::start_data_table_row()."\n".
217: ' <td><span class="LC_nobreak">'.$lt{'chqu'}.
218: ': <label>'.
219: '<input type="radio" name="custom_'.$name.'quota" id="custom_'.$name.'quota_off" '.
1.379 raeburn 220: 'value="0" '.$custom_off.' onchange="javascript:quota_changes('."'custom','$name'".');"'.
1.390 bisitz 221: ' /><span class="LC_nobreak">'.
222: &mt('Default ([_1] MB)',$defquota).'</span></label> '.
1.378 raeburn 223: ' <label><input type="radio" name="custom_'.$name.'quota" id="custom_'.$name.'quota_on" '.
1.379 raeburn 224: 'value="1" '.$custom_on.' onchange="javascript:quota_changes('."'custom','$name'".');"'.
1.378 raeburn 225: ' />'.$lt{'cust'}.':</label> '.
1.379 raeburn 226: '<input type="text" name="'.$name.'quota" id="'.$name.'quota" size ="5" '.
227: 'value="'.$showquota.'" onfocus="javascript:quota_changes('."'quota','$name'".');"'.
1.390 bisitz 228: ' /> '.&mt('MB').'</span></td>'."\n".
1.378 raeburn 229: &Apache::loncommon::end_data_table_row()."\n";
230: }
231: }
1.267 raeburn 232: $output .= &Apache::loncommon::end_data_table();
1.134 raeburn 233: return $output;
234: }
235:
1.275 raeburn 236: sub build_tools_display {
237: my ($ccuname,$ccdomain,$context) = @_;
1.306 raeburn 238: my (@usertools,%userenv,$output,@options,%validations,%reqtitles,%reqdisplay,
1.332 raeburn 239: $colspan,$isadv,%domconfig);
1.275 raeburn 240: my %lt = &Apache::lonlocal::texthash (
241: 'blog' => "Personal User Blog",
242: 'aboutme' => "Personal Information Page",
1.385 bisitz 243: 'webdav' => "WebDAV access to Authoring Spaces (if SSL and author/co-author)",
1.275 raeburn 244: 'portfolio' => "Personal User Portfolio",
245: 'avai' => "Available",
246: 'cusa' => "availability",
247: 'chse' => "Change setting",
248: 'usde' => "Use default",
249: 'uscu' => "Use custom",
250: 'official' => 'Can request creation of official courses',
1.299 raeburn 251: 'unofficial' => 'Can request creation of unofficial courses',
252: 'community' => 'Can request creation of communities',
1.384 raeburn 253: 'textbook' => 'Can request creation of textbook courses',
1.362 raeburn 254: 'requestauthor' => 'Can request author space',
1.275 raeburn 255: );
1.279 raeburn 256: if ($context eq 'requestcourses') {
1.275 raeburn 257: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
1.299 raeburn 258: 'requestcourses.official','requestcourses.unofficial',
1.384 raeburn 259: 'requestcourses.community','requestcourses.textbook');
260: @usertools = ('official','unofficial','community','textbook');
1.309 raeburn 261: @options =('norequest','approval','autolimit','validate');
1.306 raeburn 262: %validations = &Apache::lonnet::auto_courserequest_checks($ccdomain);
263: %reqtitles = &courserequest_titles();
264: %reqdisplay = &courserequest_display();
265: $colspan = ' colspan="2"';
1.332 raeburn 266: %domconfig =
267: &Apache::lonnet::get_dom('configuration',['requestcourses'],$ccdomain);
268: $isadv = &Apache::lonnet::is_advanced_user($ccuname,$ccdomain);
1.362 raeburn 269: } elsif ($context eq 'requestauthor') {
270: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
271: 'requestauthor');
272: @usertools = ('requestauthor');
273: @options =('norequest','approval','automatic');
274: %reqtitles = &requestauthor_titles();
275: %reqdisplay = &requestauthor_display();
276: $colspan = ' colspan="2"';
277: %domconfig =
278: &Apache::lonnet::get_dom('configuration',['requestauthor'],$ccdomain);
1.275 raeburn 279: } else {
280: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
1.361 raeburn 281: 'tools.aboutme','tools.portfolio','tools.blog',
282: 'tools.webdav');
283: @usertools = ('aboutme','blog','webdav','portfolio');
1.275 raeburn 284: }
285: foreach my $item (@usertools) {
1.306 raeburn 286: my ($custom_access,$curr_access,$cust_on,$cust_off,$tool_on,$tool_off,
287: $currdisp,$custdisp,$custradio);
1.275 raeburn 288: $cust_off = 'checked="checked" ';
289: $tool_on = 'checked="checked" ';
290: $curr_access =
291: &Apache::lonnet::usertools_access($ccuname,$ccdomain,$item,undef,
292: $context);
1.362 raeburn 293: if ($context eq 'requestauthor') {
294: if ($userenv{$context} ne '') {
295: $cust_on = ' checked="checked" ';
296: $cust_off = '';
297: }
298: } elsif ($userenv{$context.'.'.$item} ne '') {
1.306 raeburn 299: $cust_on = ' checked="checked" ';
300: $cust_off = '';
301: }
302: if ($context eq 'requestcourses') {
303: if ($userenv{$context.'.'.$item} eq '') {
1.314 raeburn 304: $custom_access = &mt('Currently from default setting.');
1.306 raeburn 305: } else {
306: $custom_access = &mt('Currently from custom setting.');
1.275 raeburn 307: }
1.362 raeburn 308: } elsif ($context eq 'requestauthor') {
309: if ($userenv{$context} eq '') {
310: $custom_access = &mt('Currently from default setting.');
311: } else {
312: $custom_access = &mt('Currently from custom setting.');
313: }
1.275 raeburn 314: } else {
1.306 raeburn 315: if ($userenv{$context.'.'.$item} eq '') {
1.314 raeburn 316: $custom_access =
1.306 raeburn 317: &mt('Availability determined currently from default setting.');
318: if (!$curr_access) {
319: $tool_off = 'checked="checked" ';
320: $tool_on = '';
321: }
322: } else {
1.314 raeburn 323: $custom_access =
1.306 raeburn 324: &mt('Availability determined currently from custom setting.');
325: if ($userenv{$context.'.'.$item} == 0) {
326: $tool_off = 'checked="checked" ';
327: $tool_on = '';
328: }
1.275 raeburn 329: }
330: }
331: $output .= ' <tr class="LC_info_row">'."\n".
1.306 raeburn 332: ' <td'.$colspan.'>'.$lt{$item}.'</td>'."\n".
1.275 raeburn 333: ' </tr>'."\n".
1.306 raeburn 334: &Apache::loncommon::start_data_table_row()."\n";
1.362 raeburn 335: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.306 raeburn 336: my ($curroption,$currlimit);
1.362 raeburn 337: my $envkey = $context.'.'.$item;
338: if ($context eq 'requestauthor') {
339: $envkey = $context;
340: }
341: if ($userenv{$envkey} ne '') {
342: $curroption = $userenv{$envkey};
1.332 raeburn 343: } else {
344: my (@inststatuses);
1.362 raeburn 345: if ($context eq 'requestcourses') {
346: $curroption =
347: &Apache::loncoursequeueadmin::get_processtype('course',$ccuname,$ccdomain,
348: $isadv,$ccdomain,$item,
349: \@inststatuses,\%domconfig);
350: } else {
351: $curroption =
352: &Apache::loncoursequeueadmin::get_processtype('requestauthor',$ccuname,$ccdomain,
353: $isadv,$ccdomain,undef,
354: \@inststatuses,\%domconfig);
355: }
1.332 raeburn 356: }
1.306 raeburn 357: if (!$curroption) {
358: $curroption = 'norequest';
359: }
360: if ($curroption =~ /^autolimit=(\d*)$/) {
361: $currlimit = $1;
1.314 raeburn 362: if ($currlimit eq '') {
363: $currdisp = &mt('Yes, automatic creation');
364: } else {
365: $currdisp = &mt('Yes, up to [quant,_1,request]/user',$currlimit);
366: }
1.306 raeburn 367: } else {
368: $currdisp = $reqdisplay{$curroption};
369: }
370: $custdisp = '<table>';
371: foreach my $option (@options) {
372: my $val = $option;
373: if ($option eq 'norequest') {
374: $val = 0;
375: }
376: if ($option eq 'validate') {
377: my $canvalidate = 0;
378: if (ref($validations{$item}) eq 'HASH') {
379: if ($validations{$item}{'_custom_'}) {
380: $canvalidate = 1;
381: }
382: }
383: next if (!$canvalidate);
384: }
385: my $checked = '';
386: if ($option eq $curroption) {
387: $checked = ' checked="checked"';
388: } elsif ($option eq 'autolimit') {
389: if ($curroption =~ /^autolimit/) {
390: $checked = ' checked="checked"';
391: }
392: }
1.362 raeburn 393: my $name = 'crsreq_'.$item;
394: if ($context eq 'requestauthor') {
395: $name = $item;
396: }
1.306 raeburn 397: $custdisp .= '<tr><td><span class="LC_nobreak"><label>'.
1.362 raeburn 398: '<input type="radio" name="'.$name.'" '.
399: 'value="'.$val.'"'.$checked.' />'.
1.306 raeburn 400: $reqtitles{$option}.'</label> ';
401: if ($option eq 'autolimit') {
1.362 raeburn 402: $custdisp .= '<input type="text" name="'.$name.
403: '_limit" size="1" '.
1.314 raeburn 404: 'value="'.$currlimit.'" /></span><br />'.
405: $reqtitles{'unlimited'};
1.362 raeburn 406: } else {
407: $custdisp .= '</span>';
408: }
409: $custdisp .= '</td></tr>';
1.306 raeburn 410: }
411: $custdisp .= '</table>';
412: $custradio = '</span></td><td>'.&mt('Custom setting').'<br />'.$custdisp;
413: } else {
414: $currdisp = ($curr_access?&mt('Yes'):&mt('No'));
1.362 raeburn 415: my $name = $context.'_'.$item;
416: if ($context eq 'requestauthor') {
417: $name = $context;
418: }
1.306 raeburn 419: $custdisp = '<span class="LC_nobreak"><label>'.
1.362 raeburn 420: '<input type="radio" name="'.$name.'"'.
1.361 raeburn 421: ' value="1" '.$tool_on.'/>'.&mt('On').'</label> <label>'.
1.362 raeburn 422: '<input type="radio" name="'.$name.'" value="0" '.
1.306 raeburn 423: $tool_off.'/>'.&mt('Off').'</label></span>';
424: $custradio = (' 'x2).'--'.$lt{'cusa'}.': '.$custdisp.
425: '</span>';
426: }
427: $output .= ' <td'.$colspan.'>'.$custom_access.(' 'x4).
428: $lt{'avai'}.': '.$currdisp.'</td>'."\n".
1.275 raeburn 429: &Apache::loncommon::end_data_table_row()."\n".
430: &Apache::loncommon::start_data_table_row()."\n".
1.306 raeburn 431: ' <td style="vertical-align:top;"><span class="LC_nobreak">'.
432: $lt{'chse'}.': <label>'.
1.275 raeburn 433: '<input type="radio" name="custom'.$item.'" value="0" '.
1.306 raeburn 434: $cust_off.'/>'.$lt{'usde'}.'</label>'.(' ' x3).
435: '<label><input type="radio" name="custom'.$item.'" value="1" '.
436: $cust_on.'/>'.$lt{'uscu'}.'</label>'.$custradio.'</td>'.
1.275 raeburn 437: &Apache::loncommon::end_data_table_row()."\n";
438: }
439: return $output;
440: }
441:
1.300 raeburn 442: sub coursereq_externaluser {
443: my ($ccuname,$ccdomain,$cdom) = @_;
1.306 raeburn 444: my (@usertools,@options,%validations,%userenv,$output);
1.300 raeburn 445: my %lt = &Apache::lonlocal::texthash (
446: 'official' => 'Can request creation of official courses',
447: 'unofficial' => 'Can request creation of unofficial courses',
448: 'community' => 'Can request creation of communities',
1.384 raeburn 449: 'textbook' => 'Can request creation of textbook courses',
1.300 raeburn 450: );
451:
452: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
453: 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
1.384 raeburn 454: 'reqcrsotherdom.community','reqcrsotherdom.textbook');
455: @usertools = ('official','unofficial','community','textbook');
1.309 raeburn 456: @options = ('approval','validate','autolimit');
1.306 raeburn 457: %validations = &Apache::lonnet::auto_courserequest_checks($cdom);
458: my $optregex = join('|',@options);
459: my %reqtitles = &courserequest_titles();
1.300 raeburn 460: foreach my $item (@usertools) {
1.306 raeburn 461: my ($curroption,$currlimit,$tooloff);
1.300 raeburn 462: if ($userenv{'reqcrsotherdom.'.$item} ne '') {
463: my @curr = split(',',$userenv{'reqcrsotherdom.'.$item});
1.314 raeburn 464: foreach my $req (@curr) {
465: if ($req =~ /^\Q$cdom\E\:($optregex)=?(\d*)$/) {
466: $curroption = $1;
467: $currlimit = $2;
468: last;
1.306 raeburn 469: }
470: }
1.314 raeburn 471: if (!$curroption) {
472: $curroption = 'norequest';
473: $tooloff = ' checked="checked"';
474: }
1.306 raeburn 475: } else {
476: $curroption = 'norequest';
477: $tooloff = ' checked="checked"';
478: }
479: $output.= &Apache::loncommon::start_data_table_row()."\n".
1.314 raeburn 480: ' <td><span class="LC_nobreak">'.$lt{$item}.': </span></td><td>'.
481: '<table><tr><td valign="top">'."\n".
1.306 raeburn 482: '<label><input type="radio" name="reqcrsotherdom_'.$item.
1.314 raeburn 483: '" value=""'.$tooloff.' />'.$reqtitles{'norequest'}.
484: '</label></td>';
1.306 raeburn 485: foreach my $option (@options) {
486: if ($option eq 'validate') {
487: my $canvalidate = 0;
488: if (ref($validations{$item}) eq 'HASH') {
489: if ($validations{$item}{'_external_'}) {
490: $canvalidate = 1;
491: }
492: }
493: next if (!$canvalidate);
494: }
495: my $checked = '';
496: if ($option eq $curroption) {
497: $checked = ' checked="checked"';
498: }
1.314 raeburn 499: $output .= '<td valign="top"><span class="LC_nobreak"><label>'.
1.306 raeburn 500: '<input type="radio" name="reqcrsotherdom_'.$item.
501: '" value="'.$option.'"'.$checked.' />'.
1.314 raeburn 502: $reqtitles{$option}.'</label>';
1.306 raeburn 503: if ($option eq 'autolimit') {
1.314 raeburn 504: $output .= ' <input type="text" name="reqcrsotherdom_'.
1.306 raeburn 505: $item.'_limit" size="1" '.
1.314 raeburn 506: 'value="'.$currlimit.'" /></span>'.
507: '<br />'.$reqtitles{'unlimited'};
508: } else {
509: $output .= '</span>';
1.300 raeburn 510: }
1.314 raeburn 511: $output .= '</td>';
1.300 raeburn 512: }
1.314 raeburn 513: $output .= '</td></tr></table></td>'."\n".
1.300 raeburn 514: &Apache::loncommon::end_data_table_row()."\n";
515: }
516: return $output;
517: }
518:
1.362 raeburn 519: sub domainrole_req {
520: my ($ccuname,$ccdomain) = @_;
521: return '<br /><h3>'.
522: &mt('User Can Request Assignment of Domain Roles?').
523: '</h3>'."\n".
524: &Apache::loncommon::start_data_table().
525: &build_tools_display($ccuname,$ccdomain,
526: 'requestauthor').
527: &Apache::loncommon::end_data_table();
528: }
529:
1.406.2.5! raeburn 530: sub domadhocroles {
! 531: my ($ccuname,$ccdomain) = @_;
! 532: my $confname = &Apache::lonnet::get_domainconfiguser($env{'request.role.domain'});
! 533: my %existing=&Apache::lonnet::dump('roles',$env{'request.role.domain'},
! 534: $confname,'rolesdef_');
! 535: my $output;
! 536: if (keys(%existing) > 0) {
! 537: my @current;
! 538: my $curradhoc = 'adhocroles.'.$env{'request.role.domain'};
! 539: my %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,$curradhoc);
! 540: if ($userenv{$curradhoc}) {
! 541: @current = split(/,/,$userenv{$curradhoc});
! 542: }
! 543: my %customroles;
! 544: foreach my $key (keys(%existing)) {
! 545: if ($key=~/^rolesdef\_(\w+)$/) {
! 546: my $rolename = $1;
! 547: my %privs;
! 548: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
! 549: $customroles{$rolename} = \%privs;
! 550: }
! 551: }
! 552: $output = '<br /><h3>'.
! 553: &mt('Ad Hoc Course Roles Selectable via Helpdesk Role').
! 554: '</h3>'."\n".
! 555: &Apache::loncommon::start_data_table().
! 556: &Apache::loncommon::start_data_table_header_row().
! 557: '<th>'.&mt('Action').'</th><th>'.&mt('Role').'</th>'.
! 558: '<th>'.&mt('Privileges in Course').'<th>'.
! 559: &Apache::loncommon::end_data_table_header_row();
! 560: foreach my $key (sort(keys(%customroles))) {
! 561: $output .= &Apache::loncommon::start_data_table_row();
! 562: if (grep(/^\Q$key\E$/,@current)) {
! 563: $output .= '<td><label>'.
! 564: '<input type="checkbox" name="adhocroledel" value="'.$key.'" />'.
! 565: &mt('Delete').'</label>'.
! 566: '</td>';
! 567: } else {
! 568: $output .= '<td><label>'.
! 569: '<input type="checkbox" name="adhocroleadd" value="'.$key.'" />'.
! 570: &mt('Add').'</label>'.
! 571: '</td>';
! 572: }
! 573: $output .= '<td>'.$key.'</td><td>';
! 574: foreach my $level ('course','domain','system') {
! 575: if ($customroles{$key}{$level}) {
! 576: my $suffix;
! 577: if (($level eq 'domain') || ($level eq 'system')) {
! 578: $suffix = ' ('.&mt($level).')';
! 579: }
! 580: my @privs = split(/:/,$customroles{$key}{$level});
! 581: foreach my $item (@privs) {
! 582: next if ($item eq '');
! 583: my ($priv,$cond) = split(/\&/,$item);
! 584: $output .= &Apache::lonnet::plaintext($priv,'Course').$suffix.'<br />';
! 585: }
! 586: }
! 587: }
! 588: $output .= '</td>'.
! 589: &Apache::loncommon::end_data_table_row();
! 590: }
! 591: $output .= &Apache::loncommon::end_data_table();
! 592: }
! 593: return $output;
! 594: }
! 595:
1.306 raeburn 596: sub courserequest_titles {
597: my %titles = &Apache::lonlocal::texthash (
598: official => 'Official',
599: unofficial => 'Unofficial',
600: community => 'Communities',
1.384 raeburn 601: textbook => 'Textbook',
1.306 raeburn 602: norequest => 'Not allowed',
1.309 raeburn 603: approval => 'Approval by Dom. Coord.',
1.306 raeburn 604: validate => 'With validation',
605: autolimit => 'Numerical limit',
1.314 raeburn 606: unlimited => '(blank for unlimited)',
1.306 raeburn 607: );
608: return %titles;
609: }
610:
611: sub courserequest_display {
612: my %titles = &Apache::lonlocal::texthash (
1.309 raeburn 613: approval => 'Yes, need approval',
1.306 raeburn 614: validate => 'Yes, with validation',
615: norequest => 'No',
616: );
617: return %titles;
618: }
619:
1.362 raeburn 620: sub requestauthor_titles {
621: my %titles = &Apache::lonlocal::texthash (
622: norequest => 'Not allowed',
623: approval => 'Approval by Dom. Coord.',
624: automatic => 'Automatic approval',
625: );
626: return %titles;
627:
628: }
629:
630: sub requestauthor_display {
631: my %titles = &Apache::lonlocal::texthash (
632: approval => 'Yes, need approval',
633: automatic => 'Yes, automatic approval',
634: norequest => 'No',
635: );
636: return %titles;
637: }
638:
1.383 raeburn 639: sub requestchange_display {
640: my %titles = &Apache::lonlocal::texthash (
641: approval => "availability set to 'on' (approval required)",
642: automatic => "availability set to 'on' (automatic approval)",
643: norequest => "availability set to 'off'",
644: );
645: return %titles;
646: }
647:
1.362 raeburn 648: sub curr_requestauthor {
649: my ($uname,$udom,$isadv,$inststatuses,$domconfig) = @_;
650: return unless ((ref($inststatuses) eq 'ARRAY') && (ref($domconfig) eq 'HASH'));
651: if ($uname eq '' || $udom eq '') {
652: $uname = $env{'user.name'};
653: $udom = $env{'user.domain'};
654: $isadv = $env{'user.adv'};
655: }
656: my (%userenv,%settings,$val);
657: my @options = ('automatic','approval');
658: %userenv =
659: &Apache::lonnet::userenvironment($udom,$uname,'requestauthor','inststatus');
660: if ($userenv{'requestauthor'}) {
661: $val = $userenv{'requestauthor'};
662: @{$inststatuses} = ('_custom_');
663: } else {
664: my %alltasks;
665: if (ref($domconfig->{'requestauthor'}) eq 'HASH') {
666: %settings = %{$domconfig->{'requestauthor'}};
667: if (($isadv) && ($settings{'_LC_adv'} ne '')) {
668: $val = $settings{'_LC_adv'};
669: @{$inststatuses} = ('_LC_adv_');
670: } else {
671: if ($userenv{'inststatus'} ne '') {
672: @{$inststatuses} = split(',',$userenv{'inststatus'});
673: } else {
674: @{$inststatuses} = ('default');
675: }
676: foreach my $status (@{$inststatuses}) {
677: if (exists($settings{$status})) {
678: my $value = $settings{$status};
679: next unless ($value);
680: unless (exists($alltasks{$value})) {
681: if (ref($alltasks{$value}) eq 'ARRAY') {
682: unless(grep(/^\Q$status\E$/,@{$alltasks{$value}})) {
683: push(@{$alltasks{$value}},$status);
684: }
685: } else {
686: @{$alltasks{$value}} = ($status);
687: }
688: }
689: }
690: }
691: foreach my $option (@options) {
692: if ($alltasks{$option}) {
693: $val = $option;
694: last;
695: }
696: }
697: }
698: }
699: }
700: return $val;
701: }
702:
1.2 www 703: # =================================================================== Phase one
1.1 www 704:
1.42 matthew 705: sub print_username_entry_form {
1.351 raeburn 706: my ($r,$context,$response,$srch,$forcenewuser,$crstype,$brcrum) = @_;
1.101 albertel 707: my $defdom=$env{'request.role.domain'};
1.160 raeburn 708: my $formtoset = 'crtuser';
709: if (exists($env{'form.startrolename'})) {
710: $formtoset = 'docustom';
711: $env{'form.rolename'} = $env{'form.startrolename'};
1.207 raeburn 712: } elsif ($env{'form.origform'} eq 'crtusername') {
713: $formtoset = $env{'form.origform'};
1.160 raeburn 714: }
715:
716: my ($jsback,$elements) = &crumb_utilities();
717:
718: my $jscript = &Apache::loncommon::studentbrowser_javascript()."\n".
1.165 albertel 719: '<script type="text/javascript">'."\n".
1.301 bisitz 720: '// <![CDATA['."\n".
721: &Apache::lonhtmlcommon::set_form_elements($elements->{$formtoset})."\n".
722: '// ]]>'."\n".
1.162 raeburn 723: '</script>'."\n";
1.160 raeburn 724:
1.324 raeburn 725: my %existingroles=&Apache::lonuserutils::my_custom_roles($crstype);
726: if (($env{'form.action'} eq 'custom') && (keys(%existingroles) > 0)
727: && (&Apache::lonnet::allowed('mcr','/'))) {
728: $jscript .= &customrole_javascript();
729: }
1.224 raeburn 730: my $helpitem = 'Course_Change_Privileges';
731: if ($env{'form.action'} eq 'custom') {
732: $helpitem = 'Course_Editing_Custom_Roles';
733: } elsif ($env{'form.action'} eq 'singlestudent') {
734: $helpitem = 'Course_Add_Student';
1.406.2.5! raeburn 735: } elsif ($env{'form.action'} eq 'accesslogs') {
! 736: $helpitem = 'Domain_User_Access_Logs';
1.224 raeburn 737: }
1.351 raeburn 738: my %breadcrumb_text = &singleuser_breadcrumb($crstype);
739: if ($env{'form.action'} eq 'custom') {
740: push(@{$brcrum},
741: {href=>"javascript:backPage(document.crtuser)",
742: text=>"Pick custom role",
743: help => $helpitem,}
744: );
745: } else {
746: push (@{$brcrum},
747: {href => "javascript:backPage(document.crtuser)",
748: text => $breadcrumb_text{'search'},
749: help => $helpitem,
750: faq => 282,
751: bug => 'Instructor Interface',}
752: );
753: }
754: my %loaditems = (
755: 'onload' => "javascript:setFormElements(document.$formtoset)",
756: );
757: my $args = {bread_crumbs => $brcrum,
758: bread_crumbs_component => 'User Management',
759: add_entries => \%loaditems,};
760: $r->print(&Apache::loncommon::start_page('User Management',$jscript,$args));
761:
1.71 sakharuk 762: my %lt=&Apache::lonlocal::texthash(
1.229 raeburn 763: 'srst' => 'Search for a user and enroll as a student',
1.318 raeburn 764: 'srme' => 'Search for a user and enroll as a member',
1.229 raeburn 765: 'srad' => 'Search for a user and modify/add user information or roles',
1.406.2.5! raeburn 766: 'srva' => 'Search for a user and view access log information',
1.71 sakharuk 767: 'usr' => "Username",
768: 'dom' => "Domain",
1.324 raeburn 769: 'ecrp' => "Define or Edit Custom Role",
770: 'nr' => "role name",
1.282 schafran 771: 'cre' => "Next",
1.71 sakharuk 772: );
1.351 raeburn 773:
1.214 raeburn 774: if ($env{'form.action'} eq 'custom') {
1.190 raeburn 775: if (&Apache::lonnet::allowed('mcr','/')) {
1.324 raeburn 776: my $newroletext = &mt('Define new custom role:');
777: $r->print('<form action="/adm/createuser" method="post" name="docustom">'.
778: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
779: '<input type="hidden" name="phase" value="selected_custom_edit" />'.
780: '<h3>'.$lt{'ecrp'}.'</h3>'.
781: &Apache::loncommon::start_data_table().
782: &Apache::loncommon::start_data_table_row().
783: '<td>');
784: if (keys(%existingroles) > 0) {
785: $r->print('<br /><label><input type="radio" name="customroleaction" value="new" checked="checked" onclick="setCustomFields();" /><b>'.$newroletext.'</b></label>');
786: } else {
787: $r->print('<br /><input type="hidden" name="customroleaction" value="new" /><b>'.$newroletext.'</b>');
788: }
789: $r->print('</td><td align="center">'.$lt{'nr'}.'<br /><input type="text" size="15" name="newrolename" onfocus="setCustomAction('."'new'".');" /></td>'.
790: &Apache::loncommon::end_data_table_row());
791: if (keys(%existingroles) > 0) {
792: $r->print(&Apache::loncommon::start_data_table_row().'<td><br />'.
793: '<label><input type="radio" name="customroleaction" value="edit" onclick="setCustomFields();"/><b>'.
794: &mt('View/Modify existing role:').'</b></label></td>'.
795: '<td align="center"><br />'.
796: '<select name="rolename" onchange="setCustomAction('."'edit'".');">'.
1.326 raeburn 797: '<option value="" selected="selected">'.
1.324 raeburn 798: &mt('Select'));
799: foreach my $role (sort(keys(%existingroles))) {
1.326 raeburn 800: $r->print('<option value="'.$role.'">'.$role.'</option>');
1.324 raeburn 801: }
802: $r->print('</select>'.
803: '</td>'.
804: &Apache::loncommon::end_data_table_row());
805: }
806: $r->print(&Apache::loncommon::end_data_table().'<p>'.
807: '<input name="customeditor" type="submit" value="'.
808: $lt{'cre'}.'" /></p>'.
809: '</form>');
1.190 raeburn 810: }
1.213 raeburn 811: } else {
1.229 raeburn 812: my $actiontext = $lt{'srad'};
1.213 raeburn 813: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 814: if ($crstype eq 'Community') {
815: $actiontext = $lt{'srme'};
816: } else {
817: $actiontext = $lt{'srst'};
818: }
1.406.2.5! raeburn 819: } elsif ($env{'form.action'} eq 'accesslogs') {
! 820: $actiontext = $lt{'srva'};
1.213 raeburn 821: }
1.324 raeburn 822: $r->print("<h3>$actiontext</h3>");
1.213 raeburn 823: if ($env{'form.origform'} ne 'crtusername') {
1.406.2.5! raeburn 824: if ($response) {
! 825: $r->print("\n<div>$response</div>".
! 826: '<br clear="all" />');
! 827: }
1.213 raeburn 828: }
1.406.2.5! raeburn 829: $r->print(&entry_form($defdom,$srch,$forcenewuser,$context,$response,$crstype,1));
1.107 www 830: }
1.110 albertel 831: }
832:
1.324 raeburn 833: sub customrole_javascript {
834: my $js = <<"END";
835: <script type="text/javascript">
836: // <![CDATA[
837:
838: function setCustomFields() {
839: if (document.docustom.customroleaction.length > 0) {
840: for (var i=0; i<document.docustom.customroleaction.length; i++) {
841: if (document.docustom.customroleaction[i].checked) {
842: if (document.docustom.customroleaction[i].value == 'new') {
843: document.docustom.rolename.selectedIndex = 0;
844: } else {
845: document.docustom.newrolename.value = '';
846: }
847: }
848: }
849: }
850: return;
851: }
852:
853: function setCustomAction(caller) {
854: if (document.docustom.customroleaction.length > 0) {
855: for (var i=0; i<document.docustom.customroleaction.length; i++) {
856: if (document.docustom.customroleaction[i].value == caller) {
857: document.docustom.customroleaction[i].checked = true;
858: }
859: }
860: }
861: setCustomFields();
862: return;
863: }
864:
865: // ]]>
866: </script>
867: END
868: return $js;
869: }
870:
1.160 raeburn 871: sub entry_form {
1.406.2.5! raeburn 872: my ($dom,$srch,$forcenewuser,$context,$responsemsg,$crstype,$fixeddom) = @_;
1.229 raeburn 873: my ($usertype,$inexact);
1.214 raeburn 874: if (ref($srch) eq 'HASH') {
875: if (($srch->{'srchin'} eq 'dom') &&
876: ($srch->{'srchby'} eq 'uname') &&
877: ($srch->{'srchtype'} eq 'exact') &&
878: ($srch->{'srchdomain'} ne '') &&
879: ($srch->{'srchterm'} ne '')) {
1.353 raeburn 880: my (%curr_rules,%got_rules);
1.214 raeburn 881: my ($rules,$ruleorder) =
882: &Apache::lonnet::inst_userrules($srch->{'srchdomain'},'username');
1.353 raeburn 883: $usertype = &Apache::lonuserutils::check_usertype($srch->{'srchdomain'},$srch->{'srchterm'},$rules,\%curr_rules,\%got_rules);
1.229 raeburn 884: } else {
885: $inexact = 1;
1.214 raeburn 886: }
1.207 raeburn 887: }
1.214 raeburn 888: my $cancreate =
889: &Apache::lonuserutils::can_create_user($dom,$context,$usertype);
1.406.2.3 raeburn 890: my ($userpicker,$cansearch) =
1.179 raeburn 891: &Apache::loncommon::user_picker($dom,$srch,$forcenewuser,
1.406.2.5! raeburn 892: 'document.crtuser',$cancreate,$usertype,$context,$fixeddom);
1.160 raeburn 893: my $srchbutton = &mt('Search');
1.229 raeburn 894: if ($env{'form.action'} eq 'singlestudent') {
895: $srchbutton = &mt('Search and Enroll');
1.406.2.5! raeburn 896: } elsif ($env{'form.action'} eq 'accesslogs') {
! 897: $srchbutton = &mt('Search');
1.229 raeburn 898: } elsif ($cancreate && $responsemsg ne '' && $inexact) {
899: $srchbutton = &mt('Search or Add New User');
900: }
1.406.2.3 raeburn 901: my $output;
902: if ($cansearch) {
903: $output = <<"ENDBLOCK";
1.160 raeburn 904: <form action="/adm/createuser" method="post" name="crtuser">
1.190 raeburn 905: <input type="hidden" name="action" value="$env{'form.action'}" />
1.160 raeburn 906: <input type="hidden" name="phase" value="get_user_info" />
907: $userpicker
1.179 raeburn 908: <input name="userrole" type="button" value="$srchbutton" onclick="javascript:validateEntry(document.crtuser)" />
1.160 raeburn 909: </form>
1.207 raeburn 910: ENDBLOCK
1.406.2.3 raeburn 911: } else {
912: $output = '<p>'.$userpicker.'</p>';
913: }
1.406.2.5! raeburn 914: if (($env{'form.phase'} eq '') && ($env{'form.action'} ne 'accesslogs')) {
1.207 raeburn 915: my $defdom=$env{'request.role.domain'};
916: my $domform = &Apache::loncommon::select_dom_form($defdom,'srchdomain');
917: my %lt=&Apache::lonlocal::texthash(
1.229 raeburn 918: 'enro' => 'Enroll one student',
1.318 raeburn 919: 'enrm' => 'Enroll one member',
1.229 raeburn 920: 'admo' => 'Add/modify a single user',
921: 'crea' => 'create new user if required',
922: 'uskn' => "username is known",
1.207 raeburn 923: 'crnu' => 'Create a new user',
924: 'usr' => 'Username',
925: 'dom' => 'in domain',
1.229 raeburn 926: 'enrl' => 'Enroll',
927: 'cram' => 'Create/Modify user',
1.207 raeburn 928: );
1.229 raeburn 929: my $sellink=&Apache::loncommon::selectstudent_link('crtusername','srchterm','srchdomain');
930: my ($title,$buttontext,$showresponse);
1.318 raeburn 931: if ($env{'form.action'} eq 'singlestudent') {
932: if ($crstype eq 'Community') {
933: $title = $lt{'enrm'};
934: } else {
935: $title = $lt{'enro'};
936: }
1.229 raeburn 937: $buttontext = $lt{'enrl'};
938: } else {
939: $title = $lt{'admo'};
940: $buttontext = $lt{'cram'};
941: }
942: if ($cancreate) {
943: $title .= ' <span class="LC_cusr_subheading">('.$lt{'crea'}.')</span>';
944: } else {
945: $title .= ' <span class="LC_cusr_subheading">('.$lt{'uskn'}.')</span>';
946: }
947: if ($env{'form.origform'} eq 'crtusername') {
948: $showresponse = $responsemsg;
949: }
1.207 raeburn 950: $output .= <<"ENDDOCUMENT";
1.229 raeburn 951: <br />
1.207 raeburn 952: <form action="/adm/createuser" method="post" name="crtusername">
953: <input type="hidden" name="action" value="$env{'form.action'}" />
954: <input type="hidden" name="phase" value="createnewuser" />
955: <input type="hidden" name="srchtype" value="exact" />
1.233 raeburn 956: <input type="hidden" name="srchby" value="uname" />
1.207 raeburn 957: <input type="hidden" name="srchin" value="dom" />
958: <input type="hidden" name="forcenewuser" value="1" />
959: <input type="hidden" name="origform" value="crtusername" />
1.229 raeburn 960: <h3>$title</h3>
961: $showresponse
1.207 raeburn 962: <table>
963: <tr>
964: <td>$lt{'usr'}:</td>
965: <td><input type="text" size="15" name="srchterm" /></td>
966: <td> $lt{'dom'}:</td><td>$domform</td>
1.229 raeburn 967: <td> $sellink </td>
968: <td> <input name="userrole" type="submit" value="$buttontext" /></td>
1.207 raeburn 969: </tr>
970: </table>
971: </form>
1.160 raeburn 972: ENDDOCUMENT
1.207 raeburn 973: }
1.160 raeburn 974: return $output;
975: }
1.110 albertel 976:
977: sub user_modification_js {
1.113 raeburn 978: my ($pjump_def,$dc_setcourse_code,$nondc_setsection_code,$groupslist)=@_;
979:
1.110 albertel 980: return <<END;
981: <script type="text/javascript" language="Javascript">
1.301 bisitz 982: // <![CDATA[
1.314 raeburn 983:
1.110 albertel 984: $pjump_def
985: $dc_setcourse_code
986:
987: function dateset() {
988: eval("document.cu."+document.cu.pres_marker.value+
989: ".value=document.cu.pres_value.value");
1.359 www 990: modalWindow.close();
1.110 albertel 991: }
992:
1.113 raeburn 993: $nondc_setsection_code
1.301 bisitz 994: // ]]>
1.110 albertel 995: </script>
996: END
1.2 www 997: }
998:
999: # =================================================================== Phase two
1.160 raeburn 1000: sub print_user_selection_page {
1.351 raeburn 1001: my ($r,$response,$srch,$srch_results,$srcharray,$context,$opener_elements,$crstype,$brcrum) = @_;
1.160 raeburn 1002: my @fields = ('username','domain','lastname','firstname','permanentemail');
1003: my $sortby = $env{'form.sortby'};
1004:
1005: if (!grep(/^\Q$sortby\E$/,@fields)) {
1006: $sortby = 'lastname';
1007: }
1008:
1009: my ($jsback,$elements) = &crumb_utilities();
1010:
1011: my $jscript = (<<ENDSCRIPT);
1012: <script type="text/javascript">
1.301 bisitz 1013: // <![CDATA[
1.160 raeburn 1014: function pickuser(uname,udom) {
1015: document.usersrchform.seluname.value=uname;
1016: document.usersrchform.seludom.value=udom;
1017: document.usersrchform.phase.value="userpicked";
1018: document.usersrchform.submit();
1019: }
1020:
1021: $jsback
1.301 bisitz 1022: // ]]>
1.160 raeburn 1023: </script>
1024: ENDSCRIPT
1025:
1026: my %lt=&Apache::lonlocal::texthash(
1.179 raeburn 1027: 'usrch' => "User Search to add/modify roles",
1028: 'stusrch' => "User Search to enroll student",
1.318 raeburn 1029: 'memsrch' => "User Search to enroll member",
1.406.2.5! raeburn 1030: 'srcva' => "Search for a user and view access log information",
1.179 raeburn 1031: 'usel' => "Select a user to add/modify roles",
1.318 raeburn 1032: 'stusel' => "Select a user to enroll as a student",
1033: 'memsel' => "Select a user to enroll as a member",
1.406.2.5! raeburn 1034: 'vacsel' => "Select a user to view access log",
1.160 raeburn 1035: 'username' => "username",
1036: 'domain' => "domain",
1037: 'lastname' => "last name",
1038: 'firstname' => "first name",
1039: 'permanentemail' => "permanent e-mail",
1040: );
1.302 raeburn 1041: if ($context eq 'requestcrs') {
1042: $r->print('<div>');
1043: } else {
1.318 raeburn 1044: my %breadcrumb_text = &singleuser_breadcrumb($crstype);
1.351 raeburn 1045: my $helpitem;
1046: if ($env{'form.action'} eq 'singleuser') {
1047: $helpitem = 'Course_Change_Privileges';
1048: } elsif ($env{'form.action'} eq 'singlestudent') {
1049: $helpitem = 'Course_Add_Student';
1050: }
1051: push (@{$brcrum},
1052: {href => "javascript:backPage(document.usersrchform,'','')",
1053: text => $breadcrumb_text{'search'},
1054: faq => 282,
1055: bug => 'Instructor Interface',},
1056: {href => "javascript:backPage(document.usersrchform,'get_user_info','select')",
1057: text => $breadcrumb_text{'userpicked'},
1058: faq => 282,
1059: bug => 'Instructor Interface',
1060: help => $helpitem}
1061: );
1062: $r->print(&Apache::loncommon::start_page('User Management',$jscript,{bread_crumbs => $brcrum}));
1.302 raeburn 1063: if ($env{'form.action'} eq 'singleuser') {
1064: $r->print("<b>$lt{'usrch'}</b><br />");
1.318 raeburn 1065: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,$crstype));
1.302 raeburn 1066: $r->print('<h3>'.$lt{'usel'}.'</h3>');
1067: } elsif ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1068: $r->print($jscript."<b>");
1069: if ($crstype eq 'Community') {
1070: $r->print($lt{'memsrch'});
1071: } else {
1072: $r->print($lt{'stusrch'});
1073: }
1074: $r->print("</b><br />");
1075: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,$crstype));
1076: $r->print('</form><h3>');
1077: if ($crstype eq 'Community') {
1078: $r->print($lt{'memsel'});
1079: } else {
1080: $r->print($lt{'stusel'});
1081: }
1082: $r->print('</h3>');
1.406.2.5! raeburn 1083: } elsif ($env{'form.action'} eq 'accesslogs') {
! 1084: $r->print("<b>$lt{'srcva'}</b><br />");
! 1085: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,'accesslogs',undef,undef,1));
! 1086: $r->print('<h3>'.$lt{'vacsel'}.'</h3>');
1.302 raeburn 1087: }
1.179 raeburn 1088: }
1.380 bisitz 1089: $r->print('<form name="usersrchform" method="post" action="">'.
1.160 raeburn 1090: &Apache::loncommon::start_data_table()."\n".
1091: &Apache::loncommon::start_data_table_header_row()."\n".
1092: ' <th> </th>'."\n");
1093: foreach my $field (@fields) {
1094: $r->print(' <th><a href="javascript:document.usersrchform.sortby.value='.
1095: "'".$field."'".';document.usersrchform.submit();">'.
1096: $lt{$field}.'</a></th>'."\n");
1097: }
1098: $r->print(&Apache::loncommon::end_data_table_header_row());
1099:
1100: my @sorted_users = sort {
1.167 albertel 1101: lc($srch_results->{$a}->{$sortby}) cmp lc($srch_results->{$b}->{$sortby})
1.160 raeburn 1102: ||
1.167 albertel 1103: lc($srch_results->{$a}->{lastname}) cmp lc($srch_results->{$b}->{lastname})
1.160 raeburn 1104: ||
1105: lc($srch_results->{$a}->{firstname}) cmp lc($srch_results->{$b}->{firstname})
1.167 albertel 1106: ||
1107: lc($a) cmp lc($b)
1.160 raeburn 1108: } (keys(%$srch_results));
1109:
1110: foreach my $user (@sorted_users) {
1111: my ($uname,$udom) = split(/:/,$user);
1.302 raeburn 1112: my $onclick;
1113: if ($context eq 'requestcrs') {
1.314 raeburn 1114: $onclick =
1.302 raeburn 1115: 'onclick="javascript:gochoose('."'$uname','$udom',".
1116: "'$srch_results->{$user}->{firstname}',".
1117: "'$srch_results->{$user}->{lastname}',".
1118: "'$srch_results->{$user}->{permanentemail}'".');"';
1119: } else {
1.314 raeburn 1120: $onclick =
1.302 raeburn 1121: ' onclick="javascript:pickuser('."'".$uname."'".','."'".$udom."'".');"';
1122: }
1.160 raeburn 1123: $r->print(&Apache::loncommon::start_data_table_row().
1.302 raeburn 1124: '<td><input type="button" name="seluser" value="'.&mt('Select').'" '.
1125: $onclick.' /></td>'.
1.160 raeburn 1126: '<td><tt>'.$uname.'</tt></td>'.
1127: '<td><tt>'.$udom.'</tt></td>');
1128: foreach my $field ('lastname','firstname','permanentemail') {
1129: $r->print('<td>'.$srch_results->{$user}->{$field}.'</td>');
1130: }
1131: $r->print(&Apache::loncommon::end_data_table_row());
1132: }
1133: $r->print(&Apache::loncommon::end_data_table().'<br /><br />');
1.179 raeburn 1134: if (ref($srcharray) eq 'ARRAY') {
1135: foreach my $item (@{$srcharray}) {
1136: $r->print('<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n");
1137: }
1138: }
1.160 raeburn 1139: $r->print(' <input type="hidden" name="sortby" value="'.$sortby.'" />'."\n".
1140: ' <input type="hidden" name="seluname" value="" />'."\n".
1141: ' <input type="hidden" name="seludom" value="" />'."\n".
1.179 raeburn 1142: ' <input type="hidden" name="currstate" value="select" />'."\n".
1.190 raeburn 1143: ' <input type="hidden" name="phase" value="get_user_info" />'."\n".
1.214 raeburn 1144: ' <input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n");
1.302 raeburn 1145: if ($context eq 'requestcrs') {
1146: $r->print($opener_elements.'</form></div>');
1147: } else {
1.351 raeburn 1148: $r->print($response.'</form>');
1.302 raeburn 1149: }
1.160 raeburn 1150: }
1151:
1152: sub print_user_query_page {
1.351 raeburn 1153: my ($r,$caller,$brcrum) = @_;
1.160 raeburn 1154: # FIXME - this is for a network-wide name search (similar to catalog search)
1155: # To use frames with similar behavior to catalog/portfolio search.
1156: # To be implemented.
1157: return;
1158: }
1159:
1.42 matthew 1160: sub print_user_modification_page {
1.375 raeburn 1161: my ($r,$ccuname,$ccdomain,$srch,$response,$context,$permission,$crstype,
1162: $brcrum,$showcredits) = @_;
1.185 raeburn 1163: if (($ccuname eq '') || ($ccdomain eq '')) {
1.215 raeburn 1164: my $usermsg = &mt('No username and/or domain provided.');
1165: $env{'form.phase'} = '';
1.351 raeburn 1166: &print_username_entry_form($r,$context,$usermsg,'','',$crstype,$brcrum);
1.58 www 1167: return;
1168: }
1.213 raeburn 1169: my ($form,$formname);
1170: if ($env{'form.action'} eq 'singlestudent') {
1171: $form = 'document.enrollstudent';
1172: $formname = 'enrollstudent';
1173: } else {
1174: $form = 'document.cu';
1175: $formname = 'cu';
1176: }
1.188 raeburn 1177: my %abv_auth = &auth_abbrev();
1.227 raeburn 1178: my (%rulematch,%inst_results,$newuser,%alerts,%curr_rules,%got_rules);
1.185 raeburn 1179: my $uhome=&Apache::lonnet::homeserver($ccuname,$ccdomain);
1180: if ($uhome eq 'no_host') {
1.215 raeburn 1181: my $usertype;
1182: my ($rules,$ruleorder) =
1183: &Apache::lonnet::inst_userrules($ccdomain,'username');
1184: $usertype =
1.353 raeburn 1185: &Apache::lonuserutils::check_usertype($ccdomain,$ccuname,$rules,
1.362 raeburn 1186: \%curr_rules,\%got_rules);
1.215 raeburn 1187: my $cancreate =
1188: &Apache::lonuserutils::can_create_user($ccdomain,$context,
1189: $usertype);
1190: if (!$cancreate) {
1.292 bisitz 1191: my $helplink = 'javascript:helpMenu('."'display'".')';
1.215 raeburn 1192: my %usertypetext = (
1193: official => 'institutional',
1194: unofficial => 'non-institutional',
1195: );
1196: my $response;
1197: if ($env{'form.origform'} eq 'crtusername') {
1.362 raeburn 1198: $response = '<span class="LC_warning">'.
1199: &mt('No match found for the username [_1] in LON-CAPA domain: [_2]',
1200: '<b>'.$ccuname.'</b>',$ccdomain).
1.215 raeburn 1201: '</span><br />';
1202: }
1.292 bisitz 1203: $response .= '<p class="LC_warning">'
1204: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
1205: .' '
1206: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
1207: ,'<a href="'.$helplink.'">','</a>')
1208: .'</p><br />';
1.215 raeburn 1209: $env{'form.phase'} = '';
1.351 raeburn 1210: &print_username_entry_form($r,$context,$response,undef,undef,$crstype,$brcrum);
1.215 raeburn 1211: return;
1212: }
1.188 raeburn 1213: $newuser = 1;
1.193 raeburn 1214: my $checkhash;
1215: my $checks = { 'username' => 1 };
1.196 raeburn 1216: $checkhash->{$ccuname.':'.$ccdomain} = { 'newuser' => $newuser };
1.193 raeburn 1217: &Apache::loncommon::user_rule_check($checkhash,$checks,
1.196 raeburn 1218: \%alerts,\%rulematch,\%inst_results,\%curr_rules,\%got_rules);
1219: if (ref($alerts{'username'}) eq 'HASH') {
1220: if (ref($alerts{'username'}{$ccdomain}) eq 'HASH') {
1221: my $domdesc =
1.193 raeburn 1222: &Apache::lonnet::domain($ccdomain,'description');
1.196 raeburn 1223: if ($alerts{'username'}{$ccdomain}{$ccuname}) {
1224: my $userchkmsg;
1225: if (ref($curr_rules{$ccdomain}) eq 'HASH') {
1226: $userchkmsg =
1227: &Apache::loncommon::instrule_disallow_msg('username',
1.193 raeburn 1228: $domdesc,1).
1229: &Apache::loncommon::user_rule_formats($ccdomain,
1230: $domdesc,$curr_rules{$ccdomain}{'username'},
1231: 'username');
1.196 raeburn 1232: }
1.215 raeburn 1233: $env{'form.phase'} = '';
1.351 raeburn 1234: &print_username_entry_form($r,$context,$userchkmsg,undef,undef,$crstype,$brcrum);
1.196 raeburn 1235: return;
1.215 raeburn 1236: }
1.193 raeburn 1237: }
1.185 raeburn 1238: }
1.187 raeburn 1239: } else {
1.188 raeburn 1240: $newuser = 0;
1.185 raeburn 1241: }
1.160 raeburn 1242: if ($response) {
1.215 raeburn 1243: $response = '<br />'.$response;
1.160 raeburn 1244: }
1.149 raeburn 1245:
1.52 matthew 1246: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
1.88 raeburn 1247: my $dc_setcourse_code = '';
1.119 raeburn 1248: my $nondc_setsection_code = '';
1.112 albertel 1249: my %loaditem;
1.114 albertel 1250:
1.216 raeburn 1251: my $groupslist = &Apache::lonuserutils::get_groupslist();
1.88 raeburn 1252:
1.375 raeburn 1253: my $js = &validation_javascript($context,$ccdomain,$pjump_def,$crstype,
1.216 raeburn 1254: $groupslist,$newuser,$formname,\%loaditem);
1.318 raeburn 1255: my %breadcrumb_text = &singleuser_breadcrumb($crstype);
1.224 raeburn 1256: my $helpitem = 'Course_Change_Privileges';
1257: if ($env{'form.action'} eq 'singlestudent') {
1258: $helpitem = 'Course_Add_Student';
1259: }
1.351 raeburn 1260: push (@{$brcrum},
1261: {href => "javascript:backPage($form)",
1262: text => $breadcrumb_text{'search'},
1263: faq => 282,
1264: bug => 'Instructor Interface',});
1265: if ($env{'form.phase'} eq 'userpicked') {
1266: push(@{$brcrum},
1267: {href => "javascript:backPage($form,'get_user_info','select')",
1268: text => $breadcrumb_text{'userpicked'},
1269: faq => 282,
1270: bug => 'Instructor Interface',});
1271: }
1272: push(@{$brcrum},
1273: {href => "javascript:backPage($form,'$env{'form.phase'}','modify')",
1274: text => $breadcrumb_text{'modify'},
1275: faq => 282,
1276: bug => 'Instructor Interface',
1277: help => $helpitem});
1278: my $args = {'add_entries' => \%loaditem,
1279: 'bread_crumbs' => $brcrum,
1280: 'bread_crumbs_component' => 'User Management'};
1281: if ($env{'form.popup'}) {
1282: $args->{'no_nav_bar'} = 1;
1283: }
1284: my $start_page =
1285: &Apache::loncommon::start_page('User Management',$js,$args);
1.3 www 1286:
1.25 matthew 1287: my $forminfo =<<"ENDFORMINFO";
1.216 raeburn 1288: <form action="/adm/createuser" method="post" name="$formname">
1.190 raeburn 1289: <input type="hidden" name="phase" value="update_user_data" />
1.188 raeburn 1290: <input type="hidden" name="ccuname" value="$ccuname" />
1291: <input type="hidden" name="ccdomain" value="$ccdomain" />
1.157 albertel 1292: <input type="hidden" name="pres_value" value="" />
1293: <input type="hidden" name="pres_type" value="" />
1294: <input type="hidden" name="pres_marker" value="" />
1.25 matthew 1295: ENDFORMINFO
1.375 raeburn 1296: my (%inccourses,$roledom,$defaultcredits);
1.329 raeburn 1297: if ($context eq 'course') {
1298: $inccourses{$env{'request.course.id'}}=1;
1299: $roledom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1.375 raeburn 1300: if ($showcredits) {
1301: $defaultcredits = &Apache::lonuserutils::get_defaultcredits();
1302: }
1.329 raeburn 1303: } elsif ($context eq 'author') {
1304: $roledom = $env{'request.role.domain'};
1305: } elsif ($context eq 'domain') {
1306: foreach my $key (keys(%env)) {
1307: $roledom = $env{'request.role.domain'};
1308: if ($key=~/^user\.priv\.cm\.\/($roledom)\/($match_username)/) {
1309: $inccourses{$1.'_'.$2}=1;
1310: }
1311: }
1312: } else {
1313: foreach my $key (keys(%env)) {
1314: if ($key=~/^user\.priv\.cm\.\/($match_domain)\/($match_username)/) {
1315: $inccourses{$1.'_'.$2}=1;
1316: }
1.2 www 1317: }
1.24 matthew 1318: }
1.389 bisitz 1319: my $title = '';
1.216 raeburn 1320: if ($newuser) {
1.406.2.5! raeburn 1321: my ($portfolioform,$domroleform,$adhocroleform);
1.267 raeburn 1322: if ((&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) ||
1323: (&Apache::lonnet::allowed('mut',$env{'request.role.domain'}))) {
1324: # Current user has quota or user tools modification privileges
1.378 raeburn 1325: $portfolioform = '<br />'.&user_quotas($ccuname,$ccdomain);
1.134 raeburn 1326: }
1.383 raeburn 1327: if ((&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) &&
1328: ($ccdomain eq $env{'request.role.domain'})) {
1.362 raeburn 1329: $domroleform = '<br />'.&domainrole_req($ccuname,$ccdomain);
1330: }
1.406.2.5! raeburn 1331: if (&Apache::lonnet::allowed('cdh',$env{'request.role.domain'})) {
! 1332: $adhocroleform = &domadhocroles($ccuname,$ccdomain);
! 1333: if ($adhocroleform) {
! 1334: $adhocroleform = '<br />'.$adhocroleform;
! 1335: }
! 1336: }
1.227 raeburn 1337: &initialize_authen_forms($ccdomain,$formname);
1.188 raeburn 1338: my %lt=&Apache::lonlocal::texthash(
1339: 'lg' => 'Login Data',
1.190 raeburn 1340: 'hs' => "Home Server",
1.188 raeburn 1341: );
1.185 raeburn 1342: $r->print(<<ENDTITLE);
1.110 albertel 1343: $start_page
1.160 raeburn 1344: $response
1.25 matthew 1345: $forminfo
1.31 matthew 1346: <script type="text/javascript" language="Javascript">
1.301 bisitz 1347: // <![CDATA[
1.20 harris41 1348: $loginscript
1.301 bisitz 1349: // ]]>
1.31 matthew 1350: </script>
1.20 harris41 1351: <input type='hidden' name='makeuser' value='1' />
1.185 raeburn 1352: ENDTITLE
1.213 raeburn 1353: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1354: if ($crstype eq 'Community') {
1.389 bisitz 1355: $title = &mt('Create New User [_1] in domain [_2] as a member',
1356: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1357: } else {
1.389 bisitz 1358: $title = &mt('Create New User [_1] in domain [_2] as a student',
1359: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1360: }
1.389 bisitz 1361: } else {
1362: $title = &mt('Create New User [_1] in domain [_2]',
1363: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.213 raeburn 1364: }
1.389 bisitz 1365: $r->print('<h2>'.$title.'</h2>'."\n");
1366: $r->print('<div class="LC_left_float">');
1.393 raeburn 1367: $r->print(&personal_data_display($ccuname,$ccdomain,$newuser,$context,
1368: $inst_results{$ccuname.':'.$ccdomain}));
1369: # Option to disable student/employee ID conflict checking not offerred for new users.
1.187 raeburn 1370: my ($home_server_pick,$numlib) =
1371: &Apache::loncommon::home_server_form_item($ccdomain,'hserver',
1372: 'default','hide');
1373: if ($numlib > 1) {
1374: $r->print("
1.185 raeburn 1375: <br />
1.187 raeburn 1376: $lt{'hs'}: $home_server_pick
1377: <br />");
1378: } else {
1379: $r->print($home_server_pick);
1380: }
1.304 raeburn 1381: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.362 raeburn 1382: $r->print('<br /><h3>'.
1383: &mt('User Can Request Creation of Courses/Communities in this Domain?').'</h3>'.
1.304 raeburn 1384: &Apache::loncommon::start_data_table().
1385: &build_tools_display($ccuname,$ccdomain,
1386: 'requestcourses').
1387: &Apache::loncommon::end_data_table());
1388: }
1.188 raeburn 1389: $r->print('</div>'."\n".'<div class="LC_left_float"><h3>'.
1390: $lt{'lg'}.'</h3>');
1.185 raeburn 1391: my ($fixedauth,$varauth,$authmsg);
1.193 raeburn 1392: if (ref($rulematch{$ccuname.':'.$ccdomain}) eq 'HASH') {
1393: my $matchedrule = $rulematch{$ccuname.':'.$ccdomain}{'username'};
1394: my ($rules,$ruleorder) =
1395: &Apache::lonnet::inst_userrules($ccdomain,'username');
1.185 raeburn 1396: if (ref($rules) eq 'HASH') {
1.193 raeburn 1397: if (ref($rules->{$matchedrule}) eq 'HASH') {
1398: my $authtype = $rules->{$matchedrule}{'authtype'};
1.185 raeburn 1399: if ($authtype !~ /^(krb4|krb5|int|fsys|loc)$/) {
1.190 raeburn 1400: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.275 raeburn 1401: } else {
1.193 raeburn 1402: my $authparm = $rules->{$matchedrule}{'authparm'};
1.273 raeburn 1403: $authmsg = $rules->{$matchedrule}{'authmsg'};
1.185 raeburn 1404: if ($authtype =~ /^krb(4|5)$/) {
1405: my $ver = $1;
1406: if ($authparm ne '') {
1407: $fixedauth = <<"KERB";
1408: <input type="hidden" name="login" value="krb" />
1409: <input type="hidden" name="krbver" value="$ver" />
1410: <input type="hidden" name="krbarg" value="$authparm" />
1411: KERB
1412: }
1413: } else {
1414: $fixedauth =
1415: '<input type="hidden" name="login" value="'.$authtype.'" />'."\n";
1.193 raeburn 1416: if ($rules->{$matchedrule}{'authparmfixed'}) {
1.185 raeburn 1417: $fixedauth .=
1418: '<input type="hidden" name="'.$authtype.'arg" value="'.$authparm.'" />'."\n";
1419: } else {
1.273 raeburn 1420: if ($authtype eq 'int') {
1421: $varauth = '<br />'.
1.301 bisitz 1422: &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 1423: } elsif ($authtype eq 'loc') {
1424: $varauth = '<br />'.
1425: &mt('[_1] Local Authentication with argument [_2]','','<input type="text" name="'.$authtype.'arg" value="" />')."\n";
1426: } else {
1427: $varauth =
1.185 raeburn 1428: '<input type="text" name="'.$authtype.'arg" value="" />'."\n";
1.273 raeburn 1429: }
1.185 raeburn 1430: }
1431: }
1432: }
1433: } else {
1.190 raeburn 1434: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.185 raeburn 1435: }
1436: }
1437: if ($authmsg) {
1438: $r->print(<<ENDAUTH);
1439: $fixedauth
1440: $authmsg
1441: $varauth
1442: ENDAUTH
1443: }
1444: } else {
1.190 raeburn 1445: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.187 raeburn 1446: }
1.406.2.5! raeburn 1447: $r->print($portfolioform.$domroleform.$adhocroleform);
1.215 raeburn 1448: if ($env{'form.action'} eq 'singlestudent') {
1449: $r->print(&date_sections_select($context,$newuser,$formname,
1.375 raeburn 1450: $permission,$crstype,$ccuname,
1451: $ccdomain,$showcredits));
1.215 raeburn 1452: }
1453: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.216 raeburn 1454: } else { # user already exists
1.389 bisitz 1455: $r->print($start_page.$forminfo);
1.213 raeburn 1456: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1457: if ($crstype eq 'Community') {
1.389 bisitz 1458: $title = &mt('Enroll one member: [_1] in domain [_2]',
1459: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1460: } else {
1.389 bisitz 1461: $title = &mt('Enroll one student: [_1] in domain [_2]',
1462: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1463: }
1.213 raeburn 1464: } else {
1.389 bisitz 1465: $title = &mt('Modify existing user: [_1] in domain [_2]',
1466: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.213 raeburn 1467: }
1.389 bisitz 1468: $r->print('<h2>'.$title.'</h2>'."\n");
1469: $r->print('<div class="LC_left_float">');
1.393 raeburn 1470: $r->print(&personal_data_display($ccuname,$ccdomain,$newuser,$context,
1471: $inst_results{$ccuname.':'.$ccdomain}));
1.275 raeburn 1472: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.362 raeburn 1473: $r->print('<br /><h3>'.&mt('User Can Request Creation of Courses/Communities in this Domain?').'</h3>'.
1.300 raeburn 1474: &Apache::loncommon::start_data_table());
1.314 raeburn 1475: if ($env{'request.role.domain'} eq $ccdomain) {
1.300 raeburn 1476: $r->print(&build_tools_display($ccuname,$ccdomain,'requestcourses'));
1477: } else {
1478: $r->print(&coursereq_externaluser($ccuname,$ccdomain,
1479: $env{'request.role.domain'}));
1480: }
1481: $r->print(&Apache::loncommon::end_data_table());
1.275 raeburn 1482: }
1.199 raeburn 1483: $r->print('</div>');
1.406.2.5! raeburn 1484: my @order = ('auth','quota','tools','requestauthor','adhocroles');
1.362 raeburn 1485: my %user_text;
1486: my ($isadv,$isauthor) =
1487: &Apache::lonnet::is_advanced_user($ccuname,$ccdomain);
1488: if ((!$isauthor) &&
1.383 raeburn 1489: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))
1490: && ($env{'request.role.domain'} eq $ccdomain)) {
1.362 raeburn 1491: $user_text{'requestauthor'} = &domainrole_req($ccuname,$ccdomain);
1492: }
1.406.2.5! raeburn 1493: if (&Apache::lonnet::allowed('cdh',$env{'request.role.domain'})) {
! 1494: $user_text{'adhocroles'} = &domadhocroles($ccuname,$ccdomain);
! 1495: }
1.362 raeburn 1496: $user_text{'auth'} = &user_authentication($ccuname,$ccdomain,$formname);
1.267 raeburn 1497: if ((&Apache::lonnet::allowed('mpq',$ccdomain)) ||
1498: (&Apache::lonnet::allowed('mut',$ccdomain))) {
1.188 raeburn 1499: # Current user has quota modification privileges
1.378 raeburn 1500: $user_text{'quota'} = &user_quotas($ccuname,$ccdomain);
1.267 raeburn 1501: }
1502: if (!&Apache::lonnet::allowed('mpq',$ccdomain)) {
1503: if (&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) {
1504: my %lt=&Apache::lonlocal::texthash(
1.385 bisitz 1505: 'dska' => "Disk quotas for user's portfolio and Authoring Space",
1506: 'youd' => "You do not have privileges to modify the portfolio and/or Authoring Space quotas for this user.",
1.267 raeburn 1507: 'ichr' => "If a change is required, contact a domain coordinator for the domain",
1508: );
1.362 raeburn 1509: $user_text{'quota'} = <<ENDNOPORTPRIV;
1.188 raeburn 1510: <h3>$lt{'dska'}</h3>
1511: $lt{'youd'} $lt{'ichr'}: $ccdomain
1512: ENDNOPORTPRIV
1.267 raeburn 1513: }
1514: }
1515: if (!&Apache::lonnet::allowed('mut',$ccdomain)) {
1516: if (&Apache::lonnet::allowed('mut',$env{'request.role.domain'})) {
1517: my %lt=&Apache::lonlocal::texthash(
1518: 'utav' => "User Tools Availability",
1.361 raeburn 1519: 'yodo' => "You do not have privileges to modify Portfolio, Blog, WebDAV, or Personal Information Page settings for this user.",
1.267 raeburn 1520: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
1521: );
1.362 raeburn 1522: $user_text{'tools'} = <<ENDNOTOOLSPRIV;
1.267 raeburn 1523: <h3>$lt{'utav'}</h3>
1524: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1525: ENDNOTOOLSPRIV
1526: }
1.188 raeburn 1527: }
1.362 raeburn 1528: my $gotdiv = 0;
1529: foreach my $item (@order) {
1530: if ($user_text{$item} ne '') {
1531: unless ($gotdiv) {
1532: $r->print('<div class="LC_left_float">');
1533: $gotdiv = 1;
1534: }
1535: $r->print('<br />'.$user_text{$item});
1536: }
1537: }
1538: if ($env{'form.action'} eq 'singlestudent') {
1539: unless ($gotdiv) {
1540: $r->print('<div class="LC_left_float">');
1.213 raeburn 1541: }
1.375 raeburn 1542: my $credits;
1543: if ($showcredits) {
1544: $credits = &get_user_credits($ccuname,$ccdomain,$defaultcredits);
1545: if ($credits eq '') {
1546: $credits = $defaultcredits;
1547: }
1548: }
1.374 raeburn 1549: $r->print(&date_sections_select($context,$newuser,$formname,
1.375 raeburn 1550: $permission,$crstype,$ccuname,
1551: $ccdomain,$showcredits));
1.374 raeburn 1552: }
1.362 raeburn 1553: if ($gotdiv) {
1554: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.188 raeburn 1555: }
1.217 raeburn 1556: if ($env{'form.action'} ne 'singlestudent') {
1.329 raeburn 1557: &display_existing_roles($r,$ccuname,$ccdomain,\%inccourses,$context,
1558: $roledom,$crstype);
1.217 raeburn 1559: }
1.25 matthew 1560: } ## End of new user/old user logic
1.218 raeburn 1561: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1562: my $btntxt;
1563: if ($crstype eq 'Community') {
1564: $btntxt = &mt('Enroll Member');
1565: } else {
1566: $btntxt = &mt('Enroll Student');
1567: }
1568: $r->print('<br /><input type="button" value="'.$btntxt.'" onclick="setSections(this.form)" />'."\n");
1.218 raeburn 1569: } else {
1.393 raeburn 1570: $r->print('<div class="LC_left_float">'.
1571: '<fieldset><legend>'.&mt('Add Roles').'</legend>');
1.218 raeburn 1572: my $addrolesdisplay = 0;
1573: if ($context eq 'domain' || $context eq 'author') {
1574: $addrolesdisplay = &new_coauthor_roles($r,$ccuname,$ccdomain);
1575: }
1576: if ($context eq 'domain') {
1.357 raeburn 1577: my $add_domainroles = &new_domain_roles($r,$ccdomain);
1.218 raeburn 1578: if (!$addrolesdisplay) {
1579: $addrolesdisplay = $add_domainroles;
1.2 www 1580: }
1.375 raeburn 1581: $r->print(&course_level_dc($env{'request.role.domain'},$showcredits));
1.393 raeburn 1582: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1583: '<br /><input type="button" value="'.&mt('Save').'" onclick="setCourse()" />'."\n");
1.218 raeburn 1584: } elsif ($context eq 'author') {
1585: if ($addrolesdisplay) {
1.393 raeburn 1586: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1587: '<br /><input type="button" value="'.&mt('Save').'"');
1.218 raeburn 1588: if ($newuser) {
1.301 bisitz 1589: $r->print(' onclick="auth_check()" \>'."\n");
1.218 raeburn 1590: } else {
1.301 bisitz 1591: $r->print('onclick="this.form.submit()" \>'."\n");
1.218 raeburn 1592: }
1.188 raeburn 1593: } else {
1.393 raeburn 1594: $r->print('</fieldset></div>'.
1595: '<div class="LC_clear_float_footer"></div>'.
1596: '<br /><a href="javascript:backPage(document.cu)">'.
1.218 raeburn 1597: &mt('Back to previous page').'</a>');
1.188 raeburn 1598: }
1599: } else {
1.375 raeburn 1600: $r->print(&course_level_table(\%inccourses,$showcredits,$defaultcredits));
1.393 raeburn 1601: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1602: '<br /><input type="button" value="'.&mt('Save').'" onclick="setSections(this.form)" />'."\n");
1.188 raeburn 1603: }
1.88 raeburn 1604: }
1.188 raeburn 1605: $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','userrole','ccdomain','prevphase','currstate','ccuname','ccdomain']));
1.179 raeburn 1606: $r->print('<input type="hidden" name="currstate" value="" />');
1.393 raeburn 1607: $r->print('<input type="hidden" name="prevphase" value="'.$env{'form.phase'}.'" /></form><br /><br />');
1.218 raeburn 1608: return;
1.2 www 1609: }
1.1 www 1610:
1.213 raeburn 1611: sub singleuser_breadcrumb {
1.318 raeburn 1612: my ($crstype) = @_;
1.213 raeburn 1613: my %breadcrumb_text;
1614: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1615: if ($crstype eq 'Community') {
1616: $breadcrumb_text{'search'} = 'Enroll a member';
1617: } else {
1618: $breadcrumb_text{'search'} = 'Enroll a student';
1619: }
1.213 raeburn 1620: $breadcrumb_text{'userpicked'} = 'Select a user',
1621: $breadcrumb_text{'modify'} = 'Set section/dates',
1.406.2.5! raeburn 1622: } elsif ($env{'form.action'} eq 'accesslogs') {
! 1623: $breadcrumb_text{'search'} = 'View access logs for a user';
! 1624: $breadcrumb_text{'userpicked'} = 'Select a user',
! 1625: $breadcrumb_text{'activity'} = 'Activity',
1.213 raeburn 1626: } else {
1.229 raeburn 1627: $breadcrumb_text{'search'} = 'Create/modify a user';
1.213 raeburn 1628: $breadcrumb_text{'userpicked'} = 'Select a user',
1629: $breadcrumb_text{'modify'} = 'Set user role',
1630: }
1631: return %breadcrumb_text;
1632: }
1633:
1634: sub date_sections_select {
1.375 raeburn 1635: my ($context,$newuser,$formname,$permission,$crstype,$ccuname,$ccdomain,
1636: $showcredits) = @_;
1637: my $credits;
1638: if ($showcredits) {
1639: my $defaultcredits = &Apache::lonuserutils::get_defaultcredits();
1640: $credits = &get_user_credits($ccuname,$ccdomain,$defaultcredits);
1641: if ($credits eq '') {
1642: $credits = $defaultcredits;
1643: }
1644: }
1.213 raeburn 1645: my $cid = $env{'request.course.id'};
1646: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity($cid);
1647: my $date_table = '<h3>'.&mt('Starting and Ending Dates').'</h3>'."\n".
1648: &Apache::lonuserutils::date_setting_table(undef,undef,$context,
1649: undef,$formname,$permission);
1650: my $rowtitle = 'Section';
1.375 raeburn 1651: my $secbox = '<h3>'.&mt('Section and Credits').'</h3>'."\n".
1.213 raeburn 1652: &Apache::lonuserutils::section_picker($cdom,$cnum,'st',$rowtitle,
1.375 raeburn 1653: $permission,$context,'',$crstype,
1654: $showcredits,$credits);
1.213 raeburn 1655: my $output = $date_table.$secbox;
1656: return $output;
1657: }
1658:
1.216 raeburn 1659: sub validation_javascript {
1.375 raeburn 1660: my ($context,$ccdomain,$pjump_def,$crstype,$groupslist,$newuser,$formname,
1.216 raeburn 1661: $loaditem) = @_;
1662: my $dc_setcourse_code = '';
1663: my $nondc_setsection_code = '';
1664: if ($context eq 'domain') {
1665: my $dcdom = $env{'request.role.domain'};
1666: $loaditem->{'onload'} = "document.cu.coursedesc.value='';";
1.227 raeburn 1667: $dc_setcourse_code =
1668: &Apache::lonuserutils::dc_setcourse_js('cu','singleuser',$context);
1.216 raeburn 1669: } else {
1.227 raeburn 1670: my $checkauth;
1671: if (($newuser) || (&Apache::lonnet::allowed('mau',$ccdomain))) {
1672: $checkauth = 1;
1673: }
1674: if ($context eq 'course') {
1675: $nondc_setsection_code =
1676: &Apache::lonuserutils::setsections_javascript($formname,$groupslist,
1.375 raeburn 1677: undef,$checkauth,
1678: $crstype);
1.227 raeburn 1679: }
1680: if ($checkauth) {
1681: $nondc_setsection_code .=
1682: &Apache::lonuserutils::verify_authen($formname,$context);
1683: }
1.216 raeburn 1684: }
1685: my $js = &user_modification_js($pjump_def,$dc_setcourse_code,
1686: $nondc_setsection_code,$groupslist);
1687: my ($jsback,$elements) = &crumb_utilities();
1688: $js .= "\n".
1.301 bisitz 1689: '<script type="text/javascript">'."\n".
1690: '// <![CDATA['."\n".
1691: $jsback."\n".
1692: '// ]]>'."\n".
1693: '</script>'."\n";
1.216 raeburn 1694: return $js;
1695: }
1696:
1.217 raeburn 1697: sub display_existing_roles {
1.375 raeburn 1698: my ($r,$ccuname,$ccdomain,$inccourses,$context,$roledom,$crstype,
1699: $showcredits) = @_;
1.329 raeburn 1700: my $now=time;
1701: my %lt=&Apache::lonlocal::texthash(
1.217 raeburn 1702: 'rer' => "Existing Roles",
1703: 'rev' => "Revoke",
1704: 'del' => "Delete",
1705: 'ren' => "Re-Enable",
1706: 'rol' => "Role",
1707: 'ext' => "Extent",
1.375 raeburn 1708: 'crd' => "Credits",
1.217 raeburn 1709: 'sta' => "Start",
1710: 'end' => "End",
1711: );
1.329 raeburn 1712: my (%rolesdump,%roletext,%sortrole,%roleclass,%rolepriv);
1713: if ($context eq 'course' || $context eq 'author') {
1714: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
1715: my %roleshash =
1716: &Apache::lonnet::get_my_roles($ccuname,$ccdomain,'userroles',
1717: ['active','previous','future'],\@roles,$roledom,1);
1718: foreach my $key (keys(%roleshash)) {
1719: my ($start,$end) = split(':',$roleshash{$key});
1720: next if ($start eq '-1' || $end eq '-1');
1721: my ($rnum,$rdom,$role,$sec) = split(':',$key);
1722: if ($context eq 'course') {
1723: next unless (($rnum eq $env{'course.'.$env{'request.course.id'}.'.num'})
1724: && ($rdom eq $env{'course.'.$env{'request.course.id'}.'.domain'}));
1725: } elsif ($context eq 'author') {
1726: next unless (($rnum eq $env{'user.name'}) && ($rdom eq $env{'request.role.domain'}));
1727: }
1728: my ($newkey,$newvalue,$newrole);
1729: $newkey = '/'.$rdom.'/'.$rnum;
1730: if ($sec ne '') {
1731: $newkey .= '/'.$sec;
1732: }
1733: $newvalue = $role;
1734: if ($role =~ /^cr/) {
1735: $newrole = 'cr';
1736: } else {
1737: $newrole = $role;
1738: }
1739: $newkey .= '_'.$newrole;
1740: if ($start ne '' && $end ne '') {
1741: $newvalue .= '_'.$end.'_'.$start;
1.335 raeburn 1742: } elsif ($end ne '') {
1743: $newvalue .= '_'.$end;
1.329 raeburn 1744: }
1745: $rolesdump{$newkey} = $newvalue;
1746: }
1747: } else {
1.360 raeburn 1748: %rolesdump=&Apache::lonnet::dump('roles',$ccdomain,$ccuname);
1.329 raeburn 1749: }
1750: # Build up table of user roles to allow revocation and re-enabling of roles.
1751: my ($tmp) = keys(%rolesdump);
1752: return if ($tmp =~ /^(con_lost|error)/i);
1753: foreach my $area (sort { my $a1=join('_',(split('_',$a))[1,0]);
1754: my $b1=join('_',(split('_',$b))[1,0]);
1755: return $a1 cmp $b1;
1756: } keys(%rolesdump)) {
1757: next if ($area =~ /^rolesdef/);
1758: my $envkey=$area;
1759: my $role = $rolesdump{$area};
1760: my $thisrole=$area;
1761: $area =~ s/\_\w\w$//;
1762: my ($role_code,$role_end_time,$role_start_time) =
1763: split(/_/,$role);
1.217 raeburn 1764: # Is this a custom role? Get role owner and title.
1.329 raeburn 1765: my ($croleudom,$croleuname,$croletitle)=
1766: ($role_code=~m{^cr/($match_domain)/($match_username)/(\w+)$});
1767: my $allowed=0;
1768: my $delallowed=0;
1769: my $sortkey=$role_code;
1770: my $class='Unknown';
1.375 raeburn 1771: my $credits='';
1.329 raeburn 1772: if ($area =~ m{^/($match_domain)/($match_courseid)} ) {
1773: $class='Course';
1774: my ($coursedom,$coursedir) = ($1,$2);
1775: my $cid = $1.'_'.$2;
1776: # $1.'_'.$2 is the course id (eg. 103_12345abcef103l3).
1777: my %coursedata=
1778: &Apache::lonnet::coursedescription($cid);
1779: if ($coursedir =~ /^$match_community$/) {
1780: $class='Community';
1781: }
1782: $sortkey.="\0$coursedom";
1783: my $carea;
1784: if (defined($coursedata{'description'})) {
1785: $carea=$coursedata{'description'}.
1786: '<br />'.&mt('Domain').': '.$coursedom.(' 'x8).
1787: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$coursedir,$coursedom);
1788: $sortkey.="\0".$coursedata{'description'};
1789: } else {
1790: if ($class eq 'Community') {
1791: $carea=&mt('Unavailable community').': '.$area;
1792: $sortkey.="\0".&mt('Unavailable community').': '.$area;
1.217 raeburn 1793: } else {
1794: $carea=&mt('Unavailable course').': '.$area;
1795: $sortkey.="\0".&mt('Unavailable course').': '.$area;
1796: }
1.329 raeburn 1797: }
1798: $sortkey.="\0$coursedir";
1799: $inccourses->{$cid}=1;
1.375 raeburn 1800: if (($showcredits) && ($class eq 'Course') && ($role_code eq 'st')) {
1801: my $defaultcredits = $coursedata{'internal.defaultcredits'};
1802: $credits =
1803: &get_user_credits($ccuname,$ccdomain,$defaultcredits,
1804: $coursedom,$coursedir);
1805: if ($credits eq '') {
1806: $credits = $defaultcredits;
1807: }
1808: }
1.329 raeburn 1809: if ((&Apache::lonnet::allowed('c'.$role_code,$coursedom.'/'.$coursedir)) ||
1810: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
1811: $allowed=1;
1812: }
1813: unless ($allowed) {
1.365 raeburn 1814: my $isowner = &Apache::lonuserutils::is_courseowner($cid,$coursedata{'internal.courseowner'});
1.329 raeburn 1815: if ($isowner) {
1816: if (($role_code eq 'co') && ($class eq 'Community')) {
1817: $allowed = 1;
1818: } elsif (($role_code eq 'cc') && ($class eq 'Course')) {
1819: $allowed = 1;
1820: }
1.217 raeburn 1821: }
1.329 raeburn 1822: }
1823: if ((&Apache::lonnet::allowed('dro',$coursedom)) ||
1824: (&Apache::lonnet::allowed('dro',$ccdomain))) {
1825: $delallowed=1;
1826: }
1.217 raeburn 1827: # - custom role. Needs more info, too
1.329 raeburn 1828: if ($croletitle) {
1829: if (&Apache::lonnet::allowed('ccr',$coursedom.'/'.$coursedir)) {
1830: $allowed=1;
1831: $thisrole.='.'.$role_code;
1.217 raeburn 1832: }
1.329 raeburn 1833: }
1834: if ($area=~m{^/($match_domain)/($match_courseid)/(\w+)}) {
1.373 bisitz 1835: $carea.='<br />'.&mt('Section: [_1]',$3);
1.329 raeburn 1836: $sortkey.="\0$3";
1837: if (!$allowed) {
1838: if ($env{'request.course.sec'} eq $3) {
1839: if (&Apache::lonnet::allowed('c'.$role_code,$1.'/'.$2.'/'.$3)) {
1840: $allowed = 1;
1.217 raeburn 1841: }
1842: }
1843: }
1.329 raeburn 1844: }
1845: $area=$carea;
1846: } else {
1847: $sortkey.="\0".$area;
1848: # Determine if current user is able to revoke privileges
1849: if ($area=~m{^/($match_domain)/}) {
1850: if ((&Apache::lonnet::allowed('c'.$role_code,$1)) ||
1851: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
1852: $allowed=1;
1.217 raeburn 1853: }
1.329 raeburn 1854: if (((&Apache::lonnet::allowed('dro',$1)) ||
1855: (&Apache::lonnet::allowed('dro',$ccdomain))) &&
1856: ($role_code ne 'dc')) {
1857: $delallowed=1;
1.217 raeburn 1858: }
1.329 raeburn 1859: } else {
1860: if (&Apache::lonnet::allowed('c'.$role_code,'/')) {
1.217 raeburn 1861: $allowed=1;
1862: }
1863: }
1.363 raeburn 1864: if ($role_code eq 'ca' || $role_code eq 'au' || $role_code eq 'aa') {
1.377 raeburn 1865: $class='Authoring Space';
1.329 raeburn 1866: } elsif ($role_code eq 'su') {
1867: $class='System';
1.217 raeburn 1868: } else {
1.329 raeburn 1869: $class='Domain';
1.217 raeburn 1870: }
1.329 raeburn 1871: }
1872: if (($role_code eq 'ca') || ($role_code eq 'aa')) {
1873: $area=~m{/($match_domain)/($match_username)};
1874: if (&Apache::lonuserutils::authorpriv($2,$1)) {
1875: $allowed=1;
1.217 raeburn 1876: } else {
1.329 raeburn 1877: $allowed=0;
1.217 raeburn 1878: }
1.329 raeburn 1879: }
1880: my $row = '';
1881: $row.= '<td>';
1882: my $active=1;
1883: $active=0 if (($role_end_time) && ($now>$role_end_time));
1884: if (($active) && ($allowed)) {
1885: $row.= '<input type="checkbox" name="rev:'.$thisrole.'" />';
1886: } else {
1887: if ($active) {
1888: $row.=' ';
1.217 raeburn 1889: } else {
1.329 raeburn 1890: $row.=&mt('expired or revoked');
1.217 raeburn 1891: }
1.329 raeburn 1892: }
1893: $row.='</td><td>';
1894: if ($allowed && !$active) {
1895: $row.= '<input type="checkbox" name="ren:'.$thisrole.'" />';
1896: } else {
1897: $row.=' ';
1898: }
1899: $row.='</td><td>';
1900: if ($delallowed) {
1901: $row.= '<input type="checkbox" name="del:'.$thisrole.'" />';
1902: } else {
1903: $row.=' ';
1904: }
1905: my $plaintext='';
1906: if (!$croletitle) {
1.375 raeburn 1907: $plaintext=&Apache::lonnet::plaintext($role_code,$class);
1908: if (($showcredits) && ($credits ne '')) {
1909: $plaintext .= '<br/ ><span class="LC_nobreak">'.
1910: '<span class="LC_fontsize_small">'.
1911: &mt('Credits: [_1]',$credits).
1912: '</span></span>';
1913: }
1.329 raeburn 1914: } else {
1915: $plaintext=
1.395 bisitz 1916: &mt('Custom role [_1][_2]defined by [_3]',
1.346 bisitz 1917: '"'.$croletitle.'"',
1918: '<br />',
1919: $croleuname.':'.$croleudom);
1.329 raeburn 1920: }
1921: $row.= '</td><td>'.$plaintext.
1922: '</td><td>'.$area.
1923: '</td><td>'.($role_start_time?&Apache::lonlocal::locallocaltime($role_start_time)
1924: : ' ' ).
1925: '</td><td>'.($role_end_time ?&Apache::lonlocal::locallocaltime($role_end_time)
1926: : ' ' )
1927: ."</td>";
1928: $sortrole{$sortkey}=$envkey;
1929: $roletext{$envkey}=$row;
1930: $roleclass{$envkey}=$class;
1931: $rolepriv{$envkey}=$allowed;
1932: } # end of foreach (table building loop)
1933:
1934: my $rolesdisplay = 0;
1935: my %output = ();
1.377 raeburn 1936: foreach my $type ('Authoring Space','Course','Community','Domain','System','Unknown') {
1.329 raeburn 1937: $output{$type} = '';
1938: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
1939: if ( ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/ ) && ($rolepriv{$sortrole{$which}}) ) {
1940: $output{$type}.=
1941: &Apache::loncommon::start_data_table_row().
1942: $roletext{$sortrole{$which}}.
1943: &Apache::loncommon::end_data_table_row();
1.217 raeburn 1944: }
1.329 raeburn 1945: }
1946: unless($output{$type} eq '') {
1947: $output{$type} = '<tr class="LC_info_row">'.
1948: "<td align='center' colspan='7'>".&mt($type)."</td></tr>".
1949: $output{$type};
1950: $rolesdisplay = 1;
1951: }
1952: }
1953: if ($rolesdisplay == 1) {
1954: my $contextrole='';
1955: if ($env{'request.course.id'}) {
1956: if (&Apache::loncommon::course_type() eq 'Community') {
1957: $contextrole = &mt('Existing Roles in this Community');
1.290 bisitz 1958: } else {
1.329 raeburn 1959: $contextrole = &mt('Existing Roles in this Course');
1.290 bisitz 1960: }
1.329 raeburn 1961: } elsif ($env{'request.role'} =~ /^au\./) {
1.377 raeburn 1962: $contextrole = &mt('Existing Co-Author Roles in your Authoring Space');
1.329 raeburn 1963: } else {
1964: $contextrole = &mt('Existing Roles in this Domain');
1965: }
1.393 raeburn 1966: $r->print('<div class="LC_left_float">'.
1.375 raeburn 1967: '<fieldset><legend>'.$contextrole.'</legend>'.
1.217 raeburn 1968: &Apache::loncommon::start_data_table("LC_createuser").
1969: &Apache::loncommon::start_data_table_header_row().
1970: '<th>'.$lt{'rev'}.'</th><th>'.$lt{'ren'}.'</th><th>'.$lt{'del'}.
1971: '</th><th>'.$lt{'rol'}.'</th><th>'.$lt{'ext'}.
1972: '</th><th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
1973: &Apache::loncommon::end_data_table_header_row());
1.377 raeburn 1974: foreach my $type ('Authoring Space','Course','Community','Domain','System','Unknown') {
1.329 raeburn 1975: if ($output{$type}) {
1976: $r->print($output{$type}."\n");
1.217 raeburn 1977: }
1978: }
1.375 raeburn 1979: $r->print(&Apache::loncommon::end_data_table().
1980: '</fieldset></div>');
1.329 raeburn 1981: }
1.217 raeburn 1982: return;
1983: }
1984:
1.218 raeburn 1985: sub new_coauthor_roles {
1986: my ($r,$ccuname,$ccdomain) = @_;
1987: my $addrolesdisplay = 0;
1988: #
1989: # Co-Author
1990: #
1991: if (&Apache::lonuserutils::authorpriv($env{'user.name'},
1992: $env{'request.role.domain'}) &&
1993: ($env{'user.name'} ne $ccuname || $env{'user.domain'} ne $ccdomain)) {
1994: # No sense in assigning co-author role to yourself
1995: $addrolesdisplay = 1;
1996: my $cuname=$env{'user.name'};
1997: my $cudom=$env{'request.role.domain'};
1998: my %lt=&Apache::lonlocal::texthash(
1.377 raeburn 1999: 'cs' => "Authoring Space",
1.218 raeburn 2000: 'act' => "Activate",
2001: 'rol' => "Role",
2002: 'ext' => "Extent",
2003: 'sta' => "Start",
2004: 'end' => "End",
2005: 'cau' => "Co-Author",
2006: 'caa' => "Assistant Co-Author",
2007: 'ssd' => "Set Start Date",
2008: 'sed' => "Set End Date"
2009: );
2010: $r->print('<h4>'.$lt{'cs'}.'</h4>'."\n".
2011: &Apache::loncommon::start_data_table()."\n".
2012: &Apache::loncommon::start_data_table_header_row()."\n".
2013: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'.
2014: '<th>'.$lt{'ext'}.'</th><th>'.$lt{'sta'}.'</th>'.
2015: '<th>'.$lt{'end'}.'</th>'."\n".
2016: &Apache::loncommon::end_data_table_header_row()."\n".
2017: &Apache::loncommon::start_data_table_row().'
2018: <td>
1.291 bisitz 2019: <input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_ca" />
1.218 raeburn 2020: </td>
2021: <td>'.$lt{'cau'}.'</td>
2022: <td>'.$cudom.'_'.$cuname.'</td>
2023: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_ca" value="" />
2024: <a href=
2025: "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>
2026: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_ca" value="" />
2027: <a href=
2028: "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".
2029: &Apache::loncommon::end_data_table_row()."\n".
2030: &Apache::loncommon::start_data_table_row()."\n".
1.291 bisitz 2031: '<td><input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_aa" /></td>
1.218 raeburn 2032: <td>'.$lt{'caa'}.'</td>
2033: <td>'.$cudom.'_'.$cuname.'</td>
2034: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_aa" value="" />
2035: <a href=
2036: "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>
2037: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_aa" value="" />
2038: <a href=
2039: "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".
2040: &Apache::loncommon::end_data_table_row()."\n".
2041: &Apache::loncommon::end_data_table());
2042: } elsif ($env{'request.role'} =~ /^au\./) {
2043: if (!(&Apache::lonuserutils::authorpriv($env{'user.name'},
2044: $env{'request.role.domain'}))) {
2045: $r->print('<span class="LC_error">'.
2046: &mt('You do not have privileges to assign co-author roles.').
2047: '</span>');
2048: } elsif (($env{'user.name'} eq $ccuname) &&
2049: ($env{'user.domain'} eq $ccdomain)) {
1.377 raeburn 2050: $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 2051: }
2052: }
2053: return $addrolesdisplay;;
2054: }
2055:
2056: sub new_domain_roles {
1.357 raeburn 2057: my ($r,$ccdomain) = @_;
1.218 raeburn 2058: my $addrolesdisplay = 0;
2059: #
2060: # Domain level
2061: #
2062: my $num_domain_level = 0;
2063: my $domaintext =
2064: '<h4>'.&mt('Domain Level').'</h4>'.
2065: &Apache::loncommon::start_data_table().
2066: &Apache::loncommon::start_data_table_header_row().
2067: '<th>'.&mt('Activate').'</th><th>'.&mt('Role').'</th><th>'.
2068: &mt('Extent').'</th>'.
2069: '<th>'.&mt('Start').'</th><th>'.&mt('End').'</th>'.
2070: &Apache::loncommon::end_data_table_header_row();
1.312 raeburn 2071: my @allroles = &Apache::lonuserutils::roles_by_context('domain');
1.218 raeburn 2072: foreach my $thisdomain (sort(&Apache::lonnet::all_domains())) {
1.312 raeburn 2073: foreach my $role (@allroles) {
2074: next if ($role eq 'ad');
1.357 raeburn 2075: next if (($role eq 'au') && ($ccdomain ne $thisdomain));
1.218 raeburn 2076: if (&Apache::lonnet::allowed('c'.$role,$thisdomain)) {
2077: my $plrole=&Apache::lonnet::plaintext($role);
2078: my %lt=&Apache::lonlocal::texthash(
2079: 'ssd' => "Set Start Date",
2080: 'sed' => "Set End Date"
2081: );
2082: $num_domain_level ++;
2083: $domaintext .=
2084: &Apache::loncommon::start_data_table_row().
1.291 bisitz 2085: '<td><input type="checkbox" name="act_'.$thisdomain.'_'.$role.'" /></td>
1.218 raeburn 2086: <td>'.$plrole.'</td>
2087: <td>'.$thisdomain.'</td>
2088: <td><input type="hidden" name="start_'.$thisdomain.'_'.$role.'" value="" />
2089: <a href=
2090: "javascript:pjump('."'date_start','Start Date $plrole',document.cu.start_$thisdomain\_$role.value,'start_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'ssd'}.'</a></td>
2091: <td><input type="hidden" name="end_'.$thisdomain.'_'.$role.'" value="" />
2092: <a href=
2093: "javascript:pjump('."'date_end','End Date $plrole',document.cu.end_$thisdomain\_$role.value,'end_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'sed'}.'</a></td>'.
2094: &Apache::loncommon::end_data_table_row();
2095: }
2096: }
2097: }
2098: $domaintext.= &Apache::loncommon::end_data_table();
2099: if ($num_domain_level > 0) {
2100: $r->print($domaintext);
2101: $addrolesdisplay = 1;
2102: }
2103: return $addrolesdisplay;
2104: }
2105:
1.188 raeburn 2106: sub user_authentication {
1.227 raeburn 2107: my ($ccuname,$ccdomain,$formname) = @_;
1.188 raeburn 2108: my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
1.227 raeburn 2109: my $outcome;
1.188 raeburn 2110: # Check for a bad authentication type
2111: if ($currentauth !~ /^(krb4|krb5|unix|internal|localauth):/) {
2112: # bad authentication scheme
2113: my %lt=&Apache::lonlocal::texthash(
2114: 'err' => "ERROR",
2115: 'uuas' => "This user has an unrecognized authentication scheme",
2116: 'adcs' => "Please alert a domain coordinator of this situation",
2117: 'sldb' => "Please specify login data below",
2118: 'ld' => "Login Data"
2119: );
2120: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
1.227 raeburn 2121: &initialize_authen_forms($ccdomain,$formname);
2122:
1.190 raeburn 2123: my $choices = &Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc);
1.188 raeburn 2124: $outcome = <<ENDBADAUTH;
2125: <script type="text/javascript" language="Javascript">
1.301 bisitz 2126: // <![CDATA[
1.188 raeburn 2127: $loginscript
1.301 bisitz 2128: // ]]>
1.188 raeburn 2129: </script>
2130: <span class="LC_error">$lt{'err'}:
2131: $lt{'uuas'} ($currentauth). $lt{'sldb'}.</span>
2132: <h3>$lt{'ld'}</h3>
2133: $choices
2134: ENDBADAUTH
2135: } else {
2136: # This user is not allowed to modify the user's
2137: # authentication scheme, so just notify them of the problem
2138: $outcome = <<ENDBADAUTH;
2139: <span class="LC_error"> $lt{'err'}:
2140: $lt{'uuas'} ($currentauth). $lt{'adcs'}.
2141: </span>
2142: ENDBADAUTH
2143: }
2144: } else { # Authentication type is valid
1.227 raeburn 2145: &initialize_authen_forms($ccdomain,$formname,$currentauth,'modifyuser');
1.205 raeburn 2146: my ($authformcurrent,$can_modify,@authform_others) =
1.188 raeburn 2147: &modify_login_block($ccdomain,$currentauth);
2148: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
2149: # Current user has login modification privileges
2150: my %lt=&Apache::lonlocal::texthash (
2151: 'ld' => "Login Data",
2152: 'ccld' => "Change Current Login Data",
2153: 'enld' => "Enter New Login Data"
2154: );
2155: $outcome =
2156: '<script type="text/javascript" language="Javascript">'."\n".
1.301 bisitz 2157: '// <![CDATA['."\n".
1.188 raeburn 2158: $loginscript."\n".
1.301 bisitz 2159: '// ]]>'."\n".
1.188 raeburn 2160: '</script>'."\n".
2161: '<h3>'.$lt{'ld'}.'</h3>'.
2162: &Apache::loncommon::start_data_table().
1.205 raeburn 2163: &Apache::loncommon::start_data_table_row().
1.188 raeburn 2164: '<td>'.$authformnop;
2165: if ($can_modify) {
2166: $outcome .= '</td>'."\n".
2167: &Apache::loncommon::end_data_table_row().
2168: &Apache::loncommon::start_data_table_row().
2169: '<td>'.$authformcurrent.'</td>'.
2170: &Apache::loncommon::end_data_table_row()."\n";
2171: } else {
1.200 raeburn 2172: $outcome .= ' ('.$authformcurrent.')</td>'.
2173: &Apache::loncommon::end_data_table_row()."\n";
1.188 raeburn 2174: }
1.205 raeburn 2175: foreach my $item (@authform_others) {
2176: $outcome .= &Apache::loncommon::start_data_table_row().
2177: '<td>'.$item.'</td>'.
2178: &Apache::loncommon::end_data_table_row()."\n";
1.188 raeburn 2179: }
1.205 raeburn 2180: $outcome .= &Apache::loncommon::end_data_table();
1.188 raeburn 2181: } else {
2182: if (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
2183: my %lt=&Apache::lonlocal::texthash(
2184: 'ccld' => "Change Current Login Data",
2185: 'yodo' => "You do not have privileges to modify the authentication configuration for this user.",
2186: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
2187: );
2188: $outcome .= <<ENDNOPRIV;
2189: <h3>$lt{'ccld'}</h3>
2190: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1.235 raeburn 2191: <input type="hidden" name="login" value="nochange" />
1.188 raeburn 2192: ENDNOPRIV
2193: }
2194: }
2195: } ## End of "check for bad authentication type" logic
2196: return $outcome;
2197: }
2198:
1.187 raeburn 2199: sub modify_login_block {
2200: my ($dom,$currentauth) = @_;
2201: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2202: my ($authnum,%can_assign) =
2203: &Apache::loncommon::get_assignable_auth($dom);
1.205 raeburn 2204: my ($authformcurrent,@authform_others,$show_override_msg);
1.187 raeburn 2205: if ($currentauth=~/^krb(4|5):/) {
2206: $authformcurrent=$authformkrb;
2207: if ($can_assign{'int'}) {
1.205 raeburn 2208: push(@authform_others,$authformint);
1.187 raeburn 2209: }
2210: if ($can_assign{'loc'}) {
1.205 raeburn 2211: push(@authform_others,$authformloc);
1.187 raeburn 2212: }
2213: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
2214: $show_override_msg = 1;
2215: }
2216: } elsif ($currentauth=~/^internal:/) {
2217: $authformcurrent=$authformint;
2218: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2219: push(@authform_others,$authformkrb);
1.187 raeburn 2220: }
2221: if ($can_assign{'loc'}) {
1.205 raeburn 2222: push(@authform_others,$authformloc);
1.187 raeburn 2223: }
2224: if ($can_assign{'int'}) {
2225: $show_override_msg = 1;
2226: }
2227: } elsif ($currentauth=~/^unix:/) {
2228: $authformcurrent=$authformfsys;
2229: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2230: push(@authform_others,$authformkrb);
1.187 raeburn 2231: }
2232: if ($can_assign{'int'}) {
1.205 raeburn 2233: push(@authform_others,$authformint);
1.187 raeburn 2234: }
2235: if ($can_assign{'loc'}) {
1.205 raeburn 2236: push(@authform_others,$authformloc);
1.187 raeburn 2237: }
2238: if ($can_assign{'fsys'}) {
2239: $show_override_msg = 1;
2240: }
2241: } elsif ($currentauth=~/^localauth:/) {
2242: $authformcurrent=$authformloc;
2243: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2244: push(@authform_others,$authformkrb);
1.187 raeburn 2245: }
2246: if ($can_assign{'int'}) {
1.205 raeburn 2247: push(@authform_others,$authformint);
1.187 raeburn 2248: }
2249: if ($can_assign{'loc'}) {
2250: $show_override_msg = 1;
2251: }
2252: }
2253: if ($show_override_msg) {
1.205 raeburn 2254: $authformcurrent = '<table><tr><td colspan="3">'.$authformcurrent.
2255: '</td></tr>'."\n".
2256: '<tr><td> </td>'.
2257: '<td><b>'.&mt('Currently in use').'</b></td>'.
2258: '<td align="right"><span class="LC_cusr_emph">'.
1.187 raeburn 2259: &mt('will override current values').
1.205 raeburn 2260: '</span></td></tr></table>';
1.187 raeburn 2261: }
1.205 raeburn 2262: return ($authformcurrent,$show_override_msg,@authform_others);
1.187 raeburn 2263: }
2264:
1.188 raeburn 2265: sub personal_data_display {
1.391 raeburn 2266: my ($ccuname,$ccdomain,$newuser,$context,$inst_results,$rolesarray,
1.396 raeburn 2267: $now,$captchaform,$emailusername,$usertype) = @_;
1.388 bisitz 2268: my ($output,%userenv,%canmodify,%canmodify_status);
1.219 raeburn 2269: my @userinfo = ('firstname','middlename','lastname','generation',
2270: 'permanentemail','id');
1.252 raeburn 2271: my $rowcount = 0;
2272: my $editable = 0;
1.391 raeburn 2273: my %textboxsize = (
2274: firstname => '15',
2275: middlename => '15',
2276: lastname => '15',
2277: generation => '5',
2278: permanentemail => '25',
2279: id => '15',
2280: );
2281:
2282: my %lt=&Apache::lonlocal::texthash(
2283: 'pd' => "Personal Data",
2284: 'firstname' => "First Name",
2285: 'middlename' => "Middle Name",
2286: 'lastname' => "Last Name",
2287: 'generation' => "Generation",
2288: 'permanentemail' => "Permanent e-mail address",
2289: 'id' => "Student/Employee ID",
2290: 'lg' => "Login Data",
2291: 'inststatus' => "Affiliation",
2292: 'email' => 'E-mail address',
2293: 'valid' => 'Validation',
2294: );
2295:
2296: %canmodify_status =
1.286 raeburn 2297: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
2298: ['inststatus'],$rolesarray);
1.253 raeburn 2299: if (!$newuser) {
1.188 raeburn 2300: # Get the users information
2301: %userenv = &Apache::lonnet::get('environment',
2302: ['firstname','middlename','lastname','generation',
1.286 raeburn 2303: 'permanentemail','id','inststatus'],$ccdomain,$ccuname);
1.219 raeburn 2304: %canmodify =
2305: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
1.252 raeburn 2306: \@userinfo,$rolesarray);
1.257 raeburn 2307: } elsif ($context eq 'selfcreate') {
1.391 raeburn 2308: if ($newuser eq 'email') {
1.396 raeburn 2309: if (ref($emailusername) eq 'HASH') {
2310: if (ref($emailusername->{$usertype}) eq 'HASH') {
2311: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
2312: @userinfo = ();
2313: if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
2314: foreach my $field (@{$infofields}) {
2315: if ($emailusername->{$usertype}->{$field}) {
2316: push(@userinfo,$field);
2317: $canmodify{$field} = 1;
2318: unless ($textboxsize{$field}) {
2319: $textboxsize{$field} = 25;
2320: }
2321: unless ($lt{$field}) {
2322: $lt{$field} = $infotitles->{$field};
2323: }
2324: if ($emailusername->{$usertype}->{$field} eq 'required') {
2325: $lt{$field} .= '<b>*</b>';
2326: }
1.391 raeburn 2327: }
2328: }
2329: }
2330: }
2331: }
2332: } else {
2333: %canmodify = &selfcreate_canmodify($context,$ccdomain,\@userinfo,
2334: $inst_results,$rolesarray);
2335: }
1.188 raeburn 2336: }
1.391 raeburn 2337:
1.188 raeburn 2338: my $genhelp=&Apache::loncommon::help_open_topic('Generation');
2339: $output = '<h3>'.$lt{'pd'}.'</h3>'.
2340: &Apache::lonhtmlcommon::start_pick_box();
1.391 raeburn 2341: if (($context eq 'selfcreate') && ($newuser eq 'email')) {
1.396 raeburn 2342: $output .= &Apache::lonhtmlcommon::row_title($lt{'email'}.'<b>*</b>',undef,
1.391 raeburn 2343: 'LC_oddrow_value')."\n".
1.394 raeburn 2344: '<input type="text" name="uname" size="25" value="" autocomplete="off" />';
1.391 raeburn 2345: $rowcount ++;
2346: $output .= &Apache::lonhtmlcommon::row_closure(1);
1.406.2.1 raeburn 2347: my $upassone = '<input type="password" name="upass'.$now.'" size="20" autocomplete="off" />';
2348: my $upasstwo = '<input type="password" name="upasscheck'.$now.'" size="20" autocomplete="off" />';
1.396 raeburn 2349: $output .= &Apache::lonhtmlcommon::row_title(&mt('Password').'<b>*</b>',
1.391 raeburn 2350: 'LC_pick_box_title',
2351: 'LC_oddrow_value')."\n".
2352: $upassone."\n".
2353: &Apache::lonhtmlcommon::row_closure(1)."\n".
1.396 raeburn 2354: &Apache::lonhtmlcommon::row_title(&mt('Confirm password').'<b>*</b>',
1.391 raeburn 2355: 'LC_pick_box_title',
2356: 'LC_oddrow_value')."\n".
2357: $upasstwo.
2358: &Apache::lonhtmlcommon::row_closure()."\n";
2359: }
1.188 raeburn 2360: foreach my $item (@userinfo) {
2361: my $rowtitle = $lt{$item};
1.252 raeburn 2362: my $hiderow = 0;
1.188 raeburn 2363: if ($item eq 'generation') {
2364: $rowtitle = $genhelp.$rowtitle;
2365: }
1.252 raeburn 2366: my $row = &Apache::lonhtmlcommon::row_title($rowtitle,undef,'LC_oddrow_value')."\n";
1.188 raeburn 2367: if ($newuser) {
1.210 raeburn 2368: if (ref($inst_results) eq 'HASH') {
2369: if ($inst_results->{$item} ne '') {
1.252 raeburn 2370: $row .= '<input type="hidden" name="c'.$item.'" value="'.$inst_results->{$item}.'" />'.$inst_results->{$item};
1.210 raeburn 2371: } else {
1.252 raeburn 2372: if ($context eq 'selfcreate') {
1.391 raeburn 2373: if ($canmodify{$item}) {
1.394 raeburn 2374: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.252 raeburn 2375: $editable ++;
2376: } else {
2377: $hiderow = 1;
2378: }
1.253 raeburn 2379: } else {
2380: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1.252 raeburn 2381: }
1.210 raeburn 2382: }
1.188 raeburn 2383: } else {
1.252 raeburn 2384: if ($context eq 'selfcreate') {
1.401 raeburn 2385: if ($canmodify{$item}) {
2386: if ($newuser eq 'email') {
2387: $row .= '<input type="text" name="'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.287 raeburn 2388: } else {
1.401 raeburn 2389: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.287 raeburn 2390: }
1.401 raeburn 2391: $editable ++;
2392: } else {
2393: $hiderow = 1;
1.252 raeburn 2394: }
1.253 raeburn 2395: } else {
2396: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1.252 raeburn 2397: }
1.188 raeburn 2398: }
2399: } else {
1.219 raeburn 2400: if ($canmodify{$item}) {
1.252 raeburn 2401: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="'.$userenv{$item}.'" />';
1.393 raeburn 2402: if (($item eq 'id') && (!$newuser)) {
2403: $row .= '<br />'.&Apache::lonuserutils::forceid_change($context);
2404: }
1.188 raeburn 2405: } else {
1.252 raeburn 2406: $row .= $userenv{$item};
1.188 raeburn 2407: }
2408: }
1.252 raeburn 2409: $row .= &Apache::lonhtmlcommon::row_closure(1);
2410: if (!$hiderow) {
2411: $output .= $row;
2412: $rowcount ++;
2413: }
1.188 raeburn 2414: }
1.286 raeburn 2415: if (($canmodify_status{'inststatus'}) || ($context ne 'selfcreate')) {
2416: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($ccdomain);
2417: if (ref($types) eq 'ARRAY') {
2418: if (@{$types} > 0) {
2419: my ($hiderow,$shown);
2420: if ($canmodify_status{'inststatus'}) {
2421: $shown = &pick_inst_statuses($userenv{'inststatus'},$usertypes,$types);
2422: } else {
2423: if ($userenv{'inststatus'} eq '') {
2424: $hiderow = 1;
1.334 raeburn 2425: } else {
2426: my @showitems;
2427: foreach my $item ( map { &unescape($_); } split(':',$userenv{'inststatus'})) {
2428: if (exists($usertypes->{$item})) {
2429: push(@showitems,$usertypes->{$item});
2430: } else {
2431: push(@showitems,$item);
2432: }
2433: }
2434: if (@showitems) {
2435: $shown = join(', ',@showitems);
2436: } else {
2437: $hiderow = 1;
2438: }
1.286 raeburn 2439: }
2440: }
2441: if (!$hiderow) {
1.389 bisitz 2442: my $row = &Apache::lonhtmlcommon::row_title(&mt('Affiliations'),undef,'LC_oddrow_value')."\n".
1.286 raeburn 2443: $shown.&Apache::lonhtmlcommon::row_closure(1);
2444: if ($context eq 'selfcreate') {
2445: $rowcount ++;
2446: }
2447: $output .= $row;
2448: }
2449: }
2450: }
2451: }
1.391 raeburn 2452: if (($context eq 'selfcreate') && ($newuser eq 'email')) {
2453: if ($captchaform) {
1.406.2.2 raeburn 2454: $output .= &Apache::lonhtmlcommon::row_title($lt{'valid'}.'*',
1.391 raeburn 2455: 'LC_pick_box_title')."\n".
2456: $captchaform."\n".'<br /><br />'.
2457: &Apache::lonhtmlcommon::row_closure(1);
2458: $rowcount ++;
2459: }
2460: my $submit_text = &mt('Create account');
2461: $output .= &Apache::lonhtmlcommon::row_title()."\n".
2462: '<br /><input type="submit" name="createaccount" value="'.
2463: $submit_text.'" />'.
1.396 raeburn 2464: '<input type="hidden" name="type" value="'.$usertype.'" />'.
1.391 raeburn 2465: &Apache::lonhtmlcommon::row_closure(1);
2466: }
1.188 raeburn 2467: $output .= &Apache::lonhtmlcommon::end_pick_box();
1.206 raeburn 2468: if (wantarray) {
1.252 raeburn 2469: if ($context eq 'selfcreate') {
2470: return($output,$rowcount,$editable);
2471: } else {
1.388 bisitz 2472: return $output;
1.252 raeburn 2473: }
1.206 raeburn 2474: } else {
2475: return $output;
2476: }
1.188 raeburn 2477: }
2478:
1.286 raeburn 2479: sub pick_inst_statuses {
2480: my ($curr,$usertypes,$types) = @_;
2481: my ($output,$rem,@currtypes);
2482: if ($curr ne '') {
2483: @currtypes = map { &unescape($_); } split(/:/,$curr);
2484: }
2485: my $numinrow = 2;
2486: if (ref($types) eq 'ARRAY') {
2487: $output = '<table>';
2488: my $lastcolspan;
2489: for (my $i=0; $i<@{$types}; $i++) {
2490: if (defined($usertypes->{$types->[$i]})) {
2491: my $rem = $i%($numinrow);
2492: if ($rem == 0) {
2493: if ($i<@{$types}-1) {
2494: if ($i > 0) {
2495: $output .= '</tr>';
2496: }
2497: $output .= '<tr>';
2498: }
2499: } elsif ($i==@{$types}-1) {
2500: my $colsleft = $numinrow - $rem;
2501: if ($colsleft > 1) {
2502: $lastcolspan = ' colspan="'.$colsleft.'"';
2503: }
2504: }
2505: my $check = ' ';
2506: if (grep(/^\Q$types->[$i]\E$/,@currtypes)) {
2507: $check = ' checked="checked" ';
2508: }
2509: $output .= '<td class="LC_left_item"'.$lastcolspan.'>'.
2510: '<span class="LC_nobreak"><label>'.
2511: '<input type="checkbox" name="inststatus" '.
2512: 'value="'.$types->[$i].'"'.$check.'/>'.
2513: $usertypes->{$types->[$i]}.'</label></span></td>';
2514: }
2515: }
2516: $output .= '</tr></table>';
2517: }
2518: return $output;
2519: }
2520:
1.257 raeburn 2521: sub selfcreate_canmodify {
2522: my ($context,$dom,$userinfo,$inst_results,$rolesarray) = @_;
2523: if (ref($inst_results) eq 'HASH') {
2524: my @inststatuses = &get_inststatuses($inst_results);
2525: if (@inststatuses == 0) {
2526: @inststatuses = ('default');
2527: }
2528: $rolesarray = \@inststatuses;
2529: }
2530: my %canmodify =
2531: &Apache::lonuserutils::can_modify_userinfo($context,$dom,$userinfo,
2532: $rolesarray);
2533: return %canmodify;
2534: }
2535:
1.252 raeburn 2536: sub get_inststatuses {
2537: my ($insthashref) = @_;
2538: my @inststatuses = ();
2539: if (ref($insthashref) eq 'HASH') {
2540: if (ref($insthashref->{'inststatus'}) eq 'ARRAY') {
2541: @inststatuses = @{$insthashref->{'inststatus'}};
2542: }
2543: }
2544: return @inststatuses;
2545: }
2546:
1.4 www 2547: # ================================================================= Phase Three
1.42 matthew 2548: sub update_user_data {
1.375 raeburn 2549: my ($r,$context,$crstype,$brcrum,$showcredits) = @_;
1.101 albertel 2550: my $uhome=&Apache::lonnet::homeserver($env{'form.ccuname'},
2551: $env{'form.ccdomain'});
1.27 matthew 2552: # Error messages
1.188 raeburn 2553: my $error = '<span class="LC_error">'.&mt('Error').': ';
1.193 raeburn 2554: my $end = '</span><br /><br />';
2555: my $rtnlink = '<a href="javascript:backPage(document.userupdate,'.
1.188 raeburn 2556: "'$env{'form.prevphase'}','modify')".'" />'.
1.219 raeburn 2557: &mt('Return to previous page').'</a>'.
2558: &Apache::loncommon::end_page();
2559: my $now = time;
1.40 www 2560: my $title;
1.101 albertel 2561: if (exists($env{'form.makeuser'})) {
1.40 www 2562: $title='Set Privileges for New User';
2563: } else {
2564: $title='Modify User Privileges';
2565: }
1.213 raeburn 2566: my $newuser = 0;
1.160 raeburn 2567: my ($jsback,$elements) = &crumb_utilities();
2568: my $jscript = '<script type="text/javascript">'."\n".
1.301 bisitz 2569: '// <![CDATA['."\n".
2570: $jsback."\n".
2571: '// ]]>'."\n".
2572: '</script>'."\n";
1.318 raeburn 2573: my %breadcrumb_text = &singleuser_breadcrumb($crstype);
1.351 raeburn 2574: push (@{$brcrum},
2575: {href => "javascript:backPage(document.userupdate)",
2576: text => $breadcrumb_text{'search'},
2577: faq => 282,
2578: bug => 'Instructor Interface',}
2579: );
2580: if ($env{'form.prevphase'} eq 'userpicked') {
2581: push(@{$brcrum},
2582: {href => "javascript:backPage(document.userupdate,'get_user_info','select')",
2583: text => $breadcrumb_text{'userpicked'},
2584: faq => 282,
2585: bug => 'Instructor Interface',});
1.233 raeburn 2586: }
1.224 raeburn 2587: my $helpitem = 'Course_Change_Privileges';
2588: if ($env{'form.action'} eq 'singlestudent') {
2589: $helpitem = 'Course_Add_Student';
2590: }
1.351 raeburn 2591: push(@{$brcrum},
2592: {href => "javascript:backPage(document.userupdate,'$env{'form.prevphase'}','modify')",
2593: text => $breadcrumb_text{'modify'},
2594: faq => 282,
2595: bug => 'Instructor Interface',},
2596: {href => "/adm/createuser",
2597: text => "Result",
2598: faq => 282,
2599: bug => 'Instructor Interface',
2600: help => $helpitem});
2601: my $args = {bread_crumbs => $brcrum,
2602: bread_crumbs_component => 'User Management'};
2603: if ($env{'form.popup'}) {
2604: $args->{'no_nav_bar'} = 1;
2605: }
2606: $r->print(&Apache::loncommon::start_page($title,$jscript,$args));
1.188 raeburn 2607: $r->print(&update_result_form($uhome));
1.27 matthew 2608: # Check Inputs
1.101 albertel 2609: if (! $env{'form.ccuname'} ) {
1.193 raeburn 2610: $r->print($error.&mt('No login name specified').'.'.$end.$rtnlink);
1.27 matthew 2611: return;
2612: }
1.138 albertel 2613: if ( $env{'form.ccuname'} ne
2614: &LONCAPA::clean_username($env{'form.ccuname'}) ) {
1.281 bisitz 2615: $r->print($error.&mt('Invalid login name.').' '.
2616: &mt('Only letters, numbers, periods, dashes, @, and underscores are valid.').
1.193 raeburn 2617: $end.$rtnlink);
1.27 matthew 2618: return;
2619: }
1.101 albertel 2620: if (! $env{'form.ccdomain'} ) {
1.193 raeburn 2621: $r->print($error.&mt('No domain specified').'.'.$end.$rtnlink);
1.27 matthew 2622: return;
2623: }
1.138 albertel 2624: if ( $env{'form.ccdomain'} ne
2625: &LONCAPA::clean_domain($env{'form.ccdomain'}) ) {
1.281 bisitz 2626: $r->print($error.&mt('Invalid domain name.').' '.
2627: &mt('Only letters, numbers, periods, dashes, and underscores are valid.').
1.193 raeburn 2628: $end.$rtnlink);
1.27 matthew 2629: return;
2630: }
1.219 raeburn 2631: if ($uhome eq 'no_host') {
2632: $newuser = 1;
2633: }
1.101 albertel 2634: if (! exists($env{'form.makeuser'})) {
1.29 matthew 2635: # Modifying an existing user, so check the validity of the name
2636: if ($uhome eq 'no_host') {
1.389 bisitz 2637: $r->print(
2638: $error
2639: .'<p class="LC_error">'
2640: .&mt('Unable to determine home server for [_1] in domain [_2].',
2641: '"'.$env{'form.ccuname'}.'"','"'.$env{'form.ccdomain'}.'"')
2642: .'</p>');
1.29 matthew 2643: return;
2644: }
2645: }
1.27 matthew 2646: # Determine authentication method and password for the user being modified
2647: my $amode='';
2648: my $genpwd='';
1.101 albertel 2649: if ($env{'form.login'} eq 'krb') {
1.41 albertel 2650: $amode='krb';
1.101 albertel 2651: $amode.=$env{'form.krbver'};
2652: $genpwd=$env{'form.krbarg'};
2653: } elsif ($env{'form.login'} eq 'int') {
1.27 matthew 2654: $amode='internal';
1.101 albertel 2655: $genpwd=$env{'form.intarg'};
2656: } elsif ($env{'form.login'} eq 'fsys') {
1.27 matthew 2657: $amode='unix';
1.101 albertel 2658: $genpwd=$env{'form.fsysarg'};
2659: } elsif ($env{'form.login'} eq 'loc') {
1.27 matthew 2660: $amode='localauth';
1.101 albertel 2661: $genpwd=$env{'form.locarg'};
1.27 matthew 2662: $genpwd=" " if (!$genpwd);
1.101 albertel 2663: } elsif (($env{'form.login'} eq 'nochange') ||
2664: ($env{'form.login'} eq '' )) {
1.34 matthew 2665: # There is no need to tell the user we did not change what they
2666: # did not ask us to change.
1.35 matthew 2667: # If they are creating a new user but have not specified login
2668: # information this will be caught below.
1.30 matthew 2669: } else {
1.367 golterma 2670: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
2671: return;
1.27 matthew 2672: }
1.164 albertel 2673:
1.188 raeburn 2674: $r->print('<h3>'.&mt('User [_1] in domain [_2]',
1.367 golterma 2675: $env{'form.ccuname'}.' ('.&Apache::loncommon::plainname($env{'form.ccuname'},
2676: $env{'form.ccdomain'}).')', $env{'form.ccdomain'}).'</h3>');
2677: my %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($r,2);
1.344 bisitz 2678:
1.193 raeburn 2679: my (%alerts,%rulematch,%inst_results,%curr_rules);
1.334 raeburn 2680: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
1.361 raeburn 2681: my @usertools = ('aboutme','blog','webdav','portfolio');
1.384 raeburn 2682: my @requestcourses = ('official','unofficial','community','textbook');
1.362 raeburn 2683: my @requestauthor = ('requestauthor');
1.286 raeburn 2684: my ($othertitle,$usertypes,$types) =
2685: &Apache::loncommon::sorted_inst_types($env{'form.ccdomain'});
1.334 raeburn 2686: my %canmodify_status =
2687: &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},
2688: ['inststatus']);
1.101 albertel 2689: if ($env{'form.makeuser'}) {
1.164 albertel 2690: $r->print('<h3>'.&mt('Creating new account.').'</h3>');
1.27 matthew 2691: # Check for the authentication mode and password
2692: if (! $amode || ! $genpwd) {
1.193 raeburn 2693: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
1.27 matthew 2694: return;
1.18 albertel 2695: }
1.29 matthew 2696: # Determine desired host
1.101 albertel 2697: my $desiredhost = $env{'form.hserver'};
1.29 matthew 2698: if (lc($desiredhost) eq 'default') {
2699: $desiredhost = undef;
2700: } else {
1.147 albertel 2701: my %home_servers =
2702: &Apache::lonnet::get_servers($env{'form.ccdomain'},'library');
1.29 matthew 2703: if (! exists($home_servers{$desiredhost})) {
1.193 raeburn 2704: $r->print($error.&mt('Invalid home server specified').$end.$rtnlink);
2705: return;
2706: }
2707: }
2708: # Check ID format
2709: my %checkhash;
2710: my %checks = ('id' => 1);
2711: %{$checkhash{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}}} = (
1.219 raeburn 2712: 'newuser' => $newuser,
1.196 raeburn 2713: 'id' => $env{'form.cid'},
1.193 raeburn 2714: );
1.196 raeburn 2715: if ($env{'form.cid'} ne '') {
2716: &Apache::loncommon::user_rule_check(\%checkhash,\%checks,\%alerts,
2717: \%rulematch,\%inst_results,\%curr_rules);
2718: if (ref($alerts{'id'}) eq 'HASH') {
2719: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
2720: my $domdesc =
2721: &Apache::lonnet::domain($env{'form.ccdomain'},'description');
2722: if ($alerts{'id'}{$env{'form.ccdomain'}}{$env{'form.cid'}}) {
2723: my $userchkmsg;
2724: if (ref($curr_rules{$env{'form.ccdomain'}}) eq 'HASH') {
2725: $userchkmsg =
2726: &Apache::loncommon::instrule_disallow_msg('id',
2727: $domdesc,1).
2728: &Apache::loncommon::user_rule_formats($env{'form.ccdomain'},
2729: $domdesc,$curr_rules{$env{'form.ccdomain'}}{'id'},'id');
2730: }
2731: $r->print($error.&mt('Invalid ID format').$end.
2732: $userchkmsg.$rtnlink);
2733: return;
2734: }
2735: }
1.29 matthew 2736: }
2737: }
1.367 golterma 2738: &Apache::lonhtmlcommon::Increment_PrgWin($r, \%prog_state);
1.27 matthew 2739: # Call modifyuser
2740: my $result = &Apache::lonnet::modifyuser
1.193 raeburn 2741: ($env{'form.ccdomain'},$env{'form.ccuname'},$env{'form.cid'},
1.188 raeburn 2742: $amode,$genpwd,$env{'form.cfirstname'},
2743: $env{'form.cmiddlename'},$env{'form.clastname'},
2744: $env{'form.cgeneration'},undef,$desiredhost,
2745: $env{'form.cpermanentemail'});
1.77 www 2746: $r->print(&mt('Generating user').': '.$result);
1.219 raeburn 2747: $uhome = &Apache::lonnet::homeserver($env{'form.ccuname'},
1.101 albertel 2748: $env{'form.ccdomain'});
1.334 raeburn 2749: my (%changeHash,%newcustom,%changed,%changedinfo);
1.267 raeburn 2750: if ($uhome ne 'no_host') {
1.334 raeburn 2751: if ($context eq 'domain') {
1.378 raeburn 2752: foreach my $name ('portfolio','author') {
2753: if ($env{'form.custom_'.$name.'quota'} == 1) {
2754: if ($env{'form.'.$name.'quota'} eq '') {
2755: $newcustom{$name.'quota'} = 0;
2756: } else {
2757: $newcustom{$name.'quota'} = $env{'form.'.$name.'quota'};
2758: $newcustom{$name.'quota'} =~ s/[^\d\.]//g;
2759: }
2760: if ("a_admin($newcustom{$name.'quota'},\%changeHash,$name)) {
2761: $changed{$name.'quota'} = 1;
2762: }
1.334 raeburn 2763: }
2764: }
2765: foreach my $item (@usertools) {
2766: if ($env{'form.custom'.$item} == 1) {
2767: $newcustom{$item} = $env{'form.tools_'.$item};
2768: $changed{$item} = &tool_admin($item,$newcustom{$item},
2769: \%changeHash,'tools');
2770: }
1.267 raeburn 2771: }
1.334 raeburn 2772: foreach my $item (@requestcourses) {
1.341 raeburn 2773: if ($env{'form.custom'.$item} == 1) {
2774: $newcustom{$item} = $env{'form.crsreq_'.$item};
2775: if ($env{'form.crsreq_'.$item} eq 'autolimit') {
2776: $newcustom{$item} .= '=';
1.383 raeburn 2777: $env{'form.crsreq_'.$item.'_limit'} =~ s/\D+//g;
2778: if ($env{'form.crsreq_'.$item.'_limit'}) {
1.341 raeburn 2779: $newcustom{$item} .= $env{'form.crsreq_'.$item.'_limit'};
2780: }
1.334 raeburn 2781: }
1.341 raeburn 2782: $changed{$item} = &tool_admin($item,$newcustom{$item},
2783: \%changeHash,'requestcourses');
1.334 raeburn 2784: }
1.275 raeburn 2785: }
1.362 raeburn 2786: if ($env{'form.customrequestauthor'} == 1) {
2787: $newcustom{'requestauthor'} = $env{'form.requestauthor'};
2788: $changed{'requestauthor'} = &tool_admin('requestauthor',
2789: $newcustom{'requestauthor'},
2790: \%changeHash,'requestauthor');
2791: }
1.406.2.5! raeburn 2792: if (&Apache::lonnet::allowed('cdh',$env{'request.role.domain'})) {
! 2793: my @adds = &Apache::loncommon::get_env_multiple('form.adhocroleadd');
! 2794: if (&adhocrole_changes(\%changeHash)) {
! 2795: $changed{'adhocroles.'.$env{'request.role.domain'}} = $changeHash{'adhocroles.'.$env{'request.role.domain'}};
! 2796: }
! 2797: }
1.275 raeburn 2798: }
1.334 raeburn 2799: if ($canmodify_status{'inststatus'}) {
2800: if (exists($env{'form.inststatus'})) {
2801: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
2802: if (@inststatuses > 0) {
2803: $changeHash{'inststatus'} = join(',',@inststatuses);
2804: $changed{'inststatus'} = $changeHash{'inststatus'};
1.306 raeburn 2805: }
2806: }
1.232 raeburn 2807: }
1.334 raeburn 2808: if (keys(%changed)) {
2809: foreach my $item (@userinfo) {
2810: $changeHash{$item} = $env{'form.c'.$item};
1.286 raeburn 2811: }
1.267 raeburn 2812: my $chgresult =
2813: &Apache::lonnet::put('environment',\%changeHash,
2814: $env{'form.ccdomain'},$env{'form.ccuname'});
2815: }
1.232 raeburn 2816: }
1.219 raeburn 2817: $r->print('<br />'.&mt('Home server').': '.$uhome.' '.
2818: &Apache::lonnet::hostname($uhome));
1.101 albertel 2819: } elsif (($env{'form.login'} ne 'nochange') &&
2820: ($env{'form.login'} ne '' )) {
1.27 matthew 2821: # Modify user privileges
2822: if (! $amode || ! $genpwd) {
1.193 raeburn 2823: $r->print($error.'Invalid login mode or password'.$end.$rtnlink);
1.27 matthew 2824: return;
1.20 harris41 2825: }
1.395 bisitz 2826: # Only allow authentication modification if the person has authority
1.101 albertel 2827: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.20 harris41 2828: $r->print('Modifying authentication: '.
1.31 matthew 2829: &Apache::lonnet::modifyuserauth(
1.101 albertel 2830: $env{'form.ccdomain'},$env{'form.ccuname'},
1.21 harris41 2831: $amode,$genpwd));
1.102 albertel 2832: $r->print('<br />'.&mt('Home server').': '.&Apache::lonnet::homeserver
1.101 albertel 2833: ($env{'form.ccuname'},$env{'form.ccdomain'}));
1.4 www 2834: } else {
1.27 matthew 2835: # Okay, this is a non-fatal error.
1.395 bisitz 2836: $r->print($error.&mt('You do not have the authority to modify this users authentication information.').$end);
1.27 matthew 2837: }
1.28 matthew 2838: }
1.344 bisitz 2839: $r->rflush(); # Finish display of header before time consuming actions start
1.367 golterma 2840: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state);
1.28 matthew 2841: ##
1.375 raeburn 2842: my (@userroles,%userupdate,$cnum,$cdom,$defaultcredits,%namechanged);
1.213 raeburn 2843: if ($context eq 'course') {
1.375 raeburn 2844: ($cnum,$cdom) =
2845: &Apache::lonuserutils::get_course_identity();
1.318 raeburn 2846: $crstype = &Apache::loncommon::course_type($cdom.'_'.$cnum);
1.375 raeburn 2847: if ($showcredits) {
2848: $defaultcredits = &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
2849: }
1.213 raeburn 2850: }
1.101 albertel 2851: if (! $env{'form.makeuser'} ) {
1.28 matthew 2852: # Check for need to change
2853: my %userenv = &Apache::lonnet::get
1.134 raeburn 2854: ('environment',['firstname','middlename','lastname','generation',
1.378 raeburn 2855: 'id','permanentemail','portfolioquota','authorquota','inststatus',
2856: 'tools.aboutme','tools.blog','tools.webdav','tools.portfolio',
1.361 raeburn 2857: 'requestcourses.official','requestcourses.unofficial',
1.384 raeburn 2858: 'requestcourses.community','requestcourses.textbook',
2859: 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
2860: 'reqcrsotherdom.community','reqcrsotherdom.textbook',
1.406.2.5! raeburn 2861: 'requestauthor','adhocroles.'.$env{'request.role.domain'}],
1.160 raeburn 2862: $env{'form.ccdomain'},$env{'form.ccuname'});
1.28 matthew 2863: my ($tmp) = keys(%userenv);
2864: if ($tmp =~ /^(con_lost|error)/i) {
2865: %userenv = ();
2866: }
1.206 raeburn 2867: my $no_forceid_alert;
2868: # Check to see if user information can be changed
2869: my %domconfig =
2870: &Apache::lonnet::get_dom('configuration',['usermodification'],
2871: $env{'form.ccdomain'});
1.213 raeburn 2872: my @statuses = ('active','future');
2873: my %roles = &Apache::lonnet::get_my_roles($env{'form.ccuname'},$env{'form.ccdomain'},'userroles',\@statuses,undef,$env{'request.role.domain'});
2874: my ($auname,$audom);
1.220 raeburn 2875: if ($context eq 'author') {
1.206 raeburn 2876: $auname = $env{'user.name'};
2877: $audom = $env{'user.domain'};
2878: }
2879: foreach my $item (keys(%roles)) {
1.220 raeburn 2880: my ($rolenum,$roledom,$role) = split(/:/,$item,-1);
1.206 raeburn 2881: if ($context eq 'course') {
2882: if ($cnum ne '' && $cdom ne '') {
2883: if ($rolenum eq $cnum && $roledom eq $cdom) {
2884: if (!grep(/^\Q$role\E$/,@userroles)) {
2885: push(@userroles,$role);
2886: }
2887: }
2888: }
2889: } elsif ($context eq 'author') {
2890: if ($rolenum eq $auname && $roledom eq $audom) {
2891: if (!grep(/^\Q$role\E$/,@userroles)) {
2892: push(@userroles,$role);
2893: }
2894: }
2895: }
2896: }
1.220 raeburn 2897: if ($env{'form.action'} eq 'singlestudent') {
2898: if (!grep(/^st$/,@userroles)) {
2899: push(@userroles,'st');
2900: }
2901: } else {
2902: # Check for course or co-author roles being activated or re-enabled
2903: if ($context eq 'author' || $context eq 'course') {
2904: foreach my $key (keys(%env)) {
2905: if ($context eq 'author') {
2906: if ($key=~/^form\.act_\Q$audom\E_\Q$auname\E_([^_]+)/) {
2907: if (!grep(/^\Q$1\E$/,@userroles)) {
2908: push(@userroles,$1);
2909: }
2910: } elsif ($key =~/^form\.ren\:\Q$audom\E\/\Q$auname\E_([^_]+)/) {
2911: if (!grep(/^\Q$1\E$/,@userroles)) {
2912: push(@userroles,$1);
2913: }
1.206 raeburn 2914: }
1.220 raeburn 2915: } elsif ($context eq 'course') {
2916: if ($key=~/^form\.act_\Q$cdom\E_\Q$cnum\E_([^_]+)/) {
2917: if (!grep(/^\Q$1\E$/,@userroles)) {
2918: push(@userroles,$1);
2919: }
2920: } elsif ($key =~/^form\.ren\:\Q$cdom\E\/\Q$cnum\E(\/?\w*)_([^_]+)/) {
2921: if (!grep(/^\Q$1\E$/,@userroles)) {
2922: push(@userroles,$1);
2923: }
1.206 raeburn 2924: }
2925: }
2926: }
2927: }
2928: }
2929: #Check to see if we can change personal data for the user
2930: my (@mod_disallowed,@longroles);
2931: foreach my $role (@userroles) {
2932: if ($role eq 'cr') {
2933: push(@longroles,'Custom');
2934: } else {
1.318 raeburn 2935: push(@longroles,&Apache::lonnet::plaintext($role,$crstype));
1.206 raeburn 2936: }
2937: }
1.219 raeburn 2938: my %canmodify = &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},\@userinfo,\@userroles);
2939: foreach my $item (@userinfo) {
1.28 matthew 2940: # Strip leading and trailing whitespace
1.203 raeburn 2941: $env{'form.c'.$item} =~ s/(\s+$|^\s+)//g;
1.219 raeburn 2942: if (!$canmodify{$item}) {
1.207 raeburn 2943: if (defined($env{'form.c'.$item})) {
2944: if ($env{'form.c'.$item} ne $userenv{$item}) {
2945: push(@mod_disallowed,$item);
2946: }
1.206 raeburn 2947: }
2948: $env{'form.c'.$item} = $userenv{$item};
2949: }
1.28 matthew 2950: }
1.259 bisitz 2951: # Check to see if we can change the Student/Employee ID
1.196 raeburn 2952: my $forceid = $env{'form.forceid'};
2953: my $recurseid = $env{'form.recurseid'};
2954: my (%alerts,%rulematch,%idinst_results,%curr_rules,%got_rules);
1.203 raeburn 2955: my %uidhash = &Apache::lonnet::idrget($env{'form.ccdomain'},
2956: $env{'form.ccuname'});
2957: if (($uidhash{$env{'form.ccuname'}}) &&
2958: ($uidhash{$env{'form.ccuname'}}!~/error\:/) &&
2959: (!$forceid)) {
2960: if ($env{'form.cid'} ne $uidhash{$env{'form.ccuname'}}) {
2961: $env{'form.cid'} = $userenv{'id'};
1.293 bisitz 2962: $no_forceid_alert = &mt('New student/employee ID does not match existing ID for this user.')
1.259 bisitz 2963: .'<br />'
2964: .&mt("Change is not permitted without checking the 'Force ID change' checkbox on the previous page.")
2965: .'<br />'."\n";
1.203 raeburn 2966: }
2967: }
2968: if ($env{'form.cid'} ne $userenv{'id'}) {
1.196 raeburn 2969: my $checkhash;
2970: my $checks = { 'id' => 1 };
2971: $checkhash->{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}} =
2972: { 'newuser' => $newuser,
2973: 'id' => $env{'form.cid'},
2974: };
2975: &Apache::loncommon::user_rule_check($checkhash,$checks,
2976: \%alerts,\%rulematch,\%idinst_results,\%curr_rules,\%got_rules);
2977: if (ref($alerts{'id'}) eq 'HASH') {
2978: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
1.203 raeburn 2979: $env{'form.cid'} = $userenv{'id'};
1.196 raeburn 2980: }
2981: }
2982: }
1.378 raeburn 2983: my (%quotachanged,%oldquota,%newquota,%olddefquota,%newdefquota,
2984: $oldinststatus,$newinststatus,%oldisdefault,%newisdefault,%oldsettings,
1.339 raeburn 2985: %oldsettingstext,%newsettings,%newsettingstext,@disporder,
1.378 raeburn 2986: %oldsettingstatus,%newsettingstatus);
1.334 raeburn 2987: @disporder = ('inststatus');
2988: if ($env{'request.role.domain'} eq $env{'form.ccdomain'}) {
1.362 raeburn 2989: push(@disporder,'requestcourses','requestauthor');
1.334 raeburn 2990: } else {
2991: push(@disporder,'reqcrsotherdom');
2992: }
2993: push(@disporder,('quota','tools'));
1.338 raeburn 2994: $oldinststatus = $userenv{'inststatus'};
1.378 raeburn 2995: foreach my $name ('portfolio','author') {
2996: ($olddefquota{$name},$oldsettingstatus{$name}) =
2997: &Apache::loncommon::default_quota($env{'form.ccdomain'},$oldinststatus,$name);
2998: ($newdefquota{$name},$newsettingstatus{$name}) = ($olddefquota{$name},$oldsettingstatus{$name});
2999: }
1.406.2.5! raeburn 3000: push(@disporder,'adhocroles');
1.334 raeburn 3001: my %canshow;
1.220 raeburn 3002: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
1.334 raeburn 3003: $canshow{'quota'} = 1;
1.220 raeburn 3004: }
1.267 raeburn 3005: if (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
1.334 raeburn 3006: $canshow{'tools'} = 1;
1.267 raeburn 3007: }
1.275 raeburn 3008: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
1.334 raeburn 3009: $canshow{'requestcourses'} = 1;
1.300 raeburn 3010: } elsif (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.334 raeburn 3011: $canshow{'reqcrsotherdom'} = 1;
1.275 raeburn 3012: }
1.286 raeburn 3013: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.334 raeburn 3014: $canshow{'inststatus'} = 1;
1.286 raeburn 3015: }
1.362 raeburn 3016: if (&Apache::lonnet::allowed('cau',$env{'form.ccdomain'})) {
3017: $canshow{'requestauthor'} = 1;
3018: }
1.406.2.5! raeburn 3019: if (&Apache::lonnet::allowed('cdh',$env{'request.role.domain'})) {
! 3020: $canshow{'adhocroles'} = 1;
! 3021: }
1.267 raeburn 3022: my (%changeHash,%changed);
1.286 raeburn 3023: if ($oldinststatus eq '') {
1.334 raeburn 3024: $oldsettings{'inststatus'} = $othertitle;
1.286 raeburn 3025: } else {
3026: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 3027: $oldsettings{'inststatus'} = join(', ',map{ $usertypes->{ &unescape($_) }; } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 3028: } else {
1.334 raeburn 3029: $oldsettings{'inststatus'} = join(', ',map{ &unescape($_); } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 3030: }
3031: }
3032: $changeHash{'inststatus'} = $userenv{'inststatus'};
1.334 raeburn 3033: if ($canmodify_status{'inststatus'}) {
3034: $canshow{'inststatus'} = 1;
1.286 raeburn 3035: if (exists($env{'form.inststatus'})) {
3036: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
3037: if (@inststatuses > 0) {
3038: $newinststatus = join(':',map { &escape($_); } @inststatuses);
3039: $changeHash{'inststatus'} = $newinststatus;
3040: if ($newinststatus ne $oldinststatus) {
3041: $changed{'inststatus'} = $newinststatus;
1.378 raeburn 3042: foreach my $name ('portfolio','author') {
3043: ($newdefquota{$name},$newsettingstatus{$name}) =
3044: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
3045: }
1.286 raeburn 3046: }
3047: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 3048: $newsettings{'inststatus'} = join(', ',map{ $usertypes->{$_}; } (@inststatuses));
1.286 raeburn 3049: } else {
1.337 raeburn 3050: $newsettings{'inststatus'} = join(', ',@inststatuses);
1.286 raeburn 3051: }
1.334 raeburn 3052: }
3053: } else {
3054: $newinststatus = '';
3055: $changeHash{'inststatus'} = $newinststatus;
3056: $newsettings{'inststatus'} = $othertitle;
3057: if ($newinststatus ne $oldinststatus) {
3058: $changed{'inststatus'} = $changeHash{'inststatus'};
1.378 raeburn 3059: foreach my $name ('portfolio','author') {
3060: ($newdefquota{$name},$newsettingstatus{$name}) =
3061: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
3062: }
1.286 raeburn 3063: }
3064: }
1.334 raeburn 3065: } elsif ($context ne 'selfcreate') {
3066: $canshow{'inststatus'} = 1;
1.337 raeburn 3067: $newsettings{'inststatus'} = $oldsettings{'inststatus'};
1.286 raeburn 3068: }
1.378 raeburn 3069: foreach my $name ('portfolio','author') {
3070: $changeHash{$name.'quota'} = $userenv{$name.'quota'};
3071: }
1.334 raeburn 3072: if ($context eq 'domain') {
1.378 raeburn 3073: foreach my $name ('portfolio','author') {
3074: if ($userenv{$name.'quota'} ne '') {
3075: $oldquota{$name} = $userenv{$name.'quota'};
3076: if ($env{'form.custom_'.$name.'quota'} == 1) {
3077: if ($env{'form.'.$name.'quota'} eq '') {
3078: $newquota{$name} = 0;
3079: } else {
3080: $newquota{$name} = $env{'form.'.$name.'quota'};
3081: $newquota{$name} =~ s/[^\d\.]//g;
3082: }
3083: if ($newquota{$name} != $oldquota{$name}) {
3084: if ("a_admin($newquota{$name},\%changeHash,$name)) {
3085: $changed{$name.'quota'} = 1;
3086: }
3087: }
1.334 raeburn 3088: } else {
1.378 raeburn 3089: if ("a_admin('',\%changeHash,$name)) {
3090: $changed{$name.'quota'} = 1;
3091: $newquota{$name} = $newdefquota{$name};
3092: $newisdefault{$name} = 1;
3093: }
1.334 raeburn 3094: }
1.149 raeburn 3095: } else {
1.378 raeburn 3096: $oldisdefault{$name} = 1;
3097: $oldquota{$name} = $olddefquota{$name};
3098: if ($env{'form.custom_'.$name.'quota'} == 1) {
3099: if ($env{'form.'.$name.'quota'} eq '') {
3100: $newquota{$name} = 0;
3101: } else {
3102: $newquota{$name} = $env{'form.'.$name.'quota'};
3103: $newquota{$name} =~ s/[^\d\.]//g;
3104: }
3105: if ("a_admin($newquota{$name},\%changeHash,$name)) {
3106: $changed{$name.'quota'} = 1;
3107: }
1.334 raeburn 3108: } else {
1.378 raeburn 3109: $newquota{$name} = $newdefquota{$name};
3110: $newisdefault{$name} = 1;
1.334 raeburn 3111: }
1.378 raeburn 3112: }
3113: if ($oldisdefault{$name}) {
3114: $oldsettingstext{'quota'}{$name} = &get_defaultquota_text($oldsettingstatus{$name});
1.383 raeburn 3115: } else {
3116: $oldsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$oldquota{$name});
1.378 raeburn 3117: }
3118: if ($newisdefault{$name}) {
3119: $newsettingstext{'quota'}{$name} = &get_defaultquota_text($newsettingstatus{$name});
1.383 raeburn 3120: } else {
3121: $newsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$newquota{$name});
1.134 raeburn 3122: }
3123: }
1.334 raeburn 3124: &tool_changes('tools',\@usertools,\%oldsettings,\%oldsettingstext,\%userenv,
3125: \%changeHash,\%changed,\%newsettings,\%newsettingstext);
3126: if ($env{'form.ccdomain'} eq $env{'request.role.domain'}) {
3127: &tool_changes('requestcourses',\@requestcourses,\%oldsettings,\%oldsettingstext,
3128: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.384 raeburn 3129: &tool_changes('requestauthor',\@requestauthor,\%oldsettings,\%oldsettingstext,
3130: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 3131: } else {
1.334 raeburn 3132: &tool_changes('reqcrsotherdom',\@requestcourses,\%oldsettings,\%oldsettingstext,
3133: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 3134: }
1.406.2.5! raeburn 3135: if ($userenv{'adhocroles.'.$env{'request.role.domain'}}) {
! 3136: $changeHash{'adhocroles.'.$env{'request.role.domain'}} = $userenv{'adhocroles.'.$env{'request.role.domain'}};
! 3137: }
! 3138: if (&adhocrole_changes(\%changeHash,\%userenv)) {
! 3139: $changed{'adhocroles'} = 1;
! 3140: $oldsettings{'adhocroles'} = $userenv{'adhocroles.'.$env{'request.role.domain'}};
! 3141: $newsettings{'adhocroles'} = $changeHash{'adhocroles.'.$env{'request.role.domain'}};
! 3142: }
1.149 raeburn 3143: }
1.334 raeburn 3144: foreach my $item (@userinfo) {
3145: if ($env{'form.c'.$item} ne $userenv{$item}) {
3146: $namechanged{$item} = 1;
3147: }
1.204 raeburn 3148: }
1.378 raeburn 3149: foreach my $name ('portfolio','author') {
1.390 bisitz 3150: $oldsettings{'quota'}{$name} = &mt('[_1] MB',$oldquota{$name});
3151: $newsettings{'quota'}{$name} = &mt('[_1] MB',$newquota{$name});
1.378 raeburn 3152: }
1.334 raeburn 3153: if ((keys(%namechanged) > 0) || (keys(%changed) > 0)) {
1.267 raeburn 3154: my ($chgresult,$namechgresult);
3155: if (keys(%changed) > 0) {
3156: $chgresult =
1.204 raeburn 3157: &Apache::lonnet::put('environment',\%changeHash,
3158: $env{'form.ccdomain'},$env{'form.ccuname'});
1.267 raeburn 3159: if ($chgresult eq 'ok') {
3160: if (($env{'user.name'} eq $env{'form.ccuname'}) &&
3161: ($env{'user.domain'} eq $env{'form.ccdomain'})) {
1.270 raeburn 3162: my %newenvhash;
3163: foreach my $key (keys(%changed)) {
1.299 raeburn 3164: if (($key eq 'official') || ($key eq 'unofficial')
1.403 raeburn 3165: || ($key eq 'community') || ($key eq 'textbook')) {
1.279 raeburn 3166: $newenvhash{'environment.requestcourses.'.$key} =
3167: $changeHash{'requestcourses.'.$key};
1.362 raeburn 3168: if ($changeHash{'requestcourses.'.$key}) {
1.332 raeburn 3169: $newenvhash{'environment.canrequest.'.$key} = 1;
1.279 raeburn 3170: } else {
3171: $newenvhash{'environment.canrequest.'.$key} =
3172: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3173: $key,'reload','requestcourses');
3174: }
1.362 raeburn 3175: } elsif ($key eq 'requestauthor') {
3176: $newenvhash{'environment.'.$key} = $changeHash{$key};
3177: if ($changeHash{$key}) {
3178: $newenvhash{'environment.canrequest.author'} = 1;
3179: } else {
3180: $newenvhash{'environment.canrequest.author'} =
3181: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3182: $key,'reload','requestauthor');
3183: }
1.406.2.5! raeburn 3184: } elsif ($key eq 'adhocroles') {
! 3185: $newenvhash{'adhocroles.'.$env{'request.role.domain'}} =
! 3186: $changeHash{'adhocroles.'.$env{'request.role.domain'}};
1.275 raeburn 3187: } elsif ($key ne 'quota') {
1.270 raeburn 3188: $newenvhash{'environment.tools.'.$key} =
3189: $changeHash{'tools.'.$key};
1.279 raeburn 3190: if ($changeHash{'tools.'.$key} ne '') {
3191: $newenvhash{'environment.availabletools.'.$key} =
3192: $changeHash{'tools.'.$key};
3193: } else {
3194: $newenvhash{'environment.availabletools.'.$key} =
1.367 golterma 3195: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3196: $key,'reload','tools');
1.279 raeburn 3197: }
1.270 raeburn 3198: }
3199: }
1.271 raeburn 3200: if (keys(%newenvhash)) {
3201: &Apache::lonnet::appenv(\%newenvhash);
3202: }
1.267 raeburn 3203: }
3204: }
1.204 raeburn 3205: }
1.334 raeburn 3206: if (keys(%namechanged) > 0) {
1.337 raeburn 3207: foreach my $field (@userinfo) {
3208: $changeHash{$field} = $env{'form.c'.$field};
3209: }
3210: # Make the change
1.204 raeburn 3211: $namechgresult =
3212: &Apache::lonnet::modifyuser($env{'form.ccdomain'},
3213: $env{'form.ccuname'},$changeHash{'id'},undef,undef,
3214: $changeHash{'firstname'},$changeHash{'middlename'},
3215: $changeHash{'lastname'},$changeHash{'generation'},
1.337 raeburn 3216: $changeHash{'id'},undef,$changeHash{'permanentemail'},undef,\@userinfo);
1.220 raeburn 3217: %userupdate = (
3218: lastname => $env{'form.clastname'},
3219: middlename => $env{'form.cmiddlename'},
3220: firstname => $env{'form.cfirstname'},
3221: generation => $env{'form.cgeneration'},
3222: id => $env{'form.cid'},
3223: );
1.204 raeburn 3224: }
1.334 raeburn 3225: if (((keys(%namechanged) > 0) && $namechgresult eq 'ok') ||
1.267 raeburn 3226: ((keys(%changed) > 0) && $chgresult eq 'ok')) {
1.28 matthew 3227: # Tell the user we changed the name
1.334 raeburn 3228: &display_userinfo($r,1,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 3229: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,
1.334 raeburn 3230: \%oldsettings, \%oldsettingstext,\%newsettings,
3231: \%newsettingstext);
1.203 raeburn 3232: if ($env{'form.cid'} ne $userenv{'id'}) {
3233: &Apache::lonnet::idput($env{'form.ccdomain'},
1.406.2.5! raeburn 3234: {$env{'form.ccuname'} => $env{'form.cid'}});
1.203 raeburn 3235: if (($recurseid) &&
3236: (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}))) {
3237: my $idresult =
3238: &Apache::lonuserutils::propagate_id_change(
3239: $env{'form.ccuname'},$env{'form.ccdomain'},
3240: \%userupdate);
3241: $r->print('<br />'.$idresult.'<br />');
3242: }
1.196 raeburn 3243: }
1.149 raeburn 3244: if (($env{'form.ccdomain'} eq $env{'user.domain'}) &&
3245: ($env{'form.ccuname'} eq $env{'user.name'})) {
3246: my %newenvhash;
3247: foreach my $key (keys(%changeHash)) {
3248: $newenvhash{'environment.'.$key} = $changeHash{$key};
3249: }
1.238 raeburn 3250: &Apache::lonnet::appenv(\%newenvhash);
1.149 raeburn 3251: }
1.28 matthew 3252: } else { # error occurred
1.389 bisitz 3253: $r->print(
3254: '<p class="LC_error">'
3255: .&mt('Unable to successfully change environment for [_1] in domain [_2].',
3256: '"'.$env{'form.ccuname'}.'"',
3257: '"'.$env{'form.ccdomain'}.'"')
3258: .'</p>');
1.28 matthew 3259: }
1.334 raeburn 3260: } else { # End of if ($env ... ) logic
1.275 raeburn 3261: # They did not want to change the users name, quota, tool availability,
3262: # or ability to request creation of courses,
1.267 raeburn 3263: # but we can still tell them what the name and quota and availabilities are
1.334 raeburn 3264: &display_userinfo($r,undef,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 3265: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,\%oldsettings,
1.334 raeburn 3266: \%oldsettingstext,\%newsettings,\%newsettingstext);
1.28 matthew 3267: }
1.206 raeburn 3268: if (@mod_disallowed) {
3269: my ($rolestr,$contextname);
3270: if (@longroles > 0) {
3271: $rolestr = join(', ',@longroles);
3272: } else {
3273: $rolestr = &mt('No roles');
3274: }
3275: if ($context eq 'course') {
1.399 bisitz 3276: $contextname = 'course';
1.206 raeburn 3277: } elsif ($context eq 'author') {
1.399 bisitz 3278: $contextname = 'co-author';
1.206 raeburn 3279: }
3280: $r->print(&mt('The following fields were not updated: ').'<ul>');
3281: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
3282: foreach my $field (@mod_disallowed) {
3283: $r->print('<li>'.$fieldtitles{$field}.'</li>'."\n");
3284: }
1.207 raeburn 3285: $r->print('</ul>');
3286: if (@mod_disallowed == 1) {
1.399 bisitz 3287: $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 3288: } else {
1.399 bisitz 3289: $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 3290: }
1.292 bisitz 3291: my $helplink = 'javascript:helpMenu('."'display'".')';
3292: $r->print('<span class="LC_cusr_emph">'.$rolestr.'</span><br />'
3293: .&mt('Please contact your [_1]helpdesk[_2] for more information.'
3294: ,'<a href="'.$helplink.'">','</a>')
3295: .'<br />');
1.206 raeburn 3296: }
1.259 bisitz 3297: $r->print('<span class="LC_warning">'
3298: .$no_forceid_alert
3299: .&Apache::lonuserutils::print_namespacing_alerts($env{'form.ccdomain'},\%alerts,\%curr_rules)
3300: .'</span>');
1.4 www 3301: }
1.367 golterma 3302: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1.220 raeburn 3303: if ($env{'form.action'} eq 'singlestudent') {
1.375 raeburn 3304: &enroll_single_student($r,$uhome,$amode,$genpwd,$now,$newuser,$context,
3305: $crstype,$showcredits,$defaultcredits);
1.386 bisitz 3306: my $linktext = ($crstype eq 'Community' ?
3307: &mt('Enroll Another Member') : &mt('Enroll Another Student'));
3308: $r->print(
3309: &Apache::lonhtmlcommon::actionbox([
3310: '<a href="javascript:backPage(document.userupdate)">'
3311: .($crstype eq 'Community' ?
3312: &mt('Enroll Another Member') : &mt('Enroll Another Student'))
3313: .'</a>']));
1.220 raeburn 3314: } else {
1.375 raeburn 3315: my @rolechanges = &update_roles($r,$context,$showcredits);
1.334 raeburn 3316: if (keys(%namechanged) > 0) {
1.220 raeburn 3317: if ($context eq 'course') {
3318: if (@userroles > 0) {
1.225 raeburn 3319: if ((@rolechanges == 0) ||
3320: (!(grep(/^st$/,@rolechanges)))) {
3321: if (grep(/^st$/,@userroles)) {
3322: my $classlistupdated =
3323: &Apache::lonuserutils::update_classlist($cdom,
1.220 raeburn 3324: $cnum,$env{'form.ccdomain'},
3325: $env{'form.ccuname'},\%userupdate);
1.225 raeburn 3326: }
1.220 raeburn 3327: }
3328: }
3329: }
3330: }
1.226 raeburn 3331: my $userinfo = &Apache::loncommon::plainname($env{'form.ccuname'},
1.233 raeburn 3332: $env{'form.ccdomain'});
3333: if ($env{'form.popup'}) {
3334: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
3335: } else {
1.367 golterma 3336: $r->print('<br />'.&Apache::lonhtmlcommon::actionbox(['<a href="javascript:backPage(document.userupdate,'."'$env{'form.prevphase'}','modify'".')">'
3337: .&mt('Modify this user: [_1]','<span class="LC_cusr_emph">'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.' ('.$userinfo.')</span>').'</a>',
3338: '<a href="javascript:backPage(document.userupdate)">'.&mt('Create/Modify Another User').'</a>']));
1.233 raeburn 3339: }
1.220 raeburn 3340: }
3341: }
3342:
1.334 raeburn 3343: sub display_userinfo {
1.362 raeburn 3344: my ($r,$changed,$order,$canshow,$requestcourses,$usertools,$requestauthor,
3345: $userenv,$changedhash,$namechangedhash,$oldsetting,$oldsettingtext,
1.334 raeburn 3346: $newsetting,$newsettingtext) = @_;
3347: return unless (ref($order) eq 'ARRAY' &&
3348: ref($canshow) eq 'HASH' &&
3349: ref($requestcourses) eq 'ARRAY' &&
1.362 raeburn 3350: ref($requestauthor) eq 'ARRAY' &&
1.334 raeburn 3351: ref($usertools) eq 'ARRAY' &&
3352: ref($userenv) eq 'HASH' &&
3353: ref($changedhash) eq 'HASH' &&
3354: ref($oldsetting) eq 'HASH' &&
3355: ref($oldsettingtext) eq 'HASH' &&
3356: ref($newsetting) eq 'HASH' &&
3357: ref($newsettingtext) eq 'HASH');
3358: my %lt=&Apache::lonlocal::texthash(
1.372 raeburn 3359: 'ui' => 'User Information',
1.334 raeburn 3360: 'uic' => 'User Information Changed',
3361: 'firstname' => 'First Name',
3362: 'middlename' => 'Middle Name',
3363: 'lastname' => 'Last Name',
3364: 'generation' => 'Generation',
3365: 'id' => 'Student/Employee ID',
3366: 'permanentemail' => 'Permanent e-mail address',
1.378 raeburn 3367: 'portfolioquota' => 'Disk space allocated to portfolio files',
1.385 bisitz 3368: 'authorquota' => 'Disk space allocated to Authoring Space',
1.334 raeburn 3369: 'blog' => 'Blog Availability',
1.361 raeburn 3370: 'webdav' => 'WebDAV Availability',
1.334 raeburn 3371: 'aboutme' => 'Personal Information Page Availability',
3372: 'portfolio' => 'Portfolio Availability',
3373: 'official' => 'Can Request Official Courses',
3374: 'unofficial' => 'Can Request Unofficial Courses',
3375: 'community' => 'Can Request Communities',
1.384 raeburn 3376: 'textbook' => 'Can Request Textbook Courses',
1.362 raeburn 3377: 'requestauthor' => 'Can Request Author Role',
1.406.2.5! raeburn 3378: 'adhocroles' => 'Ad Hoc Roles Selectable via Helpdesk Role',
1.334 raeburn 3379: 'inststatus' => "Affiliation",
3380: 'prvs' => 'Previous Value:',
3381: 'chto' => 'Changed To:'
3382: );
3383: if ($changed) {
1.372 raeburn 3384: $r->print('<h3>'.$lt{'uic'}.'</h3>'.
1.367 golterma 3385: &Apache::loncommon::start_data_table().
3386: &Apache::loncommon::start_data_table_header_row());
1.334 raeburn 3387: $r->print("<th> </th>\n");
1.367 golterma 3388: $r->print('<th><b>'.$lt{'prvs'}.'</b></th>');
3389: $r->print('<th><span class="LC_nobreak"><b>'.$lt{'chto'}.'</b></span></th>');
3390: $r->print(&Apache::loncommon::end_data_table_header_row());
3391: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
3392:
1.334 raeburn 3393: foreach my $item (@userinfo) {
3394: my $value = $env{'form.c'.$item};
1.367 golterma 3395: #show changes only:
1.383 raeburn 3396: unless ($value eq $userenv->{$item}){
1.367 golterma 3397: $r->print(&Apache::loncommon::start_data_table_row());
3398: $r->print("<td>$lt{$item}</td>\n");
1.383 raeburn 3399: $r->print("<td>".$userenv->{$item}."</td>\n");
1.367 golterma 3400: $r->print("<td>$value </td>\n");
3401: $r->print(&Apache::loncommon::end_data_table_row());
1.334 raeburn 3402: }
3403: }
3404: foreach my $entry (@{$order}) {
1.383 raeburn 3405: if ($canshow->{$entry}) {
3406: if (($entry eq 'requestcourses') || ($entry eq 'reqcrsotherdom') || ($entry eq 'requestauthor')) {
3407: my @items;
3408: if ($entry eq 'requestauthor') {
3409: @items = ($entry);
3410: } else {
3411: @items = @{$requestcourses};
1.384 raeburn 3412: }
1.383 raeburn 3413: foreach my $item (@items) {
3414: if (($newsetting->{$item} ne $oldsetting->{$item}) ||
3415: ($newsettingtext->{$item} ne $oldsettingtext->{$item})) {
3416: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3417: $r->print("<td>$lt{$item}</td>\n");
3418: $r->print("<td>".$oldsetting->{$item});
3419: if ($oldsettingtext->{$item}) {
3420: if ($oldsetting->{$item}) {
3421: $r->print(' -- ');
3422: }
3423: $r->print($oldsettingtext->{$item});
3424: }
3425: $r->print("</td>\n");
3426: $r->print("<td>".$newsetting->{$item});
3427: if ($newsettingtext->{$item}) {
3428: if ($newsetting->{$item}) {
3429: $r->print(' -- ');
3430: }
3431: $r->print($newsettingtext->{$item});
3432: }
3433: $r->print("</td>\n");
3434: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3435: }
3436: }
3437: } elsif ($entry eq 'tools') {
3438: foreach my $item (@{$usertools}) {
1.383 raeburn 3439: if ($newsetting->{$item} ne $oldsetting->{$item}) {
3440: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3441: $r->print("<td>$lt{$item}</td>\n");
3442: $r->print("<td>".$oldsetting->{$item}.' '.$oldsettingtext->{$item}."</td>\n");
3443: $r->print("<td>".$newsetting->{$item}.' '.$newsettingtext->{$item}."</td>\n");
3444: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3445: }
3446: }
1.378 raeburn 3447: } elsif ($entry eq 'quota') {
3448: if ((ref($oldsetting->{$entry}) eq 'HASH') && (ref($oldsettingtext->{$entry}) eq 'HASH') &&
3449: (ref($newsetting->{$entry}) eq 'HASH') && (ref($newsettingtext->{$entry}) eq 'HASH')) {
3450: foreach my $name ('portfolio','author') {
1.383 raeburn 3451: if ($newsetting->{$entry}->{$name} ne $oldsetting->{$entry}->{$name}) {
3452: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3453: $r->print("<td>$lt{$name.$entry}</td>\n");
3454: $r->print("<td>".$oldsettingtext->{$entry}->{$name}."</td>\n");
3455: $r->print("<td>".$newsettingtext->{$entry}->{$name}."</td>\n");
3456: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.378 raeburn 3457: }
3458: }
3459: }
1.334 raeburn 3460: } else {
1.383 raeburn 3461: if ($newsetting->{$entry} ne $oldsetting->{$entry}) {
3462: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3463: $r->print("<td>$lt{$entry}</td>\n");
3464: $r->print("<td>".$oldsetting->{$entry}.' '.$oldsettingtext->{$entry}."</td>\n");
3465: $r->print("<td>".$newsetting->{$entry}.' '.$newsettingtext->{$entry}."</td>\n");
3466: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3467: }
3468: }
3469: }
3470: }
1.367 golterma 3471: $r->print(&Apache::loncommon::end_data_table().'<br />');
1.372 raeburn 3472: } else {
3473: $r->print('<h3>'.$lt{'ui'}.'</h3>'.
3474: '<p>'.&mt('No changes made to user information').'</p>');
1.334 raeburn 3475: }
3476: return;
3477: }
3478:
1.275 raeburn 3479: sub tool_changes {
3480: my ($context,$usertools,$oldaccess,$oldaccesstext,$userenv,$changeHash,
3481: $changed,$newaccess,$newaccesstext) = @_;
3482: if (!((ref($usertools) eq 'ARRAY') && (ref($oldaccess) eq 'HASH') &&
3483: (ref($oldaccesstext) eq 'HASH') && (ref($userenv) eq 'HASH') &&
3484: (ref($changeHash) eq 'HASH') && (ref($changed) eq 'HASH') &&
3485: (ref($newaccess) eq 'HASH') && (ref($newaccesstext) eq 'HASH'))) {
3486: return;
3487: }
1.383 raeburn 3488: my %reqdisplay = &requestchange_display();
1.300 raeburn 3489: if ($context eq 'reqcrsotherdom') {
1.309 raeburn 3490: my @options = ('approval','validate','autolimit');
1.306 raeburn 3491: my $optregex = join('|',@options);
1.300 raeburn 3492: my $cdom = $env{'request.role.domain'};
3493: foreach my $tool (@{$usertools}) {
1.383 raeburn 3494: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
1.314 raeburn 3495: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
1.300 raeburn 3496: $changeHash->{$context.'.'.$tool} = $userenv->{$context.'.'.$tool};
1.383 raeburn 3497: my ($newop,$limit);
1.314 raeburn 3498: if ($env{'form.'.$context.'_'.$tool}) {
3499: $newop = $env{'form.'.$context.'_'.$tool};
3500: if ($newop eq 'autolimit') {
1.383 raeburn 3501: $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
1.314 raeburn 3502: $limit =~ s/\D+//g;
3503: $newop .= '='.$limit;
3504: }
3505: }
1.300 raeburn 3506: if ($userenv->{$context.'.'.$tool} eq '') {
1.314 raeburn 3507: if ($newop) {
3508: $changed->{$tool}=&tool_admin($tool,$cdom.':'.$newop,
1.300 raeburn 3509: $changeHash,$context);
3510: if ($changed->{$tool}) {
1.383 raeburn 3511: if ($newop =~ /^autolimit/) {
3512: if ($limit) {
3513: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3514: } else {
3515: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3516: }
3517: } else {
3518: $newaccesstext->{$tool} = $reqdisplay{$newop};
3519: }
1.300 raeburn 3520: } else {
3521: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3522: }
3523: }
3524: } else {
3525: my @curr = split(',',$userenv->{$context.'.'.$tool});
3526: my @new;
3527: my $changedoms;
1.314 raeburn 3528: foreach my $req (@curr) {
3529: if ($req =~ /^\Q$cdom\E\:($optregex\=?\d*)$/) {
3530: my $oldop = $1;
1.383 raeburn 3531: if ($oldop =~ /^autolimit=(\d*)/) {
3532: my $limit = $1;
3533: if ($limit) {
3534: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3535: } else {
3536: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3537: }
3538: } else {
3539: $oldaccesstext->{$tool} = $reqdisplay{$oldop};
3540: }
1.314 raeburn 3541: if ($oldop ne $newop) {
3542: $changedoms = 1;
3543: foreach my $item (@curr) {
3544: my ($reqdom,$option) = split(':',$item);
3545: unless ($reqdom eq $cdom) {
3546: push(@new,$item);
3547: }
3548: }
3549: if ($newop) {
3550: push(@new,$cdom.':'.$newop);
1.300 raeburn 3551: }
1.314 raeburn 3552: @new = sort(@new);
1.300 raeburn 3553: }
1.314 raeburn 3554: last;
1.300 raeburn 3555: }
1.314 raeburn 3556: }
3557: if ((!$changedoms) && ($newop)) {
1.300 raeburn 3558: $changedoms = 1;
1.306 raeburn 3559: @new = sort(@curr,$cdom.':'.$newop);
1.300 raeburn 3560: }
3561: if ($changedoms) {
1.314 raeburn 3562: my $newdomstr;
1.300 raeburn 3563: if (@new) {
3564: $newdomstr = join(',',@new);
3565: }
3566: $changed->{$tool}=&tool_admin($tool,$newdomstr,$changeHash,
3567: $context);
3568: if ($changed->{$tool}) {
3569: if ($env{'form.'.$context.'_'.$tool}) {
1.306 raeburn 3570: if ($env{'form.'.$context.'_'.$tool} eq 'autolimit') {
1.314 raeburn 3571: my $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
3572: $limit =~ s/\D+//g;
3573: if ($limit) {
1.383 raeburn 3574: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
1.314 raeburn 3575: } else {
1.383 raeburn 3576: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
1.306 raeburn 3577: }
1.314 raeburn 3578: } else {
1.306 raeburn 3579: $newaccesstext->{$tool} = $reqdisplay{$env{'form.'.$context.'_'.$tool}};
3580: }
1.300 raeburn 3581: } else {
1.383 raeburn 3582: $newaccesstext->{$tool} = &mt("availability set to 'off'");
1.300 raeburn 3583: }
3584: }
3585: }
3586: }
3587: }
3588: return;
3589: }
1.275 raeburn 3590: foreach my $tool (@{$usertools}) {
1.383 raeburn 3591: my ($newval,$limit,$envkey);
1.362 raeburn 3592: $envkey = $context.'.'.$tool;
1.306 raeburn 3593: if ($context eq 'requestcourses') {
3594: $newval = $env{'form.crsreq_'.$tool};
3595: if ($newval eq 'autolimit') {
1.383 raeburn 3596: $limit = $env{'form.crsreq_'.$tool.'_limit'};
3597: $limit =~ s/\D+//g;
3598: $newval .= '='.$limit;
1.306 raeburn 3599: }
1.362 raeburn 3600: } elsif ($context eq 'requestauthor') {
3601: $newval = $env{'form.'.$context};
3602: $envkey = $context;
1.314 raeburn 3603: } else {
1.306 raeburn 3604: $newval = $env{'form.'.$context.'_'.$tool};
3605: }
1.362 raeburn 3606: if ($userenv->{$envkey} ne '') {
1.275 raeburn 3607: $oldaccess->{$tool} = &mt('custom');
1.383 raeburn 3608: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3609: if ($userenv->{$envkey} =~ /^autolimit=(\d*)$/) {
3610: my $currlimit = $1;
3611: if ($currlimit eq '') {
3612: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3613: } else {
3614: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$currlimit);
3615: }
3616: } elsif ($userenv->{$envkey}) {
3617: $oldaccesstext->{$tool} = $reqdisplay{$userenv->{$envkey}};
3618: } else {
3619: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
3620: }
1.275 raeburn 3621: } else {
1.383 raeburn 3622: if ($userenv->{$envkey}) {
3623: $oldaccesstext->{$tool} = &mt("availability set to 'on'");
3624: } else {
3625: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
3626: }
1.275 raeburn 3627: }
1.362 raeburn 3628: $changeHash->{$envkey} = $userenv->{$envkey};
1.275 raeburn 3629: if ($env{'form.custom'.$tool} == 1) {
1.362 raeburn 3630: if ($newval ne $userenv->{$envkey}) {
1.306 raeburn 3631: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
3632: $context);
1.275 raeburn 3633: if ($changed->{$tool}) {
3634: $newaccess->{$tool} = &mt('custom');
1.383 raeburn 3635: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3636: if ($newval =~ /^autolimit/) {
3637: if ($limit) {
3638: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3639: } else {
3640: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3641: }
3642: } elsif ($newval) {
3643: $newaccesstext->{$tool} = $reqdisplay{$newval};
3644: } else {
3645: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3646: }
1.275 raeburn 3647: } else {
1.383 raeburn 3648: if ($newval) {
3649: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3650: } else {
3651: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3652: }
1.275 raeburn 3653: }
3654: } else {
3655: $newaccess->{$tool} = $oldaccess->{$tool};
1.383 raeburn 3656: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3657: if ($newval =~ /^autolimit/) {
3658: if ($limit) {
3659: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3660: } else {
3661: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3662: }
3663: } elsif ($newval) {
3664: $newaccesstext->{$tool} = $reqdisplay{$newval};
3665: } else {
3666: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3667: }
1.275 raeburn 3668: } else {
1.383 raeburn 3669: if ($userenv->{$context.'.'.$tool}) {
3670: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3671: } else {
3672: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3673: }
1.275 raeburn 3674: }
3675: }
3676: } else {
3677: $newaccess->{$tool} = $oldaccess->{$tool};
3678: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3679: }
3680: } else {
3681: $changed->{$tool} = &tool_admin($tool,'',$changeHash,$context);
3682: if ($changed->{$tool}) {
3683: $newaccess->{$tool} = &mt('default');
3684: } else {
3685: $newaccess->{$tool} = $oldaccess->{$tool};
1.383 raeburn 3686: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3687: if ($newval =~ /^autolimit/) {
3688: if ($limit) {
3689: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3690: } else {
3691: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3692: }
3693: } elsif ($newval) {
3694: $newaccesstext->{$tool} = $reqdisplay{$newval};
3695: } else {
3696: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3697: }
1.275 raeburn 3698: } else {
1.383 raeburn 3699: if ($userenv->{$context.'.'.$tool}) {
3700: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3701: } else {
3702: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3703: }
1.275 raeburn 3704: }
3705: }
3706: }
3707: } else {
3708: $oldaccess->{$tool} = &mt('default');
3709: if ($env{'form.custom'.$tool} == 1) {
1.306 raeburn 3710: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
3711: $context);
1.275 raeburn 3712: if ($changed->{$tool}) {
3713: $newaccess->{$tool} = &mt('custom');
1.383 raeburn 3714: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3715: if ($newval =~ /^autolimit/) {
3716: if ($limit) {
3717: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3718: } else {
3719: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3720: }
3721: } elsif ($newval) {
3722: $newaccesstext->{$tool} = $reqdisplay{$newval};
3723: } else {
3724: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3725: }
1.275 raeburn 3726: } else {
1.383 raeburn 3727: if ($newval) {
3728: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3729: } else {
3730: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3731: }
1.275 raeburn 3732: }
3733: } else {
3734: $newaccess->{$tool} = $oldaccess->{$tool};
3735: }
3736: } else {
3737: $newaccess->{$tool} = $oldaccess->{$tool};
3738: }
3739: }
3740: }
3741: return;
3742: }
3743:
1.406.2.5! raeburn 3744: sub adhocrole_changes {
! 3745: my ($changehashref,$userenv) = @_;
! 3746: my @adds = &Apache::loncommon::get_env_multiple('form.adhocroleadd');
! 3747: my @dels = &Apache::loncommon::get_env_multiple('form.adhocroledel');
! 3748: my (@saved,@added,@alladhoc,$changed);
! 3749: my $adhoc_key = 'adhocroles.'.$env{'request.role.domain'};
! 3750: if (!$env{'form.makeuser'}) {
! 3751: if (ref($userenv) eq 'HASH') {
! 3752: my @current;
! 3753: if ($userenv->{$adhoc_key}) {
! 3754: @current = split(/,/,$userenv->{$adhoc_key});
! 3755: if (@dels) {
! 3756: foreach my $curr (@current) {
! 3757: next if ($curr eq '');
! 3758: unless (grep(/\Q$curr\E$/,@dels)) {
! 3759: push(@saved,$curr);
! 3760: }
! 3761: }
! 3762: $changed = 1;
! 3763: } else {
! 3764: @saved = @current;
! 3765: }
! 3766: }
! 3767: }
! 3768: }
! 3769: if (@adds) {
! 3770: my $confname = &Apache::lonnet::get_domainconfiguser($env{'request.role.domain'});
! 3771: my %existing=&Apache::lonnet::dump('roles',$env{'request.role.domain'},
! 3772: $confname,'rolesdef_');
! 3773: foreach my $poss (@adds) {
! 3774: if (exists($existing{'rolesdef_'.$poss})) {
! 3775: push(@added,$poss);
! 3776: $changed = 1;
! 3777: }
! 3778: }
! 3779: }
! 3780: if (@added) {
! 3781: if (@saved) {
! 3782: foreach my $add (@added) {
! 3783: unless (grep(/^\Q$add\E$/,@saved)) {
! 3784: push(@alladhoc,$add);
! 3785: }
! 3786: }
! 3787: } else {
! 3788: push(@alladhoc,@added);
! 3789: }
! 3790: }
! 3791: if (@saved) {
! 3792: push(@alladhoc,@saved);
! 3793: }
! 3794: if (@alladhoc) {
! 3795: my $adhocstr = join(',',sort(@alladhoc));
! 3796: $changehashref->{$adhoc_key} = $adhocstr;
! 3797: } elsif (@dels) {
! 3798: &Apache::lonnet::del('environment',[$adhoc_key],$env{'form.ccdomain'},$env{'form.ccuname'});
! 3799: delete($changehashref->{$adhoc_key});
! 3800: if (($env{'form.ccdomain'} eq $env{'user.domain'}) &&
! 3801: ($env{'form.ccuname'} eq $env{'user.name'})) {
! 3802: &Apache::lonnet::delenv($adhoc_key);
! 3803: }
! 3804: }
! 3805: return $changed;
! 3806: }
! 3807:
1.220 raeburn 3808: sub update_roles {
1.375 raeburn 3809: my ($r,$context,$showcredits) = @_;
1.4 www 3810: my $now=time;
1.225 raeburn 3811: my @rolechanges;
1.220 raeburn 3812: my %disallowed;
1.73 sakharuk 3813: $r->print('<h3>'.&mt('Modifying Roles').'</h3>');
1.404 raeburn 3814: foreach my $key (keys(%env)) {
1.135 raeburn 3815: next if (! $env{$key});
1.190 raeburn 3816: next if ($key eq 'form.action');
1.27 matthew 3817: # Revoke roles
1.135 raeburn 3818: if ($key=~/^form\.rev/) {
3819: if ($key=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) {
1.64 www 3820: # Revoke standard role
1.170 albertel 3821: my ($scope,$role) = ($1,$2);
3822: my $result =
3823: &Apache::lonnet::revokerole($env{'form.ccdomain'},
3824: $env{'form.ccuname'},
1.239 raeburn 3825: $scope,$role,'','',$context);
1.367 golterma 3826: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 3827: &mt('Revoking [_1] in [_2]',
3828: &Apache::lonnet::plaintext($role),
1.372 raeburn 3829: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 3830: $result ne "ok").'<br />');
3831: if ($result ne "ok") {
3832: $r->print(&mt('Error: [_1]',$result).'<br />');
3833: }
1.170 albertel 3834: if ($role eq 'st') {
1.202 raeburn 3835: my $result =
1.198 raeburn 3836: &Apache::lonuserutils::classlist_drop($scope,
3837: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 3838: $now);
1.367 golterma 3839: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.53 www 3840: }
1.225 raeburn 3841: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3842: push(@rolechanges,$role);
3843: }
1.196 raeburn 3844: }
1.195 raeburn 3845: if ($key=~m{^form\.rev\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}s) {
1.64 www 3846: # Revoke custom role
1.369 bisitz 3847: my $result = &Apache::lonnet::revokecustomrole(
3848: $env{'form.ccdomain'},$env{'form.ccuname'},$1,$2,$3,$4,'','',$context);
1.367 golterma 3849: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 3850: &mt('Revoking custom role [_1] by [_2] in [_3]',
1.372 raeburn 3851: $4,$3.':'.$2,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 3852: $result ne 'ok').'<br />');
3853: if ($result ne "ok") {
3854: $r->print(&mt('Error: [_1]',$result).'<br />');
3855: }
1.225 raeburn 3856: if (!grep(/^cr$/,@rolechanges)) {
3857: push(@rolechanges,'cr');
3858: }
1.64 www 3859: }
1.135 raeburn 3860: } elsif ($key=~/^form\.del/) {
3861: if ($key=~/^form\.del\:([^\_]+)\_([^\_\.]+)$/) {
1.116 raeburn 3862: # Delete standard role
1.170 albertel 3863: my ($scope,$role) = ($1,$2);
3864: my $result =
3865: &Apache::lonnet::assignrole($env{'form.ccdomain'},
3866: $env{'form.ccuname'},
1.239 raeburn 3867: $scope,$role,$now,0,1,'',
3868: $context);
1.367 golterma 3869: $r->print(&Apache::lonhtmlcommon::confirm_success(
3870: &mt('Deleting [_1] in [_2]',
1.369 bisitz 3871: &Apache::lonnet::plaintext($role),
1.372 raeburn 3872: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 3873: $result ne 'ok').'<br />');
3874: if ($result ne "ok") {
3875: $r->print(&mt('Error: [_1]',$result).'<br />');
3876: }
1.367 golterma 3877:
1.170 albertel 3878: if ($role eq 'st') {
1.202 raeburn 3879: my $result =
1.198 raeburn 3880: &Apache::lonuserutils::classlist_drop($scope,
3881: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 3882: $now);
1.369 bisitz 3883: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.81 albertel 3884: }
1.225 raeburn 3885: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3886: push(@rolechanges,$role);
3887: }
1.116 raeburn 3888: }
1.139 albertel 3889: if ($key=~m{^form\.del\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 3890: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
3891: # Delete custom role
1.369 bisitz 3892: my $result =
3893: &Apache::lonnet::assigncustomrole($env{'form.ccdomain'},
3894: $env{'form.ccuname'},$url,$rdom,$rnam,$rolename,$now,
3895: 0,1,$context);
3896: $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('Deleting custom role [_1] by [_2] in [_3]',
1.372 raeburn 3897: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 3898: $result ne "ok").'<br />');
3899: if ($result ne "ok") {
3900: $r->print(&mt('Error: [_1]',$result).'<br />');
3901: }
1.367 golterma 3902:
1.225 raeburn 3903: if (!grep(/^cr$/,@rolechanges)) {
3904: push(@rolechanges,'cr');
3905: }
1.116 raeburn 3906: }
1.135 raeburn 3907: } elsif ($key=~/^form\.ren/) {
1.101 albertel 3908: my $udom = $env{'form.ccdomain'};
3909: my $uname = $env{'form.ccuname'};
1.116 raeburn 3910: # Re-enable standard role
1.135 raeburn 3911: if ($key=~/^form\.ren\:([^\_]+)\_([^\_\.]+)$/) {
1.89 raeburn 3912: my $url = $1;
3913: my $role = $2;
3914: my $logmsg;
3915: my $output;
3916: if ($role eq 'st') {
1.141 albertel 3917: if ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
1.374 raeburn 3918: my ($cdom,$cnum,$csec) = ($1,$2,$3);
1.375 raeburn 3919: my $credits;
3920: if ($showcredits) {
3921: my $defaultcredits =
3922: &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
3923: $credits = &get_user_credits($defaultcredits,$cdom,$cnum);
3924: }
3925: my $result = &Apache::loncommon::commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$cdom,$cnum,$csec,$context,$credits);
1.220 raeburn 3926: if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course') || ($result eq 'refused')) {
1.223 raeburn 3927: if ($result eq 'refused' && $logmsg) {
3928: $output = $logmsg;
3929: } else {
1.369 bisitz 3930: $output = &mt('Error: [_1]',$result)."\n";
1.223 raeburn 3931: }
1.89 raeburn 3932: } else {
1.372 raeburn 3933: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Assigning [_1] in [_2] starting [_3]',
3934: &Apache::lonnet::plaintext($role),
3935: &Apache::loncommon::show_role_extent($url,$context,'st'),
3936: &Apache::lonlocal::locallocaltime($now))).'<br />'.$logmsg.'<br />';
1.89 raeburn 3937: }
3938: }
3939: } else {
1.101 albertel 3940: my $result=&Apache::lonnet::assignrole($env{'form.ccdomain'},
1.239 raeburn 3941: $env{'form.ccuname'},$url,$role,0,$now,'','',
3942: $context);
1.367 golterma 3943: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Re-enabling [_1] in [_2]',
1.372 raeburn 3944: &Apache::lonnet::plaintext($role),
3945: &Apache::loncommon::show_role_extent($url,$context,$role)),$result ne "ok").'<br />';
1.369 bisitz 3946: if ($result ne "ok") {
3947: $output .= &mt('Error: [_1]',$result).'<br />';
3948: }
3949: }
1.89 raeburn 3950: $r->print($output);
1.225 raeburn 3951: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3952: push(@rolechanges,$role);
3953: }
1.113 raeburn 3954: }
1.116 raeburn 3955: # Re-enable custom role
1.139 albertel 3956: if ($key=~m{^form\.ren\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 3957: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
3958: my $result = &Apache::lonnet::assigncustomrole(
3959: $env{'form.ccdomain'}, $env{'form.ccuname'},
1.240 raeburn 3960: $url,$rdom,$rnam,$rolename,0,$now,undef,$context);
1.369 bisitz 3961: $r->print(&Apache::lonhtmlcommon::confirm_success(
3962: &mt('Re-enabling custom role [_1] by [_2] in [_3]',
1.372 raeburn 3963: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 3964: $result ne "ok").'<br />');
3965: if ($result ne "ok") {
3966: $r->print(&mt('Error: [_1]',$result).'<br />');
3967: }
1.225 raeburn 3968: if (!grep(/^cr$/,@rolechanges)) {
3969: push(@rolechanges,'cr');
3970: }
1.116 raeburn 3971: }
1.135 raeburn 3972: } elsif ($key=~/^form\.act/) {
1.101 albertel 3973: my $udom = $env{'form.ccdomain'};
3974: my $uname = $env{'form.ccuname'};
1.141 albertel 3975: if ($key=~/^form\.act\_($match_domain)\_($match_courseid)\_cr_cr_($match_domain)_($match_username)_([^\_]+)$/) {
1.65 www 3976: # Activate a custom role
1.83 albertel 3977: my ($one,$two,$three,$four,$five)=($1,$2,$3,$4,$5);
3978: my $url='/'.$one.'/'.$two;
3979: my $full=$one.'_'.$two.'_cr_cr_'.$three.'_'.$four.'_'.$five;
1.65 www 3980:
1.101 albertel 3981: my $start = ( $env{'form.start_'.$full} ?
3982: $env{'form.start_'.$full} :
1.88 raeburn 3983: $now );
1.101 albertel 3984: my $end = ( $env{'form.end_'.$full} ?
3985: $env{'form.end_'.$full} :
1.88 raeburn 3986: 0 );
3987:
3988: # split multiple sections
3989: my %sections = ();
1.101 albertel 3990: my $num_sections = &build_roles($env{'form.sec_'.$full},\%sections,$5);
1.88 raeburn 3991: if ($num_sections == 0) {
1.240 raeburn 3992: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end,$context));
1.88 raeburn 3993: } else {
1.114 albertel 3994: my %curr_groups =
1.117 raeburn 3995: &Apache::longroup::coursegroups($one,$two);
1.404 raeburn 3996: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.113 raeburn 3997: if (($sec eq 'none') || ($sec eq 'all') ||
3998: exists($curr_groups{$sec})) {
3999: $disallowed{$sec} = $url;
4000: next;
4001: }
4002: my $securl = $url.'/'.$sec;
1.240 raeburn 4003: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end,$context));
1.88 raeburn 4004: }
4005: }
1.225 raeburn 4006: if (!grep(/^cr$/,@rolechanges)) {
4007: push(@rolechanges,'cr');
4008: }
1.142 raeburn 4009: } elsif ($key=~/^form\.act\_($match_domain)\_($match_name)\_([^\_]+)$/) {
1.27 matthew 4010: # Activate roles for sections with 3 id numbers
4011: # set start, end times, and the url for the class
1.83 albertel 4012: my ($one,$two,$three)=($1,$2,$3);
1.101 albertel 4013: my $start = ( $env{'form.start_'.$one.'_'.$two.'_'.$three} ?
4014: $env{'form.start_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 4015: $now );
1.101 albertel 4016: my $end = ( $env{'form.end_'.$one.'_'.$two.'_'.$three} ?
4017: $env{'form.end_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 4018: 0 );
1.83 albertel 4019: my $url='/'.$one.'/'.$two;
1.88 raeburn 4020: my $type = 'three';
4021: # split multiple sections
4022: my %sections = ();
1.101 albertel 4023: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections,$three);
1.375 raeburn 4024: my $credits;
4025: if ($three eq 'st') {
4026: if ($showcredits) {
4027: my $defaultcredits =
4028: &Apache::lonuserutils::get_defaultcredits($one,$two);
4029: $credits = $env{'form.credits_'.$one.'_'.$two.'_'.$three};
4030: $credits =~ s/[^\d\.]//g;
4031: if ($credits eq $defaultcredits) {
4032: undef($credits);
4033: }
4034: }
4035: }
1.88 raeburn 4036: if ($num_sections == 0) {
1.375 raeburn 4037: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 4038: } else {
1.114 albertel 4039: my %curr_groups =
1.117 raeburn 4040: &Apache::longroup::coursegroups($one,$two);
1.88 raeburn 4041: my $emptysec = 0;
1.404 raeburn 4042: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.88 raeburn 4043: $sec =~ s/\W//g;
1.113 raeburn 4044: if ($sec ne '') {
4045: if (($sec eq 'none') || ($sec eq 'all') ||
4046: exists($curr_groups{$sec})) {
4047: $disallowed{$sec} = $url;
4048: next;
4049: }
1.88 raeburn 4050: my $securl = $url.'/'.$sec;
1.375 raeburn 4051: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec,$context,$credits));
1.88 raeburn 4052: } else {
4053: $emptysec = 1;
4054: }
4055: }
4056: if ($emptysec) {
1.375 raeburn 4057: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 4058: }
1.225 raeburn 4059: }
4060: if (!grep(/^\Q$three\E$/,@rolechanges)) {
4061: push(@rolechanges,$three);
4062: }
1.135 raeburn 4063: } elsif ($key=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
1.27 matthew 4064: # Activate roles for sections with two id numbers
4065: # set start, end times, and the url for the class
1.101 albertel 4066: my $start = ( $env{'form.start_'.$1.'_'.$2} ?
4067: $env{'form.start_'.$1.'_'.$2} :
1.27 matthew 4068: $now );
1.101 albertel 4069: my $end = ( $env{'form.end_'.$1.'_'.$2} ?
4070: $env{'form.end_'.$1.'_'.$2} :
1.27 matthew 4071: 0 );
1.225 raeburn 4072: my $one = $1;
4073: my $two = $2;
4074: my $url='/'.$one.'/';
1.88 raeburn 4075: # split multiple sections
4076: my %sections = ();
1.225 raeburn 4077: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two},\%sections,$two);
1.88 raeburn 4078: if ($num_sections == 0) {
1.240 raeburn 4079: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 4080: } else {
4081: my $emptysec = 0;
1.404 raeburn 4082: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.88 raeburn 4083: if ($sec ne '') {
4084: my $securl = $url.'/'.$sec;
1.240 raeburn 4085: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$two,$start,$end,$one,undef,$sec,$context));
1.88 raeburn 4086: } else {
4087: $emptysec = 1;
4088: }
4089: }
4090: if ($emptysec) {
1.240 raeburn 4091: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 4092: }
4093: }
1.225 raeburn 4094: if (!grep(/^\Q$two\E$/,@rolechanges)) {
4095: push(@rolechanges,$two);
4096: }
1.64 www 4097: } else {
1.190 raeburn 4098: $r->print('<p><span class="LC_error">'.&mt('ERROR').': '.&mt('Unknown command').' <tt>'.$key.'</tt></span></p><br />');
1.64 www 4099: }
1.113 raeburn 4100: foreach my $key (sort(keys(%disallowed))) {
1.274 bisitz 4101: $r->print('<p class="LC_warning">');
1.113 raeburn 4102: if (($key eq 'none') || ($key eq 'all')) {
1.274 bisitz 4103: $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 4104: } else {
1.274 bisitz 4105: $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 4106: }
1.274 bisitz 4107: $r->print('</p><p>'
4108: .&mt('Please [_1]go back[_2] and choose a different section name.'
4109: ,'<a href="javascript:history.go(-1)'
4110: ,'</a>')
4111: .'</p><br />'
4112: );
1.113 raeburn 4113: }
4114: }
1.101 albertel 4115: } # End of foreach (keys(%env))
1.75 www 4116: # Flush the course logs so reverse user roles immediately updated
1.349 raeburn 4117: $r->register_cleanup(\&Apache::lonnet::flushcourselogs);
1.225 raeburn 4118: if (@rolechanges == 0) {
1.372 raeburn 4119: $r->print('<p>'.&mt('No roles to modify').'</p>');
1.193 raeburn 4120: }
1.225 raeburn 4121: return @rolechanges;
1.220 raeburn 4122: }
4123:
1.375 raeburn 4124: sub get_user_credits {
4125: my ($uname,$udom,$defaultcredits,$cdom,$cnum) = @_;
4126: if ($cdom eq '' || $cnum eq '') {
4127: return unless ($env{'request.course.id'});
4128: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4129: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
4130: }
4131: my $credits;
4132: my %currhash =
4133: &Apache::lonnet::get('classlist',[$uname.':'.$udom],$cdom,$cnum);
4134: if (keys(%currhash) > 0) {
4135: my @items = split(/:/,$currhash{$uname.':'.$udom});
4136: my $crdidx = &Apache::loncoursedata::CL_CREDITS() - 3;
4137: $credits = $items[$crdidx];
4138: $credits =~ s/[^\d\.]//g;
4139: }
4140: if ($credits eq $defaultcredits) {
4141: undef($credits);
4142: }
4143: return $credits;
4144: }
4145:
1.220 raeburn 4146: sub enroll_single_student {
1.375 raeburn 4147: my ($r,$uhome,$amode,$genpwd,$now,$newuser,$context,$crstype,
4148: $showcredits,$defaultcredits) = @_;
1.318 raeburn 4149: $r->print('<h3>');
4150: if ($crstype eq 'Community') {
4151: $r->print(&mt('Enrolling Member'));
4152: } else {
4153: $r->print(&mt('Enrolling Student'));
4154: }
4155: $r->print('</h3>');
1.220 raeburn 4156:
4157: # Remove non alphanumeric values from section
4158: $env{'form.sections'}=~s/\W//g;
4159:
1.375 raeburn 4160: my $credits;
4161: if (($showcredits) && ($env{'form.credits'} ne '')) {
4162: $credits = $env{'form.credits'};
4163: $credits =~ s/[^\d\.]//g;
4164: if ($credits ne '') {
4165: if ($credits eq $defaultcredits) {
4166: undef($credits);
4167: }
4168: }
4169: }
4170:
1.220 raeburn 4171: # Clean out any old student roles the user has in this class.
4172: &Apache::lonuserutils::modifystudent($env{'form.ccdomain'},
4173: $env{'form.ccuname'},$env{'request.course.id'},undef,$uhome);
4174: my ($startdate,$enddate) = &Apache::lonuserutils::get_dates_from_form();
4175: my $enroll_result =
4176: &Apache::lonnet::modify_student_enrollment($env{'form.ccdomain'},
4177: $env{'form.ccuname'},$env{'form.cid'},$env{'form.cfirstname'},
4178: $env{'form.cmiddlename'},$env{'form.clastname'},
4179: $env{'form.generation'},$env{'form.sections'},$enddate,
1.375 raeburn 4180: $startdate,'manual',undef,$env{'request.course.id'},'',$context,
4181: $credits);
1.220 raeburn 4182: if ($enroll_result =~ /^ok/) {
1.381 bisitz 4183: $r->print(&mt('[_1] enrolled','<b>'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.'</b>'));
1.220 raeburn 4184: if ($env{'form.sections'} ne '') {
4185: $r->print(' '.&mt('in section [_1]',$env{'form.sections'}));
4186: }
4187: my ($showstart,$showend);
4188: if ($startdate <= $now) {
4189: $showstart = &mt('Access starts immediately');
4190: } else {
4191: $showstart = &mt('Access starts: ').&Apache::lonlocal::locallocaltime($startdate);
4192: }
4193: if ($enddate == 0) {
4194: $showend = &mt('ends: no ending date');
4195: } else {
4196: $showend = &mt('ends: ').&Apache::lonlocal::locallocaltime($enddate);
4197: }
4198: $r->print('.<br />'.$showstart.'; '.$showend);
4199: if ($startdate <= $now && !$newuser) {
1.386 bisitz 4200: $r->print('<p class="LC_info">');
1.318 raeburn 4201: if ($crstype eq 'Community') {
1.392 raeburn 4202: $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 4203: } else {
1.392 raeburn 4204: $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 4205: }
4206: $r->print('</p>');
1.220 raeburn 4207: }
4208: } else {
4209: $r->print(&mt('unable to enroll').": ".$enroll_result);
4210: }
4211: return;
1.188 raeburn 4212: }
4213:
1.204 raeburn 4214: sub get_defaultquota_text {
4215: my ($settingstatus) = @_;
4216: my $defquotatext;
4217: if ($settingstatus eq '') {
1.383 raeburn 4218: $defquotatext = &mt('default');
1.204 raeburn 4219: } else {
4220: my ($usertypes,$order) =
4221: &Apache::lonnet::retrieve_inst_usertypes($env{'form.ccdomain'});
4222: if ($usertypes->{$settingstatus} eq '') {
1.383 raeburn 4223: $defquotatext = &mt('default');
1.204 raeburn 4224: } else {
1.383 raeburn 4225: $defquotatext = &mt('default for [_1]',$usertypes->{$settingstatus});
1.204 raeburn 4226: }
4227: }
4228: return $defquotatext;
4229: }
4230:
1.188 raeburn 4231: sub update_result_form {
4232: my ($uhome) = @_;
4233: my $outcome =
1.367 golterma 4234: '<form name="userupdate" method="post" action="">'."\n";
1.160 raeburn 4235: foreach my $item ('srchby','srchin','srchtype','srchterm','srchdomain','ccuname','ccdomain') {
1.188 raeburn 4236: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 4237: }
1.207 raeburn 4238: if ($env{'form.origname'} ne '') {
4239: $outcome .= '<input type="hidden" name="origname" value="'.$env{'form.origname'}.'" />'."\n";
4240: }
1.160 raeburn 4241: foreach my $item ('sortby','seluname','seludom') {
4242: if (exists($env{'form.'.$item})) {
1.188 raeburn 4243: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 4244: }
4245: }
1.188 raeburn 4246: if ($uhome eq 'no_host') {
4247: $outcome .= '<input type="hidden" name="forcenewuser" value="1" />'."\n";
4248: }
4249: $outcome .= '<input type="hidden" name="phase" value="" />'."\n".
1.383 raeburn 4250: '<input type="hidden" name="currstate" value="" />'."\n".
4251: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
1.188 raeburn 4252: '</form>';
4253: return $outcome;
1.4 www 4254: }
4255:
1.149 raeburn 4256: sub quota_admin {
1.378 raeburn 4257: my ($setquota,$changeHash,$name) = @_;
1.149 raeburn 4258: my $quotachanged;
4259: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
4260: # Current user has quota modification privileges
1.267 raeburn 4261: if (ref($changeHash) eq 'HASH') {
4262: $quotachanged = 1;
1.378 raeburn 4263: $changeHash->{$name.'quota'} = $setquota;
1.267 raeburn 4264: }
1.149 raeburn 4265: }
4266: return $quotachanged;
4267: }
4268:
1.267 raeburn 4269: sub tool_admin {
1.275 raeburn 4270: my ($tool,$settool,$changeHash,$context) = @_;
4271: my $canchange = 0;
1.279 raeburn 4272: if ($context eq 'requestcourses') {
1.275 raeburn 4273: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
4274: $canchange = 1;
4275: }
1.300 raeburn 4276: } elsif ($context eq 'reqcrsotherdom') {
4277: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
4278: $canchange = 1;
4279: }
1.362 raeburn 4280: } elsif ($context eq 'requestauthor') {
4281: if (&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) {
4282: $canchange = 1;
4283: }
1.275 raeburn 4284: } elsif (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
4285: # Current user has quota modification privileges
4286: $canchange = 1;
4287: }
1.267 raeburn 4288: my $toolchanged;
1.275 raeburn 4289: if ($canchange) {
1.267 raeburn 4290: if (ref($changeHash) eq 'HASH') {
4291: $toolchanged = 1;
1.362 raeburn 4292: if ($tool eq 'requestauthor') {
4293: $changeHash->{$context} = $settool;
4294: } else {
4295: $changeHash->{$context.'.'.$tool} = $settool;
4296: }
1.267 raeburn 4297: }
4298: }
4299: return $toolchanged;
4300: }
4301:
1.88 raeburn 4302: sub build_roles {
1.89 raeburn 4303: my ($sectionstr,$sections,$role) = @_;
1.88 raeburn 4304: my $num_sections = 0;
4305: if ($sectionstr=~ /,/) {
4306: my @secnums = split/,/,$sectionstr;
1.89 raeburn 4307: if ($role eq 'st') {
4308: $secnums[0] =~ s/\W//g;
4309: $$sections{$secnums[0]} = 1;
4310: $num_sections = 1;
4311: } else {
4312: foreach my $sec (@secnums) {
4313: $sec =~ ~s/\W//g;
1.150 banghart 4314: if (!($sec eq "")) {
1.89 raeburn 4315: if (exists($$sections{$sec})) {
4316: $$sections{$sec} ++;
4317: } else {
4318: $$sections{$sec} = 1;
4319: $num_sections ++;
4320: }
1.88 raeburn 4321: }
4322: }
4323: }
4324: } else {
4325: $sectionstr=~s/\W//g;
4326: unless ($sectionstr eq '') {
4327: $$sections{$sectionstr} = 1;
4328: $num_sections ++;
4329: }
4330: }
1.129 albertel 4331:
1.88 raeburn 4332: return $num_sections;
4333: }
4334:
1.58 www 4335: # ========================================================== Custom Role Editor
4336:
4337: sub custom_role_editor {
1.406.2.5! raeburn 4338: my ($r,$brcrum,$prefix) = @_;
1.324 raeburn 4339: my $action = $env{'form.customroleaction'};
4340: my $rolename;
4341: if ($action eq 'new') {
4342: $rolename=$env{'form.newrolename'};
4343: } else {
4344: $rolename=$env{'form.rolename'};
1.59 www 4345: }
4346:
1.324 raeburn 4347: my ($crstype,$context);
4348: if ($env{'request.course.id'}) {
4349: $crstype = &Apache::loncommon::course_type();
4350: $context = 'course';
4351: } else {
4352: $context = 'domain';
1.406.2.5! raeburn 4353: $crstype = 'course';
1.324 raeburn 4354: }
1.351 raeburn 4355:
4356: $rolename=~s/[^A-Za-z0-9]//gs;
4357: if (!$rolename || $env{'form.phase'} eq 'pickrole') {
4358: &print_username_entry_form($r,undef,undef,undef,undef,$crstype,$brcrum);
4359: return;
4360: }
4361:
1.406.2.5! raeburn 4362: my $formname = 'form1';
! 4363: my %privs=();
! 4364: my $body_top = '<h2>';
! 4365: # ------------------------------------------------------- Does this role exist?
1.59 www 4366: my ($rdummy,$roledef)=
4367: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
4368: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.406.2.5! raeburn 4369: $body_top .= &mt('Existing Role').' "';
1.61 www 4370: # ------------------------------------------------- Get current role privileges
1.406.2.5! raeburn 4371: ($privs{'system'},$privs{'domain'},$privs{'course'})=split(/\_/,$roledef);
! 4372: if ($privs{'system'} =~ /bre\&S/) {
! 4373: if ($context eq 'domain') {
! 4374: $crstype = 'Course';
! 4375: } elsif ($crstype eq 'Community') {
! 4376: $privs{'system'} =~ s/bre\&S//;
! 4377: }
! 4378: } elsif ($context eq 'domain') {
! 4379: $crstype = 'Course';
1.324 raeburn 4380: }
1.59 www 4381: } else {
1.406.2.5! raeburn 4382: $body_top .= &mt('New Role').' "';
! 4383: $roledef='';
1.59 www 4384: }
1.153 banghart 4385: $body_top .= $rolename.'"</h2>';
1.406.2.5! raeburn 4386:
! 4387: # ------------------------------------------------------- What can be assigned?
! 4388: my %full=();
! 4389: my %levels=(
! 4390: course => {},
! 4391: domain => {},
! 4392: system => {},
! 4393: );
! 4394: my %levelscurrent=(
! 4395: course => {},
! 4396: domain => {},
! 4397: system => {},
! 4398: );
! 4399: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
1.160 raeburn 4400: my ($jsback,$elements) = &crumb_utilities();
1.406.2.5! raeburn 4401: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
! 4402: my $head_script =
! 4403: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,
! 4404: \%full,\@templateroles,$jsback);
1.351 raeburn 4405: push (@{$brcrum},
1.406.2.5! raeburn 4406: {href => "javascript:backPage(document.$formname,'pickrole','')",
1.351 raeburn 4407: text => "Pick custom role",
4408: faq => 282,bug=>'Instructor Interface',},
1.406.2.5! raeburn 4409: {href => "javascript:backPage(document.$formname,'','')",
1.351 raeburn 4410: text => "Edit custom role",
4411: faq => 282,
4412: bug => 'Instructor Interface',
4413: help => 'Course_Editing_Custom_Roles'}
4414: );
4415: my $args = { bread_crumbs => $brcrum,
4416: bread_crumbs_component => 'User Management'};
1.406.2.5! raeburn 4417:
1.351 raeburn 4418: $r->print(&Apache::loncommon::start_page('Custom Role Editor',
4419: $head_script,$args).
4420: $body_top);
1.406.2.5! raeburn 4421: $r->print('<form name="'.$formname.'" method="post" action="">'."\n".
! 4422: &Apache::lonuserutils::custom_role_header($context,$crstype,
! 4423: \@templateroles,$prefix));
1.264 bisitz 4424:
1.61 www 4425: $r->print(<<ENDCCF);
4426: <input type="hidden" name="phase" value="set_custom_roles" />
4427: <input type="hidden" name="rolename" value="$rolename" />
4428: ENDCCF
1.406.2.5! raeburn 4429: $r->print(&Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
! 4430: \%levelscurrent,$prefix));
1.135 raeburn 4431: $r->print(&Apache::loncommon::end_data_table().
1.190 raeburn 4432: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
1.160 raeburn 4433: '<input type="hidden" name="startrolename" value="'.$env{'form.rolename'}.
1.406.2.5! raeburn 4434: '" />'."\n".'<input type="hidden" name="currstate" value="" />'."\n".
1.160 raeburn 4435: '<input type="reset" value="'.&mt("Reset").'" />'."\n".
1.351 raeburn 4436: '<input type="submit" value="'.&mt('Save').'" /></form>');
1.61 www 4437: }
1.406.2.5! raeburn 4438:
1.61 www 4439: # ---------------------------------------------------------- Call to definerole
4440: sub set_custom_role {
1.406.2.5! raeburn 4441: my ($r,$context,$brcrum,$prefix) = @_;
1.101 albertel 4442: my $rolename=$env{'form.rolename'};
1.63 www 4443: $rolename=~s/[^A-Za-z0-9]//gs;
1.150 banghart 4444: if (!$rolename) {
1.406.2.5! raeburn 4445: &custom_role_editor($r,$brcrum,$prefix);
1.61 www 4446: return;
4447: }
1.160 raeburn 4448: my ($jsback,$elements) = &crumb_utilities();
1.301 bisitz 4449: my $jscript = '<script type="text/javascript">'
4450: .'// <![CDATA['."\n"
4451: .$jsback."\n"
4452: .'// ]]>'."\n"
4453: .'</script>'."\n";
1.352 raeburn 4454: push(@{$brcrum},
4455: {href => "javascript:backPage(document.customresult,'pickrole','')",
4456: text => "Pick custom role",
4457: faq => 282,
4458: bug => 'Instructor Interface',},
4459: {href => "javascript:backPage(document.customresult,'selected_custom_edit','')",
4460: text => "Edit custom role",
4461: faq => 282,
4462: bug => 'Instructor Interface',},
4463: {href => "javascript:backPage(document.customresult,'set_custom_roles','')",
4464: text => "Result",
4465: faq => 282,
4466: bug => 'Instructor Interface',
4467: help => 'Course_Editing_Custom_Roles'},
4468: );
4469: my $args = { bread_crumbs => $brcrum,
1.406.2.5! raeburn 4470: bread_crumbs_component => 'User Management'};
1.351 raeburn 4471: $r->print(&Apache::loncommon::start_page('Save Custom Role',$jscript,$args));
1.160 raeburn 4472:
1.393 raeburn 4473: my $newrole;
1.61 www 4474: my ($rdummy,$roledef)=
1.110 albertel 4475: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
4476:
1.61 www 4477: # ------------------------------------------------------- Does this role exist?
1.188 raeburn 4478: $r->print('<h3>');
1.61 www 4479: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.73 sakharuk 4480: $r->print(&mt('Existing Role').' "');
1.61 www 4481: } else {
1.73 sakharuk 4482: $r->print(&mt('New Role').' "');
1.61 www 4483: $roledef='';
1.393 raeburn 4484: $newrole = 1;
1.61 www 4485: }
1.188 raeburn 4486: $r->print($rolename.'"</h3>');
1.406.2.5! raeburn 4487: # ------------------------------------------------- Assign role and show result
1.61 www 4488:
1.387 bisitz 4489: my $errmsg;
1.406.2.5! raeburn 4490: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$prefix);
! 4491: # Assign role and return result
! 4492: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
! 4493: $newprivs{'c'});
1.387 bisitz 4494: if ($result ne 'ok') {
4495: $errmsg = ': '.$result;
4496: }
4497: my $message =
4498: &Apache::lonhtmlcommon::confirm_success(
4499: &mt('Defining Role').$errmsg, ($result eq 'ok' ? 0 : 1));
1.101 albertel 4500: if ($env{'request.course.id'}) {
4501: my $url='/'.$env{'request.course.id'};
1.63 www 4502: $url=~s/\_/\//g;
1.387 bisitz 4503: $result =
4504: &Apache::lonnet::assigncustomrole(
4505: $env{'user.domain'},$env{'user.name'},
4506: $url,
4507: $env{'user.domain'},$env{'user.name'},
4508: $rolename,undef,undef,undef,$context);
4509: if ($result ne 'ok') {
4510: $errmsg = ': '.$result;
4511: }
4512: $message .=
4513: '<br />'
4514: .&Apache::lonhtmlcommon::confirm_success(
4515: &mt('Assigning Role to Self').$errmsg, ($result eq 'ok' ? 0 : 1));
1.63 www 4516: }
1.380 bisitz 4517: $r->print(
1.387 bisitz 4518: &Apache::loncommon::confirmwrapper($message)
4519: .'<br />'
4520: .&Apache::lonhtmlcommon::actionbox([
4521: '<a href="javascript:backPage(document.customresult,'."'pickrole'".')">'
4522: .&mt('Create or edit another custom role')
4523: .'</a>'])
1.380 bisitz 4524: .'<form name="customresult" method="post" action="">'
1.387 bisitz 4525: .&Apache::lonhtmlcommon::echo_form_input([])
4526: .'</form>'
1.380 bisitz 4527: );
1.58 www 4528: }
4529:
1.2 www 4530: # ================================================================ Main Handler
4531: sub handler {
4532: my $r = shift;
4533: if ($r->header_only) {
1.68 www 4534: &Apache::loncommon::content_type($r,'text/html');
1.2 www 4535: $r->send_http_header;
4536: return OK;
4537: }
1.318 raeburn 4538: my ($context,$crstype);
1.190 raeburn 4539: if ($env{'request.course.id'}) {
4540: $context = 'course';
1.318 raeburn 4541: $crstype = &Apache::loncommon::course_type();
1.190 raeburn 4542: } elsif ($env{'request.role'} =~ /^au\./) {
1.206 raeburn 4543: $context = 'author';
1.190 raeburn 4544: } else {
4545: $context = 'domain';
4546: }
1.375 raeburn 4547:
1.190 raeburn 4548: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.233 raeburn 4549: ['action','state','callingform','roletype','showrole','bulkaction','popup','phase',
1.391 raeburn 4550: 'username','domain','srchterm','srchdomain','srchin','srchby','srchtype','queue']);
1.190 raeburn 4551: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.351 raeburn 4552: my $args;
4553: my $brcrum = [];
4554: my $bread_crumbs_component = 'User Management';
1.391 raeburn 4555: if (($env{'form.action'} ne 'dateselect') && ($env{'form.action'} ne 'displayuserreq')) {
1.351 raeburn 4556: $brcrum = [{href=>"/adm/createuser",
4557: text=>"User Management",
4558: help=>'Course_Create_Class_List,Course_Change_Privileges,Course_View_Class_List,Course_Editing_Custom_Roles,Course_Add_Student,Course_Drop_Student,Course_Automated_Enrollment,Course_Self_Enrollment,Course_Manage_Group'}
4559: ];
1.202 raeburn 4560: }
1.289 droeschl 4561: #SD Following files not added to help, because the corresponding .tex-files seem to
4562: #be missing: Course_Approve_Selfenroll,Course_User_Logs,
1.209 raeburn 4563: my ($permission,$allowed) =
1.318 raeburn 4564: &Apache::lonuserutils::get_permission($context,$crstype);
1.190 raeburn 4565: if (!$allowed) {
1.358 raeburn 4566: if ($context eq 'course') {
4567: $r->internal_redirect('/adm/viewclasslist');
4568: return OK;
4569: }
1.190 raeburn 4570: $env{'user.error.msg'}=
4571: "/adm/createuser:cst:0:0:Cannot create/modify user data ".
4572: "or view user status.";
4573: return HTTP_NOT_ACCEPTABLE;
4574: }
4575:
4576: &Apache::loncommon::content_type($r,'text/html');
4577: $r->send_http_header;
4578:
1.375 raeburn 4579: my $showcredits;
4580: if ((($context eq 'course') && ($crstype eq 'Course')) ||
4581: ($context eq 'domain')) {
4582: my %domdefaults =
4583: &Apache::lonnet::get_domain_defaults($env{'request.role.domain'});
4584: if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'}) {
4585: $showcredits = 1;
4586: }
4587: }
4588:
1.190 raeburn 4589: # Main switch on form.action and form.state, as appropriate
4590: if (! exists($env{'form.action'})) {
1.351 raeburn 4591: $args = {bread_crumbs => $brcrum,
4592: bread_crumbs_component => $bread_crumbs_component};
4593: $r->print(&header(undef,$args));
1.318 raeburn 4594: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 4595: } elsif ($env{'form.action'} eq 'upload' && $permission->{'cusr'}) {
1.351 raeburn 4596: push(@{$brcrum},
4597: { href => '/adm/createuser?action=upload&state=',
4598: text => 'Upload Users List',
4599: help => 'Course_Create_Class_List',
4600: });
4601: $bread_crumbs_component = 'Upload Users List';
4602: $args = {bread_crumbs => $brcrum,
4603: bread_crumbs_component => $bread_crumbs_component};
4604: $r->print(&header(undef,$args));
1.190 raeburn 4605: $r->print('<form name="studentform" method="post" '.
4606: 'enctype="multipart/form-data" '.
4607: ' action="/adm/createuser">'."\n");
4608: if (! exists($env{'form.state'})) {
4609: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4610: } elsif ($env{'form.state'} eq 'got_file') {
1.375 raeburn 4611: &Apache::lonuserutils::print_upload_manager_form($r,$context,$permission,
4612: $crstype,$showcredits);
1.190 raeburn 4613: } elsif ($env{'form.state'} eq 'enrolling') {
4614: if ($env{'form.datatoken'}) {
1.375 raeburn 4615: &Apache::lonuserutils::upfile_drop_add($r,$context,$permission,
4616: $showcredits);
1.190 raeburn 4617: }
4618: } else {
4619: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4620: }
1.406.2.5! raeburn 4621: } elsif (((($env{'form.action'} eq 'singleuser') || ($env{'form.action'}
! 4622: eq 'singlestudent')) && ($permission->{'cusr'})) ||
! 4623: (($env{'form.action'} eq 'accesslogs') && ($permission->{'activity'}))) {
1.190 raeburn 4624: my $phase = $env{'form.phase'};
4625: my @search = ('srchterm','srchby','srchin','srchtype','srchdomain');
1.192 albertel 4626: &Apache::loncreateuser::restore_prev_selections();
4627: my $srch;
4628: foreach my $item (@search) {
4629: $srch->{$item} = $env{'form.'.$item};
4630: }
1.207 raeburn 4631: if (($phase eq 'get_user_info') || ($phase eq 'userpicked') ||
1.406.2.5! raeburn 4632: ($phase eq 'createnewuser') || ($phase eq 'activity')) {
1.207 raeburn 4633: if ($env{'form.phase'} eq 'createnewuser') {
4634: my $response;
4635: if ($env{'form.srchterm'} !~ /^$match_username$/) {
1.366 bisitz 4636: my $response =
4637: '<span class="LC_warning">'
4638: .&mt('You must specify a valid username. Only the following are allowed:'
4639: .' letters numbers - . @')
4640: .'</span>';
1.221 raeburn 4641: $env{'form.phase'} = '';
1.375 raeburn 4642: &print_username_entry_form($r,$context,$response,$srch,undef,
4643: $crstype,$brcrum,$showcredits);
1.207 raeburn 4644: } else {
4645: my $ccuname =&LONCAPA::clean_username($srch->{'srchterm'});
4646: my $ccdomain=&LONCAPA::clean_domain($srch->{'srchdomain'});
4647: &print_user_modification_page($r,$ccuname,$ccdomain,
1.221 raeburn 4648: $srch,$response,$context,
1.375 raeburn 4649: $permission,$crstype,$brcrum,
4650: $showcredits);
1.207 raeburn 4651: }
4652: } elsif ($env{'form.phase'} eq 'get_user_info') {
1.190 raeburn 4653: my ($currstate,$response,$forcenewuser,$results) =
1.221 raeburn 4654: &user_search_result($context,$srch);
1.190 raeburn 4655: if ($env{'form.currstate'} eq 'modify') {
4656: $currstate = $env{'form.currstate'};
4657: }
4658: if ($currstate eq 'select') {
4659: &print_user_selection_page($r,$response,$srch,$results,
1.351 raeburn 4660: \@search,$context,undef,$crstype,
4661: $brcrum);
1.406.2.5! raeburn 4662: } elsif (($currstate eq 'modify') || ($env{'form.action'} eq 'accesslogs')) {
! 4663: my ($ccuname,$ccdomain,$uhome);
1.190 raeburn 4664: if (($srch->{'srchby'} eq 'uname') &&
4665: ($srch->{'srchtype'} eq 'exact')) {
4666: $ccuname = $srch->{'srchterm'};
4667: $ccdomain= $srch->{'srchdomain'};
4668: } else {
4669: my @matchedunames = keys(%{$results});
4670: ($ccuname,$ccdomain) = split(/:/,$matchedunames[0]);
4671: }
4672: $ccuname =&LONCAPA::clean_username($ccuname);
4673: $ccdomain=&LONCAPA::clean_domain($ccdomain);
1.406.2.5! raeburn 4674: if ($env{'form.action'} eq 'accesslogs') {
! 4675: my $uhome;
! 4676: if (($ccuname ne '') && ($ccdomain ne '')) {
! 4677: $uhome = &Apache::lonnet::homeserver($ccuname,$ccdomain);
! 4678: }
! 4679: if (($uhome eq '') || ($uhome eq 'no_host')) {
! 4680: $env{'form.phase'} = '';
! 4681: undef($forcenewuser);
! 4682: #if ($response) {
! 4683: # unless ($response =~ m{\Q<br /><br />\E$}) {
! 4684: # $response .= '<br /><br />';
! 4685: # }
! 4686: #}
! 4687: &print_username_entry_form($r,$context,$response,$srch,
! 4688: $forcenewuser,$crstype,$brcrum);
! 4689: } else {
! 4690: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
! 4691: }
! 4692: } else {
! 4693: if ($env{'form.forcenewuser'}) {
! 4694: $response = '';
! 4695: }
! 4696: &print_user_modification_page($r,$ccuname,$ccdomain,
! 4697: $srch,$response,$context,
! 4698: $permission,$crstype,$brcrum);
1.190 raeburn 4699: }
4700: } elsif ($currstate eq 'query') {
1.351 raeburn 4701: &print_user_query_page($r,'createuser',$brcrum);
1.190 raeburn 4702: } else {
1.229 raeburn 4703: $env{'form.phase'} = '';
1.207 raeburn 4704: &print_username_entry_form($r,$context,$response,$srch,
1.351 raeburn 4705: $forcenewuser,$crstype,$brcrum);
1.190 raeburn 4706: }
4707: } elsif ($env{'form.phase'} eq 'userpicked') {
4708: my $ccuname = &LONCAPA::clean_username($env{'form.seluname'});
4709: my $ccdomain = &LONCAPA::clean_domain($env{'form.seludom'});
1.406.2.5! raeburn 4710: if ($env{'form.action'} eq 'accesslogs') {
! 4711: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
! 4712: } else {
! 4713: &print_user_modification_page($r,$ccuname,$ccdomain,$srch,'',
! 4714: $context,$permission,$crstype,
! 4715: $brcrum);
! 4716: }
! 4717: } elsif ($env{'form.action'} eq 'accesslogs') {
! 4718: my $ccuname = &LONCAPA::clean_username($env{'form.accessuname'});
! 4719: my $ccdomain = &LONCAPA::clean_domain($env{'form.accessudom'});
! 4720: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
1.190 raeburn 4721: }
4722: } elsif ($env{'form.phase'} eq 'update_user_data') {
1.375 raeburn 4723: &update_user_data($r,$context,$crstype,$brcrum,$showcredits);
1.190 raeburn 4724: } else {
1.351 raeburn 4725: &print_username_entry_form($r,$context,undef,$srch,undef,$crstype,
4726: $brcrum);
1.190 raeburn 4727: }
4728: } elsif ($env{'form.action'} eq 'custom' && $permission->{'custom'}) {
1.406.2.5! raeburn 4729: my $prefix;
1.190 raeburn 4730: if ($env{'form.phase'} eq 'set_custom_roles') {
1.406.2.5! raeburn 4731: &set_custom_role($r,$context,$brcrum,$prefix);
1.190 raeburn 4732: } else {
1.406.2.5! raeburn 4733: &custom_role_editor($r,$brcrum,$prefix);
1.190 raeburn 4734: }
1.362 raeburn 4735: } elsif (($env{'form.action'} eq 'processauthorreq') &&
4736: ($permission->{'cusr'}) &&
4737: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
4738: push(@{$brcrum},
4739: {href => '/adm/createuser?action=processauthorreq',
1.385 bisitz 4740: text => 'Authoring Space requests',
1.362 raeburn 4741: help => 'Domain_Role_Approvals'});
4742: $bread_crumbs_component = 'Authoring requests';
4743: if ($env{'form.state'} eq 'done') {
4744: push(@{$brcrum},
4745: {href => '/adm/createuser?action=authorreqqueue',
4746: text => 'Result',
4747: help => 'Domain_Role_Approvals'});
4748: $bread_crumbs_component = 'Authoring request result';
4749: }
4750: $args = { bread_crumbs => $brcrum,
4751: bread_crumbs_component => $bread_crumbs_component};
1.391 raeburn 4752: my $js = &usernamerequest_javascript();
4753: $r->print(&header(&add_script($js),$args));
1.362 raeburn 4754: if (!exists($env{'form.state'})) {
4755: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestauthor',
4756: $env{'request.role.domain'}));
4757: } elsif ($env{'form.state'} eq 'done') {
4758: $r->print('<h3>'.&mt('Authoring request processing').'</h3>'."\n");
4759: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestauthor',
4760: $env{'request.role.domain'}));
4761: }
1.391 raeburn 4762: } elsif (($env{'form.action'} eq 'processusernamereq') &&
4763: ($permission->{'cusr'}) &&
4764: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
4765: push(@{$brcrum},
4766: {href => '/adm/createuser?action=processusernamereq',
4767: text => 'LON-CAPA account requests',
4768: help => 'Domain_Username_Approvals'});
4769: $bread_crumbs_component = 'Account requests';
4770: if ($env{'form.state'} eq 'done') {
4771: push(@{$brcrum},
4772: {href => '/adm/createuser?action=usernamereqqueue',
4773: text => 'Result',
4774: help => 'Domain_Username_Approvals'});
4775: $bread_crumbs_component = 'LON-CAPA account request result';
4776: }
4777: $args = { bread_crumbs => $brcrum,
4778: bread_crumbs_component => $bread_crumbs_component};
4779: my $js = &usernamerequest_javascript();
4780: $r->print(&header(&add_script($js),$args));
4781: if (!exists($env{'form.state'})) {
4782: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestusername',
4783: $env{'request.role.domain'}));
4784: } elsif ($env{'form.state'} eq 'done') {
4785: $r->print('<h3>'.&mt('LON-CAPA account request processing').'</h3>'."\n");
4786: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestusername',
4787: $env{'request.role.domain'}));
4788: }
4789: } elsif (($env{'form.action'} eq 'displayuserreq') &&
4790: ($permission->{'cusr'})) {
4791: my $dom = $env{'form.domain'};
4792: my $uname = $env{'form.username'};
4793: my $warning;
4794: if (($dom =~ /^$match_domain$/) && (&Apache::lonnet::domain($dom) ne '')) {
4795: if (($dom eq $env{'request.role.domain'}) && (&Apache::lonnet::allowed('ccc',$dom))) {
4796: if (($uname =~ /^$match_username$/) && ($env{'form.queue'} eq 'approval')) {
4797: my $uhome = &Apache::lonnet::homeserver($uname,$dom);
4798: if ($uhome eq 'no_host') {
4799: my $queue = $env{'form.queue'};
4800: my $reqkey = &escape($uname).'_'.$queue;
4801: my $namespace = 'usernamequeue';
4802: my $domconfig = &Apache::lonnet::get_domainconfiguser($dom);
4803: my %queued =
4804: &Apache::lonnet::get($namespace,[$reqkey],$dom,$domconfig);
4805: unless ($queued{$reqkey}) {
4806: $warning = &mt('No information was found for this LON-CAPA account request.');
4807: }
4808: } else {
4809: $warning = &mt('A LON-CAPA account already exists for the requested username and domain.');
4810: }
4811: } else {
4812: $warning = &mt('LON-CAPA account request status check is for an invalid username.');
4813: }
4814: } else {
4815: $warning = &mt('You do not have rights to view LON-CAPA account requests in the domain specified.');
4816: }
4817: } else {
4818: $warning = &mt('LON-CAPA account request status check is for an invalid domain.');
4819: }
4820: my $args = { only_body => 1 };
4821: $r->print(&header(undef,$args).
4822: '<h3>'.&mt('LON-CAPA Account Request Details').'</h3>');
4823: if ($warning ne '') {
4824: $r->print('<div class="LC_warning">'.$warning.'</div>');
4825: } else {
4826: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
4827: my $domconfiguser = &Apache::lonnet::get_domainconfiguser($dom);
4828: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
4829: if (ref($domconfig{'usercreation'}) eq 'HASH') {
4830: if (ref($domconfig{'usercreation'}{'cancreate'}) eq 'HASH') {
4831: if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}) eq 'HASH') {
4832: my %info =
4833: &Apache::lonnet::get('nohist_requestedusernames',[$uname],$dom,$domconfiguser);
4834: if (ref($info{$uname}) eq 'HASH') {
1.396 raeburn 4835: my $usertype = $info{$uname}{'inststatus'};
4836: unless ($usertype) {
4837: $usertype = 'default';
4838: }
4839: if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}) eq 'HASH') {
4840: if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
4841: $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box());
4842: my ($num,$count,$showstatus);
4843: $count = scalar(keys(%{$domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}}));
4844: unless ($usertype eq 'default') {
4845: my ($othertitle,$usertypes,$types) =
4846: &Apache::loncommon::sorted_inst_types($dom);
4847: if (ref($usertypes) eq 'HASH') {
4848: if ($usertypes->{$usertype}) {
4849: $showstatus = $usertypes->{$usertype};
4850: $count ++;
4851: }
4852: }
4853: }
4854: foreach my $field (@{$infofields}) {
4855: next unless ($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}{$field});
4856: next unless ($infotitles->{$field});
4857: $r->print(&Apache::lonhtmlcommon::row_title($infotitles->{$field}).
4858: $info{$uname}{$field});
4859: $num ++;
4860: if ($count == $num) {
4861: $r->print(&Apache::lonhtmlcommon::row_closure(1));
4862: } else {
4863: $r->print(&Apache::lonhtmlcommon::row_closure());
4864: }
4865: }
4866: if ($showstatus) {
4867: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Status type (self-reported)')).
4868: $showstatus.
4869: &Apache::lonhtmlcommon::row_closure(1));
1.391 raeburn 4870: }
1.396 raeburn 4871: $r->print(&Apache::lonhtmlcommon::end_pick_box().'</div>');
1.391 raeburn 4872: }
4873: }
4874: }
4875: }
4876: }
4877: }
4878: $r->print(&close_popup_form());
4879: }
1.207 raeburn 4880: } elsif (($env{'form.action'} eq 'listusers') &&
4881: ($permission->{'view'} || $permission->{'cusr'})) {
1.202 raeburn 4882: if ($env{'form.phase'} eq 'bulkchange') {
1.351 raeburn 4883: push(@{$brcrum},
4884: {href => '/adm/createuser?action=listusers',
4885: text => "List Users"},
4886: {href => "/adm/createuser",
4887: text => "Result",
4888: help => 'Course_View_Class_List'});
4889: $bread_crumbs_component = 'Update Users';
4890: $args = {bread_crumbs => $brcrum,
4891: bread_crumbs_component => $bread_crumbs_component};
4892: $r->print(&header(undef,$args));
1.202 raeburn 4893: my $setting = $env{'form.roletype'};
4894: my $choice = $env{'form.bulkaction'};
4895: if ($permission->{'cusr'}) {
1.336 raeburn 4896: &Apache::lonuserutils::update_user_list($r,$context,$setting,$choice,$crstype);
1.221 raeburn 4897: } else {
4898: $r->print(&mt('You are not authorized to make bulk changes to user roles'));
1.223 raeburn 4899: $r->print('<p><a href="/adm/createuser?action=listusers">'.&mt('Display User Lists').'</a>');
1.202 raeburn 4900: }
4901: } else {
1.351 raeburn 4902: push(@{$brcrum},
4903: {href => '/adm/createuser?action=listusers',
4904: text => "List Users",
4905: help => 'Course_View_Class_List'});
4906: $bread_crumbs_component = 'List Users';
4907: $args = {bread_crumbs => $brcrum,
4908: bread_crumbs_component => $bread_crumbs_component};
1.202 raeburn 4909: my ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles);
4910: my $formname = 'studentform';
1.364 raeburn 4911: my $hidecall = "hide_searching();";
1.321 raeburn 4912: if (($context eq 'domain') && (($env{'form.roletype'} eq 'course') ||
4913: ($env{'form.roletype'} eq 'community'))) {
4914: if ($env{'form.roletype'} eq 'course') {
4915: ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles) =
4916: &Apache::lonuserutils::courses_selector($env{'request.role.domain'},
4917: $formname);
4918: } elsif ($env{'form.roletype'} eq 'community') {
4919: $cb_jscript =
4920: &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
4921: my %elements = (
4922: coursepick => 'radio',
4923: coursetotal => 'text',
4924: courselist => 'text',
4925: );
4926: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements);
4927: }
1.364 raeburn 4928: $jscript .= &verify_user_display($context)."\n".
4929: &Apache::loncommon::check_uncheck_jscript();
1.202 raeburn 4930: my $js = &add_script($jscript).$cb_jscript;
4931: my $loadcode =
4932: &Apache::lonuserutils::course_selector_loadcode($formname);
4933: if ($loadcode ne '') {
1.364 raeburn 4934: $args->{add_entries} = {onload => "$loadcode;$hidecall"};
4935: } else {
4936: $args->{add_entries} = {onload => $hidecall};
1.202 raeburn 4937: }
1.351 raeburn 4938: $r->print(&header($js,$args));
1.191 raeburn 4939: } else {
1.364 raeburn 4940: $args->{add_entries} = {onload => $hidecall};
4941: $jscript = &verify_user_display($context).
4942: &Apache::loncommon::check_uncheck_jscript();
4943: $r->print(&header(&add_script($jscript),$args));
1.191 raeburn 4944: }
1.202 raeburn 4945: &Apache::lonuserutils::print_userlist($r,undef,$permission,$context,
1.375 raeburn 4946: $formname,$totcodes,$codetitles,$idlist,$idlist_titles,
4947: $showcredits);
1.191 raeburn 4948: }
1.213 raeburn 4949: } elsif ($env{'form.action'} eq 'drop' && $permission->{'cusr'}) {
1.318 raeburn 4950: my $brtext;
4951: if ($crstype eq 'Community') {
4952: $brtext = 'Drop Members';
4953: } else {
4954: $brtext = 'Drop Students';
4955: }
1.351 raeburn 4956: push(@{$brcrum},
4957: {href => '/adm/createuser?action=drop',
4958: text => $brtext,
4959: help => 'Course_Drop_Student'});
4960: if ($env{'form.state'} eq 'done') {
4961: push(@{$brcrum},
4962: {href=>'/adm/createuser?action=drop',
4963: text=>"Result"});
4964: }
4965: $bread_crumbs_component = $brtext;
4966: $args = {bread_crumbs => $brcrum,
4967: bread_crumbs_component => $bread_crumbs_component};
4968: $r->print(&header(undef,$args));
1.213 raeburn 4969: if (!exists($env{'form.state'})) {
1.318 raeburn 4970: &Apache::lonuserutils::print_drop_menu($r,$context,$permission,$crstype);
1.213 raeburn 4971: } elsif ($env{'form.state'} eq 'done') {
4972: &Apache::lonuserutils::update_user_list($r,$context,undef,
4973: $env{'form.action'});
4974: }
1.202 raeburn 4975: } elsif ($env{'form.action'} eq 'dateselect') {
4976: if ($permission->{'cusr'}) {
1.351 raeburn 4977: $r->print(&header(undef,{'no_nav_bar' => 1}).
1.375 raeburn 4978: &Apache::lonuserutils::date_section_selector($context,$permission,
4979: $crstype,$showcredits));
1.202 raeburn 4980: } else {
1.351 raeburn 4981: $r->print(&header(undef,{'no_nav_bar' => 1}).
4982: '<span class="LC_error">'.&mt('You do not have permission to modify dates or sections for users').'</span>');
1.202 raeburn 4983: }
1.237 raeburn 4984: } elsif ($env{'form.action'} eq 'selfenroll') {
1.398 raeburn 4985: if ($permission->{selfenrolladmin}) {
4986: my $cid = $env{'request.course.id'};
4987: my $cdom = $env{'course.'.$cid.'.domain'};
4988: my $cnum = $env{'course.'.$cid.'.num'};
4989: my %currsettings = (
4990: selfenroll_types => $env{'course.'.$cid.'.internal.selfenroll_types'},
4991: selfenroll_registered => $env{'course.'.$cid.'.internal.selfenroll_registered'},
4992: selfenroll_section => $env{'course.'.$cid.'.internal.selfenroll_section'},
4993: selfenroll_notifylist => $env{'course.'.$cid.'.internal.selfenroll_notifylist'},
4994: selfenroll_approval => $env{'course.'.$cid.'.internal.selfenroll_approval'},
4995: selfenroll_limit => $env{'course.'.$cid.'.internal.selfenroll_limit'},
4996: selfenroll_cap => $env{'course.'.$cid.'.internal.selfenroll_cap'},
4997: selfenroll_start_date => $env{'course.'.$cid.'.internal.selfenroll_start_date'},
4998: selfenroll_end_date => $env{'course.'.$cid.'.internal.selfenroll_end_date'},
4999: selfenroll_start_access => $env{'course.'.$cid.'.internal.selfenroll_start_access'},
5000: selfenroll_end_access => $env{'course.'.$cid.'.internal.selfenroll_end_access'},
5001: default_enrollment_start_date => $env{'course.'.$cid.'.default_enrollment_start_date'},
5002: default_enrollment_end_date => $env{'course.'.$cid.'.default_enrollment_end_date'},
1.400 raeburn 5003: uniquecode => $env{'course.'.$cid.'.internal.uniquecode'},
1.398 raeburn 5004: );
5005: push(@{$brcrum},
5006: {href => '/adm/createuser?action=selfenroll',
5007: text => "Configure Self-enrollment",
5008: help => 'Course_Self_Enrollment'});
5009: if (!exists($env{'form.state'})) {
5010: $args = { bread_crumbs => $brcrum,
5011: bread_crumbs_component => 'Configure Self-enrollment'};
5012: $r->print(&header(undef,$args));
5013: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
5014: &print_selfenroll_menu($r,'course',$cid,$cdom,$cnum,\%currsettings);
5015: } elsif ($env{'form.state'} eq 'done') {
5016: push (@{$brcrum},
5017: {href=>'/adm/createuser?action=selfenroll',
5018: text=>"Result"});
5019: $args = { bread_crumbs => $brcrum,
5020: bread_crumbs_component => 'Self-enrollment result'};
5021: $r->print(&header(undef,$args));
5022: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
1.400 raeburn 5023: &update_selfenroll_config($r,$cid,$cdom,$cnum,$context,$crstype,\%currsettings);
1.398 raeburn 5024: }
5025: } else {
5026: $r->print(&header(undef,{'no_nav_bar' => 1}).
5027: '<span class="LC_error">'.&mt('You do not have permission to configure self-enrollment').'</span>');
1.237 raeburn 5028: }
1.277 raeburn 5029: } elsif ($env{'form.action'} eq 'selfenrollqueue') {
1.351 raeburn 5030: push(@{$brcrum},
5031: {href => '/adm/createuser?action=selfenrollqueue',
5032: text => 'Enrollment requests',
5033: help => 'Course_Self_Enrollment'});
5034: $bread_crumbs_component = 'Enrollment requests';
5035: if ($env{'form.state'} eq 'done') {
5036: push(@{$brcrum},
5037: {href => '/adm/createuser?action=selfenrollqueue',
5038: text => 'Result',
5039: help => 'Course_Self_Enrollment'});
5040: $bread_crumbs_component = 'Enrollment result';
5041: }
5042: $args = { bread_crumbs => $brcrum,
5043: bread_crumbs_component => $bread_crumbs_component};
5044: $r->print(&header(undef,$args));
1.277 raeburn 5045: my $cid = $env{'request.course.id'};
5046: my $cdom = $env{'course.'.$cid.'.domain'};
5047: my $cnum = $env{'course.'.$cid.'.num'};
1.307 raeburn 5048: my $coursedesc = $env{'course.'.$cid.'.description'};
1.277 raeburn 5049: if (!exists($env{'form.state'})) {
5050: $r->print('<h3>'.&mt('Pending enrollment requests').'</h3>'."\n");
1.307 raeburn 5051: $r->print(&Apache::loncoursequeueadmin::display_queued_requests($context,
5052: $cdom,$cnum));
1.277 raeburn 5053: } elsif ($env{'form.state'} eq 'done') {
5054: $r->print('<h3>'.&mt('Enrollment request processing').'</h3>'."\n");
1.307 raeburn 5055: $r->print(&Apache::loncoursequeueadmin::update_request_queue($context,
5056: $cdom,$cnum,$coursedesc));
1.277 raeburn 5057: }
1.239 raeburn 5058: } elsif ($env{'form.action'} eq 'changelogs') {
1.406.2.5! raeburn 5059: &print_userchangelogs_display($r,$context,$permission,$brcrum);
1.190 raeburn 5060: } else {
1.351 raeburn 5061: $bread_crumbs_component = 'User Management';
5062: $args = { bread_crumbs => $brcrum,
5063: bread_crumbs_component => $bread_crumbs_component};
5064: $r->print(&header(undef,$args));
1.318 raeburn 5065: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 5066: }
1.351 raeburn 5067: $r->print(&Apache::loncommon::end_page());
1.190 raeburn 5068: return OK;
5069: }
5070:
5071: sub header {
1.351 raeburn 5072: my ($jscript,$args) = @_;
1.190 raeburn 5073: my $start_page;
1.351 raeburn 5074: if (ref($args) eq 'HASH') {
5075: $start_page=&Apache::loncommon::start_page('User Management',$jscript,$args);
1.190 raeburn 5076: } else {
1.351 raeburn 5077: $start_page=&Apache::loncommon::start_page('User Management',$jscript);
1.190 raeburn 5078: }
5079: return $start_page;
5080: }
1.2 www 5081:
1.191 raeburn 5082: sub add_script {
5083: my ($js) = @_;
1.301 bisitz 5084: return '<script type="text/javascript">'."\n"
5085: .'// <![CDATA['."\n"
5086: .$js."\n"
5087: .'// ]]>'."\n"
5088: .'</script>'."\n";
1.191 raeburn 5089: }
5090:
1.391 raeburn 5091: sub usernamerequest_javascript {
5092: my $js = <<ENDJS;
5093:
5094: function openusernamereqdisplay(dom,uname,queue) {
5095: var url = '/adm/createuser?action=displayuserreq';
5096: url += '&domain='+dom+'&username='+uname+'&queue='+queue;
5097: var title = 'Account_Request_Browser';
5098: var options = 'scrollbars=1,resizable=1,menubar=0';
5099: options += ',width=700,height=600';
5100: var stdeditbrowser = open(url,title,options,'1');
5101: stdeditbrowser.focus();
5102: return;
5103: }
5104:
5105: ENDJS
5106: }
5107:
5108: sub close_popup_form {
5109: my $close= &mt('Close Window');
5110: return << "END";
5111: <p><form name="displayreq" action="" method="post">
5112: <input type="button" name="closeme" value="$close" onclick="javascript:self.close();" />
5113: </form></p>
5114: END
5115: }
5116:
1.202 raeburn 5117: sub verify_user_display {
1.364 raeburn 5118: my ($context) = @_;
1.374 raeburn 5119: my %lt = &Apache::lonlocal::texthash (
5120: course => 'course(s): description, section(s), status',
5121: community => 'community(s): description, section(s), status',
5122: author => 'author',
5123: );
1.364 raeburn 5124: my $photos;
5125: if (($context eq 'course') && $env{'request.course.id'}) {
5126: $photos = $env{'course.'.$env{'request.course.id'}.'.internal.showphoto'};
5127: }
1.202 raeburn 5128: my $output = <<"END";
5129:
1.364 raeburn 5130: function hide_searching() {
5131: if (document.getElementById('searching')) {
5132: document.getElementById('searching').style.display = 'none';
5133: }
5134: return;
5135: }
5136:
1.202 raeburn 5137: function display_update() {
5138: document.studentform.action.value = 'listusers';
5139: document.studentform.phase.value = 'display';
5140: document.studentform.submit();
5141: }
5142:
1.364 raeburn 5143: function updateCols(caller) {
5144: var context = '$context';
5145: var photos = '$photos';
5146: if (caller == 'Status') {
1.374 raeburn 5147: if ((context == 'domain') &&
5148: ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
5149: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community'))) {
1.364 raeburn 5150: document.getElementById('showcolstatus').checked = false;
5151: document.getElementById('showcolstatus').disabled = 'disabled';
5152: document.getElementById('showcolstart').checked = false;
5153: document.getElementById('showcolend').checked = false;
1.374 raeburn 5154: } else {
5155: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
5156: document.getElementById('showcolstatus').checked = true;
5157: document.getElementById('showcolstatus').disabled = '';
5158: document.getElementById('showcolstart').checked = true;
5159: document.getElementById('showcolend').checked = true;
5160: } else {
5161: document.getElementById('showcolstatus').checked = false;
5162: document.getElementById('showcolstatus').disabled = 'disabled';
5163: document.getElementById('showcolstart').checked = false;
5164: document.getElementById('showcolend').checked = false;
5165: }
1.364 raeburn 5166: }
5167: }
5168: if (caller == 'output') {
5169: if (photos == 1) {
5170: if (document.getElementById('showcolphoto')) {
5171: var photoitem = document.getElementById('showcolphoto');
5172: if (document.studentform.output.options[document.studentform.output.selectedIndex].value == 'html') {
5173: photoitem.checked = true;
5174: photoitem.disabled = '';
5175: } else {
5176: photoitem.checked = false;
5177: photoitem.disabled = 'disabled';
5178: }
5179: }
5180: }
5181: }
5182: if (caller == 'showrole') {
1.371 raeburn 5183: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any') ||
5184: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'cr')) {
1.364 raeburn 5185: document.getElementById('showcolrole').checked = true;
5186: document.getElementById('showcolrole').disabled = '';
5187: } else {
5188: document.getElementById('showcolrole').checked = false;
5189: document.getElementById('showcolrole').disabled = 'disabled';
5190: }
1.374 raeburn 5191: if (context == 'domain') {
1.382 raeburn 5192: var quotausageshow = 0;
1.374 raeburn 5193: if ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
5194: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community')) {
5195: document.getElementById('showcolstatus').checked = false;
5196: document.getElementById('showcolstatus').disabled = 'disabled';
5197: document.getElementById('showcolstart').checked = false;
5198: document.getElementById('showcolend').checked = false;
5199: } else {
5200: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
5201: document.getElementById('showcolstatus').checked = true;
5202: document.getElementById('showcolstatus').disabled = '';
5203: document.getElementById('showcolstart').checked = true;
5204: document.getElementById('showcolend').checked = true;
5205: }
5206: }
5207: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'domain') {
5208: document.getElementById('showcolextent').disabled = 'disabled';
5209: document.getElementById('showcolextent').checked = 'false';
5210: document.getElementById('showextent').style.display='none';
5211: document.getElementById('showcoltextextent').innerHTML = '';
1.382 raeburn 5212: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'au') ||
5213: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any')) {
5214: if (document.getElementById('showcolauthorusage')) {
5215: document.getElementById('showcolauthorusage').disabled = '';
5216: }
5217: if (document.getElementById('showcolauthorquota')) {
5218: document.getElementById('showcolauthorquota').disabled = '';
5219: }
5220: quotausageshow = 1;
5221: }
1.374 raeburn 5222: } else {
5223: document.getElementById('showextent').style.display='block';
5224: document.getElementById('showextent').style.textAlign='left';
5225: document.getElementById('showextent').style.textFace='normal';
5226: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'author') {
5227: document.getElementById('showcolextent').disabled = '';
5228: document.getElementById('showcolextent').checked = 'true';
5229: document.getElementById('showcoltextextent').innerHTML="$lt{'author'}";
5230: } else {
5231: document.getElementById('showcolextent').disabled = '';
5232: document.getElementById('showcolextent').checked = 'true';
5233: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community') {
5234: document.getElementById('showcoltextextent').innerHTML="$lt{'community'}";
5235: } else {
5236: document.getElementById('showcoltextextent').innerHTML="$lt{'course'}";
5237: }
5238: }
5239: }
1.382 raeburn 5240: if (quotausageshow == 0) {
5241: if (document.getElementById('showcolauthorusage')) {
5242: document.getElementById('showcolauthorusage').checked = false;
5243: document.getElementById('showcolauthorusage').disabled = 'disabled';
5244: }
5245: if (document.getElementById('showcolauthorquota')) {
5246: document.getElementById('showcolauthorquota').checked = false;
5247: document.getElementById('showcolauthorquota').disabled = 'disabled';
5248: }
5249: }
1.374 raeburn 5250: }
1.364 raeburn 5251: }
5252: return;
5253: }
5254:
1.202 raeburn 5255: END
5256: return $output;
5257:
5258: }
5259:
1.190 raeburn 5260: ###############################################################
5261: ###############################################################
5262: # Menu Phase One
5263: sub print_main_menu {
1.318 raeburn 5264: my ($permission,$context,$crstype) = @_;
5265: my $linkcontext = $context;
5266: my $stuterm = lc(&Apache::lonnet::plaintext('st',$crstype));
5267: if (($context eq 'course') && ($crstype eq 'Community')) {
5268: $linkcontext = lc($crstype);
5269: $stuterm = 'Members';
5270: }
1.208 raeburn 5271: my %links = (
1.298 droeschl 5272: domain => {
5273: upload => 'Upload a File of Users',
5274: singleuser => 'Add/Modify a User',
5275: listusers => 'Manage Users',
5276: },
5277: author => {
5278: upload => 'Upload a File of Co-authors',
5279: singleuser => 'Add/Modify a Co-author',
5280: listusers => 'Manage Co-authors',
5281: },
5282: course => {
5283: upload => 'Upload a File of Course Users',
5284: singleuser => 'Add/Modify a Course User',
1.354 www 5285: listusers => 'List and Modify Multiple Course Users',
1.298 droeschl 5286: },
1.318 raeburn 5287: community => {
5288: upload => 'Upload a File of Community Users',
5289: singleuser => 'Add/Modify a Community User',
1.354 www 5290: listusers => 'List and Modify Multiple Community Users',
1.318 raeburn 5291: },
5292: );
5293: my %linktitles = (
5294: domain => {
5295: singleuser => 'Add a user to the domain, and/or a course or community in the domain.',
5296: listusers => 'Show and manage users in this domain.',
5297: },
5298: author => {
5299: singleuser => 'Add a user with a co- or assistant author role.',
5300: listusers => 'Show and manage co- or assistant authors.',
5301: },
5302: course => {
5303: singleuser => 'Add a user with a certain role to this course.',
5304: listusers => 'Show and manage users in this course.',
5305: },
5306: community => {
5307: singleuser => 'Add a user with a certain role to this community.',
5308: listusers => 'Show and manage users in this community.',
5309: },
1.298 droeschl 5310: );
5311: my @menu = ( {categorytitle => 'Single Users',
5312: items =>
5313: [
5314: {
1.318 raeburn 5315: linktext => $links{$linkcontext}{'singleuser'},
1.298 droeschl 5316: icon => 'edit-redo.png',
5317: #help => 'Course_Change_Privileges',
5318: url => '/adm/createuser?action=singleuser',
5319: permission => $permission->{'cusr'},
1.318 raeburn 5320: linktitle => $linktitles{$linkcontext}{'singleuser'},
1.298 droeschl 5321: },
5322: ]},
5323:
5324: {categorytitle => 'Multiple Users',
5325: items =>
5326: [
5327: {
1.318 raeburn 5328: linktext => $links{$linkcontext}{'upload'},
1.340 wenzelju 5329: icon => 'uplusr.png',
1.298 droeschl 5330: #help => 'Course_Create_Class_List',
5331: url => '/adm/createuser?action=upload',
5332: permission => $permission->{'cusr'},
5333: linktitle => 'Upload a CSV or a text file containing users.',
5334: },
5335: {
1.318 raeburn 5336: linktext => $links{$linkcontext}{'listusers'},
1.340 wenzelju 5337: icon => 'mngcu.png',
1.298 droeschl 5338: #help => 'Course_View_Class_List',
5339: url => '/adm/createuser?action=listusers',
5340: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.318 raeburn 5341: linktitle => $linktitles{$linkcontext}{'listusers'},
1.298 droeschl 5342: },
5343:
5344: ]},
5345:
5346: {categorytitle => 'Administration',
5347: items => [ ]},
5348: );
1.406.2.5! raeburn 5349:
1.265 mielkec 5350: if ($context eq 'domain'){
1.406.2.5! raeburn 5351: push(@{ $menu[0]->{items} }, # Single Users
! 5352: {
! 5353: linktext => 'User Access Log',
! 5354: icon => 'document-properties.png',
! 5355: #help => 'User_Access_Logs',
! 5356: url => '/adm/createuser?action=accesslogs',
! 5357: permission => $permission->{'activity'},
! 5358: linktitle => 'View user access log.',
! 5359: }
! 5360: );
1.298 droeschl 5361:
5362: push(@{ $menu[2]->{items} }, #Category: Administration
5363: {
5364: linktext => 'Custom Roles',
5365: icon => 'emblem-photos.png',
5366: #help => 'Course_Editing_Custom_Roles',
5367: url => '/adm/createuser?action=custom',
5368: permission => $permission->{'custom'},
5369: linktitle => 'Configure a custom role.',
5370: },
1.362 raeburn 5371: {
5372: linktext => 'Authoring Space Requests',
5373: icon => 'selfenrl-queue.png',
5374: #help => 'Domain_Role_Approvals',
5375: url => '/adm/createuser?action=processauthorreq',
5376: permission => $permission->{'cusr'},
5377: linktitle => 'Approve or reject author role requests',
5378: },
1.363 raeburn 5379: {
1.391 raeburn 5380: linktext => 'LON-CAPA Account Requests',
5381: icon => 'list-add.png',
5382: #help => 'Domain_Username_Approvals',
5383: url => '/adm/createuser?action=processusernamereq',
5384: permission => $permission->{'cusr'},
5385: linktitle => 'Approve or reject LON-CAPA account requests',
5386: },
5387: {
1.363 raeburn 5388: linktext => 'Change Log',
5389: icon => 'document-properties.png',
5390: #help => 'Course_User_Logs',
5391: url => '/adm/createuser?action=changelogs',
5392: permission => $permission->{'cusr'},
5393: linktitle => 'View change log.',
5394: },
1.298 droeschl 5395: );
5396:
1.265 mielkec 5397: }elsif ($context eq 'course'){
1.298 droeschl 5398: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity();
1.318 raeburn 5399:
5400: my %linktext = (
5401: 'Course' => {
5402: single => 'Add/Modify a Student',
5403: drop => 'Drop Students',
5404: groups => 'Course Groups',
5405: },
5406: 'Community' => {
5407: single => 'Add/Modify a Member',
5408: drop => 'Drop Members',
5409: groups => 'Community Groups',
5410: },
5411: );
5412:
5413: my %linktitle = (
5414: 'Course' => {
5415: single => 'Add a user with the role of student to this course',
5416: drop => 'Remove a student from this course.',
5417: groups => 'Manage course groups',
5418: },
5419: 'Community' => {
5420: single => 'Add a user with the role of member to this community',
5421: drop => 'Remove a member from this community.',
5422: groups => 'Manage community groups',
5423: },
5424: );
5425:
1.298 droeschl 5426: push(@{ $menu[0]->{items} }, #Category: Single Users
5427: {
1.318 raeburn 5428: linktext => $linktext{$crstype}{'single'},
1.298 droeschl 5429: #help => 'Course_Add_Student',
5430: icon => 'list-add.png',
5431: url => '/adm/createuser?action=singlestudent',
5432: permission => $permission->{'cusr'},
1.318 raeburn 5433: linktitle => $linktitle{$crstype}{'single'},
1.298 droeschl 5434: },
5435: );
5436:
5437: push(@{ $menu[1]->{items} }, #Category: Multiple Users
5438: {
1.318 raeburn 5439: linktext => $linktext{$crstype}{'drop'},
1.298 droeschl 5440: icon => 'edit-undo.png',
5441: #help => 'Course_Drop_Student',
5442: url => '/adm/createuser?action=drop',
5443: permission => $permission->{'cusr'},
1.318 raeburn 5444: linktitle => $linktitle{$crstype}{'drop'},
1.298 droeschl 5445: },
5446: );
5447: push(@{ $menu[2]->{items} }, #Category: Administration
5448: {
5449: linktext => 'Custom Roles',
5450: icon => 'emblem-photos.png',
5451: #help => 'Course_Editing_Custom_Roles',
5452: url => '/adm/createuser?action=custom',
5453: permission => $permission->{'custom'},
5454: linktitle => 'Configure a custom role.',
5455: },
5456: {
1.318 raeburn 5457: linktext => $linktext{$crstype}{'groups'},
1.333 wenzelju 5458: icon => 'grps.png',
1.298 droeschl 5459: #help => 'Course_Manage_Group',
5460: url => '/adm/coursegroups?refpage=cusr',
5461: permission => $permission->{'grp_manage'},
1.318 raeburn 5462: linktitle => $linktitle{$crstype}{'groups'},
1.298 droeschl 5463: },
5464: {
1.328 wenzelju 5465: linktext => 'Change Log',
1.298 droeschl 5466: icon => 'document-properties.png',
5467: #help => 'Course_User_Logs',
5468: url => '/adm/createuser?action=changelogs',
5469: permission => $permission->{'cusr'},
5470: linktitle => 'View change log.',
5471: },
5472: );
1.277 raeburn 5473: if ($env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'}) {
1.298 droeschl 5474: push(@{ $menu[2]->{items} },
1.398 raeburn 5475: {
1.298 droeschl 5476: linktext => 'Enrollment Requests',
5477: icon => 'selfenrl-queue.png',
5478: #help => 'Course_Approve_Selfenroll',
5479: url => '/adm/createuser?action=selfenrollqueue',
1.398 raeburn 5480: permission => $permission->{'selfenrolladmin'},
1.298 droeschl 5481: linktitle =>'Approve or reject enrollment requests.',
5482: },
5483: );
1.277 raeburn 5484: }
1.298 droeschl 5485:
1.265 mielkec 5486: if (!exists($permission->{'cusr_section'})){
1.320 raeburn 5487: if ($crstype ne 'Community') {
5488: push(@{ $menu[2]->{items} },
5489: {
5490: linktext => 'Automated Enrollment',
5491: icon => 'roles.png',
5492: #help => 'Course_Automated_Enrollment',
5493: permission => (&Apache::lonnet::auto_run($cnum,$cdom)
5494: && $permission->{'cusr'}),
5495: url => '/adm/populate',
5496: linktitle => 'Automated enrollment manager.',
5497: }
5498: );
5499: }
5500: push(@{ $menu[2]->{items} },
1.298 droeschl 5501: {
5502: linktext => 'User Self-Enrollment',
1.342 wenzelju 5503: icon => 'self_enroll.png',
1.298 droeschl 5504: #help => 'Course_Self_Enrollment',
5505: url => '/adm/createuser?action=selfenroll',
1.398 raeburn 5506: permission => $permission->{'selfenrolladmin'},
1.317 bisitz 5507: linktitle => 'Configure user self-enrollment.',
1.298 droeschl 5508: },
5509: );
5510: }
1.363 raeburn 5511: } elsif ($context eq 'author') {
1.370 raeburn 5512: push(@{ $menu[2]->{items} }, #Category: Administration
1.363 raeburn 5513: {
5514: linktext => 'Change Log',
5515: icon => 'document-properties.png',
5516: #help => 'Course_User_Logs',
5517: url => '/adm/createuser?action=changelogs',
5518: permission => $permission->{'cusr'},
5519: linktitle => 'View change log.',
5520: },
1.370 raeburn 5521: );
1.363 raeburn 5522: }
5523: return Apache::lonhtmlcommon::generate_menu(@menu);
1.250 raeburn 5524: # { text => 'View Log-in History',
5525: # help => 'Course_User_Logins',
5526: # action => 'logins',
5527: # permission => $permission->{'cusr'},
5528: # });
1.190 raeburn 5529: }
5530:
1.189 albertel 5531: sub restore_prev_selections {
5532: my %saveable_parameters = ('srchby' => 'scalar',
5533: 'srchin' => 'scalar',
5534: 'srchtype' => 'scalar',
5535: );
5536: &Apache::loncommon::store_settings('user','user_picker',
5537: \%saveable_parameters);
5538: &Apache::loncommon::restore_settings('user','user_picker',
5539: \%saveable_parameters);
5540: }
5541:
1.237 raeburn 5542: sub print_selfenroll_menu {
1.398 raeburn 5543: my ($r,$context,$cid,$cdom,$cnum,$currsettings,$additional) = @_;
1.322 raeburn 5544: my $crstype = &Apache::loncommon::course_type();
1.398 raeburn 5545: my $formname = 'selfenroll';
1.237 raeburn 5546: my $nolink = 1;
1.398 raeburn 5547: my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles();
1.237 raeburn 5548: my $groupslist = &Apache::lonuserutils::get_groupslist();
5549: my $setsec_js =
5550: &Apache::lonuserutils::setsections_javascript($formname,$groupslist);
1.249 raeburn 5551: my %alerts = &Apache::lonlocal::texthash(
5552: acto => 'Activation of self-enrollment was selected for the following domain(s)',
5553: butn => 'but no user types have been checked.',
5554: wilf => "Please uncheck 'activate' or check at least one type.",
5555: );
1.405 damieng 5556: &js_escape(\%alerts);
1.249 raeburn 5557: my $selfenroll_js = <<"ENDSCRIPT";
5558: function update_types(caller,num) {
5559: var delidx = getIndexByName('selfenroll_delete');
5560: var actidx = getIndexByName('selfenroll_activate');
5561: if (caller == 'selfenroll_all') {
5562: var selall;
5563: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5564: if (document.$formname.selfenroll_all[i].checked) {
5565: selall = document.$formname.selfenroll_all[i].value;
5566: }
5567: }
5568: if (selall == 1) {
5569: if (delidx != -1) {
5570: if (document.$formname.selfenroll_delete.length) {
5571: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
5572: document.$formname.selfenroll_delete[j].checked = true;
5573: }
5574: } else {
5575: document.$formname.elements[delidx].checked = true;
5576: }
5577: }
5578: if (actidx != -1) {
5579: if (document.$formname.selfenroll_activate.length) {
5580: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5581: document.$formname.selfenroll_activate[j].checked = false;
5582: }
5583: } else {
5584: document.$formname.elements[actidx].checked = false;
5585: }
5586: }
5587: document.$formname.selfenroll_newdom.selectedIndex = 0;
5588: }
5589: }
5590: if (caller == 'selfenroll_activate') {
5591: if (document.$formname.selfenroll_activate.length) {
5592: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5593: if (document.$formname.selfenroll_activate[j].value == num) {
5594: if (document.$formname.selfenroll_activate[j].checked) {
5595: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5596: if (document.$formname.selfenroll_all[i].value == '1') {
5597: document.$formname.selfenroll_all[i].checked = false;
5598: }
5599: if (document.$formname.selfenroll_all[i].value == '0') {
5600: document.$formname.selfenroll_all[i].checked = true;
5601: }
5602: }
5603: }
5604: }
5605: }
5606: } else {
5607: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5608: if (document.$formname.selfenroll_all[i].value == '1') {
5609: document.$formname.selfenroll_all[i].checked = false;
5610: }
5611: if (document.$formname.selfenroll_all[i].value == '0') {
5612: document.$formname.selfenroll_all[i].checked = true;
5613: }
5614: }
5615: }
5616: }
5617: if (caller == 'selfenroll_delete') {
5618: if (document.$formname.selfenroll_delete.length) {
5619: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
5620: if (document.$formname.selfenroll_delete[j].value == num) {
5621: if (document.$formname.selfenroll_delete[j].checked) {
5622: var delindex = getIndexByName('selfenroll_types_'+num);
5623: if (delindex != -1) {
5624: if (document.$formname.elements[delindex].length) {
5625: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
5626: document.$formname.elements[delindex][k].checked = false;
5627: }
5628: } else {
5629: document.$formname.elements[delindex].checked = false;
5630: }
5631: }
5632: }
5633: }
5634: }
5635: } else {
5636: if (document.$formname.selfenroll_delete.checked) {
5637: var delindex = getIndexByName('selfenroll_types_'+num);
5638: if (delindex != -1) {
5639: if (document.$formname.elements[delindex].length) {
5640: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
5641: document.$formname.elements[delindex][k].checked = false;
5642: }
5643: } else {
5644: document.$formname.elements[delindex].checked = false;
5645: }
5646: }
5647: }
5648: }
5649: }
5650: return;
5651: }
5652:
5653: function validate_types(form) {
5654: var needaction = new Array();
5655: var countfail = 0;
5656: var actidx = getIndexByName('selfenroll_activate');
5657: if (actidx != -1) {
5658: if (document.$formname.selfenroll_activate.length) {
5659: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5660: var num = document.$formname.selfenroll_activate[j].value;
5661: if (document.$formname.selfenroll_activate[j].checked) {
5662: countfail = check_types(num,countfail,needaction)
5663: }
5664: }
5665: } else {
5666: if (document.$formname.selfenroll_activate.checked) {
1.398 raeburn 5667: var num = document.$formname.selfenroll_activate.value;
1.249 raeburn 5668: countfail = check_types(num,countfail,needaction)
5669: }
5670: }
5671: }
5672: if (countfail > 0) {
5673: var msg = "$alerts{'acto'}\\n";
5674: var loopend = needaction.length -1;
5675: if (loopend > 0) {
5676: for (var m=0; m<loopend; m++) {
5677: msg += needaction[m]+", ";
5678: }
5679: }
5680: msg += needaction[loopend]+"\\n$alerts{'butn'}\\n$alerts{'wilf'}";
5681: alert(msg);
5682: return;
5683: }
5684: setSections(form);
5685: }
5686:
5687: function check_types(num,countfail,needaction) {
5688: var typeidx = getIndexByName('selfenroll_types_'+num);
5689: var count = 0;
5690: if (typeidx != -1) {
5691: if (document.$formname.elements[typeidx].length) {
5692: for (var k=0; k<document.$formname.elements[typeidx].length; k++) {
5693: if (document.$formname.elements[typeidx][k].checked) {
5694: count ++;
5695: }
5696: }
5697: } else {
5698: if (document.$formname.elements[typeidx].checked) {
5699: count ++;
5700: }
5701: }
5702: if (count == 0) {
5703: var domidx = getIndexByName('selfenroll_dom_'+num);
5704: if (domidx != -1) {
5705: var domname = document.$formname.elements[domidx].value;
5706: needaction[countfail] = domname;
5707: countfail ++;
5708: }
5709: }
5710: }
5711: return countfail;
5712: }
5713:
1.398 raeburn 5714: function toggleNotify() {
5715: var selfenrollApproval = 0;
5716: if (document.$formname.selfenroll_approval.length) {
5717: for (var i=0; i<document.$formname.selfenroll_approval.length; i++) {
5718: if (document.$formname.selfenroll_approval[i].checked) {
5719: selfenrollApproval = document.$formname.selfenroll_approval[i].value;
5720: break;
5721: }
5722: }
5723: }
5724: if (document.getElementById('notified')) {
5725: if (selfenrollApproval == 0) {
5726: document.getElementById('notified').style.display='none';
5727: } else {
5728: document.getElementById('notified').style.display='block';
5729: }
5730: }
5731: return;
5732: }
5733:
1.249 raeburn 5734: function getIndexByName(item) {
5735: for (var i=0;i<document.$formname.elements.length;i++) {
5736: if (document.$formname.elements[i].name == item) {
5737: return i;
5738: }
5739: }
5740: return -1;
5741: }
5742: ENDSCRIPT
1.256 raeburn 5743:
1.237 raeburn 5744: my $output = '<script type="text/javascript">'."\n".
1.301 bisitz 5745: '// <![CDATA['."\n".
1.249 raeburn 5746: $setsec_js."\n".$selfenroll_js."\n".
1.301 bisitz 5747: '// ]]>'."\n".
1.237 raeburn 5748: '</script>'."\n".
1.256 raeburn 5749: '<h3>'.$lt->{'selfenroll'}.'</h3>'."\n";
1.400 raeburn 5750:
5751: my $visactions = &cat_visibility();
5752: my ($cathash,%cattype);
5753: my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
5754: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
5755: $cathash = $domconfig{'coursecategories'}{'cats'};
5756: $cattype{'auth'} = $domconfig{'coursecategories'}{'auth'};
5757: $cattype{'unauth'} = $domconfig{'coursecategories'}{'unauth'};
1.406 raeburn 5758: if ($cattype{'auth'} eq '') {
5759: $cattype{'auth'} = 'std';
5760: }
5761: if ($cattype{'unauth'} eq '') {
5762: $cattype{'unauth'} = 'std';
5763: }
1.400 raeburn 5764: } else {
5765: $cathash = {};
5766: $cattype{'auth'} = 'std';
5767: $cattype{'unauth'} = 'std';
5768: }
5769: if (($cattype{'auth'} eq 'none') && ($cattype{'unauth'} eq 'none')) {
5770: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
5771: '<br />'.
5772: '<br />'.$visactions->{'take'}.'<ul>'.
5773: '<li>'.$visactions->{'dc_chgconf'}.'</li>'.
5774: '</ul>');
5775: } elsif (($cattype{'auth'} !~ /^(std|domonly)$/) && ($cattype{'unauth'} !~ /^(std|domonly)$/)) {
5776: if ($currsettings->{'uniquecode'}) {
5777: $r->print('<span class="LC_info">'.$visactions->{'vis'}.'</span>');
5778: } else {
5779: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
5780: '<br />'.
5781: '<br />'.$visactions->{'take'}.'<ul>'.
5782: '<li>'.$visactions->{'dc_setcode'}.'</li>'.
5783: '</ul><br />');
5784: }
5785: } else {
5786: my ($visible,$cansetvis,$vismsgs) = &visible_in_stdcat($cdom,$cnum,\%domconfig);
5787: if (ref($visactions) eq 'HASH') {
5788: if ($visible) {
5789: $output .= '<p class="LC_info">'.$visactions->{'vis'}.'</p>';
5790: } else {
5791: $output .= '<p class="LC_warning">'.$visactions->{'miss'}.'</p>'
5792: .$visactions->{'yous'}.
5793: '<p>'.$visactions->{'gen'}.'<br />'.$visactions->{'coca'};
5794: if (ref($vismsgs) eq 'ARRAY') {
5795: $output .= '<br />'.$visactions->{'make'}.'<ul>';
5796: foreach my $item (@{$vismsgs}) {
5797: $output .= '<li>'.$visactions->{$item}.'</li>';
5798: }
5799: $output .= '</ul>';
1.256 raeburn 5800: }
1.400 raeburn 5801: $output .= '</p>';
1.256 raeburn 5802: }
5803: }
5804: }
1.398 raeburn 5805: my $actionhref = '/adm/createuser';
5806: if ($context eq 'domain') {
5807: $actionhref = '/adm/modifycourse';
5808: }
1.400 raeburn 5809:
5810: my %noedit;
5811: unless ($context eq 'domain') {
5812: %noedit = &get_noedit_fields($cdom,$cnum,$crstype,$row);
5813: }
1.398 raeburn 5814: $output .= '<form name="'.$formname.'" method="post" action="'.$actionhref.'">'."\n".
1.256 raeburn 5815: &Apache::lonhtmlcommon::start_pick_box();
1.237 raeburn 5816: if (ref($row) eq 'ARRAY') {
5817: foreach my $item (@{$row}) {
5818: my $title = $item;
5819: if (ref($lt) eq 'HASH') {
5820: $title = $lt->{$item};
5821: }
1.297 bisitz 5822: $output .= &Apache::lonhtmlcommon::row_title($title);
1.237 raeburn 5823: if ($item eq 'types') {
1.398 raeburn 5824: my $curr_types;
5825: if (ref($currsettings) eq 'HASH') {
5826: $curr_types = $currsettings->{'selfenroll_types'};
5827: }
1.400 raeburn 5828: if ($noedit{$item}) {
5829: if ($curr_types eq '*') {
5830: $output .= &mt('Any user in any domain');
5831: } else {
5832: my @entries = split(/;/,$curr_types);
5833: if (@entries > 0) {
5834: $output .= '<ul>';
5835: foreach my $entry (@entries) {
5836: my ($currdom,$typestr) = split(/:/,$entry);
5837: next if ($typestr eq '');
5838: my $domdesc = &Apache::lonnet::domain($currdom);
5839: my @currinsttypes = split(',',$typestr);
5840: my ($othertitle,$usertypes,$types) =
5841: &Apache::loncommon::sorted_inst_types($currdom);
5842: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
5843: $usertypes->{'any'} = &mt('any user');
5844: if (keys(%{$usertypes}) > 0) {
5845: $usertypes->{'other'} = &mt('other users');
5846: }
5847: my @longinsttypes = map { $usertypes->{$_}; } @currinsttypes;
5848: $output .= '<li>'.$domdesc.':'.join(', ',@longinsttypes).'</li>';
5849: }
5850: }
5851: $output .= '</ul>';
5852: } else {
5853: $output .= &mt('None');
5854: }
5855: }
5856: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
5857: next;
5858: }
1.241 raeburn 5859: my $showdomdesc = 1;
5860: my $includeempty = 1;
5861: my $num = 0;
5862: $output .= &Apache::loncommon::start_data_table().
5863: &Apache::loncommon::start_data_table_row()
5864: .'<td colspan="2"><span class="LC_nobreak"><label>'
5865: .&mt('Any user in any domain:')
5866: .' <input type="radio" name="selfenroll_all" value="1" ';
5867: if ($curr_types eq '*') {
5868: $output .= ' checked="checked" ';
5869: }
1.249 raeburn 5870: $output .= 'onchange="javascript:update_types('.
5871: "'selfenroll_all'".');" />'.&mt('Yes').'</label>'.
5872: ' <input type="radio" name="selfenroll_all" value="0" ';
1.241 raeburn 5873: if ($curr_types ne '*') {
5874: $output .= ' checked="checked" ';
5875: }
1.249 raeburn 5876: $output .= ' onchange="javascript:update_types('.
5877: "'selfenroll_all'".');"/>'.&mt('No').'</label></td>'.
5878: &Apache::loncommon::end_data_table_row().
5879: &Apache::loncommon::end_data_table().
5880: &mt('Or').'<br />'.
5881: &Apache::loncommon::start_data_table();
1.241 raeburn 5882: my %currdoms;
1.249 raeburn 5883: if ($curr_types eq '') {
1.241 raeburn 5884: $output .= &new_selfenroll_dom_row($cdom,'0');
5885: } elsif ($curr_types ne '*') {
5886: my @entries = split(/;/,$curr_types);
5887: if (@entries > 0) {
5888: foreach my $entry (@entries) {
5889: my ($currdom,$typestr) = split(/:/,$entry);
5890: $currdoms{$currdom} = 1;
5891: my $domdesc = &Apache::lonnet::domain($currdom);
1.249 raeburn 5892: my @currinsttypes = split(',',$typestr);
1.241 raeburn 5893: $output .= &Apache::loncommon::start_data_table_row()
5894: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').'<b>'
5895: .' '.$domdesc.' ('.$currdom.')'
5896: .'</b><input type="hidden" name="selfenroll_dom_'.$num
5897: .'" value="'.$currdom.'" /></span><br />'
5898: .'<span class="LC_nobreak"><label><input type="checkbox" '
1.249 raeburn 5899: .'name="selfenroll_delete" value="'.$num.'" onchange="javascript:update_types('."'selfenroll_delete','$num'".');" />'
1.241 raeburn 5900: .&mt('Delete').'</label></span></td>';
1.249 raeburn 5901: $output .= '<td valign="top"> '.&mt('User types:').'<br />'
1.241 raeburn 5902: .&selfenroll_inst_types($num,$currdom,\@currinsttypes).'</td>'
5903: .&Apache::loncommon::end_data_table_row();
5904: $num ++;
5905: }
5906: }
5907: }
1.249 raeburn 5908: my $add_domtitle = &mt('Users in additional domain:');
1.241 raeburn 5909: if ($curr_types eq '*') {
1.249 raeburn 5910: $add_domtitle = &mt('Users in specific domain:');
1.241 raeburn 5911: } elsif ($curr_types eq '') {
1.249 raeburn 5912: $add_domtitle = &mt('Users in other domain:');
1.241 raeburn 5913: }
5914: $output .= &Apache::loncommon::start_data_table_row()
5915: .'<td colspan="2"><span class="LC_nobreak">'.$add_domtitle.'</span><br />'
5916: .&Apache::loncommon::select_dom_form('','selfenroll_newdom',
5917: $includeempty,$showdomdesc)
5918: .'<input type="hidden" name="selfenroll_types_total" value="'.$num.'" />'
5919: .'</td>'.&Apache::loncommon::end_data_table_row()
5920: .&Apache::loncommon::end_data_table();
1.237 raeburn 5921: } elsif ($item eq 'registered') {
5922: my ($regon,$regoff);
1.398 raeburn 5923: my $registered;
5924: if (ref($currsettings) eq 'HASH') {
5925: $registered = $currsettings->{'selfenroll_registered'};
5926: }
1.400 raeburn 5927: if ($noedit{$item}) {
5928: if ($registered) {
5929: $output .= &mt('Must be registered in course');
5930: } else {
5931: $output .= &mt('No requirement');
5932: }
5933: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
5934: next;
5935: }
1.398 raeburn 5936: if ($registered) {
1.237 raeburn 5937: $regon = ' checked="checked" ';
5938: $regoff = ' ';
5939: } else {
5940: $regon = ' ';
5941: $regoff = ' checked="checked" ';
5942: }
5943: $output .= '<label>'.
1.245 raeburn 5944: '<input type="radio" name="selfenroll_registered" value="1"'.$regon.'/>'.
1.244 bisitz 5945: &mt('Yes').'</label> <label>'.
1.245 raeburn 5946: '<input type="radio" name="selfenroll_registered" value="0"'.$regoff.'/>'.
1.244 bisitz 5947: &mt('No').'</label>';
1.237 raeburn 5948: } elsif ($item eq 'enroll_dates') {
1.398 raeburn 5949: my ($starttime,$endtime);
5950: if (ref($currsettings) eq 'HASH') {
5951: $starttime = $currsettings->{'selfenroll_start_date'};
5952: $endtime = $currsettings->{'selfenroll_end_date'};
5953: if ($starttime eq '') {
5954: $starttime = $currsettings->{'default_enrollment_start_date'};
5955: }
5956: if ($endtime eq '') {
5957: $endtime = $currsettings->{'default_enrollment_end_date'};
5958: }
1.237 raeburn 5959: }
1.400 raeburn 5960: if ($noedit{$item}) {
5961: $output .= &mt('From: [_1], to: [_2]',&Apache::lonlocal::locallocaltime($starttime),
5962: &Apache::lonlocal::locallocaltime($endtime));
5963: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
5964: next;
5965: }
1.237 raeburn 5966: my $startform =
5967: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_date',$starttime,
5968: undef,undef,undef,undef,undef,undef,undef,$nolink);
5969: my $endform =
5970: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_date',$endtime,
5971: undef,undef,undef,undef,undef,undef,undef,$nolink);
5972: $output .= &selfenroll_date_forms($startform,$endform);
5973: } elsif ($item eq 'access_dates') {
1.398 raeburn 5974: my ($starttime,$endtime);
5975: if (ref($currsettings) eq 'HASH') {
5976: $starttime = $currsettings->{'selfenroll_start_access'};
5977: $endtime = $currsettings->{'selfenroll_end_access'};
5978: if ($starttime eq '') {
5979: $starttime = $currsettings->{'default_enrollment_start_date'};
5980: }
5981: if ($endtime eq '') {
5982: $endtime = $currsettings->{'default_enrollment_end_date'};
5983: }
1.237 raeburn 5984: }
1.400 raeburn 5985: if ($noedit{$item}) {
5986: $output .= &mt('From: [_1], to: [_2]',&Apache::lonlocal::locallocaltime($starttime),
5987: &Apache::lonlocal::locallocaltime($endtime));
5988: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
5989: next;
5990: }
1.237 raeburn 5991: my $startform =
5992: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_access',$starttime,
5993: undef,undef,undef,undef,undef,undef,undef,$nolink);
5994: my $endform =
5995: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_access',$endtime,
5996: undef,undef,undef,undef,undef,undef,undef,$nolink);
5997: $output .= &selfenroll_date_forms($startform,$endform);
5998: } elsif ($item eq 'section') {
1.398 raeburn 5999: my $currsec;
6000: if (ref($currsettings) eq 'HASH') {
6001: $currsec = $currsettings->{'selfenroll_section'};
6002: }
1.237 raeburn 6003: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
6004: my $newsecval;
6005: if ($currsec ne 'none' && $currsec ne '') {
6006: if (!defined($sections_count{$currsec})) {
6007: $newsecval = $currsec;
6008: }
6009: }
1.400 raeburn 6010: if ($noedit{$item}) {
6011: if ($currsec ne '') {
6012: $output .= $currsec;
6013: } else {
6014: $output .= &mt('No specific section');
6015: }
6016: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6017: next;
6018: }
1.237 raeburn 6019: my $sections_select =
6020: &Apache::lonuserutils::course_sections(\%sections_count,'st',$currsec);
6021: $output .= '<table class="LC_createuser">'."\n".
6022: '<tr class="LC_section_row">'."\n".
6023: '<td align="center">'.&mt('Existing sections')."\n".
6024: '<br />'.$sections_select.'</td><td align="center">'.
6025: &mt('New section').'<br />'."\n".
6026: '<input type="text" name="newsec" size="15" value="'.$newsecval.'" />'."\n".
6027: '<input type="hidden" name="sections" value="" />'."\n".
6028: '</td></tr></table>'."\n";
1.276 raeburn 6029: } elsif ($item eq 'approval') {
1.398 raeburn 6030: my ($currnotified,$currapproval,%appchecked);
6031: my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs();
6032: if (ref($currsettings) eq 'HASH') {
6033: $currnotified = $currsettings->{'selfenroll_notifylist'};
6034: $currapproval = $currsettings->{'selfenroll_approval'};
6035: }
6036: if ($currapproval !~ /^[012]$/) {
6037: $currapproval = 0;
6038: }
1.400 raeburn 6039: if ($noedit{$item}) {
6040: $output .= $selfdescs{'approval'}{$currapproval}.
6041: '<br />'.&mt('(Set by Domain Coordinator)');
6042: next;
6043: }
1.398 raeburn 6044: $appchecked{$currapproval} = ' checked="checked"';
6045: for my $i (0..2) {
6046: $output .= '<label>'.
6047: '<input type="radio" name="selfenroll_approval" value="'.$i.'"'.
6048: $appchecked{$i}.' onclick="toggleNotify();" />'.$selfdescs{'approval'}{$i}.
6049: '</label>'.(' 'x2);
1.276 raeburn 6050: }
6051: my %advhash = &Apache::lonnet::get_course_adv_roles($cid,1);
6052: my (@ccs,%notified);
1.322 raeburn 6053: my $ccrole = 'cc';
6054: if ($crstype eq 'Community') {
6055: $ccrole = 'co';
6056: }
6057: if ($advhash{$ccrole}) {
6058: @ccs = split(/,/,$advhash{$ccrole});
1.276 raeburn 6059: }
6060: if ($currnotified) {
6061: foreach my $current (split(/,/,$currnotified)) {
6062: $notified{$current} = 1;
6063: if (!grep(/^\Q$current\E$/,@ccs)) {
6064: push(@ccs,$current);
6065: }
6066: }
6067: }
6068: if (@ccs) {
1.398 raeburn 6069: my $style;
6070: unless ($currapproval) {
6071: $style = ' style="display: none;"';
6072: }
6073: $output .= '<br /><div id="notified"'.$style.'>'.
6074: &mt('Personnel to be notified when an enrollment request needs approval, or has been approved:').' '.
6075: &Apache::loncommon::start_data_table().
1.276 raeburn 6076: &Apache::loncommon::start_data_table_row();
6077: my $count = 0;
6078: my $numcols = 4;
6079: foreach my $cc (sort(@ccs)) {
6080: my $notifyon;
6081: my ($ccuname,$ccudom) = split(/:/,$cc);
6082: if ($notified{$cc}) {
6083: $notifyon = ' checked="checked" ';
6084: }
6085: if ($count && !$count%$numcols) {
6086: $output .= &Apache::loncommon::end_data_table_row().
6087: &Apache::loncommon::start_data_table_row()
6088: }
6089: $output .= '<td><span class="LC_nobreak"><label>'.
6090: '<input type="checkbox" name="selfenroll_notify"'.$notifyon.' value="'.$cc.'" />'.
6091: &Apache::loncommon::plainname($ccuname,$ccudom).
6092: '</label></span></td>';
1.343 raeburn 6093: $count ++;
1.276 raeburn 6094: }
6095: my $rem = $count%$numcols;
6096: if ($rem) {
6097: my $emptycols = $numcols - $rem;
6098: for (my $i=0; $i<$emptycols; $i++) {
6099: $output .= '<td> </td>';
6100: }
6101: }
6102: $output .= &Apache::loncommon::end_data_table_row().
1.398 raeburn 6103: &Apache::loncommon::end_data_table().
6104: '</div>';
1.276 raeburn 6105: }
6106: } elsif ($item eq 'limit') {
1.398 raeburn 6107: my ($crslimit,$selflimit,$nolimit,$currlim,$currcap);
6108: if (ref($currsettings) eq 'HASH') {
6109: $currlim = $currsettings->{'selfenroll_limit'};
6110: $currcap = $currsettings->{'selfenroll_cap'};
6111: }
1.400 raeburn 6112: if ($noedit{$item}) {
6113: if (($currlim eq 'allstudents') || ($currlim eq 'selfenrolled')) {
6114: if ($currlim eq 'allstudents') {
6115: $output .= &mt('Limit by total students');
6116: } elsif ($currlim eq 'selfenrolled') {
6117: $output .= &mt('Limit by total self-enrolled students');
6118: }
6119: $output .= ' '.&mt('Maximum: [_1]',$currcap).
6120: '<br />'.&mt('(Set by Domain Coordinator)');
6121: } else {
6122: $output .= &mt('No limit').'<br />'.&mt('(Set by Domain Coordinator)');
6123: }
6124: next;
6125: }
1.276 raeburn 6126: if ($currlim eq 'allstudents') {
6127: $crslimit = ' checked="checked" ';
6128: $selflimit = ' ';
6129: $nolimit = ' ';
6130: } elsif ($currlim eq 'selfenrolled') {
6131: $crslimit = ' ';
6132: $selflimit = ' checked="checked" ';
6133: $nolimit = ' ';
6134: } else {
6135: $crslimit = ' ';
6136: $selflimit = ' ';
1.398 raeburn 6137: $nolimit = ' checked="checked" ';
1.276 raeburn 6138: }
6139: $output .= '<table><tr><td><label>'.
1.278 raeburn 6140: '<input type="radio" name="selfenroll_limit" value="none"'.$nolimit.'/>'.
1.276 raeburn 6141: &mt('No limit').'</label></td><td><label>'.
6142: '<input type="radio" name="selfenroll_limit" value="allstudents"'.$crslimit.'/>'.
6143: &mt('Limit by total students').'</label></td><td><label>'.
6144: '<input type="radio" name="selfenroll_limit" value="selfenrolled"'.$selflimit.'/>'.
6145: &mt('Limit by total self-enrolled students').
6146: '</td></tr><tr>'.
6147: '<td> </td><td colspan="2"><span class="LC_nobreak">'.
6148: (' 'x3).&mt('Maximum number allowed: ').
6149: '<input type="text" name="selfenroll_cap" size = "5" value="'.$currcap.'" /></td></tr></table>';
1.237 raeburn 6150: }
6151: $output .= &Apache::lonhtmlcommon::row_closure(1);
6152: }
6153: }
6154: $output .= &Apache::lonhtmlcommon::end_pick_box().
1.241 raeburn 6155: '<br /><input type="button" name="selfenrollconf" value="'
1.282 schafran 6156: .&mt('Save').'" onclick="validate_types(this.form);" />'
1.400 raeburn 6157: .'<input type="hidden" name="action" value="selfenroll" />'
6158: .'<input type="hidden" name="state" value="done" />'."\n".
1.398 raeburn 6159: $additional.'</form>';
1.237 raeburn 6160: $r->print($output);
6161: return;
6162: }
6163:
1.400 raeburn 6164: sub get_noedit_fields {
6165: my ($cdom,$cnum,$crstype,$row) = @_;
6166: my %noedit;
6167: if (ref($row) eq 'ARRAY') {
6168: my %settings = &Apache::lonnet::get('environment',['internal.coursecode','internal.textbook',
6169: 'internal.selfenrollmgrdc',
6170: 'internal.selfenrollmgrcc'],$cdom,$cnum);
6171: my $type = &Apache::lonuserutils::get_extended_type($cdom,$cnum,$crstype,\%settings);
6172: my (%specific_managebydc,%specific_managebycc,%default_managebydc);
6173: map { $specific_managebydc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrdc'}));
6174: map { $specific_managebycc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrcc'}));
6175: my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
6176: map { $default_managebydc{$_} = 1; } (split(/,/,$domdefaults{$type.'selfenrolladmdc'}));
6177:
6178: foreach my $item (@{$row}) {
6179: next if ($specific_managebycc{$item});
6180: if (($specific_managebydc{$item}) || ($default_managebydc{$item})) {
6181: $noedit{$item} = 1;
6182: }
6183: }
6184: }
6185: return %noedit;
6186: }
6187:
6188: sub visible_in_stdcat {
6189: my ($cdom,$cnum,$domconf) = @_;
6190: my ($cathash,%settable,@vismsgs,$cansetvis,$visible);
6191: unless (ref($domconf) eq 'HASH') {
6192: return ($visible,$cansetvis,\@vismsgs);
6193: }
6194: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6195: if ($domconf->{'coursecategories'}{'togglecats'} eq 'crs') {
1.256 raeburn 6196: $settable{'togglecats'} = 1;
6197: }
1.400 raeburn 6198: if ($domconf->{'coursecategories'}{'categorize'} eq 'crs') {
1.256 raeburn 6199: $settable{'categorize'} = 1;
6200: }
1.400 raeburn 6201: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6202: }
1.260 raeburn 6203: if ($settable{'togglecats'} && $settable{'categorize'}) {
1.256 raeburn 6204: $cansetvis = &mt('You are able to both assign a course category and choose to exclude this course from the catalog.');
6205: } elsif ($settable{'togglecats'}) {
6206: $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 6207: } elsif ($settable{'categorize'}) {
1.256 raeburn 6208: $cansetvis = &mt('You may assign a course category, but only a Domain Coordinator may choose to exclude this course from the catalog.');
6209: } else {
6210: $cansetvis = &mt('Only a Domain Coordinator may assign a course category or choose to exclude this course from the catalog.');
6211: }
6212:
6213: my %currsettings =
6214: &Apache::lonnet::get('environment',['hidefromcat','categories','internal.coursecode'],
6215: $cdom,$cnum);
1.400 raeburn 6216: $visible = 0;
1.256 raeburn 6217: if ($currsettings{'internal.coursecode'} ne '') {
1.400 raeburn 6218: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6219: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6220: if (ref($cathash) eq 'HASH') {
6221: if ($cathash->{'instcode::0'} eq '') {
6222: push(@vismsgs,'dc_addinst');
6223: } else {
6224: $visible = 1;
6225: }
6226: } else {
6227: $visible = 1;
6228: }
6229: } else {
6230: $visible = 1;
6231: }
6232: } else {
6233: if (ref($cathash) eq 'HASH') {
6234: if ($cathash->{'instcode::0'} ne '') {
6235: push(@vismsgs,'dc_instcode');
6236: }
6237: } else {
6238: push(@vismsgs,'dc_instcode');
6239: }
6240: }
6241: if ($currsettings{'categories'} ne '') {
6242: my $cathash;
1.400 raeburn 6243: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6244: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6245: if (ref($cathash) eq 'HASH') {
6246: if (keys(%{$cathash}) == 0) {
6247: push(@vismsgs,'dc_catalog');
6248: } elsif ((keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} ne '')) {
6249: push(@vismsgs,'dc_categories');
6250: } else {
6251: my @currcategories = split('&',$currsettings{'categories'});
6252: my $matched = 0;
6253: foreach my $cat (@currcategories) {
6254: if ($cathash->{$cat} ne '') {
6255: $visible = 1;
6256: $matched = 1;
6257: last;
6258: }
6259: }
6260: if (!$matched) {
1.260 raeburn 6261: if ($settable{'categorize'}) {
1.256 raeburn 6262: push(@vismsgs,'chgcat');
6263: } else {
6264: push(@vismsgs,'dc_chgcat');
6265: }
6266: }
6267: }
6268: }
6269: }
6270: } else {
6271: if (ref($cathash) eq 'HASH') {
6272: if ((keys(%{$cathash}) > 1) ||
6273: (keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} eq '')) {
1.260 raeburn 6274: if ($settable{'categorize'}) {
1.256 raeburn 6275: push(@vismsgs,'addcat');
6276: } else {
6277: push(@vismsgs,'dc_addcat');
6278: }
6279: }
6280: }
6281: }
6282: if ($currsettings{'hidefromcat'} eq 'yes') {
6283: $visible = 0;
6284: if ($settable{'togglecats'}) {
6285: unshift(@vismsgs,'unhide');
6286: } else {
6287: unshift(@vismsgs,'dc_unhide')
6288: }
6289: }
1.400 raeburn 6290: return ($visible,$cansetvis,\@vismsgs);
6291: }
6292:
6293: sub cat_visibility {
6294: my %visactions = &Apache::lonlocal::texthash(
6295: vis => 'This course/community currently appears in the Course/Community Catalog for this domain.',
6296: 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.',
6297: miss => 'This course/community does not currently appear in the Course/Community Catalog for this domain.',
6298: none => 'Display of a course catalog is disabled for this domain.',
6299: yous => 'You should remedy this if you plan to allow self-enrollment, otherwise students will have difficulty finding this course.',
6300: 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.',
6301: make => 'Make any changes to self-enrollment settings below, click "Save", then take action to include the course in the Catalog:',
6302: take => 'Take the following action to ensure the course appears in the Catalog:',
6303: dc_chgconf => 'Ask a domain coordinator to change the Catalog type for this domain.',
6304: dc_setcode => 'Ask a domain coordinator to assign a six character code to the course',
6305: dc_unhide => 'Ask a domain coordinator to change the "Exclude from course catalog" setting.',
6306: dc_addinst => 'Ask a domain coordinator to enable display the catalog of "Official courses (with institutional codes)".',
6307: dc_instcode => 'Ask a domain coordinator to assign an institutional code (if this is an official course).',
6308: dc_catalog => 'Ask a domain coordinator to enable or create at least one course category in the domain.',
6309: dc_categories => 'Ask a domain coordinator to create a hierarchy of categories and sub categories for courses in the domain.',
6310: 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',
6311: dc_addcat => 'Ask a domain coordinator to assign a category to the course.',
6312: );
6313: $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>"');
6314: $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>"');
6315: $visactions{'addcat'} = &mt('Use [_1]Categorize course[_2] to assign a category to the course.','"<a href="/adm/courseprefs?phase=display&actions=courseinfo">','</a>"');
6316: return \%visactions;
1.256 raeburn 6317: }
6318:
1.241 raeburn 6319: sub new_selfenroll_dom_row {
6320: my ($newdom,$num) = @_;
6321: my $domdesc = &Apache::lonnet::domain($newdom);
6322: my $output;
6323: if ($domdesc ne '') {
6324: $output .= &Apache::loncommon::start_data_table_row()
6325: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').' <b>'.$domdesc
6326: .' ('.$newdom.')</b><input type="hidden" name="selfenroll_dom_'.$num
1.249 raeburn 6327: .'" value="'.$newdom.'" /></span><br />'
6328: .'<span class="LC_nobreak"><label><input type="checkbox" '
6329: .'name="selfenroll_activate" value="'.$num.'" '
6330: .'onchange="javascript:update_types('
6331: ."'selfenroll_activate','$num'".');" />'
6332: .&mt('Activate').'</label></span></td>';
1.241 raeburn 6333: my @currinsttypes;
6334: $output .= '<td>'.&mt('User types:').'<br />'
6335: .&selfenroll_inst_types($num,$newdom,\@currinsttypes).'</td>'
6336: .&Apache::loncommon::end_data_table_row();
6337: }
6338: return $output;
6339: }
6340:
6341: sub selfenroll_inst_types {
6342: my ($num,$currdom,$currinsttypes) = @_;
6343: my $output;
6344: my $numinrow = 4;
6345: my $count = 0;
6346: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($currdom);
1.247 raeburn 6347: my $othervalue = 'any';
1.241 raeburn 6348: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
1.251 raeburn 6349: if (keys(%{$usertypes}) > 0) {
1.247 raeburn 6350: $othervalue = 'other';
6351: }
1.241 raeburn 6352: $output .= '<table><tr>';
6353: foreach my $type (@{$types}) {
6354: if (($count > 0) && ($count%$numinrow == 0)) {
6355: $output .= '</tr><tr>';
6356: }
6357: if (defined($usertypes->{$type})) {
1.257 raeburn 6358: my $esc_type = &escape($type);
1.241 raeburn 6359: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.
1.257 raeburn 6360: $esc_type.'" ';
1.241 raeburn 6361: if (ref($currinsttypes) eq 'ARRAY') {
6362: if (@{$currinsttypes} > 0) {
1.249 raeburn 6363: if (grep(/^any$/,@{$currinsttypes})) {
6364: $output .= 'checked="checked"';
1.257 raeburn 6365: } elsif (grep(/^\Q$esc_type\E$/,@{$currinsttypes})) {
1.241 raeburn 6366: $output .= 'checked="checked"';
6367: }
1.249 raeburn 6368: } else {
6369: $output .= 'checked="checked"';
1.241 raeburn 6370: }
6371: }
6372: $output .= ' name="selfenroll_types_'.$num.'" />'.$usertypes->{$type}.'</label></span></td>';
6373: }
6374: $count ++;
6375: }
6376: if (($count > 0) && ($count%$numinrow == 0)) {
6377: $output .= '</tr><tr>';
6378: }
1.249 raeburn 6379: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.$othervalue.'"';
1.241 raeburn 6380: if (ref($currinsttypes) eq 'ARRAY') {
6381: if (@{$currinsttypes} > 0) {
1.249 raeburn 6382: if (grep(/^any$/,@{$currinsttypes})) {
6383: $output .= ' checked="checked"';
6384: } elsif ($othervalue eq 'other') {
6385: if (grep(/^\Q$othervalue\E$/,@{$currinsttypes})) {
6386: $output .= ' checked="checked"';
6387: }
1.241 raeburn 6388: }
1.249 raeburn 6389: } else {
6390: $output .= ' checked="checked"';
1.241 raeburn 6391: }
1.249 raeburn 6392: } else {
6393: $output .= ' checked="checked"';
1.241 raeburn 6394: }
6395: $output .= ' name="selfenroll_types_'.$num.'" />'.$othertitle.'</label></span></td></tr></table>';
6396: }
6397: return $output;
6398: }
6399:
1.237 raeburn 6400: sub selfenroll_date_forms {
6401: my ($startform,$endform) = @_;
6402: my $output .= &Apache::lonhtmlcommon::start_pick_box()."\n".
1.244 bisitz 6403: &Apache::lonhtmlcommon::row_title(&mt('Start date'),
1.237 raeburn 6404: 'LC_oddrow_value')."\n".
6405: $startform."\n".
6406: &Apache::lonhtmlcommon::row_closure(1).
1.244 bisitz 6407: &Apache::lonhtmlcommon::row_title(&mt('End date'),
1.237 raeburn 6408: 'LC_oddrow_value')."\n".
6409: $endform."\n".
6410: &Apache::lonhtmlcommon::row_closure(1).
6411: &Apache::lonhtmlcommon::end_pick_box();
6412: return $output;
6413: }
6414:
1.239 raeburn 6415: sub print_userchangelogs_display {
1.406.2.5! raeburn 6416: my ($r,$context,$permission,$brcrum) = @_;
1.363 raeburn 6417: my $formname = 'rolelog';
6418: my ($username,$domain,$crstype,%roleslog);
6419: if ($context eq 'domain') {
6420: $domain = $env{'request.role.domain'};
6421: %roleslog=&Apache::lonnet::dump_dom('nohist_rolelog',$domain);
6422: } else {
6423: if ($context eq 'course') {
6424: $domain = $env{'course.'.$env{'request.course.id'}.'.domain'};
6425: $username = $env{'course.'.$env{'request.course.id'}.'.num'};
6426: $crstype = &Apache::loncommon::course_type();
6427: my %saveable_parameters = ('show' => 'scalar',);
6428: &Apache::loncommon::store_course_settings('roles_log',
6429: \%saveable_parameters);
6430: &Apache::loncommon::restore_course_settings('roles_log',
6431: \%saveable_parameters);
6432: } elsif ($context eq 'author') {
6433: $domain = $env{'user.domain'};
6434: if ($env{'request.role'} =~ m{^au\./\Q$domain\E/$}) {
6435: $username = $env{'user.name'};
6436: } else {
6437: undef($domain);
6438: }
6439: }
6440: if ($domain ne '' && $username ne '') {
6441: %roleslog=&Apache::lonnet::dump('nohist_rolelog',$domain,$username);
6442: }
6443: }
1.239 raeburn 6444: if ((keys(%roleslog))[0]=~/^error\:/) { undef(%roleslog); }
6445:
1.406.2.5! raeburn 6446: my $helpitem;
! 6447: if ($context eq 'course') {
! 6448: $helpitem = 'Course_User_Logs';
! 6449: }
! 6450: push (@{$brcrum},
! 6451: {href => '/adm/createuser?action=changelogs',
! 6452: text => 'User Management Logs',
! 6453: help => $helpitem});
! 6454: my $bread_crumbs_component = 'User Changes';
! 6455: my $args = { bread_crumbs => $brcrum,
! 6456: bread_crumbs_component => $bread_crumbs_component};
! 6457:
! 6458: # Create navigation javascript
! 6459: my $jsnav = &userlogdisplay_js($formname);
! 6460:
! 6461: my $jscript = (<<ENDSCRIPT);
! 6462: <script type="text/javascript">
! 6463: // <![CDATA[
! 6464: $jsnav
! 6465: // ]]>
! 6466: </script>
! 6467: ENDSCRIPT
! 6468:
! 6469: # print page header
! 6470: $r->print(&header($jscript,$args));
! 6471:
1.239 raeburn 6472: # set defaults
6473: my $now = time();
6474: my $defstart = $now - (7*24*3600); #7 days ago
6475: my %defaults = (
6476: page => '1',
6477: show => '10',
6478: role => 'any',
6479: chgcontext => 'any',
6480: rolelog_start_date => $defstart,
6481: rolelog_end_date => $now,
6482: );
6483: my $more_records = 0;
6484:
6485: # set current
6486: my %curr;
6487: foreach my $item ('show','page','role','chgcontext') {
6488: $curr{$item} = $env{'form.'.$item};
6489: }
6490: my ($startdate,$enddate) =
6491: &Apache::lonuserutils::get_dates_from_form('rolelog_start_date','rolelog_end_date');
6492: $curr{'rolelog_start_date'} = $startdate;
6493: $curr{'rolelog_end_date'} = $enddate;
6494: foreach my $key (keys(%defaults)) {
6495: if ($curr{$key} eq '') {
6496: $curr{$key} = $defaults{$key};
6497: }
6498: }
1.248 raeburn 6499: my (%whodunit,%changed,$version);
6500: ($version) = ($r->dir_config('lonVersion') =~ /^([\d\.]+)\-/);
1.239 raeburn 6501: my ($minshown,$maxshown);
1.255 raeburn 6502: $minshown = 1;
1.239 raeburn 6503: my $count = 0;
1.406.2.5! raeburn 6504: if ($curr{'show'} =~ /\D/) {
! 6505: $curr{'page'} = 1;
! 6506: } else {
1.239 raeburn 6507: $maxshown = $curr{'page'} * $curr{'show'};
6508: if ($curr{'page'} > 1) {
6509: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
6510: }
6511: }
1.301 bisitz 6512:
1.327 raeburn 6513: # Form Header
6514: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
1.363 raeburn 6515: &role_display_filter($context,$formname,$domain,$username,\%curr,
6516: $version,$crstype));
1.327 raeburn 6517:
6518: my $showntableheader = 0;
6519:
6520: # Table Header
6521: my $tableheader =
6522: &Apache::loncommon::start_data_table_header_row()
6523: .'<th> </th>'
6524: .'<th>'.&mt('When').'</th>'
6525: .'<th>'.&mt('Who made the change').'</th>'
6526: .'<th>'.&mt('Changed User').'</th>'
1.363 raeburn 6527: .'<th>'.&mt('Role').'</th>';
6528:
6529: if ($context eq 'course') {
6530: $tableheader .= '<th>'.&mt('Section').'</th>';
6531: }
6532: $tableheader .=
6533: '<th>'.&mt('Context').'</th>'
1.327 raeburn 6534: .'<th>'.&mt('Start').'</th>'
6535: .'<th>'.&mt('End').'</th>'
6536: .&Apache::loncommon::end_data_table_header_row();
6537:
6538: # Display user change log data
1.239 raeburn 6539: foreach my $id (sort { $roleslog{$b}{'exe_time'}<=>$roleslog{$a}{'exe_time'} } (keys(%roleslog))) {
6540: next if (($roleslog{$id}{'exe_time'} < $curr{'rolelog_start_date'}) ||
6541: ($roleslog{$id}{'exe_time'} > $curr{'rolelog_end_date'}));
1.406.2.5! raeburn 6542: if ($curr{'show'} !~ /\D/) {
1.239 raeburn 6543: if ($count >= $curr{'page'} * $curr{'show'}) {
6544: $more_records = 1;
6545: last;
6546: }
6547: }
6548: if ($curr{'role'} ne 'any') {
6549: next if ($roleslog{$id}{'logentry'}{'role'} ne $curr{'role'});
6550: }
6551: if ($curr{'chgcontext'} ne 'any') {
6552: if ($curr{'chgcontext'} eq 'selfenroll') {
6553: next if (!$roleslog{$id}{'logentry'}{'selfenroll'});
6554: } else {
6555: next if ($roleslog{$id}{'logentry'}{'context'} ne $curr{'chgcontext'});
6556: }
6557: }
6558: $count ++;
6559: next if ($count < $minshown);
1.327 raeburn 6560: unless ($showntableheader) {
1.406.2.5! raeburn 6561: $r->print(&Apache::loncommon::start_data_table()
1.327 raeburn 6562: .$tableheader);
6563: $r->rflush();
6564: $showntableheader = 1;
6565: }
1.239 raeburn 6566: if ($whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} eq '') {
6567: $whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} =
6568: &Apache::loncommon::plainname($roleslog{$id}{'exe_uname'},$roleslog{$id}{'exe_udom'});
6569: }
6570: if ($changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} eq '') {
6571: $changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} =
6572: &Apache::loncommon::plainname($roleslog{$id}{'uname'},$roleslog{$id}{'udom'});
6573: }
6574: my $sec = $roleslog{$id}{'logentry'}{'section'};
6575: if ($sec eq '') {
6576: $sec = &mt('None');
6577: }
6578: my ($rolestart,$roleend);
6579: if ($roleslog{$id}{'delflag'}) {
6580: $rolestart = &mt('deleted');
6581: $roleend = &mt('deleted');
6582: } else {
6583: $rolestart = $roleslog{$id}{'logentry'}{'start'};
6584: $roleend = $roleslog{$id}{'logentry'}{'end'};
6585: if ($rolestart eq '' || $rolestart == 0) {
6586: $rolestart = &mt('No start date');
6587: } else {
6588: $rolestart = &Apache::lonlocal::locallocaltime($rolestart);
6589: }
6590: if ($roleend eq '' || $roleend == 0) {
6591: $roleend = &mt('No end date');
6592: } else {
6593: $roleend = &Apache::lonlocal::locallocaltime($roleend);
6594: }
6595: }
6596: my $chgcontext = $roleslog{$id}{'logentry'}{'context'};
6597: if ($roleslog{$id}{'logentry'}{'selfenroll'}) {
6598: $chgcontext = 'selfenroll';
6599: }
1.363 raeburn 6600: my %lt = &rolechg_contexts($context,$crstype);
1.239 raeburn 6601: if ($chgcontext ne '' && $lt{$chgcontext} ne '') {
6602: $chgcontext = $lt{$chgcontext};
6603: }
1.327 raeburn 6604: $r->print(
1.301 bisitz 6605: &Apache::loncommon::start_data_table_row()
6606: .'<td>'.$count.'</td>'
6607: .'<td>'.&Apache::lonlocal::locallocaltime($roleslog{$id}{'exe_time'}).'</td>'
6608: .'<td>'.$whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}}.'</td>'
6609: .'<td>'.$changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}}.'</td>'
1.363 raeburn 6610: .'<td>'.&Apache::lonnet::plaintext($roleslog{$id}{'logentry'}{'role'},$crstype).'</td>');
6611: if ($context eq 'course') {
6612: $r->print('<td>'.$sec.'</td>');
6613: }
6614: $r->print(
6615: '<td>'.$chgcontext.'</td>'
1.301 bisitz 6616: .'<td>'.$rolestart.'</td>'
6617: .'<td>'.$roleend.'</td>'
1.327 raeburn 6618: .&Apache::loncommon::end_data_table_row()."\n");
1.301 bisitz 6619: }
6620:
1.327 raeburn 6621: if ($showntableheader) { # Table footer, if content displayed above
1.406.2.5! raeburn 6622: $r->print(&Apache::loncommon::end_data_table().
! 6623: &userlogdisplay_navlinks(\%curr,$more_records));
1.327 raeburn 6624: } else { # No content displayed above
1.301 bisitz 6625: $r->print('<p class="LC_info">'
6626: .&mt('There are no records to display.')
6627: .'</p>'
6628: );
1.239 raeburn 6629: }
1.301 bisitz 6630:
1.327 raeburn 6631: # Form Footer
6632: $r->print(
6633: '<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
6634: .'<input type="hidden" name="action" value="changelogs" />'
6635: .'</form>');
6636: return;
6637: }
1.301 bisitz 6638:
1.406.2.5! raeburn 6639: sub print_useraccesslogs_display {
! 6640: my ($r,$uname,$udom,$permission,$brcrum) = @_;
! 6641: my $formname = 'accesslog';
! 6642: my $form = 'document.accesslog';
! 6643:
! 6644: # set breadcrumbs
! 6645: my %breadcrumb_text = &singleuser_breadcrumb();
! 6646: push (@{$brcrum},
! 6647: {href => "javascript:backPage($form)",
! 6648: text => $breadcrumb_text{'search'}});
! 6649: my (@prevphases,$prevphasestr);
! 6650: if ($env{'form.prevphases'}) {
! 6651: @prevphases = split(/,/,$env{'form.prevphases'});
! 6652: $prevphasestr = $env{'form.prevphases'};
! 6653: }
! 6654: if (($env{'form.phase'} eq 'userpicked') || (grep(/^userpicked$/,@prevphases))) {
! 6655: push(@{$brcrum},
! 6656: {href => "javascript:backPage($form,'get_user_info','select')",
! 6657: text => $breadcrumb_text{'userpicked'}});
! 6658: if ($env{'form.phase'} eq 'userpicked') {
! 6659: $prevphasestr = 'userpicked';
! 6660: }
! 6661: }
! 6662: push(@{$brcrum},
! 6663: {href => '/adm/createuser?action=accesslogs',
! 6664: text => 'User access logs',
! 6665: help => 'User_Access_Logs'});
! 6666: my $bread_crumbs_component = 'User Access Logs';
! 6667: my $args = { bread_crumbs => $brcrum,
! 6668: bread_crumbs_component => 'User Management'};
! 6669:
! 6670: # set javascript
! 6671: my ($jsback,$elements) = &crumb_utilities();
! 6672: my $jsnav = &userlogdisplay_js($formname);
! 6673:
! 6674: my $jscript = (<<ENDSCRIPT);
1.239 raeburn 6675: <script type="text/javascript">
1.301 bisitz 6676: // <![CDATA[
1.406.2.5! raeburn 6677:
! 6678: $jsback
! 6679: $jsnav
! 6680:
! 6681: // ]]>
! 6682: </script>
! 6683:
! 6684: ENDSCRIPT
! 6685:
! 6686: # print page header
! 6687: $r->print(&header($jscript,$args));
! 6688:
! 6689: # early out unless log data can be displayed.
! 6690: unless ($permission->{'activity'}) {
! 6691: $r->print('<p class="LC_warning">'
! 6692: .&mt('You do not have rights to display user access logs.')
! 6693: .'</p>'
! 6694: .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
! 6695: return;
! 6696: }
! 6697:
! 6698: unless ($udom eq $env{'request.role.domain'}) {
! 6699: $r->print('<p class="LC_warning">'
! 6700: .&mt("User's domain must match role's domain")
! 6701: .'</p>'
! 6702: .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
! 6703: return;
! 6704: }
! 6705:
! 6706: if (($uname eq '') || ($udom eq '')) {
! 6707: $r->print('<p class="LC_warning">'
! 6708: .&mt('Invalid username or domain')
! 6709: .'</p>'
! 6710: .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
! 6711: return;
! 6712: }
! 6713:
! 6714: # set defaults
! 6715: my $now = time();
! 6716: my $defstart = $now - (7*24*3600);
! 6717: my %defaults = (
! 6718: page => '1',
! 6719: show => '10',
! 6720: activity => 'any',
! 6721: accesslog_start_date => $defstart,
! 6722: accesslog_end_date => $now,
! 6723: );
! 6724: my $more_records = 0;
! 6725:
! 6726: # set current
! 6727: my %curr;
! 6728: foreach my $item ('show','page','activity') {
! 6729: $curr{$item} = $env{'form.'.$item};
! 6730: }
! 6731: my ($startdate,$enddate) =
! 6732: &Apache::lonuserutils::get_dates_from_form('accesslog_start_date','accesslog_end_date');
! 6733: $curr{'accesslog_start_date'} = $startdate;
! 6734: $curr{'accesslog_end_date'} = $enddate;
! 6735: foreach my $key (keys(%defaults)) {
! 6736: if ($curr{$key} eq '') {
! 6737: $curr{$key} = $defaults{$key};
! 6738: }
! 6739: }
! 6740: my ($minshown,$maxshown);
! 6741: $minshown = 1;
! 6742: my $count = 0;
! 6743: if ($curr{'show'} =~ /\D/) {
! 6744: $curr{'page'} = 1;
! 6745: } else {
! 6746: $maxshown = $curr{'page'} * $curr{'show'};
! 6747: if ($curr{'page'} > 1) {
! 6748: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
! 6749: }
! 6750: }
! 6751:
! 6752: # form header
! 6753: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
! 6754: &activity_display_filter($formname,\%curr));
! 6755:
! 6756: my $showntableheader = 0;
! 6757: my ($nav_script,$nav_links);
! 6758:
! 6759: # table header
! 6760: my $tableheader =
! 6761: &Apache::loncommon::start_data_table_header_row()
! 6762: .'<th> </th>'
! 6763: .'<th>'.&mt('When').'</th>'
! 6764: .'<th>'.&mt('HostID').'</th>'
! 6765: .'<th>'.&mt('Event').'</th>'
! 6766: .'<th>'.&mt('Other data').'</th>'
! 6767: .&Apache::loncommon::end_data_table_header_row();
! 6768:
! 6769: my %filters=(
! 6770: start => $curr{'accesslog_start_date'},
! 6771: end => $curr{'accesslog_end_date'},
! 6772: action => $curr{'activity'},
! 6773: );
! 6774:
! 6775: my $reply = &Apache::lonnet::userlog_query($uname,$udom,%filters);
! 6776: unless ( ($reply =~/^timeout/) || ($reply =~/^error/) ) {
! 6777: my (%courses,%missing);
! 6778: my @results = split(/\&/,$reply);
! 6779: foreach my $item (reverse(@results)) {
! 6780: my ($timestamp,$host,$event) = split(/:/,$item);
! 6781: next unless ($event =~ /^(Log|Role)/);
! 6782: if ($curr{'show'} !~ /\D/) {
! 6783: if ($count >= $curr{'page'} * $curr{'show'}) {
! 6784: $more_records = 1;
! 6785: last;
! 6786: }
! 6787: }
! 6788: $count ++;
! 6789: next if ($count < $minshown);
! 6790: unless ($showntableheader) {
! 6791: $r->print($nav_script
! 6792: .&Apache::loncommon::start_data_table()
! 6793: .$tableheader);
! 6794: $r->rflush();
! 6795: $showntableheader = 1;
! 6796: }
! 6797: my ($shown,$extra,);
! 6798: my ($event,$data) = split(/\s+/,&unescape($event));
! 6799: if ($event eq 'Role') {
! 6800: my ($rolecode,$extent) = split(/\./,$data,2);
! 6801: next if ($extent eq '');
! 6802: my ($crstype,$desc,$info);
! 6803: if ($extent =~ m{^/($match_domain)/($match_courseid)$}) {
! 6804: my ($cdom,$cnum) = ($1,$2);
! 6805: my $cid = $cdom.'_'.$cnum;
! 6806: if (exists($courses{$cid})) {
! 6807: $crstype = $courses{$cid}{'type'};
! 6808: $desc = $courses{$cid}{'description'};
! 6809: } elsif ($missing{$cid}) {
! 6810: $crstype = 'Course';
! 6811: $desc = 'Course/Community';
! 6812: } else {
! 6813: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',$cnum,undef,undef,'.');
! 6814: if (ref($crsinfo{$cdom.'_'.$cnum}) eq 'HASH') {
! 6815: $courses{$cid} = $crsinfo{$cid};
! 6816: $crstype = $crsinfo{$cid}{'type'};
! 6817: $desc = $crsinfo{$cid}{'description'};
! 6818: } else {
! 6819: $missing{$cid} = 1;
! 6820: }
! 6821: }
! 6822: $extra = &mt($crstype).': <a href="/public/'.$cdom.'/'.$cnum.'/syllabus">'.$desc.'</a>';
! 6823: } elsif ($extent =~ m{^/($match_domain)/($match_username|$)}) {
! 6824: my ($dom,$name) = ($1,$2);
! 6825: if ($rolecode eq 'au') {
! 6826: $extra = '';
! 6827: } elsif ($rolecode =~ /^(ca|aa)$/) {
! 6828: $extra = &mt('Authoring Space: [_1]',$name.':'.$dom);
! 6829: } elsif ($rolecode =~ /^(li|dg|dh|dc|sc)$/) {
! 6830: $extra = &mt('Domain: [_1]',$dom);
! 6831: }
! 6832: }
! 6833: my $rolename;
! 6834: if ($rolecode =~ m{^cr/($match_domain)/($match_username)/(\w+)}) {
! 6835: my $role = $3;
! 6836: my $owner = "($2:$1)";
! 6837: if ($2 eq $1.'-domainconfig') {
! 6838: $owner = '(ad hoc)';
! 6839: }
! 6840: $rolename = &mt('Custom role: [_1]',$role.' '.$owner);
! 6841: } else {
! 6842: $rolename = &Apache::lonnet::plaintext($rolecode,$crstype);
! 6843: }
! 6844: $shown = &mt('Role selection: [_1]',$rolename);
! 6845: } else {
! 6846: $shown = &mt($event);
! 6847: if ($data ne '') {
! 6848: $extra = &mt('Client IP address: [_1]',$data);
! 6849: }
! 6850: }
! 6851: $r->print(
! 6852: &Apache::loncommon::start_data_table_row()
! 6853: .'<td>'.$count.'</td>'
! 6854: .'<td>'.&Apache::lonlocal::locallocaltime($timestamp).'</td>'
! 6855: .'<td>'.$host.'</td>'
! 6856: .'<td>'.$shown.'</td>'
! 6857: .'<td>'.$extra.'</td>'
! 6858: .&Apache::loncommon::end_data_table_row()."\n");
! 6859: }
! 6860: }
! 6861:
! 6862: if ($showntableheader) { # Table footer, if content displayed above
! 6863: $r->print(&Apache::loncommon::end_data_table().
! 6864: &userlogdisplay_navlinks(\%curr,$more_records));
! 6865: } else { # No content displayed above
! 6866: $r->print('<p class="LC_info">'
! 6867: .&mt('There are no records to display.')
! 6868: .'</p>');
! 6869: }
! 6870:
! 6871: # Form Footer
! 6872: $r->print(
! 6873: '<input type="hidden" name="currstate" value="" />'
! 6874: .'<input type="hidden" name="accessuname" value="'.$uname.'" />'
! 6875: .'<input type="hidden" name="accessudom" value="'.$udom.'" />'
! 6876: .'<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
! 6877: .'<input type="hidden" name="prevphases" value="'.$prevphasestr.'" />'
! 6878: .'<input type="hidden" name="phase" value="activity" />'
! 6879: .'<input type="hidden" name="action" value="accesslogs" />'
! 6880: .'<input type="hidden" name="srchdomain" value="'.$udom.'" />'
! 6881: .'<input type="hidden" name="srchby" value="'.$env{'form.srchby'}.'" />'
! 6882: .'<input type="hidden" name="srchtype" value="'.$env{'form.srchtype'}.'" />'
! 6883: .'<input type="hidden" name="srchterm" value="'.&HTML::Entities::encode($env{'form.srchterm'},'<>"&').'" />'
! 6884: .'<input type="hidden" name="srchin" value="'.$env{'form.srchin'}.'" />'
! 6885: .'</form>');
! 6886: return;
! 6887: }
! 6888:
! 6889: sub earlyout_accesslog_form {
! 6890: my ($formname,$prevphasestr,$udom) = @_;
! 6891: my $srchterm = &HTML::Entities::encode($env{'form.srchterm'},'<>"&');
! 6892: return <<"END";
! 6893: <form action="/adm/createuser" method="post" name="$formname">
! 6894: <input type="hidden" name="currstate" value="" />
! 6895: <input type="hidden" name="prevphases" value="$prevphasestr" />
! 6896: <input type="hidden" name="phase" value="activity" />
! 6897: <input type="hidden" name="action" value="accesslogs" />
! 6898: <input type="hidden" name="srchdomain" value="$udom" />
! 6899: <input type="hidden" name="srchby" value="$env{'form.srchby'}" />
! 6900: <input type="hidden" name="srchtype" value="$env{'form.srchtype'}" />
! 6901: <input type="hidden" name="srchterm" value="$srchterm" />
! 6902: <input type="hidden" name="srchin" value="$env{'form.srchin'}" />
! 6903: </form>
! 6904: END
! 6905: }
! 6906:
! 6907: sub activity_display_filter {
! 6908: my ($formname,$curr) = @_;
! 6909: my $nolink = 1;
! 6910: my $output = '<table><tr><td valign="top">'.
! 6911: '<span class="LC_nobreak"><b>'.&mt('Actions/page:').'</b></span><br />'.
! 6912: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
! 6913: (&mt('all'),5,10,20,50,100,1000,10000)).
! 6914: '</td><td> </td>';
! 6915: my $startform =
! 6916: &Apache::lonhtmlcommon::date_setter($formname,'accesslog_start_date',
! 6917: $curr->{'accesslog_start_date'},undef,
! 6918: undef,undef,undef,undef,undef,undef,$nolink);
! 6919: my $endform =
! 6920: &Apache::lonhtmlcommon::date_setter($formname,'accesslog_end_date',
! 6921: $curr->{'accesslog_end_date'},undef,
! 6922: undef,undef,undef,undef,undef,undef,$nolink);
! 6923: my %lt = &Apache::lonlocal::texthash (
! 6924: activity => 'Activity',
! 6925: Role => 'Role selection',
! 6926: log => 'Log-in or Logout',
! 6927: );
! 6928: $output .= '<td valign="top"><b>'.&mt('Window during which actions occurred:').'</b><br />'.
! 6929: '<table><tr><td>'.&mt('After:').
! 6930: '</td><td>'.$startform.'</td></tr>'.
! 6931: '<tr><td>'.&mt('Before:').'</td>'.
! 6932: '<td>'.$endform.'</td></tr></table>'.
! 6933: '</td>'.
! 6934: '<td> </td>'.
! 6935: '<td valign="top"><b>'.&mt('Activities').'</b><br />'.
! 6936: '<select name="activity"><option value="any"';
! 6937: if ($curr->{'activity'} eq 'any') {
! 6938: $output .= ' selected="selected"';
! 6939: }
! 6940: $output .= '>'.&mt('Any').'</option>'."\n";
! 6941: foreach my $activity ('Role','log') {
! 6942: my $selstr = '';
! 6943: if ($activity eq $curr->{'activity'}) {
! 6944: $selstr = ' selected="selected"';
! 6945: }
! 6946: $output .= '<option value="'.$activity.'"'.$selstr.'>'.$lt{$activity}.'</option>';
! 6947: }
! 6948: $output .= '</select></td>'.
! 6949: '</tr></table>';
! 6950: # Update Display button
! 6951: $output .= '<p>'
! 6952: .'<input type="submit" value="'.&mt('Update Display').'" />'
! 6953: .'</p>';
! 6954: return $output;
! 6955: }
! 6956:
! 6957: sub userlogdisplay_js {
! 6958: my ($formname) = @_;
! 6959: return <<"ENDSCRIPT";
! 6960:
1.239 raeburn 6961: function chgPage(caller) {
6962: if (caller == 'previous') {
6963: document.$formname.page.value --;
6964: }
6965: if (caller == 'next') {
6966: document.$formname.page.value ++;
6967: }
1.327 raeburn 6968: document.$formname.submit();
1.239 raeburn 6969: return;
6970: }
6971: ENDSCRIPT
1.406.2.5! raeburn 6972: }
! 6973:
! 6974: sub userlogdisplay_navlinks {
! 6975: my ($curr,$more_records) = @_;
! 6976: return unless(ref($curr) eq 'HASH');
! 6977: # Navigation Buttons
! 6978: my $nav_links = '<p>';
! 6979: if (($curr->{'page'} > 1) || ($more_records)) {
! 6980: if (($curr->{'page'} > 1) && ($curr->{'show'} !~ /\D/)) {
! 6981: $nav_links .= '<input type="button"'
! 6982: .' onclick="javascript:chgPage('."'previous'".');"'
! 6983: .' value="'.&mt('Previous [_1] changes',$curr->{'show'})
! 6984: .'" /> ';
! 6985: }
! 6986: if ($more_records) {
! 6987: $nav_links .= '<input type="button"'
! 6988: .' onclick="javascript:chgPage('."'next'".');"'
! 6989: .' value="'.&mt('Next [_1] changes',$curr->{'show'})
! 6990: .'" />';
1.301 bisitz 6991: }
6992: }
1.406.2.5! raeburn 6993: $nav_links .= '</p>';
! 6994: return $nav_links;
1.239 raeburn 6995: }
6996:
6997: sub role_display_filter {
1.363 raeburn 6998: my ($context,$formname,$cdom,$cnum,$curr,$version,$crstype) = @_;
6999: my $lctype;
7000: if ($context eq 'course') {
7001: $lctype = lc($crstype);
7002: }
1.239 raeburn 7003: my $nolink = 1;
7004: my $output = '<table><tr><td valign="top">'.
1.301 bisitz 7005: '<span class="LC_nobreak"><b>'.&mt('Changes/page:').'</b></span><br />'.
1.239 raeburn 7006: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
7007: (&mt('all'),5,10,20,50,100,1000,10000)).
7008: '</td><td> </td>';
7009: my $startform =
7010: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_start_date',
7011: $curr->{'rolelog_start_date'},undef,
7012: undef,undef,undef,undef,undef,undef,$nolink);
7013: my $endform =
7014: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_end_date',
7015: $curr->{'rolelog_end_date'},undef,
7016: undef,undef,undef,undef,undef,undef,$nolink);
1.363 raeburn 7017: my %lt = &rolechg_contexts($context,$crstype);
1.301 bisitz 7018: $output .= '<td valign="top"><b>'.&mt('Window during which changes occurred:').'</b><br />'.
7019: '<table><tr><td>'.&mt('After:').
7020: '</td><td>'.$startform.'</td></tr>'.
7021: '<tr><td>'.&mt('Before:').'</td>'.
7022: '<td>'.$endform.'</td></tr></table>'.
7023: '</td>'.
7024: '<td> </td>'.
1.239 raeburn 7025: '<td valign="top"><b>'.&mt('Role:').'</b><br />'.
7026: '<select name="role"><option value="any"';
7027: if ($curr->{'role'} eq 'any') {
7028: $output .= ' selected="selected"';
7029: }
7030: $output .= '>'.&mt('Any').'</option>'."\n";
1.363 raeburn 7031: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
1.239 raeburn 7032: foreach my $role (@roles) {
7033: my $plrole;
7034: if ($role eq 'cr') {
7035: $plrole = &mt('Custom Role');
7036: } else {
1.318 raeburn 7037: $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.239 raeburn 7038: }
7039: my $selstr = '';
7040: if ($role eq $curr->{'role'}) {
7041: $selstr = ' selected="selected"';
7042: }
7043: $output .= ' <option value="'.$role.'"'.$selstr.'>'.$plrole.'</option>';
7044: }
1.301 bisitz 7045: $output .= '</select></td>'.
7046: '<td> </td>'.
7047: '<td valign="top"><b>'.
1.239 raeburn 7048: &mt('Context:').'</b><br /><select name="chgcontext">';
1.363 raeburn 7049: my @posscontexts;
7050: if ($context eq 'course') {
1.376 raeburn 7051: @posscontexts = ('any','automated','updatenow','createcourse','course','domain','selfenroll','requestcourses');
1.363 raeburn 7052: } elsif ($context eq 'domain') {
7053: @posscontexts = ('any','domain','requestauthor','domconfig','server');
7054: } else {
7055: @posscontexts = ('any','author','domain');
7056: }
7057: foreach my $chgtype (@posscontexts) {
1.239 raeburn 7058: my $selstr = '';
7059: if ($curr->{'chgcontext'} eq $chgtype) {
1.301 bisitz 7060: $selstr = ' selected="selected"';
1.239 raeburn 7061: }
1.363 raeburn 7062: if ($context eq 'course') {
1.376 raeburn 7063: if (($chgtype eq 'automated') || ($chgtype eq 'updatenow')) {
1.363 raeburn 7064: next if (!&Apache::lonnet::auto_run($cnum,$cdom));
7065: }
1.239 raeburn 7066: }
7067: $output .= '<option value="'.$chgtype.'"'.$selstr.'>'.$lt{$chgtype}.'</option>'."\n";
1.248 raeburn 7068: }
1.303 bisitz 7069: $output .= '</select></td>'
7070: .'</tr></table>';
7071:
7072: # Update Display button
7073: $output .= '<p>'
7074: .'<input type="submit" value="'.&mt('Update Display').'" />'
7075: .'</p>';
7076:
7077: # Server version info
1.363 raeburn 7078: my $needsrev = '2.11.0';
7079: if ($context eq 'course') {
7080: $needsrev = '2.7.0';
7081: }
7082:
1.303 bisitz 7083: $output .= '<p class="LC_info">'
7084: .&mt('Only changes made from servers running LON-CAPA [_1] or later are displayed.'
1.363 raeburn 7085: ,$needsrev);
1.248 raeburn 7086: if ($version) {
1.303 bisitz 7087: $output .= ' '.&mt('This LON-CAPA server is version [_1]',$version);
7088: }
7089: $output .= '</p><hr />';
1.239 raeburn 7090: return $output;
7091: }
7092:
7093: sub rolechg_contexts {
1.363 raeburn 7094: my ($context,$crstype) = @_;
7095: my %lt;
7096: if ($context eq 'course') {
7097: %lt = &Apache::lonlocal::texthash (
1.239 raeburn 7098: any => 'Any',
1.376 raeburn 7099: automated => 'Automated Enrollment',
1.239 raeburn 7100: updatenow => 'Roster Update',
7101: createcourse => 'Course Creation',
7102: course => 'User Management in course',
7103: domain => 'User Management in domain',
1.313 raeburn 7104: selfenroll => 'Self-enrolled',
1.318 raeburn 7105: requestcourses => 'Course Request',
1.239 raeburn 7106: );
1.363 raeburn 7107: if ($crstype eq 'Community') {
7108: $lt{'createcourse'} = &mt('Community Creation');
7109: $lt{'course'} = &mt('User Management in community');
7110: $lt{'requestcourses'} = &mt('Community Request');
7111: }
7112: } elsif ($context eq 'domain') {
7113: %lt = &Apache::lonlocal::texthash (
7114: any => 'Any',
7115: domain => 'User Management in domain',
7116: requestauthor => 'Authoring Request',
7117: server => 'Command line script (DC role)',
7118: domconfig => 'Self-enrolled',
7119: );
7120: } else {
7121: %lt = &Apache::lonlocal::texthash (
7122: any => 'Any',
7123: domain => 'User Management in domain',
7124: author => 'User Management by author',
7125: );
7126: }
1.239 raeburn 7127: return %lt;
7128: }
7129:
1.27 matthew 7130: #-------------------------------------------------- functions for &phase_two
1.160 raeburn 7131: sub user_search_result {
1.221 raeburn 7132: my ($context,$srch) = @_;
1.160 raeburn 7133: my %allhomes;
7134: my %inst_matches;
7135: my %srch_results;
1.181 raeburn 7136: my ($response,$currstate,$forcenewuser,$dirsrchres);
1.183 raeburn 7137: $srch->{'srchterm'} =~ s/\s+/ /g;
1.176 raeburn 7138: if ($srch->{'srchby'} !~ /^(uname|lastname|lastfirst)$/) {
1.160 raeburn 7139: $response = &mt('Invalid search.');
7140: }
7141: if ($srch->{'srchin'} !~ /^(crs|dom|alc|instd)$/) {
7142: $response = &mt('Invalid search.');
7143: }
1.177 raeburn 7144: if ($srch->{'srchtype'} !~ /^(exact|contains|begins)$/) {
1.160 raeburn 7145: $response = &mt('Invalid search.');
7146: }
7147: if ($srch->{'srchterm'} eq '') {
7148: $response = &mt('You must enter a search term.');
7149: }
1.183 raeburn 7150: if ($srch->{'srchterm'} =~ /^\s+$/) {
7151: $response = &mt('Your search term must contain more than just spaces.');
7152: }
1.160 raeburn 7153: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'instd')) {
7154: if (($srch->{'srchdomain'} eq '') ||
1.163 albertel 7155: ! (&Apache::lonnet::domain($srch->{'srchdomain'}))) {
1.160 raeburn 7156: $response = &mt('You must specify a valid domain when searching in a domain or institutional directory.')
7157: }
7158: }
7159: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs') ||
7160: ($srch->{'srchin'} eq 'alc')) {
1.176 raeburn 7161: if ($srch->{'srchby'} eq 'uname') {
1.243 raeburn 7162: my $unamecheck = $srch->{'srchterm'};
7163: if ($srch->{'srchtype'} eq 'contains') {
7164: if ($unamecheck !~ /^\w/) {
7165: $unamecheck = 'a'.$unamecheck;
7166: }
7167: }
7168: if ($unamecheck !~ /^$match_username$/) {
1.176 raeburn 7169: $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
7170: }
1.160 raeburn 7171: }
7172: }
1.180 raeburn 7173: if ($response ne '') {
1.406.2.4 raeburn 7174: $response = '<span class="LC_warning">'.$response.'</span><br />';
1.180 raeburn 7175: }
1.160 raeburn 7176: if ($srch->{'srchin'} eq 'instd') {
1.406.2.3 raeburn 7177: my $instd_chk = &instdirectorysrch_check($srch);
1.160 raeburn 7178: if ($instd_chk ne 'ok') {
1.406.2.3 raeburn 7179: my $domd_chk = &domdirectorysrch_check($srch);
1.406.2.4 raeburn 7180: $response .= '<span class="LC_warning">'.$instd_chk.'</span><br />';
1.406.2.3 raeburn 7181: if ($domd_chk eq 'ok') {
1.406.2.4 raeburn 7182: $response .= &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.');
1.406.2.3 raeburn 7183: }
1.406.2.5! raeburn 7184: $response .= '<br />';
1.406.2.3 raeburn 7185: }
7186: } else {
7187: unless (($context eq 'requestcrs') && ($srch->{'srchtype'} eq 'exact')) {
7188: my $domd_chk = &domdirectorysrch_check($srch);
7189: if ($domd_chk ne 'ok') {
7190: my $instd_chk = &instdirectorysrch_check($srch);
1.406.2.4 raeburn 7191: $response .= '<span class="LC_warning">'.$domd_chk.'</span><br />';
1.406.2.3 raeburn 7192: if ($instd_chk eq 'ok') {
1.406.2.4 raeburn 7193: $response .= &mt('You may want to search in the institutional directory instead of the LON-CAPA domain.');
1.406.2.3 raeburn 7194: }
1.406.2.5! raeburn 7195: $response .= '<br />';
1.406.2.3 raeburn 7196: }
1.160 raeburn 7197: }
7198: }
7199: if ($response ne '') {
1.180 raeburn 7200: return ($currstate,$response);
1.160 raeburn 7201: }
7202: if ($srch->{'srchby'} eq 'uname') {
7203: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs')) {
7204: if ($env{'form.forcenew'}) {
7205: if ($srch->{'srchdomain'} ne $env{'request.role.domain'}) {
7206: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
7207: if ($uhome eq 'no_host') {
7208: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
1.180 raeburn 7209: my $showdom = &display_domain_info($env{'request.role.domain'});
7210: $response = &mt('New users can only be created in the domain to which your current role belongs - [_1].',$showdom);
1.160 raeburn 7211: } else {
1.179 raeburn 7212: $currstate = 'modify';
1.160 raeburn 7213: }
7214: } else {
1.179 raeburn 7215: $currstate = 'modify';
1.160 raeburn 7216: }
7217: } else {
7218: if ($srch->{'srchin'} eq 'dom') {
1.162 raeburn 7219: if ($srch->{'srchtype'} eq 'exact') {
7220: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
7221: if ($uhome eq 'no_host') {
1.179 raeburn 7222: ($currstate,$response,$forcenewuser) =
1.221 raeburn 7223: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 7224: } else {
1.179 raeburn 7225: $currstate = 'modify';
1.406.2.5! raeburn 7226: if ($env{'form.action'} eq 'accesslogs') {
! 7227: $currstate = 'activity';
! 7228: }
1.310 raeburn 7229: my $uname = $srch->{'srchterm'};
7230: my $udom = $srch->{'srchdomain'};
7231: $srch_results{$uname.':'.$udom} =
7232: { &Apache::lonnet::get('environment',
7233: ['firstname',
7234: 'lastname',
7235: 'permanentemail'],
7236: $udom,$uname)
7237: };
1.162 raeburn 7238: }
7239: } else {
7240: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 7241: ($currstate,$response,$forcenewuser) =
1.221 raeburn 7242: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 7243: }
7244: } else {
1.167 albertel 7245: my $courseusers = &get_courseusers();
1.162 raeburn 7246: if ($srch->{'srchtype'} eq 'exact') {
1.167 albertel 7247: if (exists($courseusers->{$srch->{'srchterm'}.':'.$srch->{'srchdomain'}})) {
1.179 raeburn 7248: $currstate = 'modify';
1.162 raeburn 7249: } else {
1.179 raeburn 7250: ($currstate,$response,$forcenewuser) =
1.221 raeburn 7251: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 7252: }
1.160 raeburn 7253: } else {
1.167 albertel 7254: foreach my $user (keys(%$courseusers)) {
1.162 raeburn 7255: my ($cuname,$cudomain) = split(/:/,$user);
7256: if ($cudomain eq $srch->{'srchdomain'}) {
1.177 raeburn 7257: my $matched = 0;
7258: if ($srch->{'srchtype'} eq 'begins') {
7259: if ($cuname =~ /^\Q$srch->{'srchterm'}\E/i) {
7260: $matched = 1;
7261: }
7262: } else {
7263: if ($cuname =~ /\Q$srch->{'srchterm'}\E/i) {
7264: $matched = 1;
7265: }
7266: }
7267: if ($matched) {
1.167 albertel 7268: $srch_results{$user} =
7269: {&Apache::lonnet::get('environment',
7270: ['firstname',
7271: 'lastname',
1.194 albertel 7272: 'permanentemail'],
7273: $cudomain,$cuname)};
1.162 raeburn 7274: }
7275: }
7276: }
1.179 raeburn 7277: ($currstate,$response,$forcenewuser) =
1.221 raeburn 7278: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 7279: }
7280: }
7281: }
7282: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 7283: $currstate = 'query';
1.160 raeburn 7284: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 7285: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
7286: if ($dirsrchres eq 'ok') {
7287: ($currstate,$response,$forcenewuser) =
1.221 raeburn 7288: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 7289: } else {
7290: my $showdom = &display_domain_info($srch->{'srchdomain'});
7291: $response = '<span class="LC_warning">'.
7292: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
7293: '</span><br />'.
7294: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
1.406.2.5! raeburn 7295: '<br />';
1.181 raeburn 7296: }
1.160 raeburn 7297: }
7298: } else {
7299: if ($srch->{'srchin'} eq 'dom') {
7300: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 7301: ($currstate,$response,$forcenewuser) =
1.221 raeburn 7302: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 7303: } elsif ($srch->{'srchin'} eq 'crs') {
1.167 albertel 7304: my $courseusers = &get_courseusers();
7305: foreach my $user (keys(%$courseusers)) {
1.160 raeburn 7306: my ($uname,$udom) = split(/:/,$user);
7307: my %names = &Apache::loncommon::getnames($uname,$udom);
7308: my %emails = &Apache::loncommon::getemails($uname,$udom);
7309: if ($srch->{'srchby'} eq 'lastname') {
7310: if ((($srch->{'srchtype'} eq 'exact') &&
7311: ($names{'lastname'} eq $srch->{'srchterm'})) ||
1.177 raeburn 7312: (($srch->{'srchtype'} eq 'begins') &&
7313: ($names{'lastname'} =~ /^\Q$srch->{'srchterm'}\E/i)) ||
1.160 raeburn 7314: (($srch->{'srchtype'} eq 'contains') &&
7315: ($names{'lastname'} =~ /\Q$srch->{'srchterm'}\E/i))) {
7316: $srch_results{$user} = {firstname => $names{'firstname'},
7317: lastname => $names{'lastname'},
7318: permanentemail => $emails{'permanentemail'},
7319: };
7320: }
7321: } elsif ($srch->{'srchby'} eq 'lastfirst') {
7322: my ($srchlast,$srchfirst) = split(/,/,$srch->{'srchterm'});
1.177 raeburn 7323: $srchlast =~ s/\s+$//;
7324: $srchfirst =~ s/^\s+//;
1.160 raeburn 7325: if ($srch->{'srchtype'} eq 'exact') {
7326: if (($names{'lastname'} eq $srchlast) &&
7327: ($names{'firstname'} eq $srchfirst)) {
7328: $srch_results{$user} = {firstname => $names{'firstname'},
7329: lastname => $names{'lastname'},
7330: permanentemail => $emails{'permanentemail'},
7331:
7332: };
7333: }
1.177 raeburn 7334: } elsif ($srch->{'srchtype'} eq 'begins') {
7335: if (($names{'lastname'} =~ /^\Q$srchlast\E/i) &&
7336: ($names{'firstname'} =~ /^\Q$srchfirst\E/i)) {
7337: $srch_results{$user} = {firstname => $names{'firstname'},
7338: lastname => $names{'lastname'},
7339: permanentemail => $emails{'permanentemail'},
7340: };
7341: }
7342: } else {
1.160 raeburn 7343: if (($names{'lastname'} =~ /\Q$srchlast\E/i) &&
7344: ($names{'firstname'} =~ /\Q$srchfirst\E/i)) {
7345: $srch_results{$user} = {firstname => $names{'firstname'},
7346: lastname => $names{'lastname'},
7347: permanentemail => $emails{'permanentemail'},
7348: };
7349: }
7350: }
7351: }
7352: }
1.179 raeburn 7353: ($currstate,$response,$forcenewuser) =
1.221 raeburn 7354: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 7355: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 7356: $currstate = 'query';
1.160 raeburn 7357: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 7358: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
7359: if ($dirsrchres eq 'ok') {
7360: ($currstate,$response,$forcenewuser) =
1.221 raeburn 7361: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 7362: } else {
1.406.2.5! raeburn 7363: my $showdom = &display_domain_info($srch->{'srchdomain'});
! 7364: $response = '<span class="LC_warning">'.
1.181 raeburn 7365: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
7366: '</span><br />'.
7367: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
1.406.2.5! raeburn 7368: '<br />';
1.181 raeburn 7369: }
1.160 raeburn 7370: }
7371: }
1.179 raeburn 7372: return ($currstate,$response,$forcenewuser,\%srch_results);
1.160 raeburn 7373: }
7374:
1.406.2.3 raeburn 7375: sub domdirectorysrch_check {
7376: my ($srch) = @_;
7377: my $response;
7378: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
7379: ['directorysrch'],$srch->{'srchdomain'});
7380: my $showdom = &display_domain_info($srch->{'srchdomain'});
7381: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
7382: if ($dom_inst_srch{'directorysrch'}{'lcavailable'} eq '0') {
7383: return &mt('LON-CAPA directory search is not available in domain: [_1]',$showdom);
7384: }
7385: if ($dom_inst_srch{'directorysrch'}{'lclocalonly'}) {
7386: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
7387: return &mt('LON-CAPA directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
7388: }
7389: }
7390: }
7391: return 'ok';
7392: }
7393:
7394: sub instdirectorysrch_check {
1.160 raeburn 7395: my ($srch) = @_;
7396: my $can_search = 0;
7397: my $response;
7398: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
7399: ['directorysrch'],$srch->{'srchdomain'});
1.180 raeburn 7400: my $showdom = &display_domain_info($srch->{'srchdomain'});
1.160 raeburn 7401: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
7402: if (!$dom_inst_srch{'directorysrch'}{'available'}) {
1.180 raeburn 7403: return &mt('Institutional directory search is not available in domain: [_1]',$showdom);
1.160 raeburn 7404: }
7405: if ($dom_inst_srch{'directorysrch'}{'localonly'}) {
7406: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
1.180 raeburn 7407: return &mt('Institutional directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
1.160 raeburn 7408: }
7409: my @usertypes = split(/:/,$env{'environment.inststatus'});
7410: if (!@usertypes) {
7411: push(@usertypes,'default');
7412: }
7413: if (ref($dom_inst_srch{'directorysrch'}{'cansearch'}) eq 'ARRAY') {
7414: foreach my $type (@usertypes) {
7415: if (grep(/^\Q$type\E$/,@{$dom_inst_srch{'directorysrch'}{'cansearch'}})) {
7416: $can_search = 1;
7417: last;
7418: }
7419: }
7420: }
7421: if (!$can_search) {
7422: my ($insttypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($srch->{'srchdomain'});
7423: my @longtypes;
7424: foreach my $item (@usertypes) {
1.229 raeburn 7425: if (defined($insttypes->{$item})) {
7426: push (@longtypes,$insttypes->{$item});
7427: } elsif ($item eq 'default') {
7428: push (@longtypes,&mt('other'));
7429: }
1.160 raeburn 7430: }
7431: my $insttype_str = join(', ',@longtypes);
1.180 raeburn 7432: return &mt('Institutional directory search in domain: [_1] is not available to your user type: ',$showdom).$insttype_str;
1.229 raeburn 7433: }
1.160 raeburn 7434: } else {
7435: $can_search = 1;
7436: }
7437: } else {
1.180 raeburn 7438: return &mt('Institutional directory search has not been configured for domain: [_1]',$showdom);
1.160 raeburn 7439: }
7440: my %longtext = &Apache::lonlocal::texthash (
1.167 albertel 7441: uname => 'username',
1.160 raeburn 7442: lastfirst => 'last name, first name',
1.167 albertel 7443: lastname => 'last name',
1.172 raeburn 7444: contains => 'contains',
1.178 raeburn 7445: exact => 'as exact match to',
7446: begins => 'begins with',
1.160 raeburn 7447: );
7448: if ($can_search) {
7449: if (ref($dom_inst_srch{'directorysrch'}{'searchby'}) eq 'ARRAY') {
7450: if (!grep(/^\Q$srch->{'srchby'}\E$/,@{$dom_inst_srch{'directorysrch'}{'searchby'}})) {
1.180 raeburn 7451: return &mt('Institutional directory search in domain: [_1] is not available for searching by "[_2]"',$showdom,$longtext{$srch->{'srchby'}});
1.160 raeburn 7452: }
7453: } else {
1.180 raeburn 7454: return &mt('Institutional directory search in domain: [_1] is not available.', $showdom);
1.160 raeburn 7455: }
7456: }
7457: if ($can_search) {
1.178 raeburn 7458: if (ref($dom_inst_srch{'directorysrch'}{'searchtypes'}) eq 'ARRAY') {
7459: if (grep(/^\Q$srch->{'srchtype'}\E/,@{$dom_inst_srch{'directorysrch'}{'searchtypes'}})) {
7460: return 'ok';
7461: } else {
1.180 raeburn 7462: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 7463: }
7464: } else {
7465: if ((($dom_inst_srch{'directorysrch'}{'searchtypes'} eq 'specify') &&
7466: ($srch->{'srchtype'} eq 'exact' || $srch->{'srchtype'} eq 'contains')) ||
7467: ($dom_inst_srch{'directorysrch'}{'searchtypes'} eq $srch->{'srchtype'})) {
7468: return 'ok';
7469: } else {
1.180 raeburn 7470: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 7471: }
1.160 raeburn 7472: }
7473: }
7474: }
7475:
7476: sub get_courseusers {
7477: my %advhash;
1.167 albertel 7478: my $classlist = &Apache::loncoursedata::get_classlist();
1.160 raeburn 7479: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles();
7480: foreach my $role (sort(keys(%coursepersonnel))) {
7481: foreach my $user (split(/\,/,$coursepersonnel{$role})) {
1.167 albertel 7482: if (!exists($classlist->{$user})) {
7483: $classlist->{$user} = [];
7484: }
1.160 raeburn 7485: }
7486: }
1.167 albertel 7487: return $classlist;
1.160 raeburn 7488: }
7489:
7490: sub build_search_response {
1.221 raeburn 7491: my ($context,$srch,%srch_results) = @_;
1.179 raeburn 7492: my ($currstate,$response,$forcenewuser);
1.160 raeburn 7493: my %names = (
1.330 bisitz 7494: 'uname' => 'username',
7495: 'lastname' => 'last name',
1.160 raeburn 7496: 'lastfirst' => 'last name, first name',
1.330 bisitz 7497: 'crs' => 'this course',
7498: 'dom' => 'LON-CAPA domain',
7499: 'instd' => 'the institutional directory for domain',
1.160 raeburn 7500: );
7501:
7502: my %single = (
1.180 raeburn 7503: begins => 'A match',
1.160 raeburn 7504: contains => 'A match',
1.180 raeburn 7505: exact => 'An exact match',
1.160 raeburn 7506: );
7507: my %nomatch = (
1.180 raeburn 7508: begins => 'No match',
1.160 raeburn 7509: contains => 'No match',
1.180 raeburn 7510: exact => 'No exact match',
1.160 raeburn 7511: );
7512: if (keys(%srch_results) > 1) {
1.179 raeburn 7513: $currstate = 'select';
1.160 raeburn 7514: } else {
7515: if (keys(%srch_results) == 1) {
1.406.2.5! raeburn 7516: if ($env{'form.action'} eq 'accesslogs') {
! 7517: $currstate = 'activity';
! 7518: } else {
! 7519: $currstate = 'modify';
! 7520: }
1.180 raeburn 7521: $response = &mt("$single{$srch->{'srchtype'}} was found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}.",$srch->{'srchterm'});
7522: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 7523: $response .= ': '.&display_domain_info($srch->{'srchdomain'});
1.180 raeburn 7524: }
1.330 bisitz 7525: } else { # Search has nothing found. Prepare message to user.
7526: $response = '<span class="LC_warning">';
1.180 raeburn 7527: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 7528: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}: [_2]",
7529: '<b>'.$srch->{'srchterm'}.'</b>',
7530: &display_domain_info($srch->{'srchdomain'}));
7531: } else {
7532: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}.",
7533: '<b>'.$srch->{'srchterm'}.'</b>');
1.180 raeburn 7534: }
7535: $response .= '</span>';
1.330 bisitz 7536:
1.160 raeburn 7537: if ($srch->{'srchin'} ne 'alc') {
7538: $forcenewuser = 1;
7539: my $cansrchinst = 0;
7540: if ($srch->{'srchdomain'}) {
7541: my %domconfig = &Apache::lonnet::get_dom('configuration',['directorysrch'],$srch->{'srchdomain'});
7542: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
7543: if ($domconfig{'directorysrch'}{'available'}) {
7544: $cansrchinst = 1;
7545: }
7546: }
7547: }
1.180 raeburn 7548: if ((($srch->{'srchby'} eq 'lastfirst') ||
7549: ($srch->{'srchby'} eq 'lastname')) &&
7550: ($srch->{'srchin'} eq 'dom')) {
7551: if ($cansrchinst) {
7552: $response .= '<br />'.&mt('You may want to broaden your search to a search of the institutional directory for the domain.');
1.160 raeburn 7553: }
7554: }
1.180 raeburn 7555: if ($srch->{'srchin'} eq 'crs') {
7556: $response .= '<br />'.&mt('You may want to broaden your search to the selected LON-CAPA domain.');
7557: }
7558: }
1.305 raeburn 7559: my $createdom = $env{'request.role.domain'};
7560: if ($context eq 'requestcrs') {
7561: if ($env{'form.coursedom'} ne '') {
7562: $createdom = $env{'form.coursedom'};
7563: }
7564: }
1.406.2.5! raeburn 7565: unless (($env{'form.action'} eq 'accesslogs') || (($srch->{'srchby'} eq 'uname') && ($srch->{'srchin'} eq 'dom') &&
! 7566: ($srch->{'srchtype'} eq 'exact') && ($srch->{'srchdomain'} eq $createdom))) {
1.221 raeburn 7567: my $cancreate =
1.305 raeburn 7568: &Apache::lonuserutils::can_create_user($createdom,$context);
7569: my $targetdom = '<span class="LC_cusr_emph">'.$createdom.'</span>';
1.221 raeburn 7570: if ($cancreate) {
1.305 raeburn 7571: my $showdom = &display_domain_info($createdom);
1.266 bisitz 7572: $response .= '<br /><br />'
7573: .'<b>'.&mt('To add a new user:').'</b>'
1.305 raeburn 7574: .'<br />';
7575: if ($context eq 'requestcrs') {
7576: $response .= &mt("(You can only define new users in the new course's domain - [_1])",$targetdom);
7577: } else {
7578: $response .= &mt("(You can only create new users in your current role's domain - [_1])",$targetdom);
7579: }
7580: $response .='<ul><li>'
1.266 bisitz 7581: .&mt("Set 'Domain/institution to search' to: [_1]",'<span class="LC_cusr_emph">'.$showdom.'</span>')
7582: .'</li><li>'
7583: .&mt("Set 'Search criteria' to: [_1]username is ..... in selected LON-CAPA domain[_2]",'<span class="LC_cusr_emph">','</span>')
7584: .'</li><li>'
7585: .&mt('Provide the proposed username')
7586: .'</li><li>'
7587: .&mt("Click 'Search'")
7588: .'</li></ul><br />';
1.221 raeburn 7589: } else {
7590: my $helplink = ' href="javascript:helpMenu('."'display'".')"';
1.305 raeburn 7591: $response .= '<br /><br />';
7592: if ($context eq 'requestcrs') {
1.314 raeburn 7593: $response .= &mt("You are not authorized to define new users in the new course's domain - [_1].",$targetdom);
1.305 raeburn 7594: } else {
7595: $response .= &mt("You are not authorized to create new users in your current role's domain - [_1].",$targetdom);
7596: }
7597: $response .= '<br />'
7598: .&mt('Please contact the [_1]helpdesk[_2] if you need to create a new user.'
1.266 bisitz 7599: ,' <a'.$helplink.'>'
7600: ,'</a>')
1.406.2.5! raeburn 7601: .'<br />';
1.221 raeburn 7602: }
1.160 raeburn 7603: }
7604: }
7605: }
1.179 raeburn 7606: return ($currstate,$response,$forcenewuser);
1.160 raeburn 7607: }
7608:
1.180 raeburn 7609: sub display_domain_info {
7610: my ($dom) = @_;
7611: my $output = $dom;
7612: if ($dom ne '') {
7613: my $domdesc = &Apache::lonnet::domain($dom,'description');
7614: if ($domdesc ne '') {
7615: $output .= ' <span class="LC_cusr_emph">('.$domdesc.')</span>';
7616: }
7617: }
7618: return $output;
7619: }
7620:
1.160 raeburn 7621: sub crumb_utilities {
7622: my %elements = (
7623: crtuser => {
7624: srchterm => 'text',
1.172 raeburn 7625: srchin => 'selectbox',
1.160 raeburn 7626: srchby => 'selectbox',
7627: srchtype => 'selectbox',
7628: srchdomain => 'selectbox',
7629: },
1.207 raeburn 7630: crtusername => {
7631: srchterm => 'text',
7632: srchdomain => 'selectbox',
7633: },
1.160 raeburn 7634: docustom => {
7635: rolename => 'selectbox',
7636: newrolename => 'textbox',
7637: },
1.179 raeburn 7638: studentform => {
7639: srchterm => 'text',
7640: srchin => 'selectbox',
7641: srchby => 'selectbox',
7642: srchtype => 'selectbox',
7643: srchdomain => 'selectbox',
7644: },
1.160 raeburn 7645: );
7646:
7647: my $jsback .= qq|
7648: function backPage(formname,prevphase,prevstate) {
1.211 raeburn 7649: if (typeof prevphase == 'undefined') {
7650: formname.phase.value = '';
7651: }
7652: else {
7653: formname.phase.value = prevphase;
7654: }
7655: if (typeof prevstate == 'undefined') {
7656: formname.currstate.value = '';
7657: }
7658: else {
7659: formname.currstate.value = prevstate;
7660: }
1.160 raeburn 7661: formname.submit();
7662: }
7663: |;
7664: return ($jsback,\%elements);
7665: }
7666:
1.26 matthew 7667: sub course_level_table {
1.375 raeburn 7668: my ($inccourses,$showcredits,$defaultcredits) = @_;
7669: return unless (ref($inccourses) eq 'HASH');
1.26 matthew 7670: my $table = '';
1.62 www 7671: # Custom Roles?
7672:
1.190 raeburn 7673: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.89 raeburn 7674: my %lt=&Apache::lonlocal::texthash(
7675: 'exs' => "Existing sections",
7676: 'new' => "Define new section",
7677: 'ssd' => "Set Start Date",
7678: 'sed' => "Set End Date",
1.131 raeburn 7679: 'crl' => "Course Level",
1.89 raeburn 7680: 'act' => "Activate",
7681: 'rol' => "Role",
7682: 'ext' => "Extent",
1.113 raeburn 7683: 'grs' => "Section",
1.375 raeburn 7684: 'crd' => "Credits",
1.89 raeburn 7685: 'sta' => "Start",
7686: 'end' => "End"
7687: );
1.62 www 7688:
1.375 raeburn 7689: foreach my $protectedcourse (sort(keys(%{$inccourses}))) {
1.135 raeburn 7690: my $thiscourse=$protectedcourse;
1.26 matthew 7691: $thiscourse=~s:_:/:g;
7692: my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
1.365 raeburn 7693: my $isowner = &Apache::lonuserutils::is_courseowner($protectedcourse,$coursedata{'internal.courseowner'});
1.26 matthew 7694: my $area=$coursedata{'description'};
1.321 raeburn 7695: my $crstype=$coursedata{'type'};
1.135 raeburn 7696: if (!defined($area)) { $area=&mt('Unavailable course').': '.$protectedcourse; }
1.89 raeburn 7697: my ($domain,$cnum)=split(/\//,$thiscourse);
1.115 albertel 7698: my %sections_count;
1.101 albertel 7699: if (defined($env{'request.course.id'})) {
7700: if ($env{'request.course.id'} eq $domain.'_'.$cnum) {
1.115 albertel 7701: %sections_count =
7702: &Apache::loncommon::get_sections($domain,$cnum);
1.92 raeburn 7703: }
7704: }
1.321 raeburn 7705: my @roles = &Apache::lonuserutils::roles_by_context('course','',$crstype);
1.213 raeburn 7706: foreach my $role (@roles) {
1.321 raeburn 7707: my $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.329 raeburn 7708: if ((&Apache::lonnet::allowed('c'.$role,$thiscourse)) ||
7709: ((($role eq 'cc') || ($role eq 'co')) && ($isowner))) {
1.221 raeburn 7710: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 7711: $plrole,\%sections_count,\%lt,
1.402 raeburn 7712: $showcredits,$defaultcredits,$crstype);
1.221 raeburn 7713: } elsif ($env{'request.course.sec'} ne '') {
7714: if (&Apache::lonnet::allowed('c'.$role,$thiscourse.'/'.
7715: $env{'request.course.sec'})) {
7716: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 7717: $plrole,\%sections_count,\%lt,
1.402 raeburn 7718: $showcredits,$defaultcredits,$crstype);
1.26 matthew 7719: }
7720: }
7721: }
1.221 raeburn 7722: if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
1.324 raeburn 7723: foreach my $cust (sort(keys(%customroles))) {
7724: next if ($crstype eq 'Community' && $customroles{$cust} =~ /bre\&S/);
1.221 raeburn 7725: my $role = 'cr_cr_'.$env{'user.domain'}.'_'.$env{'user.name'}.'_'.$cust;
7726: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.402 raeburn 7727: $cust,\%sections_count,\%lt,
7728: $showcredits,$defaultcredits,$crstype);
1.221 raeburn 7729: }
1.62 www 7730: }
1.26 matthew 7731: }
7732: return '' if ($table eq ''); # return nothing if there is nothing
7733: # in the table
1.188 raeburn 7734: my $result;
7735: if (!$env{'request.course.id'}) {
7736: $result = '<h4>'.$lt{'crl'}.'</h4>'."\n";
7737: }
7738: $result .=
1.136 raeburn 7739: &Apache::loncommon::start_data_table().
7740: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 7741: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
1.402 raeburn 7742: '<th>'.$lt{'ext'}.'</th><th>'."\n";
7743: if ($showcredits) {
7744: $result .= $lt{'crd'}.'</th>';
7745: }
7746: $result .=
1.375 raeburn 7747: '<th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th>'."\n".
7748: '<th>'.$lt{'end'}.'</th>'.
1.136 raeburn 7749: &Apache::loncommon::end_data_table_header_row().
7750: $table.
7751: &Apache::loncommon::end_data_table();
1.26 matthew 7752: return $result;
7753: }
1.88 raeburn 7754:
1.221 raeburn 7755: sub course_level_row {
1.375 raeburn 7756: my ($protectedcourse,$role,$area,$domain,$plrole,$sections_count,
1.402 raeburn 7757: $lt,$showcredits,$defaultcredits,$crstype) = @_;
1.375 raeburn 7758: my $creditem;
1.222 raeburn 7759: my $row = &Apache::loncommon::start_data_table_row().
7760: ' <td><input type="checkbox" name="act_'.
7761: $protectedcourse.'_'.$role.'" /></td>'."\n".
7762: ' <td>'.$plrole.'</td>'."\n".
7763: ' <td>'.$area.'<br />Domain: '.$domain.'</td>'."\n";
1.402 raeburn 7764: if (($showcredits) && ($role eq 'st') && ($crstype eq 'Course')) {
1.375 raeburn 7765: $row .=
7766: '<td><input type="text" name="credits_'.$protectedcourse.'_'.
7767: $role.'" size="3" value="'.$defaultcredits.'" /></td>';
7768: } else {
7769: $row .= '<td> </td>';
7770: }
1.322 raeburn 7771: if (($role eq 'cc') || ($role eq 'co')) {
1.222 raeburn 7772: $row .= '<td> </td>';
1.221 raeburn 7773: } elsif ($env{'request.course.sec'} ne '') {
1.222 raeburn 7774: $row .= ' <td><input type="hidden" value="'.
7775: $env{'request.course.sec'}.'" '.
7776: 'name="sec_'.$protectedcourse.'_'.$role.'" />'.
7777: $env{'request.course.sec'}.'</td>';
1.221 raeburn 7778: } else {
7779: if (ref($sections_count) eq 'HASH') {
7780: my $currsec =
7781: &Apache::lonuserutils::course_sections($sections_count,
7782: $protectedcourse.'_'.$role);
1.222 raeburn 7783: $row .= '<td><table class="LC_createuser">'."\n".
7784: '<tr class="LC_section_row">'."\n".
7785: ' <td valign="top">'.$lt->{'exs'}.'<br />'.
7786: $currsec.'</td>'."\n".
7787: ' <td> </td>'."\n".
7788: ' <td valign="top"> '.$lt->{'new'}.'<br />'.
1.221 raeburn 7789: '<input type="text" name="newsec_'.$protectedcourse.'_'.$role.
7790: '" value="" />'.
7791: '<input type="hidden" '.
7792: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n".
1.222 raeburn 7793: '</tr></table></td>'."\n";
1.221 raeburn 7794: } else {
1.222 raeburn 7795: $row .= '<td><input type="text" size="10" '.
1.375 raeburn 7796: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n";
1.221 raeburn 7797: }
7798: }
1.222 raeburn 7799: $row .= <<ENDTIMEENTRY;
7800: <td><input type="hidden" name="start_$protectedcourse\_$role" value="" />
1.221 raeburn 7801: <a href=
7802: "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 7803: <td><input type="hidden" name="end_$protectedcourse\_$role" value="" />
1.221 raeburn 7804: <a href=
7805: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$role.value,'end_$protectedcourse\_$role','cu.pres','dateset')">$lt->{'sed'}</a></td>
7806: ENDTIMEENTRY
1.222 raeburn 7807: $row .= &Apache::loncommon::end_data_table_row();
7808: return $row;
1.221 raeburn 7809: }
7810:
1.88 raeburn 7811: sub course_level_dc {
1.375 raeburn 7812: my ($dcdom,$showcredits) = @_;
1.190 raeburn 7813: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.213 raeburn 7814: my @roles = &Apache::lonuserutils::roles_by_context('course');
1.88 raeburn 7815: my $hiddenitems = '<input type="hidden" name="dcdomain" value="'.$dcdom.'" />'.
7816: '<input type="hidden" name="origdom" value="'.$dcdom.'" />'.
1.133 raeburn 7817: '<input type="hidden" name="dccourse" value="" />';
1.355 www 7818: my $courseform=&Apache::loncommon::selectcourse_link
1.356 raeburn 7819: ('cu','dccourse','dcdomain','coursedesc',undef,undef,'Select','crstype');
1.375 raeburn 7820: my $credit_elem;
7821: if ($showcredits) {
7822: $credit_elem = 'credits';
7823: }
7824: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,'currsec','cu','role','Course/Community Browser',$credit_elem);
1.88 raeburn 7825: my %lt=&Apache::lonlocal::texthash(
7826: 'rol' => "Role",
1.113 raeburn 7827: 'grs' => "Section",
1.88 raeburn 7828: 'exs' => "Existing sections",
7829: 'new' => "Define new section",
7830: 'sta' => "Start",
7831: 'end' => "End",
7832: 'ssd' => "Set Start Date",
1.355 www 7833: 'sed' => "Set End Date",
1.375 raeburn 7834: 'scc' => "Course/Community",
7835: 'crd' => "Credits",
1.88 raeburn 7836: );
1.323 raeburn 7837: my $header = '<h4>'.&mt('Course/Community Level').'</h4>'.
1.136 raeburn 7838: &Apache::loncommon::start_data_table().
7839: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 7840: '<th>'.$lt{'scc'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
1.397 bisitz 7841: '<th>'.$lt{'grs'}.'</th>'."\n";
7842: $header .= '<th>'.$lt{'crd'}.'</th>'."\n" if ($showcredits);
7843: $header .= '<th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'."\n".
1.136 raeburn 7844: &Apache::loncommon::end_data_table_header_row();
1.143 raeburn 7845: my $otheritems = &Apache::loncommon::start_data_table_row()."\n".
1.356 raeburn 7846: '<td><br /><span class="LC_nobreak"><input type="text" name="coursedesc" value="" onfocus="this.blur();opencrsbrowser('."'cu','dccourse','dcdomain','coursedesc','','','','crstype'".')" />'.
7847: $courseform.(' ' x4).'</span></td>'."\n".
1.389 bisitz 7848: '<td valign="top"><br /><select name="role">'."\n";
1.213 raeburn 7849: foreach my $role (@roles) {
1.135 raeburn 7850: my $plrole=&Apache::lonnet::plaintext($role);
1.389 bisitz 7851: $otheritems .= ' <option value="'.$role.'">'.$plrole.'</option>';
1.88 raeburn 7852: }
1.404 raeburn 7853: if ( keys(%customroles) > 0) {
7854: foreach my $cust (sort(keys(%customroles))) {
1.101 albertel 7855: my $custrole='cr_cr_'.$env{'user.domain'}.
1.135 raeburn 7856: '_'.$env{'user.name'}.'_'.$cust;
1.389 bisitz 7857: $otheritems .= ' <option value="'.$custrole.'">'.$cust.'</option>';
1.88 raeburn 7858: }
7859: }
7860: $otheritems .= '</select></td><td>'.
7861: '<table border="0" cellspacing="0" cellpadding="0">'.
7862: '<tr><td valign="top"><b>'.$lt{'exs'}.'</b><br /><select name="currsec">'.
1.389 bisitz 7863: ' <option value=""><--'.&mt('Pick course first').'</option></select></td>'.
1.88 raeburn 7864: '<td> </td>'.
7865: '<td valign="top"> <b>'.$lt{'new'}.'</b><br />'.
1.113 raeburn 7866: '<input type="text" name="newsec" value="" />'.
1.237 raeburn 7867: '<input type="hidden" name="section" value="" />'.
1.323 raeburn 7868: '<input type="hidden" name="groups" value="" />'.
7869: '<input type="hidden" name="crstype" value="" /></td>'.
1.375 raeburn 7870: '</tr></table></td>'."\n";
7871: if ($showcredits) {
7872: $otheritems .= '<td><br />'."\n".
1.397 bisitz 7873: '<input type="text" size="3" name="credits" value="" /></td>'."\n";
1.375 raeburn 7874: }
1.88 raeburn 7875: $otheritems .= <<ENDTIMEENTRY;
1.323 raeburn 7876: <td><br /><input type="hidden" name="start" value='' />
1.88 raeburn 7877: <a href=
7878: "javascript:pjump('date_start','Start Date',document.cu.start.value,'start','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.323 raeburn 7879: <td><br /><input type="hidden" name="end" value='' />
1.88 raeburn 7880: <a href=
7881: "javascript:pjump('date_end','End Date',document.cu.end.value,'end','cu.pres','dateset')">$lt{'sed'}</a></td>
7882: ENDTIMEENTRY
1.136 raeburn 7883: $otheritems .= &Apache::loncommon::end_data_table_row().
7884: &Apache::loncommon::end_data_table()."\n";
1.88 raeburn 7885: return $cb_jscript.$header.$hiddenitems.$otheritems;
7886: }
7887:
1.237 raeburn 7888: sub update_selfenroll_config {
1.400 raeburn 7889: my ($r,$cid,$cdom,$cnum,$context,$crstype,$currsettings) = @_;
1.398 raeburn 7890: return unless (ref($currsettings) eq 'HASH');
7891: my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles();
7892: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
1.237 raeburn 7893: my (%changes,%warning);
1.241 raeburn 7894: my $curr_types;
1.400 raeburn 7895: my %noedit;
7896: unless ($context eq 'domain') {
7897: %noedit = &get_noedit_fields($cdom,$cnum,$crstype,$row);
7898: }
1.237 raeburn 7899: if (ref($row) eq 'ARRAY') {
7900: foreach my $item (@{$row}) {
1.400 raeburn 7901: next if ($noedit{$item});
1.237 raeburn 7902: if ($item eq 'enroll_dates') {
7903: my (%currenrolldate,%newenrolldate);
7904: foreach my $type ('start','end') {
1.398 raeburn 7905: $currenrolldate{$type} = $currsettings->{'selfenroll_'.$type.'_date'};
1.237 raeburn 7906: $newenrolldate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_date');
7907: if ($newenrolldate{$type} ne $currenrolldate{$type}) {
7908: $changes{'internal.selfenroll_'.$type.'_date'} = $newenrolldate{$type};
7909: }
7910: }
7911: } elsif ($item eq 'access_dates') {
7912: my (%currdate,%newdate);
7913: foreach my $type ('start','end') {
1.398 raeburn 7914: $currdate{$type} = $currsettings->{'selfenroll_'.$type.'_access'};
1.237 raeburn 7915: $newdate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_access');
7916: if ($newdate{$type} ne $currdate{$type}) {
7917: $changes{'internal.selfenroll_'.$type.'_access'} = $newdate{$type};
7918: }
7919: }
1.241 raeburn 7920: } elsif ($item eq 'types') {
1.398 raeburn 7921: $curr_types = $currsettings->{'selfenroll_'.$item};
1.241 raeburn 7922: if ($env{'form.selfenroll_all'}) {
7923: if ($curr_types ne '*') {
7924: $changes{'internal.selfenroll_types'} = '*';
7925: } else {
7926: next;
7927: }
7928: } else {
1.249 raeburn 7929: my %currdoms;
1.241 raeburn 7930: my @entries = split(/;/,$curr_types);
7931: my @deletedoms = &Apache::loncommon::get_env_multiple('form.selfenroll_delete');
1.249 raeburn 7932: my @activations = &Apache::loncommon::get_env_multiple('form.selfenroll_activate');
1.241 raeburn 7933: my $newnum = 0;
1.249 raeburn 7934: my @latesttypes;
7935: foreach my $num (@activations) {
7936: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$num);
7937: if (@types > 0) {
1.241 raeburn 7938: @types = sort(@types);
7939: my $typestr = join(',',@types);
1.249 raeburn 7940: my $typedom = $env{'form.selfenroll_dom_'.$num};
7941: $latesttypes[$newnum] = $typedom.':'.$typestr;
7942: $currdoms{$typedom} = 1;
1.241 raeburn 7943: $newnum ++;
7944: }
7945: }
1.338 raeburn 7946: for (my $j=0; $j<$env{'form.selfenroll_types_total'}; $j++) {
7947: if ((!grep(/^$j$/,@deletedoms)) && (!grep(/^$j$/,@activations))) {
1.249 raeburn 7948: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$j);
7949: if (@types > 0) {
7950: @types = sort(@types);
7951: my $typestr = join(',',@types);
7952: my $typedom = $env{'form.selfenroll_dom_'.$j};
7953: $latesttypes[$newnum] = $typedom.':'.$typestr;
7954: $currdoms{$typedom} = 1;
7955: $newnum ++;
7956: }
7957: }
7958: }
7959: if ($env{'form.selfenroll_newdom'} ne '') {
7960: my $typedom = $env{'form.selfenroll_newdom'};
7961: if ((!defined($currdoms{$typedom})) &&
7962: (&Apache::lonnet::domain($typedom) ne '')) {
7963: my $typestr;
7964: my ($othertitle,$usertypes,$types) =
7965: &Apache::loncommon::sorted_inst_types($typedom);
7966: my $othervalue = 'any';
7967: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7968: if (@{$types} > 0) {
1.257 raeburn 7969: my @esc_types = map { &escape($_); } @{$types};
1.249 raeburn 7970: $othervalue = 'other';
1.258 raeburn 7971: $typestr = join(',',(@esc_types,$othervalue));
1.249 raeburn 7972: }
7973: $typestr = $othervalue;
7974: } else {
7975: $typestr = $othervalue;
7976: }
7977: $latesttypes[$newnum] = $typedom.':'.$typestr;
7978: $newnum ++ ;
7979: }
7980: }
1.241 raeburn 7981: my $selfenroll_types = join(';',@latesttypes);
7982: if ($selfenroll_types ne $curr_types) {
7983: $changes{'internal.selfenroll_types'} = $selfenroll_types;
7984: }
7985: }
1.276 raeburn 7986: } elsif ($item eq 'limit') {
7987: my $newlimit = $env{'form.selfenroll_limit'};
7988: my $newcap = $env{'form.selfenroll_cap'};
7989: $newcap =~s/\s+//g;
1.398 raeburn 7990: my $currlimit = $currsettings->{'selfenroll_limit'};
1.276 raeburn 7991: $currlimit = 'none' if ($currlimit eq '');
1.398 raeburn 7992: my $currcap = $currsettings->{'selfenroll_cap'};
1.276 raeburn 7993: if ($newlimit ne $currlimit) {
7994: if ($newlimit ne 'none') {
7995: if ($newcap =~ /^\d+$/) {
7996: if ($newcap ne $currcap) {
7997: $changes{'internal.selfenroll_cap'} = $newcap;
7998: }
7999: $changes{'internal.selfenroll_limit'} = $newlimit;
8000: } else {
1.398 raeburn 8001: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.
8002: &mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
1.276 raeburn 8003: }
8004: } elsif ($currcap ne '') {
8005: $changes{'internal.selfenroll_cap'} = '';
8006: $changes{'internal.selfenroll_limit'} = $newlimit;
8007: }
8008: } elsif ($currlimit ne 'none') {
8009: if ($newcap =~ /^\d+$/) {
8010: if ($newcap ne $currcap) {
8011: $changes{'internal.selfenroll_cap'} = $newcap;
8012: }
8013: } else {
1.398 raeburn 8014: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.
8015: &mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
1.276 raeburn 8016: }
8017: }
8018: } elsif ($item eq 'approval') {
8019: my (@currnotified,@newnotified);
1.398 raeburn 8020: my $currapproval = $currsettings->{'selfenroll_approval'};
8021: my $currnotifylist = $currsettings->{'selfenroll_notifylist'};
1.276 raeburn 8022: if ($currnotifylist ne '') {
8023: @currnotified = split(/,/,$currnotifylist);
8024: @currnotified = sort(@currnotified);
8025: }
8026: my $newapproval = $env{'form.selfenroll_approval'};
8027: @newnotified = &Apache::loncommon::get_env_multiple('form.selfenroll_notify');
8028: @newnotified = sort(@newnotified);
8029: if ($newapproval ne $currapproval) {
8030: $changes{'internal.selfenroll_approval'} = $newapproval;
8031: if (!$newapproval) {
8032: if ($currnotifylist ne '') {
8033: $changes{'internal.selfenroll_notifylist'} = '';
8034: }
8035: } else {
8036: my @differences =
1.295 raeburn 8037: &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 8038: if (@differences > 0) {
8039: if (@newnotified > 0) {
8040: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
8041: } else {
8042: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
8043: }
8044: }
8045: }
8046: } else {
1.295 raeburn 8047: my @differences = &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 8048: if (@differences > 0) {
8049: if (@newnotified > 0) {
8050: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
8051: } else {
8052: $changes{'internal.selfenroll_notifylist'} = '';
8053: }
8054: }
8055: }
1.237 raeburn 8056: } else {
1.398 raeburn 8057: my $curr_val = $currsettings->{'selfenroll_'.$item};
1.237 raeburn 8058: my $newval = $env{'form.selfenroll_'.$item};
8059: if ($item eq 'section') {
8060: $newval = $env{'form.sections'};
1.241 raeburn 8061: if (defined($curr_groups{$newval})) {
1.237 raeburn 8062: $newval = $curr_val;
1.398 raeburn 8063: $warning{$item} = &mt('Section for self-enrolled users unchanged as the proposed section is a group').'<br />'.
8064: &mt('Group names and section names must be distinct');
1.237 raeburn 8065: } elsif ($newval eq 'all') {
8066: $newval = $curr_val;
1.274 bisitz 8067: $warning{$item} = &mt('Section for self-enrolled users unchanged, as "all" is a reserved section name.');
1.237 raeburn 8068: }
8069: if ($newval eq '') {
8070: $newval = 'none';
8071: }
8072: }
8073: if ($newval ne $curr_val) {
8074: $changes{'internal.selfenroll_'.$item} = $newval;
8075: }
1.241 raeburn 8076: }
1.237 raeburn 8077: }
8078: if (keys(%warning) > 0) {
8079: foreach my $item (@{$row}) {
8080: if (exists($warning{$item})) {
8081: $r->print($warning{$item}.'<br />');
8082: }
8083: }
8084: }
8085: if (keys(%changes) > 0) {
8086: my $putresult = &Apache::lonnet::put('environment',\%changes,$cdom,$cnum);
8087: if ($putresult eq 'ok') {
8088: if ((exists($changes{'internal.selfenroll_types'})) ||
8089: (exists($changes{'internal.selfenroll_start_date'})) ||
8090: (exists($changes{'internal.selfenroll_end_date'}))) {
8091: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',
8092: $cnum,undef,undef,'Course');
8093: my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
1.398 raeburn 8094: if (ref($crsinfo{$cid}) eq 'HASH') {
1.237 raeburn 8095: foreach my $item ('selfenroll_types','selfenroll_start_date','selfenroll_end_date') {
8096: if (exists($changes{'internal.'.$item})) {
1.398 raeburn 8097: $crsinfo{$cid}{$item} = $changes{'internal.'.$item};
1.237 raeburn 8098: }
8099: }
8100: my $crsputresult =
8101: &Apache::lonnet::courseidput($cdom,\%crsinfo,
8102: $chome,'notime');
8103: }
8104: }
8105: $r->print(&mt('The following changes were made to self-enrollment settings:').'<ul>');
8106: foreach my $item (@{$row}) {
8107: my $title = $item;
8108: if (ref($lt) eq 'HASH') {
8109: $title = $lt->{$item};
8110: }
8111: if ($item eq 'enroll_dates') {
8112: foreach my $type ('start','end') {
8113: if (exists($changes{'internal.selfenroll_'.$type.'_date'})) {
8114: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_date'});
1.244 bisitz 8115: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 8116: $title,$type,$newdate).'</li>');
8117: }
8118: }
8119: } elsif ($item eq 'access_dates') {
8120: foreach my $type ('start','end') {
8121: if (exists($changes{'internal.selfenroll_'.$type.'_access'})) {
8122: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_access'});
1.244 bisitz 8123: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 8124: $title,$type,$newdate).'</li>');
8125: }
8126: }
1.276 raeburn 8127: } elsif ($item eq 'limit') {
8128: if ((exists($changes{'internal.selfenroll_limit'})) ||
8129: (exists($changes{'internal.selfenroll_cap'}))) {
8130: my ($newval,$newcap);
8131: if ($changes{'internal.selfenroll_cap'} ne '') {
8132: $newcap = $changes{'internal.selfenroll_cap'}
8133: } else {
1.398 raeburn 8134: $newcap = $currsettings->{'selfenroll_cap'};
1.276 raeburn 8135: }
8136: if ($changes{'internal.selfenroll_limit'} eq 'none') {
8137: $newval = &mt('No limit');
8138: } elsif ($changes{'internal.selfenroll_limit'} eq
8139: 'allstudents') {
8140: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
8141: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
8142: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
8143: } else {
1.398 raeburn 8144: my $currlimit = $currsettings->{'selfenroll_limit'};
1.276 raeburn 8145: if ($currlimit eq 'allstudents') {
8146: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
8147: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
1.308 raeburn 8148: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
1.276 raeburn 8149: }
8150: }
8151: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
8152: }
8153: } elsif ($item eq 'approval') {
8154: if ((exists($changes{'internal.selfenroll_approval'})) ||
8155: (exists($changes{'internal.selfenroll_notifylist'}))) {
1.398 raeburn 8156: my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs();
1.276 raeburn 8157: my ($newval,$newnotify);
8158: if (exists($changes{'internal.selfenroll_notifylist'})) {
8159: $newnotify = $changes{'internal.selfenroll_notifylist'};
8160: } else {
1.398 raeburn 8161: $newnotify = $currsettings->{'selfenroll_notifylist'};
1.276 raeburn 8162: }
1.398 raeburn 8163: if (exists($changes{'internal.selfenroll_approval'})) {
8164: if ($changes{'internal.selfenroll_approval'} !~ /^[012]$/) {
8165: $changes{'internal.selfenroll_approval'} = '0';
8166: }
8167: $newval = $selfdescs{'approval'}{$changes{'internal.selfenroll_approval'}};
1.276 raeburn 8168: } else {
1.398 raeburn 8169: my $currapproval = $currsettings->{'selfenroll_approval'};
8170: if ($currapproval !~ /^[012]$/) {
8171: $currapproval = 0;
1.276 raeburn 8172: }
1.398 raeburn 8173: $newval = $selfdescs{'approval'}{$currapproval};
1.276 raeburn 8174: }
8175: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval));
8176: if ($newnotify) {
1.277 raeburn 8177: $r->print('<br />'.&mt('The following will be notified when an enrollment request needs approval, or has been approved: [_1].',$newnotify));
1.276 raeburn 8178: } else {
1.277 raeburn 8179: $r->print('<br />'.&mt('No notifications sent when an enrollment request needs approval, or has been approved.'));
1.276 raeburn 8180: }
8181: $r->print('</li>'."\n");
8182: }
1.237 raeburn 8183: } else {
8184: if (exists($changes{'internal.selfenroll_'.$item})) {
1.241 raeburn 8185: my $newval = $changes{'internal.selfenroll_'.$item};
8186: if ($item eq 'types') {
8187: if ($newval eq '') {
8188: $newval = &mt('None');
8189: } elsif ($newval eq '*') {
8190: $newval = &mt('Any user in any domain');
8191: }
1.245 raeburn 8192: } elsif ($item eq 'registered') {
8193: if ($newval eq '1') {
8194: $newval = &mt('Yes');
8195: } elsif ($newval eq '0') {
8196: $newval = &mt('No');
8197: }
1.241 raeburn 8198: }
1.244 bisitz 8199: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
1.237 raeburn 8200: }
8201: }
8202: }
8203: $r->print('</ul>');
1.398 raeburn 8204: if ($env{'course.'.$cid.'.description'} ne '') {
8205: my %newenvhash;
8206: foreach my $key (keys(%changes)) {
8207: $newenvhash{'course.'.$cid.'.'.$key} = $changes{$key};
8208: }
8209: &Apache::lonnet::appenv(\%newenvhash);
1.237 raeburn 8210: }
8211: } else {
1.398 raeburn 8212: $r->print(&mt('An error occurred when saving changes to self-enrollment settings in this course.').'<br />'.
8213: &mt('The error was: [_1].',$putresult));
1.237 raeburn 8214: }
8215: } else {
1.249 raeburn 8216: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.237 raeburn 8217: }
8218: } else {
1.249 raeburn 8219: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.241 raeburn 8220: }
1.400 raeburn 8221: my $visactions = &cat_visibility();
8222: my ($cathash,%cattype);
8223: my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
8224: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
8225: $cathash = $domconfig{'coursecategories'}{'cats'};
8226: $cattype{'auth'} = $domconfig{'coursecategories'}{'auth'};
8227: $cattype{'unauth'} = $domconfig{'coursecategories'}{'unauth'};
8228: } else {
8229: $cathash = {};
8230: $cattype{'auth'} = 'std';
8231: $cattype{'unauth'} = 'std';
8232: }
8233: if (($cattype{'auth'} eq 'none') && ($cattype{'unauth'} eq 'none')) {
8234: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
8235: '<br />'.
8236: '<br />'.$visactions->{'take'}.'<ul>'.
8237: '<li>'.$visactions->{'dc_chgconf'}.'</li>'.
8238: '</ul>');
8239: } elsif (($cattype{'auth'} !~ /^(std|domonly)$/) && ($cattype{'unauth'} !~ /^(std|domonly)$/)) {
8240: if ($currsettings->{'uniquecode'}) {
8241: $r->print('<span class="LC_info">'.$visactions->{'vis'}.'</span>');
8242: } else {
1.366 bisitz 8243: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
1.400 raeburn 8244: '<br />'.
8245: '<br />'.$visactions->{'take'}.'<ul>'.
8246: '<li>'.$visactions->{'dc_setcode'}.'</li>'.
8247: '</ul><br />');
8248: }
8249: } else {
8250: my ($visible,$cansetvis,$vismsgs) = &visible_in_stdcat($cdom,$cnum,\%domconfig);
8251: if (ref($visactions) eq 'HASH') {
8252: if (!$visible) {
8253: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
8254: '<br />');
8255: if (ref($vismsgs) eq 'ARRAY') {
8256: $r->print('<br />'.$visactions->{'take'}.'<ul>');
8257: foreach my $item (@{$vismsgs}) {
8258: $r->print('<li>'.$visactions->{$item}.'</li>');
8259: }
8260: $r->print('</ul>');
1.256 raeburn 8261: }
1.400 raeburn 8262: $r->print($cansetvis);
1.256 raeburn 8263: }
8264: }
8265: }
1.237 raeburn 8266: return;
8267: }
8268:
1.27 matthew 8269: #---------------------------------------------- end functions for &phase_two
1.29 matthew 8270:
8271: #--------------------------------- functions for &phase_two and &phase_three
8272:
8273: #--------------------------end of functions for &phase_two and &phase_three
1.372 raeburn 8274:
1.1 www 8275: 1;
8276: __END__
1.2 www 8277:
8278:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>