Annotation of loncom/interface/loncreateuser.pm, revision 1.383
1.20 harris41 1: # The LearningOnline Network with CAPA
1.1 www 2: # Create a user
3: #
1.383 ! raeburn 4: # $Id: loncreateuser.pm,v 1.382 2013/12/09 21:33:32 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: 'cuqu' => "Current quota",
130: 'cust' => "Custom quota",
131: 'defa' => "Default",
132: 'chqu' => "Change quota",
1.134 raeburn 133: );
1.378 raeburn 134:
1.149 raeburn 135: my $quota_javascript = <<"END_SCRIPT";
136: <script type="text/javascript">
1.301 bisitz 137: // <![CDATA[
1.378 raeburn 138: function quota_changes(caller,context) {
139: var customoff = document.getElementById('custom_'+context+'quota_off');
140: var customon = document.getElementById('custom_'+context+'quota_on');
141: var number = document.getElementById(context+'quota');
1.149 raeburn 142: if (caller == "custom") {
1.378 raeburn 143: if (customoff) {
144: if (customoff.checked) {
145: number.value = "";
146: }
1.149 raeburn 147: }
148: }
149: if (caller == "quota") {
1.378 raeburn 150: if (customon) {
151: customon.checked = true;
152: }
1.149 raeburn 153: }
1.378 raeburn 154: return;
1.149 raeburn 155: }
1.301 bisitz 156: // ]]>
1.149 raeburn 157: </script>
158: END_SCRIPT
1.378 raeburn 159: my $longinsttype;
160: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($ccdomain);
1.267 raeburn 161: my $output = $quota_javascript."\n".
162: '<h3>'.$lt{'usrt'}.'</h3>'."\n".
163: &Apache::loncommon::start_data_table();
164:
165: if (&Apache::lonnet::allowed('mut',$ccdomain)) {
1.275 raeburn 166: $output .= &build_tools_display($ccuname,$ccdomain,'tools');
1.267 raeburn 167: }
1.378 raeburn 168:
169: my %titles = &Apache::lonlocal::texthash (
170: portfolio => "Disk space allocated to user's portfolio files",
171: author => "Disk space allocated to user's authoring space (if role assigned)",
172: );
173: foreach my $name ('portfolio','author') {
174: my ($currquota,$quotatype,$inststatus,$defquota) =
175: &Apache::loncommon::get_user_quota($ccuname,$ccdomain,$name);
176: if ($longinsttype eq '') {
177: if ($inststatus ne '') {
178: if ($usertypes->{$inststatus} ne '') {
179: $longinsttype = $usertypes->{$inststatus};
180: }
181: }
182: }
183: my ($showquota,$custom_on,$custom_off,$defaultinfo);
184: $custom_on = ' ';
185: $custom_off = ' checked="checked" ';
186: if ($quotatype eq 'custom') {
187: $custom_on = $custom_off;
188: $custom_off = ' ';
189: $showquota = $currquota;
190: if ($longinsttype eq '') {
191: $defaultinfo = &mt('For this user, the default quota would be [_1]'
1.383 ! raeburn 192: .' MB.',$defquota);
1.378 raeburn 193: } else {
194: $defaultinfo = &mt("For this user, the default quota would be [_1]".
1.383 ! raeburn 195: " MB, as determined by the user's institutional".
1.378 raeburn 196: " affiliation ([_2]).",$defquota,$longinsttype);
197: }
198: } else {
199: if ($longinsttype eq '') {
200: $defaultinfo = &mt('For this user, the default quota is [_1]'
1.383 ! raeburn 201: .' MB.',$defquota);
1.378 raeburn 202: } else {
203: $defaultinfo = &mt("For this user, the default quota of [_1]".
1.383 ! raeburn 204: " MB, is determined by the user's institutional".
1.378 raeburn 205: " affiliation ([_2]).",$defquota,$longinsttype);
206: }
207: }
208:
209: if (&Apache::lonnet::allowed('mpq',$ccdomain)) {
210: $output .= '<tr class="LC_info_row">'."\n".
211: ' <td>'.$titles{$name}.'</td>'."\n".
212: ' </tr>'."\n".
213: &Apache::loncommon::start_data_table_row()."\n".
214: ' <td>'.$lt{'cuqu'}.': '.
1.383 ! raeburn 215: $currquota.' MB. '.
1.378 raeburn 216: $defaultinfo.'</td>'."\n".
217: &Apache::loncommon::end_data_table_row()."\n".
218: &Apache::loncommon::start_data_table_row()."\n".
219: ' <td><span class="LC_nobreak">'.$lt{'chqu'}.
220: ': <label>'.
221: '<input type="radio" name="custom_'.$name.'quota" id="custom_'.$name.'quota_off" '.
1.379 raeburn 222: 'value="0" '.$custom_off.' onchange="javascript:quota_changes('."'custom','$name'".');"'.
1.383 ! raeburn 223: ' />'.$lt{'defa'}.' ('.$defquota.' MB).</label> '.
1.378 raeburn 224: ' <label><input type="radio" name="custom_'.$name.'quota" id="custom_'.$name.'quota_on" '.
1.379 raeburn 225: 'value="1" '.$custom_on.' onchange="javascript:quota_changes('."'custom','$name'".');"'.
1.378 raeburn 226: ' />'.$lt{'cust'}.':</label> '.
1.379 raeburn 227: '<input type="text" name="'.$name.'quota" id="'.$name.'quota" size ="5" '.
228: 'value="'.$showquota.'" onfocus="javascript:quota_changes('."'quota','$name'".');"'.
1.383 ! raeburn 229: ' /> MB</span></td>'."\n".
1.378 raeburn 230: &Apache::loncommon::end_data_table_row()."\n";
231: }
232: }
1.267 raeburn 233: $output .= &Apache::loncommon::end_data_table();
1.134 raeburn 234: return $output;
235: }
236:
1.275 raeburn 237: sub build_tools_display {
238: my ($ccuname,$ccdomain,$context) = @_;
1.306 raeburn 239: my (@usertools,%userenv,$output,@options,%validations,%reqtitles,%reqdisplay,
1.332 raeburn 240: $colspan,$isadv,%domconfig);
1.275 raeburn 241: my %lt = &Apache::lonlocal::texthash (
242: 'blog' => "Personal User Blog",
243: 'aboutme' => "Personal Information Page",
1.361 raeburn 244: 'webdav' => "WebDAV access to authoring spaces (if SSL and author/co-author)",
1.275 raeburn 245: 'portfolio' => "Personal User Portfolio",
246: 'avai' => "Available",
247: 'cusa' => "availability",
248: 'chse' => "Change setting",
249: 'usde' => "Use default",
250: 'uscu' => "Use custom",
251: 'official' => 'Can request creation of official courses',
1.299 raeburn 252: 'unofficial' => 'Can request creation of unofficial courses',
253: 'community' => 'Can request creation of communities',
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',
259: 'requestcourses.community');
260: @usertools = ('official','unofficial','community');
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',
449: );
450:
451: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
452: 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
453: 'reqcrsotherdom.community');
454: @usertools = ('official','unofficial','community');
1.309 raeburn 455: @options = ('approval','validate','autolimit');
1.306 raeburn 456: %validations = &Apache::lonnet::auto_courserequest_checks($cdom);
457: my $optregex = join('|',@options);
458: my %reqtitles = &courserequest_titles();
1.300 raeburn 459: foreach my $item (@usertools) {
1.306 raeburn 460: my ($curroption,$currlimit,$tooloff);
1.300 raeburn 461: if ($userenv{'reqcrsotherdom.'.$item} ne '') {
462: my @curr = split(',',$userenv{'reqcrsotherdom.'.$item});
1.314 raeburn 463: foreach my $req (@curr) {
464: if ($req =~ /^\Q$cdom\E\:($optregex)=?(\d*)$/) {
465: $curroption = $1;
466: $currlimit = $2;
467: last;
1.306 raeburn 468: }
469: }
1.314 raeburn 470: if (!$curroption) {
471: $curroption = 'norequest';
472: $tooloff = ' checked="checked"';
473: }
1.306 raeburn 474: } else {
475: $curroption = 'norequest';
476: $tooloff = ' checked="checked"';
477: }
478: $output.= &Apache::loncommon::start_data_table_row()."\n".
1.314 raeburn 479: ' <td><span class="LC_nobreak">'.$lt{$item}.': </span></td><td>'.
480: '<table><tr><td valign="top">'."\n".
1.306 raeburn 481: '<label><input type="radio" name="reqcrsotherdom_'.$item.
1.314 raeburn 482: '" value=""'.$tooloff.' />'.$reqtitles{'norequest'}.
483: '</label></td>';
1.306 raeburn 484: foreach my $option (@options) {
485: if ($option eq 'validate') {
486: my $canvalidate = 0;
487: if (ref($validations{$item}) eq 'HASH') {
488: if ($validations{$item}{'_external_'}) {
489: $canvalidate = 1;
490: }
491: }
492: next if (!$canvalidate);
493: }
494: my $checked = '';
495: if ($option eq $curroption) {
496: $checked = ' checked="checked"';
497: }
1.314 raeburn 498: $output .= '<td valign="top"><span class="LC_nobreak"><label>'.
1.306 raeburn 499: '<input type="radio" name="reqcrsotherdom_'.$item.
500: '" value="'.$option.'"'.$checked.' />'.
1.314 raeburn 501: $reqtitles{$option}.'</label>';
1.306 raeburn 502: if ($option eq 'autolimit') {
1.314 raeburn 503: $output .= ' <input type="text" name="reqcrsotherdom_'.
1.306 raeburn 504: $item.'_limit" size="1" '.
1.314 raeburn 505: 'value="'.$currlimit.'" /></span>'.
506: '<br />'.$reqtitles{'unlimited'};
507: } else {
508: $output .= '</span>';
1.300 raeburn 509: }
1.314 raeburn 510: $output .= '</td>';
1.300 raeburn 511: }
1.314 raeburn 512: $output .= '</td></tr></table></td>'."\n".
1.300 raeburn 513: &Apache::loncommon::end_data_table_row()."\n";
514: }
515: return $output;
516: }
517:
1.362 raeburn 518: sub domainrole_req {
519: my ($ccuname,$ccdomain) = @_;
520: return '<br /><h3>'.
521: &mt('User Can Request Assignment of Domain Roles?').
522: '</h3>'."\n".
523: &Apache::loncommon::start_data_table().
524: &build_tools_display($ccuname,$ccdomain,
525: 'requestauthor').
526: &Apache::loncommon::end_data_table();
527: }
528:
1.306 raeburn 529: sub courserequest_titles {
530: my %titles = &Apache::lonlocal::texthash (
531: official => 'Official',
532: unofficial => 'Unofficial',
533: community => 'Communities',
534: norequest => 'Not allowed',
1.309 raeburn 535: approval => 'Approval by Dom. Coord.',
1.306 raeburn 536: validate => 'With validation',
537: autolimit => 'Numerical limit',
1.314 raeburn 538: unlimited => '(blank for unlimited)',
1.306 raeburn 539: );
540: return %titles;
541: }
542:
543: sub courserequest_display {
544: my %titles = &Apache::lonlocal::texthash (
1.309 raeburn 545: approval => 'Yes, need approval',
1.306 raeburn 546: validate => 'Yes, with validation',
547: norequest => 'No',
548: );
549: return %titles;
550: }
551:
1.362 raeburn 552: sub requestauthor_titles {
553: my %titles = &Apache::lonlocal::texthash (
554: norequest => 'Not allowed',
555: approval => 'Approval by Dom. Coord.',
556: automatic => 'Automatic approval',
557: );
558: return %titles;
559:
560: }
561:
562: sub requestauthor_display {
563: my %titles = &Apache::lonlocal::texthash (
564: approval => 'Yes, need approval',
565: automatic => 'Yes, automatic approval',
566: norequest => 'No',
567: );
568: return %titles;
569: }
570:
1.383 ! raeburn 571: sub requestchange_display {
! 572: my %titles = &Apache::lonlocal::texthash (
! 573: approval => "availability set to 'on' (approval required)",
! 574: automatic => "availability set to 'on' (automatic approval)",
! 575: norequest => "availability set to 'off'",
! 576: );
! 577: return %titles;
! 578: }
! 579:
1.362 raeburn 580: sub curr_requestauthor {
581: my ($uname,$udom,$isadv,$inststatuses,$domconfig) = @_;
582: return unless ((ref($inststatuses) eq 'ARRAY') && (ref($domconfig) eq 'HASH'));
583: if ($uname eq '' || $udom eq '') {
584: $uname = $env{'user.name'};
585: $udom = $env{'user.domain'};
586: $isadv = $env{'user.adv'};
587: }
588: my (%userenv,%settings,$val);
589: my @options = ('automatic','approval');
590: %userenv =
591: &Apache::lonnet::userenvironment($udom,$uname,'requestauthor','inststatus');
592: if ($userenv{'requestauthor'}) {
593: $val = $userenv{'requestauthor'};
594: @{$inststatuses} = ('_custom_');
595: } else {
596: my %alltasks;
597: if (ref($domconfig->{'requestauthor'}) eq 'HASH') {
598: %settings = %{$domconfig->{'requestauthor'}};
599: if (($isadv) && ($settings{'_LC_adv'} ne '')) {
600: $val = $settings{'_LC_adv'};
601: @{$inststatuses} = ('_LC_adv_');
602: } else {
603: if ($userenv{'inststatus'} ne '') {
604: @{$inststatuses} = split(',',$userenv{'inststatus'});
605: } else {
606: @{$inststatuses} = ('default');
607: }
608: foreach my $status (@{$inststatuses}) {
609: if (exists($settings{$status})) {
610: my $value = $settings{$status};
611: next unless ($value);
612: unless (exists($alltasks{$value})) {
613: if (ref($alltasks{$value}) eq 'ARRAY') {
614: unless(grep(/^\Q$status\E$/,@{$alltasks{$value}})) {
615: push(@{$alltasks{$value}},$status);
616: }
617: } else {
618: @{$alltasks{$value}} = ($status);
619: }
620: }
621: }
622: }
623: foreach my $option (@options) {
624: if ($alltasks{$option}) {
625: $val = $option;
626: last;
627: }
628: }
629: }
630: }
631: }
632: return $val;
633: }
634:
1.2 www 635: # =================================================================== Phase one
1.1 www 636:
1.42 matthew 637: sub print_username_entry_form {
1.351 raeburn 638: my ($r,$context,$response,$srch,$forcenewuser,$crstype,$brcrum) = @_;
1.101 albertel 639: my $defdom=$env{'request.role.domain'};
1.160 raeburn 640: my $formtoset = 'crtuser';
641: if (exists($env{'form.startrolename'})) {
642: $formtoset = 'docustom';
643: $env{'form.rolename'} = $env{'form.startrolename'};
1.207 raeburn 644: } elsif ($env{'form.origform'} eq 'crtusername') {
645: $formtoset = $env{'form.origform'};
1.160 raeburn 646: }
647:
648: my ($jsback,$elements) = &crumb_utilities();
649:
650: my $jscript = &Apache::loncommon::studentbrowser_javascript()."\n".
1.165 albertel 651: '<script type="text/javascript">'."\n".
1.301 bisitz 652: '// <![CDATA['."\n".
653: &Apache::lonhtmlcommon::set_form_elements($elements->{$formtoset})."\n".
654: '// ]]>'."\n".
1.162 raeburn 655: '</script>'."\n";
1.160 raeburn 656:
1.324 raeburn 657: my %existingroles=&Apache::lonuserutils::my_custom_roles($crstype);
658: if (($env{'form.action'} eq 'custom') && (keys(%existingroles) > 0)
659: && (&Apache::lonnet::allowed('mcr','/'))) {
660: $jscript .= &customrole_javascript();
661: }
1.224 raeburn 662: my $helpitem = 'Course_Change_Privileges';
663: if ($env{'form.action'} eq 'custom') {
664: $helpitem = 'Course_Editing_Custom_Roles';
665: } elsif ($env{'form.action'} eq 'singlestudent') {
666: $helpitem = 'Course_Add_Student';
667: }
1.351 raeburn 668: my %breadcrumb_text = &singleuser_breadcrumb($crstype);
669: if ($env{'form.action'} eq 'custom') {
670: push(@{$brcrum},
671: {href=>"javascript:backPage(document.crtuser)",
672: text=>"Pick custom role",
673: help => $helpitem,}
674: );
675: } else {
676: push (@{$brcrum},
677: {href => "javascript:backPage(document.crtuser)",
678: text => $breadcrumb_text{'search'},
679: help => $helpitem,
680: faq => 282,
681: bug => 'Instructor Interface',}
682: );
683: }
684: my %loaditems = (
685: 'onload' => "javascript:setFormElements(document.$formtoset)",
686: );
687: my $args = {bread_crumbs => $brcrum,
688: bread_crumbs_component => 'User Management',
689: add_entries => \%loaditems,};
690: $r->print(&Apache::loncommon::start_page('User Management',$jscript,$args));
691:
1.71 sakharuk 692: my %lt=&Apache::lonlocal::texthash(
1.229 raeburn 693: 'srst' => 'Search for a user and enroll as a student',
1.318 raeburn 694: 'srme' => 'Search for a user and enroll as a member',
1.229 raeburn 695: 'srad' => 'Search for a user and modify/add user information or roles',
1.71 sakharuk 696: 'usr' => "Username",
697: 'dom' => "Domain",
1.324 raeburn 698: 'ecrp' => "Define or Edit Custom Role",
699: 'nr' => "role name",
1.282 schafran 700: 'cre' => "Next",
1.71 sakharuk 701: );
1.351 raeburn 702:
1.214 raeburn 703: if ($env{'form.action'} eq 'custom') {
1.190 raeburn 704: if (&Apache::lonnet::allowed('mcr','/')) {
1.324 raeburn 705: my $newroletext = &mt('Define new custom role:');
706: $r->print('<form action="/adm/createuser" method="post" name="docustom">'.
707: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
708: '<input type="hidden" name="phase" value="selected_custom_edit" />'.
709: '<h3>'.$lt{'ecrp'}.'</h3>'.
710: &Apache::loncommon::start_data_table().
711: &Apache::loncommon::start_data_table_row().
712: '<td>');
713: if (keys(%existingroles) > 0) {
714: $r->print('<br /><label><input type="radio" name="customroleaction" value="new" checked="checked" onclick="setCustomFields();" /><b>'.$newroletext.'</b></label>');
715: } else {
716: $r->print('<br /><input type="hidden" name="customroleaction" value="new" /><b>'.$newroletext.'</b>');
717: }
718: $r->print('</td><td align="center">'.$lt{'nr'}.'<br /><input type="text" size="15" name="newrolename" onfocus="setCustomAction('."'new'".');" /></td>'.
719: &Apache::loncommon::end_data_table_row());
720: if (keys(%existingroles) > 0) {
721: $r->print(&Apache::loncommon::start_data_table_row().'<td><br />'.
722: '<label><input type="radio" name="customroleaction" value="edit" onclick="setCustomFields();"/><b>'.
723: &mt('View/Modify existing role:').'</b></label></td>'.
724: '<td align="center"><br />'.
725: '<select name="rolename" onchange="setCustomAction('."'edit'".');">'.
1.326 raeburn 726: '<option value="" selected="selected">'.
1.324 raeburn 727: &mt('Select'));
728: foreach my $role (sort(keys(%existingroles))) {
1.326 raeburn 729: $r->print('<option value="'.$role.'">'.$role.'</option>');
1.324 raeburn 730: }
731: $r->print('</select>'.
732: '</td>'.
733: &Apache::loncommon::end_data_table_row());
734: }
735: $r->print(&Apache::loncommon::end_data_table().'<p>'.
736: '<input name="customeditor" type="submit" value="'.
737: $lt{'cre'}.'" /></p>'.
738: '</form>');
1.190 raeburn 739: }
1.213 raeburn 740: } else {
1.229 raeburn 741: my $actiontext = $lt{'srad'};
1.213 raeburn 742: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 743: if ($crstype eq 'Community') {
744: $actiontext = $lt{'srme'};
745: } else {
746: $actiontext = $lt{'srst'};
747: }
1.213 raeburn 748: }
1.324 raeburn 749: $r->print("<h3>$actiontext</h3>");
1.213 raeburn 750: if ($env{'form.origform'} ne 'crtusername') {
751: $r->print("\n".$response);
752: }
1.318 raeburn 753: $r->print(&entry_form($defdom,$srch,$forcenewuser,$context,$response,$crstype));
1.107 www 754: }
1.110 albertel 755: }
756:
1.324 raeburn 757: sub customrole_javascript {
758: my $js = <<"END";
759: <script type="text/javascript">
760: // <![CDATA[
761:
762: function setCustomFields() {
763: if (document.docustom.customroleaction.length > 0) {
764: for (var i=0; i<document.docustom.customroleaction.length; i++) {
765: if (document.docustom.customroleaction[i].checked) {
766: if (document.docustom.customroleaction[i].value == 'new') {
767: document.docustom.rolename.selectedIndex = 0;
768: } else {
769: document.docustom.newrolename.value = '';
770: }
771: }
772: }
773: }
774: return;
775: }
776:
777: function setCustomAction(caller) {
778: if (document.docustom.customroleaction.length > 0) {
779: for (var i=0; i<document.docustom.customroleaction.length; i++) {
780: if (document.docustom.customroleaction[i].value == caller) {
781: document.docustom.customroleaction[i].checked = true;
782: }
783: }
784: }
785: setCustomFields();
786: return;
787: }
788:
789: // ]]>
790: </script>
791: END
792: return $js;
793: }
794:
1.160 raeburn 795: sub entry_form {
1.318 raeburn 796: my ($dom,$srch,$forcenewuser,$context,$responsemsg,$crstype) = @_;
1.229 raeburn 797: my ($usertype,$inexact);
1.214 raeburn 798: if (ref($srch) eq 'HASH') {
799: if (($srch->{'srchin'} eq 'dom') &&
800: ($srch->{'srchby'} eq 'uname') &&
801: ($srch->{'srchtype'} eq 'exact') &&
802: ($srch->{'srchdomain'} ne '') &&
803: ($srch->{'srchterm'} ne '')) {
1.353 raeburn 804: my (%curr_rules,%got_rules);
1.214 raeburn 805: my ($rules,$ruleorder) =
806: &Apache::lonnet::inst_userrules($srch->{'srchdomain'},'username');
1.353 raeburn 807: $usertype = &Apache::lonuserutils::check_usertype($srch->{'srchdomain'},$srch->{'srchterm'},$rules,\%curr_rules,\%got_rules);
1.229 raeburn 808: } else {
809: $inexact = 1;
1.214 raeburn 810: }
1.207 raeburn 811: }
1.214 raeburn 812: my $cancreate =
813: &Apache::lonuserutils::can_create_user($dom,$context,$usertype);
1.160 raeburn 814: my $userpicker =
1.179 raeburn 815: &Apache::loncommon::user_picker($dom,$srch,$forcenewuser,
1.214 raeburn 816: 'document.crtuser',$cancreate,$usertype);
1.160 raeburn 817: my $srchbutton = &mt('Search');
1.229 raeburn 818: if ($env{'form.action'} eq 'singlestudent') {
819: $srchbutton = &mt('Search and Enroll');
820: } elsif ($cancreate && $responsemsg ne '' && $inexact) {
821: $srchbutton = &mt('Search or Add New User');
822: }
1.207 raeburn 823: my $output = <<"ENDBLOCK";
1.160 raeburn 824: <form action="/adm/createuser" method="post" name="crtuser">
1.190 raeburn 825: <input type="hidden" name="action" value="$env{'form.action'}" />
1.160 raeburn 826: <input type="hidden" name="phase" value="get_user_info" />
827: $userpicker
1.179 raeburn 828: <input name="userrole" type="button" value="$srchbutton" onclick="javascript:validateEntry(document.crtuser)" />
1.160 raeburn 829: </form>
1.207 raeburn 830: ENDBLOCK
1.229 raeburn 831: if ($env{'form.phase'} eq '') {
1.207 raeburn 832: my $defdom=$env{'request.role.domain'};
833: my $domform = &Apache::loncommon::select_dom_form($defdom,'srchdomain');
834: my %lt=&Apache::lonlocal::texthash(
1.229 raeburn 835: 'enro' => 'Enroll one student',
1.318 raeburn 836: 'enrm' => 'Enroll one member',
1.229 raeburn 837: 'admo' => 'Add/modify a single user',
838: 'crea' => 'create new user if required',
839: 'uskn' => "username is known",
1.207 raeburn 840: 'crnu' => 'Create a new user',
841: 'usr' => 'Username',
842: 'dom' => 'in domain',
1.229 raeburn 843: 'enrl' => 'Enroll',
844: 'cram' => 'Create/Modify user',
1.207 raeburn 845: );
1.229 raeburn 846: my $sellink=&Apache::loncommon::selectstudent_link('crtusername','srchterm','srchdomain');
847: my ($title,$buttontext,$showresponse);
1.318 raeburn 848: if ($env{'form.action'} eq 'singlestudent') {
849: if ($crstype eq 'Community') {
850: $title = $lt{'enrm'};
851: } else {
852: $title = $lt{'enro'};
853: }
1.229 raeburn 854: $buttontext = $lt{'enrl'};
855: } else {
856: $title = $lt{'admo'};
857: $buttontext = $lt{'cram'};
858: }
859: if ($cancreate) {
860: $title .= ' <span class="LC_cusr_subheading">('.$lt{'crea'}.')</span>';
861: } else {
862: $title .= ' <span class="LC_cusr_subheading">('.$lt{'uskn'}.')</span>';
863: }
864: if ($env{'form.origform'} eq 'crtusername') {
865: $showresponse = $responsemsg;
866: }
1.207 raeburn 867: $output .= <<"ENDDOCUMENT";
1.229 raeburn 868: <br />
1.207 raeburn 869: <form action="/adm/createuser" method="post" name="crtusername">
870: <input type="hidden" name="action" value="$env{'form.action'}" />
871: <input type="hidden" name="phase" value="createnewuser" />
872: <input type="hidden" name="srchtype" value="exact" />
1.233 raeburn 873: <input type="hidden" name="srchby" value="uname" />
1.207 raeburn 874: <input type="hidden" name="srchin" value="dom" />
875: <input type="hidden" name="forcenewuser" value="1" />
876: <input type="hidden" name="origform" value="crtusername" />
1.229 raeburn 877: <h3>$title</h3>
878: $showresponse
1.207 raeburn 879: <table>
880: <tr>
881: <td>$lt{'usr'}:</td>
882: <td><input type="text" size="15" name="srchterm" /></td>
883: <td> $lt{'dom'}:</td><td>$domform</td>
1.229 raeburn 884: <td> $sellink </td>
885: <td> <input name="userrole" type="submit" value="$buttontext" /></td>
1.207 raeburn 886: </tr>
887: </table>
888: </form>
1.160 raeburn 889: ENDDOCUMENT
1.207 raeburn 890: }
1.160 raeburn 891: return $output;
892: }
1.110 albertel 893:
894: sub user_modification_js {
1.113 raeburn 895: my ($pjump_def,$dc_setcourse_code,$nondc_setsection_code,$groupslist)=@_;
896:
1.110 albertel 897: return <<END;
898: <script type="text/javascript" language="Javascript">
1.301 bisitz 899: // <![CDATA[
1.314 raeburn 900:
1.110 albertel 901: $pjump_def
902: $dc_setcourse_code
903:
904: function dateset() {
905: eval("document.cu."+document.cu.pres_marker.value+
906: ".value=document.cu.pres_value.value");
1.359 www 907: modalWindow.close();
1.110 albertel 908: }
909:
1.113 raeburn 910: $nondc_setsection_code
1.301 bisitz 911: // ]]>
1.110 albertel 912: </script>
913: END
1.2 www 914: }
915:
916: # =================================================================== Phase two
1.160 raeburn 917: sub print_user_selection_page {
1.351 raeburn 918: my ($r,$response,$srch,$srch_results,$srcharray,$context,$opener_elements,$crstype,$brcrum) = @_;
1.160 raeburn 919: my @fields = ('username','domain','lastname','firstname','permanentemail');
920: my $sortby = $env{'form.sortby'};
921:
922: if (!grep(/^\Q$sortby\E$/,@fields)) {
923: $sortby = 'lastname';
924: }
925:
926: my ($jsback,$elements) = &crumb_utilities();
927:
928: my $jscript = (<<ENDSCRIPT);
929: <script type="text/javascript">
1.301 bisitz 930: // <![CDATA[
1.160 raeburn 931: function pickuser(uname,udom) {
932: document.usersrchform.seluname.value=uname;
933: document.usersrchform.seludom.value=udom;
934: document.usersrchform.phase.value="userpicked";
935: document.usersrchform.submit();
936: }
937:
938: $jsback
1.301 bisitz 939: // ]]>
1.160 raeburn 940: </script>
941: ENDSCRIPT
942:
943: my %lt=&Apache::lonlocal::texthash(
1.179 raeburn 944: 'usrch' => "User Search to add/modify roles",
945: 'stusrch' => "User Search to enroll student",
1.318 raeburn 946: 'memsrch' => "User Search to enroll member",
1.179 raeburn 947: 'usel' => "Select a user to add/modify roles",
1.318 raeburn 948: 'stusel' => "Select a user to enroll as a student",
949: 'memsel' => "Select a user to enroll as a member",
1.160 raeburn 950: 'username' => "username",
951: 'domain' => "domain",
952: 'lastname' => "last name",
953: 'firstname' => "first name",
954: 'permanentemail' => "permanent e-mail",
955: );
1.302 raeburn 956: if ($context eq 'requestcrs') {
957: $r->print('<div>');
958: } else {
1.318 raeburn 959: my %breadcrumb_text = &singleuser_breadcrumb($crstype);
1.351 raeburn 960: my $helpitem;
961: if ($env{'form.action'} eq 'singleuser') {
962: $helpitem = 'Course_Change_Privileges';
963: } elsif ($env{'form.action'} eq 'singlestudent') {
964: $helpitem = 'Course_Add_Student';
965: }
966: push (@{$brcrum},
967: {href => "javascript:backPage(document.usersrchform,'','')",
968: text => $breadcrumb_text{'search'},
969: faq => 282,
970: bug => 'Instructor Interface',},
971: {href => "javascript:backPage(document.usersrchform,'get_user_info','select')",
972: text => $breadcrumb_text{'userpicked'},
973: faq => 282,
974: bug => 'Instructor Interface',
975: help => $helpitem}
976: );
977: $r->print(&Apache::loncommon::start_page('User Management',$jscript,{bread_crumbs => $brcrum}));
1.302 raeburn 978: if ($env{'form.action'} eq 'singleuser') {
979: $r->print("<b>$lt{'usrch'}</b><br />");
1.318 raeburn 980: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,$crstype));
1.302 raeburn 981: $r->print('<h3>'.$lt{'usel'}.'</h3>');
982: } elsif ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 983: $r->print($jscript."<b>");
984: if ($crstype eq 'Community') {
985: $r->print($lt{'memsrch'});
986: } else {
987: $r->print($lt{'stusrch'});
988: }
989: $r->print("</b><br />");
990: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,$crstype));
991: $r->print('</form><h3>');
992: if ($crstype eq 'Community') {
993: $r->print($lt{'memsel'});
994: } else {
995: $r->print($lt{'stusel'});
996: }
997: $r->print('</h3>');
1.302 raeburn 998: }
1.179 raeburn 999: }
1.380 bisitz 1000: $r->print('<form name="usersrchform" method="post" action="">'.
1.160 raeburn 1001: &Apache::loncommon::start_data_table()."\n".
1002: &Apache::loncommon::start_data_table_header_row()."\n".
1003: ' <th> </th>'."\n");
1004: foreach my $field (@fields) {
1005: $r->print(' <th><a href="javascript:document.usersrchform.sortby.value='.
1006: "'".$field."'".';document.usersrchform.submit();">'.
1007: $lt{$field}.'</a></th>'."\n");
1008: }
1009: $r->print(&Apache::loncommon::end_data_table_header_row());
1010:
1011: my @sorted_users = sort {
1.167 albertel 1012: lc($srch_results->{$a}->{$sortby}) cmp lc($srch_results->{$b}->{$sortby})
1.160 raeburn 1013: ||
1.167 albertel 1014: lc($srch_results->{$a}->{lastname}) cmp lc($srch_results->{$b}->{lastname})
1.160 raeburn 1015: ||
1016: lc($srch_results->{$a}->{firstname}) cmp lc($srch_results->{$b}->{firstname})
1.167 albertel 1017: ||
1018: lc($a) cmp lc($b)
1.160 raeburn 1019: } (keys(%$srch_results));
1020:
1021: foreach my $user (@sorted_users) {
1022: my ($uname,$udom) = split(/:/,$user);
1.302 raeburn 1023: my $onclick;
1024: if ($context eq 'requestcrs') {
1.314 raeburn 1025: $onclick =
1.302 raeburn 1026: 'onclick="javascript:gochoose('."'$uname','$udom',".
1027: "'$srch_results->{$user}->{firstname}',".
1028: "'$srch_results->{$user}->{lastname}',".
1029: "'$srch_results->{$user}->{permanentemail}'".');"';
1030: } else {
1.314 raeburn 1031: $onclick =
1.302 raeburn 1032: ' onclick="javascript:pickuser('."'".$uname."'".','."'".$udom."'".');"';
1033: }
1.160 raeburn 1034: $r->print(&Apache::loncommon::start_data_table_row().
1.302 raeburn 1035: '<td><input type="button" name="seluser" value="'.&mt('Select').'" '.
1036: $onclick.' /></td>'.
1.160 raeburn 1037: '<td><tt>'.$uname.'</tt></td>'.
1038: '<td><tt>'.$udom.'</tt></td>');
1039: foreach my $field ('lastname','firstname','permanentemail') {
1040: $r->print('<td>'.$srch_results->{$user}->{$field}.'</td>');
1041: }
1042: $r->print(&Apache::loncommon::end_data_table_row());
1043: }
1044: $r->print(&Apache::loncommon::end_data_table().'<br /><br />');
1.179 raeburn 1045: if (ref($srcharray) eq 'ARRAY') {
1046: foreach my $item (@{$srcharray}) {
1047: $r->print('<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n");
1048: }
1049: }
1.160 raeburn 1050: $r->print(' <input type="hidden" name="sortby" value="'.$sortby.'" />'."\n".
1051: ' <input type="hidden" name="seluname" value="" />'."\n".
1052: ' <input type="hidden" name="seludom" value="" />'."\n".
1.179 raeburn 1053: ' <input type="hidden" name="currstate" value="select" />'."\n".
1.190 raeburn 1054: ' <input type="hidden" name="phase" value="get_user_info" />'."\n".
1.214 raeburn 1055: ' <input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n");
1.302 raeburn 1056: if ($context eq 'requestcrs') {
1057: $r->print($opener_elements.'</form></div>');
1058: } else {
1.351 raeburn 1059: $r->print($response.'</form>');
1.302 raeburn 1060: }
1.160 raeburn 1061: }
1062:
1063: sub print_user_query_page {
1.351 raeburn 1064: my ($r,$caller,$brcrum) = @_;
1.160 raeburn 1065: # FIXME - this is for a network-wide name search (similar to catalog search)
1066: # To use frames with similar behavior to catalog/portfolio search.
1067: # To be implemented.
1068: return;
1069: }
1070:
1.42 matthew 1071: sub print_user_modification_page {
1.375 raeburn 1072: my ($r,$ccuname,$ccdomain,$srch,$response,$context,$permission,$crstype,
1073: $brcrum,$showcredits) = @_;
1.185 raeburn 1074: if (($ccuname eq '') || ($ccdomain eq '')) {
1.215 raeburn 1075: my $usermsg = &mt('No username and/or domain provided.');
1076: $env{'form.phase'} = '';
1.351 raeburn 1077: &print_username_entry_form($r,$context,$usermsg,'','',$crstype,$brcrum);
1.58 www 1078: return;
1079: }
1.213 raeburn 1080: my ($form,$formname);
1081: if ($env{'form.action'} eq 'singlestudent') {
1082: $form = 'document.enrollstudent';
1083: $formname = 'enrollstudent';
1084: } else {
1085: $form = 'document.cu';
1086: $formname = 'cu';
1087: }
1.188 raeburn 1088: my %abv_auth = &auth_abbrev();
1.227 raeburn 1089: my (%rulematch,%inst_results,$newuser,%alerts,%curr_rules,%got_rules);
1.185 raeburn 1090: my $uhome=&Apache::lonnet::homeserver($ccuname,$ccdomain);
1091: if ($uhome eq 'no_host') {
1.215 raeburn 1092: my $usertype;
1093: my ($rules,$ruleorder) =
1094: &Apache::lonnet::inst_userrules($ccdomain,'username');
1095: $usertype =
1.353 raeburn 1096: &Apache::lonuserutils::check_usertype($ccdomain,$ccuname,$rules,
1.362 raeburn 1097: \%curr_rules,\%got_rules);
1.215 raeburn 1098: my $cancreate =
1099: &Apache::lonuserutils::can_create_user($ccdomain,$context,
1100: $usertype);
1101: if (!$cancreate) {
1.292 bisitz 1102: my $helplink = 'javascript:helpMenu('."'display'".')';
1.215 raeburn 1103: my %usertypetext = (
1104: official => 'institutional',
1105: unofficial => 'non-institutional',
1106: );
1107: my $response;
1108: if ($env{'form.origform'} eq 'crtusername') {
1.362 raeburn 1109: $response = '<span class="LC_warning">'.
1110: &mt('No match found for the username [_1] in LON-CAPA domain: [_2]',
1111: '<b>'.$ccuname.'</b>',$ccdomain).
1.215 raeburn 1112: '</span><br />';
1113: }
1.292 bisitz 1114: $response .= '<p class="LC_warning">'
1115: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
1116: .' '
1117: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
1118: ,'<a href="'.$helplink.'">','</a>')
1119: .'</p><br />';
1.215 raeburn 1120: $env{'form.phase'} = '';
1.351 raeburn 1121: &print_username_entry_form($r,$context,$response,undef,undef,$crstype,$brcrum);
1.215 raeburn 1122: return;
1123: }
1.188 raeburn 1124: $newuser = 1;
1.193 raeburn 1125: my $checkhash;
1126: my $checks = { 'username' => 1 };
1.196 raeburn 1127: $checkhash->{$ccuname.':'.$ccdomain} = { 'newuser' => $newuser };
1.193 raeburn 1128: &Apache::loncommon::user_rule_check($checkhash,$checks,
1.196 raeburn 1129: \%alerts,\%rulematch,\%inst_results,\%curr_rules,\%got_rules);
1130: if (ref($alerts{'username'}) eq 'HASH') {
1131: if (ref($alerts{'username'}{$ccdomain}) eq 'HASH') {
1132: my $domdesc =
1.193 raeburn 1133: &Apache::lonnet::domain($ccdomain,'description');
1.196 raeburn 1134: if ($alerts{'username'}{$ccdomain}{$ccuname}) {
1135: my $userchkmsg;
1136: if (ref($curr_rules{$ccdomain}) eq 'HASH') {
1137: $userchkmsg =
1138: &Apache::loncommon::instrule_disallow_msg('username',
1.193 raeburn 1139: $domdesc,1).
1140: &Apache::loncommon::user_rule_formats($ccdomain,
1141: $domdesc,$curr_rules{$ccdomain}{'username'},
1142: 'username');
1.196 raeburn 1143: }
1.215 raeburn 1144: $env{'form.phase'} = '';
1.351 raeburn 1145: &print_username_entry_form($r,$context,$userchkmsg,undef,undef,$crstype,$brcrum);
1.196 raeburn 1146: return;
1.215 raeburn 1147: }
1.193 raeburn 1148: }
1.185 raeburn 1149: }
1.187 raeburn 1150: } else {
1.188 raeburn 1151: $newuser = 0;
1.185 raeburn 1152: }
1.160 raeburn 1153: if ($response) {
1.215 raeburn 1154: $response = '<br />'.$response;
1.160 raeburn 1155: }
1.149 raeburn 1156:
1.52 matthew 1157: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
1.88 raeburn 1158: my $dc_setcourse_code = '';
1.119 raeburn 1159: my $nondc_setsection_code = '';
1.112 albertel 1160: my %loaditem;
1.114 albertel 1161:
1.216 raeburn 1162: my $groupslist = &Apache::lonuserutils::get_groupslist();
1.88 raeburn 1163:
1.375 raeburn 1164: my $js = &validation_javascript($context,$ccdomain,$pjump_def,$crstype,
1.216 raeburn 1165: $groupslist,$newuser,$formname,\%loaditem);
1.318 raeburn 1166: my %breadcrumb_text = &singleuser_breadcrumb($crstype);
1.224 raeburn 1167: my $helpitem = 'Course_Change_Privileges';
1168: if ($env{'form.action'} eq 'singlestudent') {
1169: $helpitem = 'Course_Add_Student';
1170: }
1.351 raeburn 1171: push (@{$brcrum},
1172: {href => "javascript:backPage($form)",
1173: text => $breadcrumb_text{'search'},
1174: faq => 282,
1175: bug => 'Instructor Interface',});
1176: if ($env{'form.phase'} eq 'userpicked') {
1177: push(@{$brcrum},
1178: {href => "javascript:backPage($form,'get_user_info','select')",
1179: text => $breadcrumb_text{'userpicked'},
1180: faq => 282,
1181: bug => 'Instructor Interface',});
1182: }
1183: push(@{$brcrum},
1184: {href => "javascript:backPage($form,'$env{'form.phase'}','modify')",
1185: text => $breadcrumb_text{'modify'},
1186: faq => 282,
1187: bug => 'Instructor Interface',
1188: help => $helpitem});
1189: my $args = {'add_entries' => \%loaditem,
1190: 'bread_crumbs' => $brcrum,
1191: 'bread_crumbs_component' => 'User Management'};
1192: if ($env{'form.popup'}) {
1193: $args->{'no_nav_bar'} = 1;
1194: }
1195: my $start_page =
1196: &Apache::loncommon::start_page('User Management',$js,$args);
1.3 www 1197:
1.25 matthew 1198: my $forminfo =<<"ENDFORMINFO";
1.216 raeburn 1199: <form action="/adm/createuser" method="post" name="$formname">
1.190 raeburn 1200: <input type="hidden" name="phase" value="update_user_data" />
1.188 raeburn 1201: <input type="hidden" name="ccuname" value="$ccuname" />
1202: <input type="hidden" name="ccdomain" value="$ccdomain" />
1.157 albertel 1203: <input type="hidden" name="pres_value" value="" />
1204: <input type="hidden" name="pres_type" value="" />
1205: <input type="hidden" name="pres_marker" value="" />
1.25 matthew 1206: ENDFORMINFO
1.375 raeburn 1207: my (%inccourses,$roledom,$defaultcredits);
1.329 raeburn 1208: if ($context eq 'course') {
1209: $inccourses{$env{'request.course.id'}}=1;
1210: $roledom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1.375 raeburn 1211: if ($showcredits) {
1212: $defaultcredits = &Apache::lonuserutils::get_defaultcredits();
1213: }
1.329 raeburn 1214: } elsif ($context eq 'author') {
1215: $roledom = $env{'request.role.domain'};
1216: } elsif ($context eq 'domain') {
1217: foreach my $key (keys(%env)) {
1218: $roledom = $env{'request.role.domain'};
1219: if ($key=~/^user\.priv\.cm\.\/($roledom)\/($match_username)/) {
1220: $inccourses{$1.'_'.$2}=1;
1221: }
1222: }
1223: } else {
1224: foreach my $key (keys(%env)) {
1225: if ($key=~/^user\.priv\.cm\.\/($match_domain)\/($match_username)/) {
1226: $inccourses{$1.'_'.$2}=1;
1227: }
1.2 www 1228: }
1.24 matthew 1229: }
1.216 raeburn 1230: if ($newuser) {
1.362 raeburn 1231: my ($portfolioform,$domroleform);
1.267 raeburn 1232: if ((&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) ||
1233: (&Apache::lonnet::allowed('mut',$env{'request.role.domain'}))) {
1234: # Current user has quota or user tools modification privileges
1.378 raeburn 1235: $portfolioform = '<br />'.&user_quotas($ccuname,$ccdomain);
1.134 raeburn 1236: }
1.383 ! raeburn 1237: if ((&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) &&
! 1238: ($ccdomain eq $env{'request.role.domain'})) {
1.362 raeburn 1239: $domroleform = '<br />'.&domainrole_req($ccuname,$ccdomain);
1240: }
1.227 raeburn 1241: &initialize_authen_forms($ccdomain,$formname);
1.188 raeburn 1242: my %lt=&Apache::lonlocal::texthash(
1243: 'cnu' => 'Create New User',
1.213 raeburn 1244: 'ast' => 'as a student',
1.318 raeburn 1245: 'ame' => 'as a member',
1.188 raeburn 1246: 'ind' => 'in domain',
1247: 'lg' => 'Login Data',
1.190 raeburn 1248: 'hs' => "Home Server",
1.188 raeburn 1249: );
1.185 raeburn 1250: $r->print(<<ENDTITLE);
1.110 albertel 1251: $start_page
1.160 raeburn 1252: $response
1.25 matthew 1253: $forminfo
1.31 matthew 1254: <script type="text/javascript" language="Javascript">
1.301 bisitz 1255: // <![CDATA[
1.20 harris41 1256: $loginscript
1.301 bisitz 1257: // ]]>
1.31 matthew 1258: </script>
1.20 harris41 1259: <input type='hidden' name='makeuser' value='1' />
1.216 raeburn 1260: <h2>$lt{'cnu'} "$ccuname" $lt{'ind'} $ccdomain
1.185 raeburn 1261: ENDTITLE
1.213 raeburn 1262: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1263: if ($crstype eq 'Community') {
1264: $r->print(' ('.$lt{'ame'}.')');
1265: } else {
1266: $r->print(' ('.$lt{'ast'}.')');
1267: }
1.213 raeburn 1268: }
1269: $r->print('</h2>'."\n".'<div class="LC_left_float">');
1.206 raeburn 1270: my $personal_table =
1.210 raeburn 1271: &personal_data_display($ccuname,$ccdomain,$newuser,$context,
1272: $inst_results{$ccuname.':'.$ccdomain});
1.206 raeburn 1273: $r->print($personal_table);
1.187 raeburn 1274: my ($home_server_pick,$numlib) =
1275: &Apache::loncommon::home_server_form_item($ccdomain,'hserver',
1276: 'default','hide');
1277: if ($numlib > 1) {
1278: $r->print("
1.185 raeburn 1279: <br />
1.187 raeburn 1280: $lt{'hs'}: $home_server_pick
1281: <br />");
1282: } else {
1283: $r->print($home_server_pick);
1284: }
1.304 raeburn 1285: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.362 raeburn 1286: $r->print('<br /><h3>'.
1287: &mt('User Can Request Creation of Courses/Communities in this Domain?').'</h3>'.
1.304 raeburn 1288: &Apache::loncommon::start_data_table().
1289: &build_tools_display($ccuname,$ccdomain,
1290: 'requestcourses').
1291: &Apache::loncommon::end_data_table());
1292: }
1.188 raeburn 1293: $r->print('</div>'."\n".'<div class="LC_left_float"><h3>'.
1294: $lt{'lg'}.'</h3>');
1.185 raeburn 1295: my ($fixedauth,$varauth,$authmsg);
1.193 raeburn 1296: if (ref($rulematch{$ccuname.':'.$ccdomain}) eq 'HASH') {
1297: my $matchedrule = $rulematch{$ccuname.':'.$ccdomain}{'username'};
1298: my ($rules,$ruleorder) =
1299: &Apache::lonnet::inst_userrules($ccdomain,'username');
1.185 raeburn 1300: if (ref($rules) eq 'HASH') {
1.193 raeburn 1301: if (ref($rules->{$matchedrule}) eq 'HASH') {
1302: my $authtype = $rules->{$matchedrule}{'authtype'};
1.185 raeburn 1303: if ($authtype !~ /^(krb4|krb5|int|fsys|loc)$/) {
1.190 raeburn 1304: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.275 raeburn 1305: } else {
1.193 raeburn 1306: my $authparm = $rules->{$matchedrule}{'authparm'};
1.273 raeburn 1307: $authmsg = $rules->{$matchedrule}{'authmsg'};
1.185 raeburn 1308: if ($authtype =~ /^krb(4|5)$/) {
1309: my $ver = $1;
1310: if ($authparm ne '') {
1311: $fixedauth = <<"KERB";
1312: <input type="hidden" name="login" value="krb" />
1313: <input type="hidden" name="krbver" value="$ver" />
1314: <input type="hidden" name="krbarg" value="$authparm" />
1315: KERB
1316: }
1317: } else {
1318: $fixedauth =
1319: '<input type="hidden" name="login" value="'.$authtype.'" />'."\n";
1.193 raeburn 1320: if ($rules->{$matchedrule}{'authparmfixed'}) {
1.185 raeburn 1321: $fixedauth .=
1322: '<input type="hidden" name="'.$authtype.'arg" value="'.$authparm.'" />'."\n";
1323: } else {
1.273 raeburn 1324: if ($authtype eq 'int') {
1325: $varauth = '<br />'.
1.301 bisitz 1326: &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 1327: } elsif ($authtype eq 'loc') {
1328: $varauth = '<br />'.
1329: &mt('[_1] Local Authentication with argument [_2]','','<input type="text" name="'.$authtype.'arg" value="" />')."\n";
1330: } else {
1331: $varauth =
1.185 raeburn 1332: '<input type="text" name="'.$authtype.'arg" value="" />'."\n";
1.273 raeburn 1333: }
1.185 raeburn 1334: }
1335: }
1336: }
1337: } else {
1.190 raeburn 1338: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.185 raeburn 1339: }
1340: }
1341: if ($authmsg) {
1342: $r->print(<<ENDAUTH);
1343: $fixedauth
1344: $authmsg
1345: $varauth
1346: ENDAUTH
1347: }
1348: } else {
1.190 raeburn 1349: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.187 raeburn 1350: }
1.362 raeburn 1351: $r->print($portfolioform.$domroleform);
1.215 raeburn 1352: if ($env{'form.action'} eq 'singlestudent') {
1353: $r->print(&date_sections_select($context,$newuser,$formname,
1.375 raeburn 1354: $permission,$crstype,$ccuname,
1355: $ccdomain,$showcredits));
1.215 raeburn 1356: }
1357: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.216 raeburn 1358: } else { # user already exists
1.79 albertel 1359: my %lt=&Apache::lonlocal::texthash(
1.191 raeburn 1360: 'cup' => "Modify existing user: ",
1.213 raeburn 1361: 'ens' => "Enroll one student: ",
1.318 raeburn 1362: 'enm' => "Enroll one member: ",
1.72 sakharuk 1363: 'id' => "in domain",
1364: );
1.26 matthew 1365: $r->print(<<ENDCHANGEUSER);
1.110 albertel 1366: $start_page
1.25 matthew 1367: $forminfo
1.213 raeburn 1368: <h2>
1.26 matthew 1369: ENDCHANGEUSER
1.213 raeburn 1370: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1371: if ($crstype eq 'Community') {
1372: $r->print($lt{'enm'});
1373: } else {
1374: $r->print($lt{'ens'});
1375: }
1.213 raeburn 1376: } else {
1377: $r->print($lt{'cup'});
1378: }
1379: $r->print(' "'.$ccuname.'" '.$lt{'id'}.' "'.$ccdomain.'"</h2>'.
1380: "\n".'<div class="LC_left_float">');
1.206 raeburn 1381: my ($personal_table,$showforceid) =
1.210 raeburn 1382: &personal_data_display($ccuname,$ccdomain,$newuser,$context,
1383: $inst_results{$ccuname.':'.$ccdomain});
1.206 raeburn 1384: $r->print($personal_table);
1385: if ($showforceid) {
1.362 raeburn 1386: $r->print('<table>'.&Apache::lonuserutils::forceid_change($context).'</table>');
1.199 raeburn 1387: }
1.275 raeburn 1388: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.362 raeburn 1389: $r->print('<br /><h3>'.&mt('User Can Request Creation of Courses/Communities in this Domain?').'</h3>'.
1.300 raeburn 1390: &Apache::loncommon::start_data_table());
1.314 raeburn 1391: if ($env{'request.role.domain'} eq $ccdomain) {
1.300 raeburn 1392: $r->print(&build_tools_display($ccuname,$ccdomain,'requestcourses'));
1393: } else {
1394: $r->print(&coursereq_externaluser($ccuname,$ccdomain,
1395: $env{'request.role.domain'}));
1396: }
1397: $r->print(&Apache::loncommon::end_data_table());
1.275 raeburn 1398: }
1.199 raeburn 1399: $r->print('</div>');
1.362 raeburn 1400: my @order = ('auth','quota','tools','requestauthor');
1401: my %user_text;
1402: my ($isadv,$isauthor) =
1403: &Apache::lonnet::is_advanced_user($ccuname,$ccdomain);
1404: if ((!$isauthor) &&
1.383 ! raeburn 1405: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))
! 1406: && ($env{'request.role.domain'} eq $ccdomain)) {
1.362 raeburn 1407: $user_text{'requestauthor'} = &domainrole_req($ccuname,$ccdomain);
1408: }
1409: $user_text{'auth'} = &user_authentication($ccuname,$ccdomain,$formname);
1.267 raeburn 1410: if ((&Apache::lonnet::allowed('mpq',$ccdomain)) ||
1411: (&Apache::lonnet::allowed('mut',$ccdomain))) {
1.188 raeburn 1412: # Current user has quota modification privileges
1.378 raeburn 1413: $user_text{'quota'} = &user_quotas($ccuname,$ccdomain);
1.267 raeburn 1414: }
1415: if (!&Apache::lonnet::allowed('mpq',$ccdomain)) {
1416: if (&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) {
1417: my %lt=&Apache::lonlocal::texthash(
1.378 raeburn 1418: 'dska' => "Disk quotas for user's portfolio and authoring space",
1419: 'youd' => "You do not have privileges to modify the portfolio and/or authoring space quotas for this user.",
1.267 raeburn 1420: 'ichr' => "If a change is required, contact a domain coordinator for the domain",
1421: );
1.362 raeburn 1422: $user_text{'quota'} = <<ENDNOPORTPRIV;
1.188 raeburn 1423: <h3>$lt{'dska'}</h3>
1424: $lt{'youd'} $lt{'ichr'}: $ccdomain
1425: ENDNOPORTPRIV
1.267 raeburn 1426: }
1427: }
1428: if (!&Apache::lonnet::allowed('mut',$ccdomain)) {
1429: if (&Apache::lonnet::allowed('mut',$env{'request.role.domain'})) {
1430: my %lt=&Apache::lonlocal::texthash(
1431: 'utav' => "User Tools Availability",
1.361 raeburn 1432: 'yodo' => "You do not have privileges to modify Portfolio, Blog, WebDAV, or Personal Information Page settings for this user.",
1.267 raeburn 1433: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
1434: );
1.362 raeburn 1435: $user_text{'tools'} = <<ENDNOTOOLSPRIV;
1.267 raeburn 1436: <h3>$lt{'utav'}</h3>
1437: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1438: ENDNOTOOLSPRIV
1439: }
1.188 raeburn 1440: }
1.362 raeburn 1441: my $gotdiv = 0;
1442: foreach my $item (@order) {
1443: if ($user_text{$item} ne '') {
1444: unless ($gotdiv) {
1445: $r->print('<div class="LC_left_float">');
1446: $gotdiv = 1;
1447: }
1448: $r->print('<br />'.$user_text{$item});
1449: }
1450: }
1451: if ($env{'form.action'} eq 'singlestudent') {
1452: unless ($gotdiv) {
1453: $r->print('<div class="LC_left_float">');
1.213 raeburn 1454: }
1.375 raeburn 1455: my $credits;
1456: if ($showcredits) {
1457: $credits = &get_user_credits($ccuname,$ccdomain,$defaultcredits);
1458: if ($credits eq '') {
1459: $credits = $defaultcredits;
1460: }
1461: }
1.374 raeburn 1462: $r->print(&date_sections_select($context,$newuser,$formname,
1.375 raeburn 1463: $permission,$crstype,$ccuname,
1464: $ccdomain,$showcredits));
1.374 raeburn 1465: }
1.362 raeburn 1466: if ($gotdiv) {
1467: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.188 raeburn 1468: }
1.217 raeburn 1469: if ($env{'form.action'} ne 'singlestudent') {
1.329 raeburn 1470: &display_existing_roles($r,$ccuname,$ccdomain,\%inccourses,$context,
1471: $roledom,$crstype);
1.217 raeburn 1472: }
1.25 matthew 1473: } ## End of new user/old user logic
1.218 raeburn 1474: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1475: my $btntxt;
1476: if ($crstype eq 'Community') {
1477: $btntxt = &mt('Enroll Member');
1478: } else {
1479: $btntxt = &mt('Enroll Student');
1480: }
1481: $r->print('<br /><input type="button" value="'.$btntxt.'" onclick="setSections(this.form)" />'."\n");
1.218 raeburn 1482: } else {
1.375 raeburn 1483: $r->print('<fieldset><legend>'.&mt('Add Roles').'</legend>');
1.218 raeburn 1484: my $addrolesdisplay = 0;
1485: if ($context eq 'domain' || $context eq 'author') {
1486: $addrolesdisplay = &new_coauthor_roles($r,$ccuname,$ccdomain);
1487: }
1488: if ($context eq 'domain') {
1.357 raeburn 1489: my $add_domainroles = &new_domain_roles($r,$ccdomain);
1.218 raeburn 1490: if (!$addrolesdisplay) {
1491: $addrolesdisplay = $add_domainroles;
1.2 www 1492: }
1.375 raeburn 1493: $r->print(&course_level_dc($env{'request.role.domain'},$showcredits));
1494: $r->print('</fieldset><br /><input type="button" value="'.&mt('Save').'" onclick="setCourse()" />'."\n");
1.218 raeburn 1495: } elsif ($context eq 'author') {
1496: if ($addrolesdisplay) {
1.375 raeburn 1497: $r->print('</fieldset><br /><input type="button" value="'.&mt('Save').'"');
1.218 raeburn 1498: if ($newuser) {
1.301 bisitz 1499: $r->print(' onclick="auth_check()" \>'."\n");
1.218 raeburn 1500: } else {
1.301 bisitz 1501: $r->print('onclick="this.form.submit()" \>'."\n");
1.218 raeburn 1502: }
1.188 raeburn 1503: } else {
1.375 raeburn 1504: $r->print('</fieldset><br /><a href="javascript:backPage(document.cu)">'.
1.218 raeburn 1505: &mt('Back to previous page').'</a>');
1.188 raeburn 1506: }
1507: } else {
1.375 raeburn 1508: $r->print(&course_level_table(\%inccourses,$showcredits,$defaultcredits));
1509: $r->print('</fieldset><br /><input type="button" value="'.&mt('Save').'" onclick="setSections(this.form)" />'."\n");
1.188 raeburn 1510: }
1.88 raeburn 1511: }
1.188 raeburn 1512: $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','userrole','ccdomain','prevphase','currstate','ccuname','ccdomain']));
1.179 raeburn 1513: $r->print('<input type="hidden" name="currstate" value="" />');
1.352 raeburn 1514: $r->print('<input type="hidden" name="prevphase" value="'.$env{'form.phase'}.'" /></form>');
1.218 raeburn 1515: return;
1.2 www 1516: }
1.1 www 1517:
1.213 raeburn 1518: sub singleuser_breadcrumb {
1.318 raeburn 1519: my ($crstype) = @_;
1.213 raeburn 1520: my %breadcrumb_text;
1521: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1522: if ($crstype eq 'Community') {
1523: $breadcrumb_text{'search'} = 'Enroll a member';
1524: } else {
1525: $breadcrumb_text{'search'} = 'Enroll a student';
1526: }
1.213 raeburn 1527: $breadcrumb_text{'userpicked'} = 'Select a user',
1528: $breadcrumb_text{'modify'} = 'Set section/dates',
1529: } else {
1.229 raeburn 1530: $breadcrumb_text{'search'} = 'Create/modify a user';
1.213 raeburn 1531: $breadcrumb_text{'userpicked'} = 'Select a user',
1532: $breadcrumb_text{'modify'} = 'Set user role',
1533: }
1534: return %breadcrumb_text;
1535: }
1536:
1537: sub date_sections_select {
1.375 raeburn 1538: my ($context,$newuser,$formname,$permission,$crstype,$ccuname,$ccdomain,
1539: $showcredits) = @_;
1540: my $credits;
1541: if ($showcredits) {
1542: my $defaultcredits = &Apache::lonuserutils::get_defaultcredits();
1543: $credits = &get_user_credits($ccuname,$ccdomain,$defaultcredits);
1544: if ($credits eq '') {
1545: $credits = $defaultcredits;
1546: }
1547: }
1.213 raeburn 1548: my $cid = $env{'request.course.id'};
1549: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity($cid);
1550: my $date_table = '<h3>'.&mt('Starting and Ending Dates').'</h3>'."\n".
1551: &Apache::lonuserutils::date_setting_table(undef,undef,$context,
1552: undef,$formname,$permission);
1553: my $rowtitle = 'Section';
1.375 raeburn 1554: my $secbox = '<h3>'.&mt('Section and Credits').'</h3>'."\n".
1.213 raeburn 1555: &Apache::lonuserutils::section_picker($cdom,$cnum,'st',$rowtitle,
1.375 raeburn 1556: $permission,$context,'',$crstype,
1557: $showcredits,$credits);
1.213 raeburn 1558: my $output = $date_table.$secbox;
1559: return $output;
1560: }
1561:
1.216 raeburn 1562: sub validation_javascript {
1.375 raeburn 1563: my ($context,$ccdomain,$pjump_def,$crstype,$groupslist,$newuser,$formname,
1.216 raeburn 1564: $loaditem) = @_;
1565: my $dc_setcourse_code = '';
1566: my $nondc_setsection_code = '';
1567: if ($context eq 'domain') {
1568: my $dcdom = $env{'request.role.domain'};
1569: $loaditem->{'onload'} = "document.cu.coursedesc.value='';";
1.227 raeburn 1570: $dc_setcourse_code =
1571: &Apache::lonuserutils::dc_setcourse_js('cu','singleuser',$context);
1.216 raeburn 1572: } else {
1.227 raeburn 1573: my $checkauth;
1574: if (($newuser) || (&Apache::lonnet::allowed('mau',$ccdomain))) {
1575: $checkauth = 1;
1576: }
1577: if ($context eq 'course') {
1578: $nondc_setsection_code =
1579: &Apache::lonuserutils::setsections_javascript($formname,$groupslist,
1.375 raeburn 1580: undef,$checkauth,
1581: $crstype);
1.227 raeburn 1582: }
1583: if ($checkauth) {
1584: $nondc_setsection_code .=
1585: &Apache::lonuserutils::verify_authen($formname,$context);
1586: }
1.216 raeburn 1587: }
1588: my $js = &user_modification_js($pjump_def,$dc_setcourse_code,
1589: $nondc_setsection_code,$groupslist);
1590: my ($jsback,$elements) = &crumb_utilities();
1591: $js .= "\n".
1.301 bisitz 1592: '<script type="text/javascript">'."\n".
1593: '// <![CDATA['."\n".
1594: $jsback."\n".
1595: '// ]]>'."\n".
1596: '</script>'."\n";
1.216 raeburn 1597: return $js;
1598: }
1599:
1.217 raeburn 1600: sub display_existing_roles {
1.375 raeburn 1601: my ($r,$ccuname,$ccdomain,$inccourses,$context,$roledom,$crstype,
1602: $showcredits) = @_;
1.329 raeburn 1603: my $now=time;
1604: my %lt=&Apache::lonlocal::texthash(
1.217 raeburn 1605: 'rer' => "Existing Roles",
1606: 'rev' => "Revoke",
1607: 'del' => "Delete",
1608: 'ren' => "Re-Enable",
1609: 'rol' => "Role",
1610: 'ext' => "Extent",
1.375 raeburn 1611: 'crd' => "Credits",
1.217 raeburn 1612: 'sta' => "Start",
1613: 'end' => "End",
1614: );
1.329 raeburn 1615: my (%rolesdump,%roletext,%sortrole,%roleclass,%rolepriv);
1616: if ($context eq 'course' || $context eq 'author') {
1617: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
1618: my %roleshash =
1619: &Apache::lonnet::get_my_roles($ccuname,$ccdomain,'userroles',
1620: ['active','previous','future'],\@roles,$roledom,1);
1621: foreach my $key (keys(%roleshash)) {
1622: my ($start,$end) = split(':',$roleshash{$key});
1623: next if ($start eq '-1' || $end eq '-1');
1624: my ($rnum,$rdom,$role,$sec) = split(':',$key);
1625: if ($context eq 'course') {
1626: next unless (($rnum eq $env{'course.'.$env{'request.course.id'}.'.num'})
1627: && ($rdom eq $env{'course.'.$env{'request.course.id'}.'.domain'}));
1628: } elsif ($context eq 'author') {
1629: next unless (($rnum eq $env{'user.name'}) && ($rdom eq $env{'request.role.domain'}));
1630: }
1631: my ($newkey,$newvalue,$newrole);
1632: $newkey = '/'.$rdom.'/'.$rnum;
1633: if ($sec ne '') {
1634: $newkey .= '/'.$sec;
1635: }
1636: $newvalue = $role;
1637: if ($role =~ /^cr/) {
1638: $newrole = 'cr';
1639: } else {
1640: $newrole = $role;
1641: }
1642: $newkey .= '_'.$newrole;
1643: if ($start ne '' && $end ne '') {
1644: $newvalue .= '_'.$end.'_'.$start;
1.335 raeburn 1645: } elsif ($end ne '') {
1646: $newvalue .= '_'.$end;
1.329 raeburn 1647: }
1648: $rolesdump{$newkey} = $newvalue;
1649: }
1650: } else {
1.360 raeburn 1651: %rolesdump=&Apache::lonnet::dump('roles',$ccdomain,$ccuname);
1.329 raeburn 1652: }
1653: # Build up table of user roles to allow revocation and re-enabling of roles.
1654: my ($tmp) = keys(%rolesdump);
1655: return if ($tmp =~ /^(con_lost|error)/i);
1656: foreach my $area (sort { my $a1=join('_',(split('_',$a))[1,0]);
1657: my $b1=join('_',(split('_',$b))[1,0]);
1658: return $a1 cmp $b1;
1659: } keys(%rolesdump)) {
1660: next if ($area =~ /^rolesdef/);
1661: my $envkey=$area;
1662: my $role = $rolesdump{$area};
1663: my $thisrole=$area;
1664: $area =~ s/\_\w\w$//;
1665: my ($role_code,$role_end_time,$role_start_time) =
1666: split(/_/,$role);
1.217 raeburn 1667: # Is this a custom role? Get role owner and title.
1.329 raeburn 1668: my ($croleudom,$croleuname,$croletitle)=
1669: ($role_code=~m{^cr/($match_domain)/($match_username)/(\w+)$});
1670: my $allowed=0;
1671: my $delallowed=0;
1672: my $sortkey=$role_code;
1673: my $class='Unknown';
1.375 raeburn 1674: my $credits='';
1.329 raeburn 1675: if ($area =~ m{^/($match_domain)/($match_courseid)} ) {
1676: $class='Course';
1677: my ($coursedom,$coursedir) = ($1,$2);
1678: my $cid = $1.'_'.$2;
1679: # $1.'_'.$2 is the course id (eg. 103_12345abcef103l3).
1680: my %coursedata=
1681: &Apache::lonnet::coursedescription($cid);
1682: if ($coursedir =~ /^$match_community$/) {
1683: $class='Community';
1684: }
1685: $sortkey.="\0$coursedom";
1686: my $carea;
1687: if (defined($coursedata{'description'})) {
1688: $carea=$coursedata{'description'}.
1689: '<br />'.&mt('Domain').': '.$coursedom.(' 'x8).
1690: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$coursedir,$coursedom);
1691: $sortkey.="\0".$coursedata{'description'};
1692: } else {
1693: if ($class eq 'Community') {
1694: $carea=&mt('Unavailable community').': '.$area;
1695: $sortkey.="\0".&mt('Unavailable community').': '.$area;
1.217 raeburn 1696: } else {
1697: $carea=&mt('Unavailable course').': '.$area;
1698: $sortkey.="\0".&mt('Unavailable course').': '.$area;
1699: }
1.329 raeburn 1700: }
1701: $sortkey.="\0$coursedir";
1702: $inccourses->{$cid}=1;
1.375 raeburn 1703: if (($showcredits) && ($class eq 'Course') && ($role_code eq 'st')) {
1704: my $defaultcredits = $coursedata{'internal.defaultcredits'};
1705: $credits =
1706: &get_user_credits($ccuname,$ccdomain,$defaultcredits,
1707: $coursedom,$coursedir);
1708: if ($credits eq '') {
1709: $credits = $defaultcredits;
1710: }
1711: }
1.329 raeburn 1712: if ((&Apache::lonnet::allowed('c'.$role_code,$coursedom.'/'.$coursedir)) ||
1713: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
1714: $allowed=1;
1715: }
1716: unless ($allowed) {
1.365 raeburn 1717: my $isowner = &Apache::lonuserutils::is_courseowner($cid,$coursedata{'internal.courseowner'});
1.329 raeburn 1718: if ($isowner) {
1719: if (($role_code eq 'co') && ($class eq 'Community')) {
1720: $allowed = 1;
1721: } elsif (($role_code eq 'cc') && ($class eq 'Course')) {
1722: $allowed = 1;
1723: }
1.217 raeburn 1724: }
1.329 raeburn 1725: }
1726: if ((&Apache::lonnet::allowed('dro',$coursedom)) ||
1727: (&Apache::lonnet::allowed('dro',$ccdomain))) {
1728: $delallowed=1;
1729: }
1.217 raeburn 1730: # - custom role. Needs more info, too
1.329 raeburn 1731: if ($croletitle) {
1732: if (&Apache::lonnet::allowed('ccr',$coursedom.'/'.$coursedir)) {
1733: $allowed=1;
1734: $thisrole.='.'.$role_code;
1.217 raeburn 1735: }
1.329 raeburn 1736: }
1737: if ($area=~m{^/($match_domain)/($match_courseid)/(\w+)}) {
1.373 bisitz 1738: $carea.='<br />'.&mt('Section: [_1]',$3);
1.329 raeburn 1739: $sortkey.="\0$3";
1740: if (!$allowed) {
1741: if ($env{'request.course.sec'} eq $3) {
1742: if (&Apache::lonnet::allowed('c'.$role_code,$1.'/'.$2.'/'.$3)) {
1743: $allowed = 1;
1.217 raeburn 1744: }
1745: }
1746: }
1.329 raeburn 1747: }
1748: $area=$carea;
1749: } else {
1750: $sortkey.="\0".$area;
1751: # Determine if current user is able to revoke privileges
1752: if ($area=~m{^/($match_domain)/}) {
1753: if ((&Apache::lonnet::allowed('c'.$role_code,$1)) ||
1754: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
1755: $allowed=1;
1.217 raeburn 1756: }
1.329 raeburn 1757: if (((&Apache::lonnet::allowed('dro',$1)) ||
1758: (&Apache::lonnet::allowed('dro',$ccdomain))) &&
1759: ($role_code ne 'dc')) {
1760: $delallowed=1;
1.217 raeburn 1761: }
1.329 raeburn 1762: } else {
1763: if (&Apache::lonnet::allowed('c'.$role_code,'/')) {
1.217 raeburn 1764: $allowed=1;
1765: }
1766: }
1.363 raeburn 1767: if ($role_code eq 'ca' || $role_code eq 'au' || $role_code eq 'aa') {
1.377 raeburn 1768: $class='Authoring Space';
1.329 raeburn 1769: } elsif ($role_code eq 'su') {
1770: $class='System';
1.217 raeburn 1771: } else {
1.329 raeburn 1772: $class='Domain';
1.217 raeburn 1773: }
1.329 raeburn 1774: }
1775: if (($role_code eq 'ca') || ($role_code eq 'aa')) {
1776: $area=~m{/($match_domain)/($match_username)};
1777: if (&Apache::lonuserutils::authorpriv($2,$1)) {
1778: $allowed=1;
1.217 raeburn 1779: } else {
1.329 raeburn 1780: $allowed=0;
1.217 raeburn 1781: }
1.329 raeburn 1782: }
1783: my $row = '';
1784: $row.= '<td>';
1785: my $active=1;
1786: $active=0 if (($role_end_time) && ($now>$role_end_time));
1787: if (($active) && ($allowed)) {
1788: $row.= '<input type="checkbox" name="rev:'.$thisrole.'" />';
1789: } else {
1790: if ($active) {
1791: $row.=' ';
1.217 raeburn 1792: } else {
1.329 raeburn 1793: $row.=&mt('expired or revoked');
1.217 raeburn 1794: }
1.329 raeburn 1795: }
1796: $row.='</td><td>';
1797: if ($allowed && !$active) {
1798: $row.= '<input type="checkbox" name="ren:'.$thisrole.'" />';
1799: } else {
1800: $row.=' ';
1801: }
1802: $row.='</td><td>';
1803: if ($delallowed) {
1804: $row.= '<input type="checkbox" name="del:'.$thisrole.'" />';
1805: } else {
1806: $row.=' ';
1807: }
1808: my $plaintext='';
1809: if (!$croletitle) {
1.375 raeburn 1810: $plaintext=&Apache::lonnet::plaintext($role_code,$class);
1811: if (($showcredits) && ($credits ne '')) {
1812: $plaintext .= '<br/ ><span class="LC_nobreak">'.
1813: '<span class="LC_fontsize_small">'.
1814: &mt('Credits: [_1]',$credits).
1815: '</span></span>';
1816: }
1.329 raeburn 1817: } else {
1818: $plaintext=
1.346 bisitz 1819: &mt('Customrole [_1][_2]defined by [_3]',
1820: '"'.$croletitle.'"',
1821: '<br />',
1822: $croleuname.':'.$croleudom);
1.329 raeburn 1823: }
1824: $row.= '</td><td>'.$plaintext.
1825: '</td><td>'.$area.
1826: '</td><td>'.($role_start_time?&Apache::lonlocal::locallocaltime($role_start_time)
1827: : ' ' ).
1828: '</td><td>'.($role_end_time ?&Apache::lonlocal::locallocaltime($role_end_time)
1829: : ' ' )
1830: ."</td>";
1831: $sortrole{$sortkey}=$envkey;
1832: $roletext{$envkey}=$row;
1833: $roleclass{$envkey}=$class;
1834: $rolepriv{$envkey}=$allowed;
1835: } # end of foreach (table building loop)
1836:
1837: my $rolesdisplay = 0;
1838: my %output = ();
1.377 raeburn 1839: foreach my $type ('Authoring Space','Course','Community','Domain','System','Unknown') {
1.329 raeburn 1840: $output{$type} = '';
1841: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
1842: if ( ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/ ) && ($rolepriv{$sortrole{$which}}) ) {
1843: $output{$type}.=
1844: &Apache::loncommon::start_data_table_row().
1845: $roletext{$sortrole{$which}}.
1846: &Apache::loncommon::end_data_table_row();
1.217 raeburn 1847: }
1.329 raeburn 1848: }
1849: unless($output{$type} eq '') {
1850: $output{$type} = '<tr class="LC_info_row">'.
1851: "<td align='center' colspan='7'>".&mt($type)."</td></tr>".
1852: $output{$type};
1853: $rolesdisplay = 1;
1854: }
1855: }
1856: if ($rolesdisplay == 1) {
1857: my $contextrole='';
1858: if ($env{'request.course.id'}) {
1859: if (&Apache::loncommon::course_type() eq 'Community') {
1860: $contextrole = &mt('Existing Roles in this Community');
1.290 bisitz 1861: } else {
1.329 raeburn 1862: $contextrole = &mt('Existing Roles in this Course');
1.290 bisitz 1863: }
1.329 raeburn 1864: } elsif ($env{'request.role'} =~ /^au\./) {
1.377 raeburn 1865: $contextrole = &mt('Existing Co-Author Roles in your Authoring Space');
1.329 raeburn 1866: } else {
1867: $contextrole = &mt('Existing Roles in this Domain');
1868: }
1.375 raeburn 1869: $r->print('<div>'.
1870: '<fieldset><legend>'.$contextrole.'</legend>'.
1.217 raeburn 1871: &Apache::loncommon::start_data_table("LC_createuser").
1872: &Apache::loncommon::start_data_table_header_row().
1873: '<th>'.$lt{'rev'}.'</th><th>'.$lt{'ren'}.'</th><th>'.$lt{'del'}.
1874: '</th><th>'.$lt{'rol'}.'</th><th>'.$lt{'ext'}.
1875: '</th><th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
1876: &Apache::loncommon::end_data_table_header_row());
1.377 raeburn 1877: foreach my $type ('Authoring Space','Course','Community','Domain','System','Unknown') {
1.329 raeburn 1878: if ($output{$type}) {
1879: $r->print($output{$type}."\n");
1.217 raeburn 1880: }
1881: }
1.375 raeburn 1882: $r->print(&Apache::loncommon::end_data_table().
1883: '</fieldset></div>');
1.329 raeburn 1884: }
1.217 raeburn 1885: return;
1886: }
1887:
1.218 raeburn 1888: sub new_coauthor_roles {
1889: my ($r,$ccuname,$ccdomain) = @_;
1890: my $addrolesdisplay = 0;
1891: #
1892: # Co-Author
1893: #
1894: if (&Apache::lonuserutils::authorpriv($env{'user.name'},
1895: $env{'request.role.domain'}) &&
1896: ($env{'user.name'} ne $ccuname || $env{'user.domain'} ne $ccdomain)) {
1897: # No sense in assigning co-author role to yourself
1898: $addrolesdisplay = 1;
1899: my $cuname=$env{'user.name'};
1900: my $cudom=$env{'request.role.domain'};
1901: my %lt=&Apache::lonlocal::texthash(
1.377 raeburn 1902: 'cs' => "Authoring Space",
1.218 raeburn 1903: 'act' => "Activate",
1904: 'rol' => "Role",
1905: 'ext' => "Extent",
1906: 'sta' => "Start",
1907: 'end' => "End",
1908: 'cau' => "Co-Author",
1909: 'caa' => "Assistant Co-Author",
1910: 'ssd' => "Set Start Date",
1911: 'sed' => "Set End Date"
1912: );
1913: $r->print('<h4>'.$lt{'cs'}.'</h4>'."\n".
1914: &Apache::loncommon::start_data_table()."\n".
1915: &Apache::loncommon::start_data_table_header_row()."\n".
1916: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'.
1917: '<th>'.$lt{'ext'}.'</th><th>'.$lt{'sta'}.'</th>'.
1918: '<th>'.$lt{'end'}.'</th>'."\n".
1919: &Apache::loncommon::end_data_table_header_row()."\n".
1920: &Apache::loncommon::start_data_table_row().'
1921: <td>
1.291 bisitz 1922: <input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_ca" />
1.218 raeburn 1923: </td>
1924: <td>'.$lt{'cau'}.'</td>
1925: <td>'.$cudom.'_'.$cuname.'</td>
1926: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_ca" value="" />
1927: <a href=
1928: "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>
1929: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_ca" value="" />
1930: <a href=
1931: "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".
1932: &Apache::loncommon::end_data_table_row()."\n".
1933: &Apache::loncommon::start_data_table_row()."\n".
1.291 bisitz 1934: '<td><input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_aa" /></td>
1.218 raeburn 1935: <td>'.$lt{'caa'}.'</td>
1936: <td>'.$cudom.'_'.$cuname.'</td>
1937: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_aa" value="" />
1938: <a href=
1939: "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>
1940: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_aa" value="" />
1941: <a href=
1942: "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".
1943: &Apache::loncommon::end_data_table_row()."\n".
1944: &Apache::loncommon::end_data_table());
1945: } elsif ($env{'request.role'} =~ /^au\./) {
1946: if (!(&Apache::lonuserutils::authorpriv($env{'user.name'},
1947: $env{'request.role.domain'}))) {
1948: $r->print('<span class="LC_error">'.
1949: &mt('You do not have privileges to assign co-author roles.').
1950: '</span>');
1951: } elsif (($env{'user.name'} eq $ccuname) &&
1952: ($env{'user.domain'} eq $ccdomain)) {
1.377 raeburn 1953: $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 1954: }
1955: }
1956: return $addrolesdisplay;;
1957: }
1958:
1959: sub new_domain_roles {
1.357 raeburn 1960: my ($r,$ccdomain) = @_;
1.218 raeburn 1961: my $addrolesdisplay = 0;
1962: #
1963: # Domain level
1964: #
1965: my $num_domain_level = 0;
1966: my $domaintext =
1967: '<h4>'.&mt('Domain Level').'</h4>'.
1968: &Apache::loncommon::start_data_table().
1969: &Apache::loncommon::start_data_table_header_row().
1970: '<th>'.&mt('Activate').'</th><th>'.&mt('Role').'</th><th>'.
1971: &mt('Extent').'</th>'.
1972: '<th>'.&mt('Start').'</th><th>'.&mt('End').'</th>'.
1973: &Apache::loncommon::end_data_table_header_row();
1.312 raeburn 1974: my @allroles = &Apache::lonuserutils::roles_by_context('domain');
1.218 raeburn 1975: foreach my $thisdomain (sort(&Apache::lonnet::all_domains())) {
1.312 raeburn 1976: foreach my $role (@allroles) {
1977: next if ($role eq 'ad');
1.357 raeburn 1978: next if (($role eq 'au') && ($ccdomain ne $thisdomain));
1.218 raeburn 1979: if (&Apache::lonnet::allowed('c'.$role,$thisdomain)) {
1980: my $plrole=&Apache::lonnet::plaintext($role);
1981: my %lt=&Apache::lonlocal::texthash(
1982: 'ssd' => "Set Start Date",
1983: 'sed' => "Set End Date"
1984: );
1985: $num_domain_level ++;
1986: $domaintext .=
1987: &Apache::loncommon::start_data_table_row().
1.291 bisitz 1988: '<td><input type="checkbox" name="act_'.$thisdomain.'_'.$role.'" /></td>
1.218 raeburn 1989: <td>'.$plrole.'</td>
1990: <td>'.$thisdomain.'</td>
1991: <td><input type="hidden" name="start_'.$thisdomain.'_'.$role.'" value="" />
1992: <a href=
1993: "javascript:pjump('."'date_start','Start Date $plrole',document.cu.start_$thisdomain\_$role.value,'start_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'ssd'}.'</a></td>
1994: <td><input type="hidden" name="end_'.$thisdomain.'_'.$role.'" value="" />
1995: <a href=
1996: "javascript:pjump('."'date_end','End Date $plrole',document.cu.end_$thisdomain\_$role.value,'end_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'sed'}.'</a></td>'.
1997: &Apache::loncommon::end_data_table_row();
1998: }
1999: }
2000: }
2001: $domaintext.= &Apache::loncommon::end_data_table();
2002: if ($num_domain_level > 0) {
2003: $r->print($domaintext);
2004: $addrolesdisplay = 1;
2005: }
2006: return $addrolesdisplay;
2007: }
2008:
1.188 raeburn 2009: sub user_authentication {
1.227 raeburn 2010: my ($ccuname,$ccdomain,$formname) = @_;
1.188 raeburn 2011: my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
1.227 raeburn 2012: my $outcome;
1.188 raeburn 2013: # Check for a bad authentication type
2014: if ($currentauth !~ /^(krb4|krb5|unix|internal|localauth):/) {
2015: # bad authentication scheme
2016: my %lt=&Apache::lonlocal::texthash(
2017: 'err' => "ERROR",
2018: 'uuas' => "This user has an unrecognized authentication scheme",
2019: 'adcs' => "Please alert a domain coordinator of this situation",
2020: 'sldb' => "Please specify login data below",
2021: 'ld' => "Login Data"
2022: );
2023: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
1.227 raeburn 2024: &initialize_authen_forms($ccdomain,$formname);
2025:
1.190 raeburn 2026: my $choices = &Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc);
1.188 raeburn 2027: $outcome = <<ENDBADAUTH;
2028: <script type="text/javascript" language="Javascript">
1.301 bisitz 2029: // <![CDATA[
1.188 raeburn 2030: $loginscript
1.301 bisitz 2031: // ]]>
1.188 raeburn 2032: </script>
2033: <span class="LC_error">$lt{'err'}:
2034: $lt{'uuas'} ($currentauth). $lt{'sldb'}.</span>
2035: <h3>$lt{'ld'}</h3>
2036: $choices
2037: ENDBADAUTH
2038: } else {
2039: # This user is not allowed to modify the user's
2040: # authentication scheme, so just notify them of the problem
2041: $outcome = <<ENDBADAUTH;
2042: <span class="LC_error"> $lt{'err'}:
2043: $lt{'uuas'} ($currentauth). $lt{'adcs'}.
2044: </span>
2045: ENDBADAUTH
2046: }
2047: } else { # Authentication type is valid
1.227 raeburn 2048: &initialize_authen_forms($ccdomain,$formname,$currentauth,'modifyuser');
1.205 raeburn 2049: my ($authformcurrent,$can_modify,@authform_others) =
1.188 raeburn 2050: &modify_login_block($ccdomain,$currentauth);
2051: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
2052: # Current user has login modification privileges
2053: my %lt=&Apache::lonlocal::texthash (
2054: 'ld' => "Login Data",
2055: 'ccld' => "Change Current Login Data",
2056: 'enld' => "Enter New Login Data"
2057: );
2058: $outcome =
2059: '<script type="text/javascript" language="Javascript">'."\n".
1.301 bisitz 2060: '// <![CDATA['."\n".
1.188 raeburn 2061: $loginscript."\n".
1.301 bisitz 2062: '// ]]>'."\n".
1.188 raeburn 2063: '</script>'."\n".
2064: '<h3>'.$lt{'ld'}.'</h3>'.
2065: &Apache::loncommon::start_data_table().
1.205 raeburn 2066: &Apache::loncommon::start_data_table_row().
1.188 raeburn 2067: '<td>'.$authformnop;
2068: if ($can_modify) {
2069: $outcome .= '</td>'."\n".
2070: &Apache::loncommon::end_data_table_row().
2071: &Apache::loncommon::start_data_table_row().
2072: '<td>'.$authformcurrent.'</td>'.
2073: &Apache::loncommon::end_data_table_row()."\n";
2074: } else {
1.200 raeburn 2075: $outcome .= ' ('.$authformcurrent.')</td>'.
2076: &Apache::loncommon::end_data_table_row()."\n";
1.188 raeburn 2077: }
1.205 raeburn 2078: foreach my $item (@authform_others) {
2079: $outcome .= &Apache::loncommon::start_data_table_row().
2080: '<td>'.$item.'</td>'.
2081: &Apache::loncommon::end_data_table_row()."\n";
1.188 raeburn 2082: }
1.205 raeburn 2083: $outcome .= &Apache::loncommon::end_data_table();
1.188 raeburn 2084: } else {
2085: if (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
2086: my %lt=&Apache::lonlocal::texthash(
2087: 'ccld' => "Change Current Login Data",
2088: 'yodo' => "You do not have privileges to modify the authentication configuration for this user.",
2089: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
2090: );
2091: $outcome .= <<ENDNOPRIV;
2092: <h3>$lt{'ccld'}</h3>
2093: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1.235 raeburn 2094: <input type="hidden" name="login" value="nochange" />
1.188 raeburn 2095: ENDNOPRIV
2096: }
2097: }
2098: } ## End of "check for bad authentication type" logic
2099: return $outcome;
2100: }
2101:
1.187 raeburn 2102: sub modify_login_block {
2103: my ($dom,$currentauth) = @_;
2104: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2105: my ($authnum,%can_assign) =
2106: &Apache::loncommon::get_assignable_auth($dom);
1.205 raeburn 2107: my ($authformcurrent,@authform_others,$show_override_msg);
1.187 raeburn 2108: if ($currentauth=~/^krb(4|5):/) {
2109: $authformcurrent=$authformkrb;
2110: if ($can_assign{'int'}) {
1.205 raeburn 2111: push(@authform_others,$authformint);
1.187 raeburn 2112: }
2113: if ($can_assign{'loc'}) {
1.205 raeburn 2114: push(@authform_others,$authformloc);
1.187 raeburn 2115: }
2116: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
2117: $show_override_msg = 1;
2118: }
2119: } elsif ($currentauth=~/^internal:/) {
2120: $authformcurrent=$authformint;
2121: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2122: push(@authform_others,$authformkrb);
1.187 raeburn 2123: }
2124: if ($can_assign{'loc'}) {
1.205 raeburn 2125: push(@authform_others,$authformloc);
1.187 raeburn 2126: }
2127: if ($can_assign{'int'}) {
2128: $show_override_msg = 1;
2129: }
2130: } elsif ($currentauth=~/^unix:/) {
2131: $authformcurrent=$authformfsys;
2132: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2133: push(@authform_others,$authformkrb);
1.187 raeburn 2134: }
2135: if ($can_assign{'int'}) {
1.205 raeburn 2136: push(@authform_others,$authformint);
1.187 raeburn 2137: }
2138: if ($can_assign{'loc'}) {
1.205 raeburn 2139: push(@authform_others,$authformloc);
1.187 raeburn 2140: }
2141: if ($can_assign{'fsys'}) {
2142: $show_override_msg = 1;
2143: }
2144: } elsif ($currentauth=~/^localauth:/) {
2145: $authformcurrent=$authformloc;
2146: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2147: push(@authform_others,$authformkrb);
1.187 raeburn 2148: }
2149: if ($can_assign{'int'}) {
1.205 raeburn 2150: push(@authform_others,$authformint);
1.187 raeburn 2151: }
2152: if ($can_assign{'loc'}) {
2153: $show_override_msg = 1;
2154: }
2155: }
2156: if ($show_override_msg) {
1.205 raeburn 2157: $authformcurrent = '<table><tr><td colspan="3">'.$authformcurrent.
2158: '</td></tr>'."\n".
2159: '<tr><td> </td>'.
2160: '<td><b>'.&mt('Currently in use').'</b></td>'.
2161: '<td align="right"><span class="LC_cusr_emph">'.
1.187 raeburn 2162: &mt('will override current values').
1.205 raeburn 2163: '</span></td></tr></table>';
1.187 raeburn 2164: }
1.205 raeburn 2165: return ($authformcurrent,$show_override_msg,@authform_others);
1.187 raeburn 2166: }
2167:
1.188 raeburn 2168: sub personal_data_display {
1.252 raeburn 2169: my ($ccuname,$ccdomain,$newuser,$context,$inst_results,$rolesarray) = @_;
1.286 raeburn 2170: my ($output,$showforceid,%userenv,%canmodify,%canmodify_status);
1.219 raeburn 2171: my @userinfo = ('firstname','middlename','lastname','generation',
2172: 'permanentemail','id');
1.252 raeburn 2173: my $rowcount = 0;
2174: my $editable = 0;
1.286 raeburn 2175: %canmodify_status =
2176: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
2177: ['inststatus'],$rolesarray);
1.253 raeburn 2178: if (!$newuser) {
1.188 raeburn 2179: # Get the users information
2180: %userenv = &Apache::lonnet::get('environment',
2181: ['firstname','middlename','lastname','generation',
1.286 raeburn 2182: 'permanentemail','id','inststatus'],$ccdomain,$ccuname);
1.219 raeburn 2183: %canmodify =
2184: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
1.252 raeburn 2185: \@userinfo,$rolesarray);
1.257 raeburn 2186: } elsif ($context eq 'selfcreate') {
2187: %canmodify = &selfcreate_canmodify($context,$ccdomain,\@userinfo,
2188: $inst_results,$rolesarray);
1.188 raeburn 2189: }
2190: my %lt=&Apache::lonlocal::texthash(
2191: 'pd' => "Personal Data",
2192: 'firstname' => "First Name",
2193: 'middlename' => "Middle Name",
2194: 'lastname' => "Last Name",
2195: 'generation' => "Generation",
2196: 'permanentemail' => "Permanent e-mail address",
1.259 bisitz 2197: 'id' => "Student/Employee ID",
1.286 raeburn 2198: 'lg' => "Login Data",
2199: 'inststatus' => "Affiliation",
1.188 raeburn 2200: );
2201: my %textboxsize = (
2202: firstname => '15',
2203: middlename => '15',
2204: lastname => '15',
2205: generation => '5',
2206: permanentemail => '25',
2207: id => '15',
2208: );
2209: my $genhelp=&Apache::loncommon::help_open_topic('Generation');
2210: $output = '<h3>'.$lt{'pd'}.'</h3>'.
2211: &Apache::lonhtmlcommon::start_pick_box();
2212: foreach my $item (@userinfo) {
2213: my $rowtitle = $lt{$item};
1.252 raeburn 2214: my $hiderow = 0;
1.188 raeburn 2215: if ($item eq 'generation') {
2216: $rowtitle = $genhelp.$rowtitle;
2217: }
1.252 raeburn 2218: my $row = &Apache::lonhtmlcommon::row_title($rowtitle,undef,'LC_oddrow_value')."\n";
1.188 raeburn 2219: if ($newuser) {
1.210 raeburn 2220: if (ref($inst_results) eq 'HASH') {
2221: if ($inst_results->{$item} ne '') {
1.252 raeburn 2222: $row .= '<input type="hidden" name="c'.$item.'" value="'.$inst_results->{$item}.'" />'.$inst_results->{$item};
1.210 raeburn 2223: } else {
1.252 raeburn 2224: if ($context eq 'selfcreate') {
2225: if ($canmodify{$item}) {
2226: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
2227: $editable ++;
2228: } else {
2229: $hiderow = 1;
2230: }
1.253 raeburn 2231: } else {
2232: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1.252 raeburn 2233: }
1.210 raeburn 2234: }
1.188 raeburn 2235: } else {
1.252 raeburn 2236: if ($context eq 'selfcreate') {
1.287 raeburn 2237: if (($item eq 'permanentemail') && ($newuser eq 'email')) {
2238: $row .= $ccuname;
1.252 raeburn 2239: } else {
1.287 raeburn 2240: if ($canmodify{$item}) {
2241: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
2242: $editable ++;
2243: } else {
2244: $hiderow = 1;
2245: }
1.252 raeburn 2246: }
1.253 raeburn 2247: } else {
2248: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1.252 raeburn 2249: }
1.188 raeburn 2250: }
2251: } else {
1.219 raeburn 2252: if ($canmodify{$item}) {
1.252 raeburn 2253: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="'.$userenv{$item}.'" />';
1.188 raeburn 2254: } else {
1.252 raeburn 2255: $row .= $userenv{$item};
1.188 raeburn 2256: }
1.206 raeburn 2257: if ($item eq 'id') {
1.219 raeburn 2258: $showforceid = $canmodify{$item};
2259: }
1.188 raeburn 2260: }
1.252 raeburn 2261: $row .= &Apache::lonhtmlcommon::row_closure(1);
2262: if (!$hiderow) {
2263: $output .= $row;
2264: $rowcount ++;
2265: }
1.188 raeburn 2266: }
1.286 raeburn 2267: if (($canmodify_status{'inststatus'}) || ($context ne 'selfcreate')) {
2268: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($ccdomain);
2269: if (ref($types) eq 'ARRAY') {
2270: if (@{$types} > 0) {
2271: my ($hiderow,$shown);
2272: if ($canmodify_status{'inststatus'}) {
2273: $shown = &pick_inst_statuses($userenv{'inststatus'},$usertypes,$types);
2274: } else {
2275: if ($userenv{'inststatus'} eq '') {
2276: $hiderow = 1;
1.334 raeburn 2277: } else {
2278: my @showitems;
2279: foreach my $item ( map { &unescape($_); } split(':',$userenv{'inststatus'})) {
2280: if (exists($usertypes->{$item})) {
2281: push(@showitems,$usertypes->{$item});
2282: } else {
2283: push(@showitems,$item);
2284: }
2285: }
2286: if (@showitems) {
2287: $shown = join(', ',@showitems);
2288: } else {
2289: $hiderow = 1;
2290: }
1.286 raeburn 2291: }
2292: }
2293: if (!$hiderow) {
2294: my $row = &Apache::lonhtmlcommon::row_title(&mt('Affliations'),undef,'LC_oddrow_value')."\n".
2295: $shown.&Apache::lonhtmlcommon::row_closure(1);
2296: if ($context eq 'selfcreate') {
2297: $rowcount ++;
2298: }
2299: $output .= $row;
2300: }
2301: }
2302: }
2303: }
1.188 raeburn 2304: $output .= &Apache::lonhtmlcommon::end_pick_box();
1.206 raeburn 2305: if (wantarray) {
1.252 raeburn 2306: if ($context eq 'selfcreate') {
2307: return($output,$rowcount,$editable);
2308: } else {
2309: return ($output,$showforceid);
2310: }
1.206 raeburn 2311: } else {
2312: return $output;
2313: }
1.188 raeburn 2314: }
2315:
1.286 raeburn 2316: sub pick_inst_statuses {
2317: my ($curr,$usertypes,$types) = @_;
2318: my ($output,$rem,@currtypes);
2319: if ($curr ne '') {
2320: @currtypes = map { &unescape($_); } split(/:/,$curr);
2321: }
2322: my $numinrow = 2;
2323: if (ref($types) eq 'ARRAY') {
2324: $output = '<table>';
2325: my $lastcolspan;
2326: for (my $i=0; $i<@{$types}; $i++) {
2327: if (defined($usertypes->{$types->[$i]})) {
2328: my $rem = $i%($numinrow);
2329: if ($rem == 0) {
2330: if ($i<@{$types}-1) {
2331: if ($i > 0) {
2332: $output .= '</tr>';
2333: }
2334: $output .= '<tr>';
2335: }
2336: } elsif ($i==@{$types}-1) {
2337: my $colsleft = $numinrow - $rem;
2338: if ($colsleft > 1) {
2339: $lastcolspan = ' colspan="'.$colsleft.'"';
2340: }
2341: }
2342: my $check = ' ';
2343: if (grep(/^\Q$types->[$i]\E$/,@currtypes)) {
2344: $check = ' checked="checked" ';
2345: }
2346: $output .= '<td class="LC_left_item"'.$lastcolspan.'>'.
2347: '<span class="LC_nobreak"><label>'.
2348: '<input type="checkbox" name="inststatus" '.
2349: 'value="'.$types->[$i].'"'.$check.'/>'.
2350: $usertypes->{$types->[$i]}.'</label></span></td>';
2351: }
2352: }
2353: $output .= '</tr></table>';
2354: }
2355: return $output;
2356: }
2357:
1.257 raeburn 2358: sub selfcreate_canmodify {
2359: my ($context,$dom,$userinfo,$inst_results,$rolesarray) = @_;
2360: if (ref($inst_results) eq 'HASH') {
2361: my @inststatuses = &get_inststatuses($inst_results);
2362: if (@inststatuses == 0) {
2363: @inststatuses = ('default');
2364: }
2365: $rolesarray = \@inststatuses;
2366: }
2367: my %canmodify =
2368: &Apache::lonuserutils::can_modify_userinfo($context,$dom,$userinfo,
2369: $rolesarray);
2370: return %canmodify;
2371: }
2372:
1.252 raeburn 2373: sub get_inststatuses {
2374: my ($insthashref) = @_;
2375: my @inststatuses = ();
2376: if (ref($insthashref) eq 'HASH') {
2377: if (ref($insthashref->{'inststatus'}) eq 'ARRAY') {
2378: @inststatuses = @{$insthashref->{'inststatus'}};
2379: }
2380: }
2381: return @inststatuses;
2382: }
2383:
1.4 www 2384: # ================================================================= Phase Three
1.42 matthew 2385: sub update_user_data {
1.375 raeburn 2386: my ($r,$context,$crstype,$brcrum,$showcredits) = @_;
1.101 albertel 2387: my $uhome=&Apache::lonnet::homeserver($env{'form.ccuname'},
2388: $env{'form.ccdomain'});
1.27 matthew 2389: # Error messages
1.188 raeburn 2390: my $error = '<span class="LC_error">'.&mt('Error').': ';
1.193 raeburn 2391: my $end = '</span><br /><br />';
2392: my $rtnlink = '<a href="javascript:backPage(document.userupdate,'.
1.188 raeburn 2393: "'$env{'form.prevphase'}','modify')".'" />'.
1.219 raeburn 2394: &mt('Return to previous page').'</a>'.
2395: &Apache::loncommon::end_page();
2396: my $now = time;
1.40 www 2397: my $title;
1.101 albertel 2398: if (exists($env{'form.makeuser'})) {
1.40 www 2399: $title='Set Privileges for New User';
2400: } else {
2401: $title='Modify User Privileges';
2402: }
1.213 raeburn 2403: my $newuser = 0;
1.160 raeburn 2404: my ($jsback,$elements) = &crumb_utilities();
2405: my $jscript = '<script type="text/javascript">'."\n".
1.301 bisitz 2406: '// <![CDATA['."\n".
2407: $jsback."\n".
2408: '// ]]>'."\n".
2409: '</script>'."\n";
1.318 raeburn 2410: my %breadcrumb_text = &singleuser_breadcrumb($crstype);
1.351 raeburn 2411: push (@{$brcrum},
2412: {href => "javascript:backPage(document.userupdate)",
2413: text => $breadcrumb_text{'search'},
2414: faq => 282,
2415: bug => 'Instructor Interface',}
2416: );
2417: if ($env{'form.prevphase'} eq 'userpicked') {
2418: push(@{$brcrum},
2419: {href => "javascript:backPage(document.userupdate,'get_user_info','select')",
2420: text => $breadcrumb_text{'userpicked'},
2421: faq => 282,
2422: bug => 'Instructor Interface',});
1.233 raeburn 2423: }
1.224 raeburn 2424: my $helpitem = 'Course_Change_Privileges';
2425: if ($env{'form.action'} eq 'singlestudent') {
2426: $helpitem = 'Course_Add_Student';
2427: }
1.351 raeburn 2428: push(@{$brcrum},
2429: {href => "javascript:backPage(document.userupdate,'$env{'form.prevphase'}','modify')",
2430: text => $breadcrumb_text{'modify'},
2431: faq => 282,
2432: bug => 'Instructor Interface',},
2433: {href => "/adm/createuser",
2434: text => "Result",
2435: faq => 282,
2436: bug => 'Instructor Interface',
2437: help => $helpitem});
2438: my $args = {bread_crumbs => $brcrum,
2439: bread_crumbs_component => 'User Management'};
2440: if ($env{'form.popup'}) {
2441: $args->{'no_nav_bar'} = 1;
2442: }
2443: $r->print(&Apache::loncommon::start_page($title,$jscript,$args));
1.188 raeburn 2444: $r->print(&update_result_form($uhome));
1.27 matthew 2445: # Check Inputs
1.101 albertel 2446: if (! $env{'form.ccuname'} ) {
1.193 raeburn 2447: $r->print($error.&mt('No login name specified').'.'.$end.$rtnlink);
1.27 matthew 2448: return;
2449: }
1.138 albertel 2450: if ( $env{'form.ccuname'} ne
2451: &LONCAPA::clean_username($env{'form.ccuname'}) ) {
1.281 bisitz 2452: $r->print($error.&mt('Invalid login name.').' '.
2453: &mt('Only letters, numbers, periods, dashes, @, and underscores are valid.').
1.193 raeburn 2454: $end.$rtnlink);
1.27 matthew 2455: return;
2456: }
1.101 albertel 2457: if (! $env{'form.ccdomain'} ) {
1.193 raeburn 2458: $r->print($error.&mt('No domain specified').'.'.$end.$rtnlink);
1.27 matthew 2459: return;
2460: }
1.138 albertel 2461: if ( $env{'form.ccdomain'} ne
2462: &LONCAPA::clean_domain($env{'form.ccdomain'}) ) {
1.281 bisitz 2463: $r->print($error.&mt('Invalid domain name.').' '.
2464: &mt('Only letters, numbers, periods, dashes, and underscores are valid.').
1.193 raeburn 2465: $end.$rtnlink);
1.27 matthew 2466: return;
2467: }
1.219 raeburn 2468: if ($uhome eq 'no_host') {
2469: $newuser = 1;
2470: }
1.101 albertel 2471: if (! exists($env{'form.makeuser'})) {
1.29 matthew 2472: # Modifying an existing user, so check the validity of the name
2473: if ($uhome eq 'no_host') {
1.73 sakharuk 2474: $r->print($error.&mt('Unable to determine home server for ').
1.101 albertel 2475: $env{'form.ccuname'}.&mt(' in domain ').
2476: $env{'form.ccdomain'}.'.');
1.29 matthew 2477: return;
2478: }
2479: }
1.27 matthew 2480: # Determine authentication method and password for the user being modified
2481: my $amode='';
2482: my $genpwd='';
1.101 albertel 2483: if ($env{'form.login'} eq 'krb') {
1.41 albertel 2484: $amode='krb';
1.101 albertel 2485: $amode.=$env{'form.krbver'};
2486: $genpwd=$env{'form.krbarg'};
2487: } elsif ($env{'form.login'} eq 'int') {
1.27 matthew 2488: $amode='internal';
1.101 albertel 2489: $genpwd=$env{'form.intarg'};
2490: } elsif ($env{'form.login'} eq 'fsys') {
1.27 matthew 2491: $amode='unix';
1.101 albertel 2492: $genpwd=$env{'form.fsysarg'};
2493: } elsif ($env{'form.login'} eq 'loc') {
1.27 matthew 2494: $amode='localauth';
1.101 albertel 2495: $genpwd=$env{'form.locarg'};
1.27 matthew 2496: $genpwd=" " if (!$genpwd);
1.101 albertel 2497: } elsif (($env{'form.login'} eq 'nochange') ||
2498: ($env{'form.login'} eq '' )) {
1.34 matthew 2499: # There is no need to tell the user we did not change what they
2500: # did not ask us to change.
1.35 matthew 2501: # If they are creating a new user but have not specified login
2502: # information this will be caught below.
1.30 matthew 2503: } else {
1.367 golterma 2504: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
2505: return;
1.27 matthew 2506: }
1.164 albertel 2507:
1.188 raeburn 2508: $r->print('<h3>'.&mt('User [_1] in domain [_2]',
1.367 golterma 2509: $env{'form.ccuname'}.' ('.&Apache::loncommon::plainname($env{'form.ccuname'},
2510: $env{'form.ccdomain'}).')', $env{'form.ccdomain'}).'</h3>');
2511: my %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($r,2);
1.344 bisitz 2512:
1.193 raeburn 2513: my (%alerts,%rulematch,%inst_results,%curr_rules);
1.334 raeburn 2514: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
1.361 raeburn 2515: my @usertools = ('aboutme','blog','webdav','portfolio');
1.299 raeburn 2516: my @requestcourses = ('official','unofficial','community');
1.362 raeburn 2517: my @requestauthor = ('requestauthor');
1.286 raeburn 2518: my ($othertitle,$usertypes,$types) =
2519: &Apache::loncommon::sorted_inst_types($env{'form.ccdomain'});
1.334 raeburn 2520: my %canmodify_status =
2521: &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},
2522: ['inststatus']);
1.101 albertel 2523: if ($env{'form.makeuser'}) {
1.164 albertel 2524: $r->print('<h3>'.&mt('Creating new account.').'</h3>');
1.27 matthew 2525: # Check for the authentication mode and password
2526: if (! $amode || ! $genpwd) {
1.193 raeburn 2527: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
1.27 matthew 2528: return;
1.18 albertel 2529: }
1.29 matthew 2530: # Determine desired host
1.101 albertel 2531: my $desiredhost = $env{'form.hserver'};
1.29 matthew 2532: if (lc($desiredhost) eq 'default') {
2533: $desiredhost = undef;
2534: } else {
1.147 albertel 2535: my %home_servers =
2536: &Apache::lonnet::get_servers($env{'form.ccdomain'},'library');
1.29 matthew 2537: if (! exists($home_servers{$desiredhost})) {
1.193 raeburn 2538: $r->print($error.&mt('Invalid home server specified').$end.$rtnlink);
2539: return;
2540: }
2541: }
2542: # Check ID format
2543: my %checkhash;
2544: my %checks = ('id' => 1);
2545: %{$checkhash{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}}} = (
1.219 raeburn 2546: 'newuser' => $newuser,
1.196 raeburn 2547: 'id' => $env{'form.cid'},
1.193 raeburn 2548: );
1.196 raeburn 2549: if ($env{'form.cid'} ne '') {
2550: &Apache::loncommon::user_rule_check(\%checkhash,\%checks,\%alerts,
2551: \%rulematch,\%inst_results,\%curr_rules);
2552: if (ref($alerts{'id'}) eq 'HASH') {
2553: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
2554: my $domdesc =
2555: &Apache::lonnet::domain($env{'form.ccdomain'},'description');
2556: if ($alerts{'id'}{$env{'form.ccdomain'}}{$env{'form.cid'}}) {
2557: my $userchkmsg;
2558: if (ref($curr_rules{$env{'form.ccdomain'}}) eq 'HASH') {
2559: $userchkmsg =
2560: &Apache::loncommon::instrule_disallow_msg('id',
2561: $domdesc,1).
2562: &Apache::loncommon::user_rule_formats($env{'form.ccdomain'},
2563: $domdesc,$curr_rules{$env{'form.ccdomain'}}{'id'},'id');
2564: }
2565: $r->print($error.&mt('Invalid ID format').$end.
2566: $userchkmsg.$rtnlink);
2567: return;
2568: }
2569: }
1.29 matthew 2570: }
2571: }
1.367 golterma 2572: &Apache::lonhtmlcommon::Increment_PrgWin($r, \%prog_state);
1.27 matthew 2573: # Call modifyuser
2574: my $result = &Apache::lonnet::modifyuser
1.193 raeburn 2575: ($env{'form.ccdomain'},$env{'form.ccuname'},$env{'form.cid'},
1.188 raeburn 2576: $amode,$genpwd,$env{'form.cfirstname'},
2577: $env{'form.cmiddlename'},$env{'form.clastname'},
2578: $env{'form.cgeneration'},undef,$desiredhost,
2579: $env{'form.cpermanentemail'});
1.77 www 2580: $r->print(&mt('Generating user').': '.$result);
1.219 raeburn 2581: $uhome = &Apache::lonnet::homeserver($env{'form.ccuname'},
1.101 albertel 2582: $env{'form.ccdomain'});
1.334 raeburn 2583: my (%changeHash,%newcustom,%changed,%changedinfo);
1.267 raeburn 2584: if ($uhome ne 'no_host') {
1.334 raeburn 2585: if ($context eq 'domain') {
1.378 raeburn 2586: foreach my $name ('portfolio','author') {
2587: if ($env{'form.custom_'.$name.'quota'} == 1) {
2588: if ($env{'form.'.$name.'quota'} eq '') {
2589: $newcustom{$name.'quota'} = 0;
2590: } else {
2591: $newcustom{$name.'quota'} = $env{'form.'.$name.'quota'};
2592: $newcustom{$name.'quota'} =~ s/[^\d\.]//g;
2593: }
2594: if ("a_admin($newcustom{$name.'quota'},\%changeHash,$name)) {
2595: $changed{$name.'quota'} = 1;
2596: }
1.334 raeburn 2597: }
2598: }
2599: foreach my $item (@usertools) {
2600: if ($env{'form.custom'.$item} == 1) {
2601: $newcustom{$item} = $env{'form.tools_'.$item};
2602: $changed{$item} = &tool_admin($item,$newcustom{$item},
2603: \%changeHash,'tools');
2604: }
1.267 raeburn 2605: }
1.334 raeburn 2606: foreach my $item (@requestcourses) {
1.341 raeburn 2607: if ($env{'form.custom'.$item} == 1) {
2608: $newcustom{$item} = $env{'form.crsreq_'.$item};
2609: if ($env{'form.crsreq_'.$item} eq 'autolimit') {
2610: $newcustom{$item} .= '=';
1.383 ! raeburn 2611: $env{'form.crsreq_'.$item.'_limit'} =~ s/\D+//g;
! 2612: if ($env{'form.crsreq_'.$item.'_limit'}) {
1.341 raeburn 2613: $newcustom{$item} .= $env{'form.crsreq_'.$item.'_limit'};
2614: }
1.334 raeburn 2615: }
1.341 raeburn 2616: $changed{$item} = &tool_admin($item,$newcustom{$item},
2617: \%changeHash,'requestcourses');
1.334 raeburn 2618: }
1.275 raeburn 2619: }
1.362 raeburn 2620: if ($env{'form.customrequestauthor'} == 1) {
2621: $newcustom{'requestauthor'} = $env{'form.requestauthor'};
2622: $changed{'requestauthor'} = &tool_admin('requestauthor',
2623: $newcustom{'requestauthor'},
2624: \%changeHash,'requestauthor');
2625: }
1.275 raeburn 2626: }
1.334 raeburn 2627: if ($canmodify_status{'inststatus'}) {
2628: if (exists($env{'form.inststatus'})) {
2629: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
2630: if (@inststatuses > 0) {
2631: $changeHash{'inststatus'} = join(',',@inststatuses);
2632: $changed{'inststatus'} = $changeHash{'inststatus'};
1.306 raeburn 2633: }
2634: }
1.232 raeburn 2635: }
1.334 raeburn 2636: if (keys(%changed)) {
2637: foreach my $item (@userinfo) {
2638: $changeHash{$item} = $env{'form.c'.$item};
1.286 raeburn 2639: }
1.267 raeburn 2640: my $chgresult =
2641: &Apache::lonnet::put('environment',\%changeHash,
2642: $env{'form.ccdomain'},$env{'form.ccuname'});
2643: }
1.232 raeburn 2644: }
1.219 raeburn 2645: $r->print('<br />'.&mt('Home server').': '.$uhome.' '.
2646: &Apache::lonnet::hostname($uhome));
1.101 albertel 2647: } elsif (($env{'form.login'} ne 'nochange') &&
2648: ($env{'form.login'} ne '' )) {
1.27 matthew 2649: # Modify user privileges
2650: if (! $amode || ! $genpwd) {
1.193 raeburn 2651: $r->print($error.'Invalid login mode or password'.$end.$rtnlink);
1.27 matthew 2652: return;
1.20 harris41 2653: }
1.27 matthew 2654: # Only allow authentification modification if the person has authority
1.101 albertel 2655: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.20 harris41 2656: $r->print('Modifying authentication: '.
1.31 matthew 2657: &Apache::lonnet::modifyuserauth(
1.101 albertel 2658: $env{'form.ccdomain'},$env{'form.ccuname'},
1.21 harris41 2659: $amode,$genpwd));
1.102 albertel 2660: $r->print('<br />'.&mt('Home server').': '.&Apache::lonnet::homeserver
1.101 albertel 2661: ($env{'form.ccuname'},$env{'form.ccdomain'}));
1.4 www 2662: } else {
1.27 matthew 2663: # Okay, this is a non-fatal error.
1.193 raeburn 2664: $r->print($error.&mt('You do not have the authority to modify this users authentification information').'.'.$end);
1.27 matthew 2665: }
1.28 matthew 2666: }
1.344 bisitz 2667: $r->rflush(); # Finish display of header before time consuming actions start
1.367 golterma 2668: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state);
1.28 matthew 2669: ##
1.375 raeburn 2670: my (@userroles,%userupdate,$cnum,$cdom,$defaultcredits,%namechanged);
1.213 raeburn 2671: if ($context eq 'course') {
1.375 raeburn 2672: ($cnum,$cdom) =
2673: &Apache::lonuserutils::get_course_identity();
1.318 raeburn 2674: $crstype = &Apache::loncommon::course_type($cdom.'_'.$cnum);
1.375 raeburn 2675: if ($showcredits) {
2676: $defaultcredits = &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
2677: }
1.213 raeburn 2678: }
1.101 albertel 2679: if (! $env{'form.makeuser'} ) {
1.28 matthew 2680: # Check for need to change
2681: my %userenv = &Apache::lonnet::get
1.134 raeburn 2682: ('environment',['firstname','middlename','lastname','generation',
1.378 raeburn 2683: 'id','permanentemail','portfolioquota','authorquota','inststatus',
2684: 'tools.aboutme','tools.blog','tools.webdav','tools.portfolio',
1.361 raeburn 2685: 'requestcourses.official','requestcourses.unofficial',
2686: 'requestcourses.community','reqcrsotherdom.official',
1.362 raeburn 2687: 'reqcrsotherdom.unofficial','reqcrsotherdom.community',
2688: 'requestauthor'],
1.160 raeburn 2689: $env{'form.ccdomain'},$env{'form.ccuname'});
1.28 matthew 2690: my ($tmp) = keys(%userenv);
2691: if ($tmp =~ /^(con_lost|error)/i) {
2692: %userenv = ();
2693: }
1.206 raeburn 2694: my $no_forceid_alert;
2695: # Check to see if user information can be changed
2696: my %domconfig =
2697: &Apache::lonnet::get_dom('configuration',['usermodification'],
2698: $env{'form.ccdomain'});
1.213 raeburn 2699: my @statuses = ('active','future');
2700: my %roles = &Apache::lonnet::get_my_roles($env{'form.ccuname'},$env{'form.ccdomain'},'userroles',\@statuses,undef,$env{'request.role.domain'});
2701: my ($auname,$audom);
1.220 raeburn 2702: if ($context eq 'author') {
1.206 raeburn 2703: $auname = $env{'user.name'};
2704: $audom = $env{'user.domain'};
2705: }
2706: foreach my $item (keys(%roles)) {
1.220 raeburn 2707: my ($rolenum,$roledom,$role) = split(/:/,$item,-1);
1.206 raeburn 2708: if ($context eq 'course') {
2709: if ($cnum ne '' && $cdom ne '') {
2710: if ($rolenum eq $cnum && $roledom eq $cdom) {
2711: if (!grep(/^\Q$role\E$/,@userroles)) {
2712: push(@userroles,$role);
2713: }
2714: }
2715: }
2716: } elsif ($context eq 'author') {
2717: if ($rolenum eq $auname && $roledom eq $audom) {
2718: if (!grep(/^\Q$role\E$/,@userroles)) {
2719: push(@userroles,$role);
2720: }
2721: }
2722: }
2723: }
1.220 raeburn 2724: if ($env{'form.action'} eq 'singlestudent') {
2725: if (!grep(/^st$/,@userroles)) {
2726: push(@userroles,'st');
2727: }
2728: } else {
2729: # Check for course or co-author roles being activated or re-enabled
2730: if ($context eq 'author' || $context eq 'course') {
2731: foreach my $key (keys(%env)) {
2732: if ($context eq 'author') {
2733: if ($key=~/^form\.act_\Q$audom\E_\Q$auname\E_([^_]+)/) {
2734: if (!grep(/^\Q$1\E$/,@userroles)) {
2735: push(@userroles,$1);
2736: }
2737: } elsif ($key =~/^form\.ren\:\Q$audom\E\/\Q$auname\E_([^_]+)/) {
2738: if (!grep(/^\Q$1\E$/,@userroles)) {
2739: push(@userroles,$1);
2740: }
1.206 raeburn 2741: }
1.220 raeburn 2742: } elsif ($context eq 'course') {
2743: if ($key=~/^form\.act_\Q$cdom\E_\Q$cnum\E_([^_]+)/) {
2744: if (!grep(/^\Q$1\E$/,@userroles)) {
2745: push(@userroles,$1);
2746: }
2747: } elsif ($key =~/^form\.ren\:\Q$cdom\E\/\Q$cnum\E(\/?\w*)_([^_]+)/) {
2748: if (!grep(/^\Q$1\E$/,@userroles)) {
2749: push(@userroles,$1);
2750: }
1.206 raeburn 2751: }
2752: }
2753: }
2754: }
2755: }
2756: #Check to see if we can change personal data for the user
2757: my (@mod_disallowed,@longroles);
2758: foreach my $role (@userroles) {
2759: if ($role eq 'cr') {
2760: push(@longroles,'Custom');
2761: } else {
1.318 raeburn 2762: push(@longroles,&Apache::lonnet::plaintext($role,$crstype));
1.206 raeburn 2763: }
2764: }
1.219 raeburn 2765: my %canmodify = &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},\@userinfo,\@userroles);
2766: foreach my $item (@userinfo) {
1.28 matthew 2767: # Strip leading and trailing whitespace
1.203 raeburn 2768: $env{'form.c'.$item} =~ s/(\s+$|^\s+)//g;
1.219 raeburn 2769: if (!$canmodify{$item}) {
1.207 raeburn 2770: if (defined($env{'form.c'.$item})) {
2771: if ($env{'form.c'.$item} ne $userenv{$item}) {
2772: push(@mod_disallowed,$item);
2773: }
1.206 raeburn 2774: }
2775: $env{'form.c'.$item} = $userenv{$item};
2776: }
1.28 matthew 2777: }
1.259 bisitz 2778: # Check to see if we can change the Student/Employee ID
1.196 raeburn 2779: my $forceid = $env{'form.forceid'};
2780: my $recurseid = $env{'form.recurseid'};
2781: my (%alerts,%rulematch,%idinst_results,%curr_rules,%got_rules);
1.203 raeburn 2782: my %uidhash = &Apache::lonnet::idrget($env{'form.ccdomain'},
2783: $env{'form.ccuname'});
2784: if (($uidhash{$env{'form.ccuname'}}) &&
2785: ($uidhash{$env{'form.ccuname'}}!~/error\:/) &&
2786: (!$forceid)) {
2787: if ($env{'form.cid'} ne $uidhash{$env{'form.ccuname'}}) {
2788: $env{'form.cid'} = $userenv{'id'};
1.293 bisitz 2789: $no_forceid_alert = &mt('New student/employee ID does not match existing ID for this user.')
1.259 bisitz 2790: .'<br />'
2791: .&mt("Change is not permitted without checking the 'Force ID change' checkbox on the previous page.")
2792: .'<br />'."\n";
1.203 raeburn 2793: }
2794: }
2795: if ($env{'form.cid'} ne $userenv{'id'}) {
1.196 raeburn 2796: my $checkhash;
2797: my $checks = { 'id' => 1 };
2798: $checkhash->{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}} =
2799: { 'newuser' => $newuser,
2800: 'id' => $env{'form.cid'},
2801: };
2802: &Apache::loncommon::user_rule_check($checkhash,$checks,
2803: \%alerts,\%rulematch,\%idinst_results,\%curr_rules,\%got_rules);
2804: if (ref($alerts{'id'}) eq 'HASH') {
2805: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
1.203 raeburn 2806: $env{'form.cid'} = $userenv{'id'};
1.196 raeburn 2807: }
2808: }
2809: }
1.378 raeburn 2810: my (%quotachanged,%oldquota,%newquota,%olddefquota,%newdefquota,
2811: $oldinststatus,$newinststatus,%oldisdefault,%newisdefault,%oldsettings,
1.339 raeburn 2812: %oldsettingstext,%newsettings,%newsettingstext,@disporder,
1.378 raeburn 2813: %oldsettingstatus,%newsettingstatus);
1.334 raeburn 2814: @disporder = ('inststatus');
2815: if ($env{'request.role.domain'} eq $env{'form.ccdomain'}) {
1.362 raeburn 2816: push(@disporder,'requestcourses','requestauthor');
1.334 raeburn 2817: } else {
2818: push(@disporder,'reqcrsotherdom');
2819: }
2820: push(@disporder,('quota','tools'));
1.338 raeburn 2821: $oldinststatus = $userenv{'inststatus'};
1.378 raeburn 2822: foreach my $name ('portfolio','author') {
2823: ($olddefquota{$name},$oldsettingstatus{$name}) =
2824: &Apache::loncommon::default_quota($env{'form.ccdomain'},$oldinststatus,$name);
2825: ($newdefquota{$name},$newsettingstatus{$name}) = ($olddefquota{$name},$oldsettingstatus{$name});
2826: }
1.334 raeburn 2827: my %canshow;
1.220 raeburn 2828: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
1.334 raeburn 2829: $canshow{'quota'} = 1;
1.220 raeburn 2830: }
1.267 raeburn 2831: if (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
1.334 raeburn 2832: $canshow{'tools'} = 1;
1.267 raeburn 2833: }
1.275 raeburn 2834: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
1.334 raeburn 2835: $canshow{'requestcourses'} = 1;
1.300 raeburn 2836: } elsif (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.334 raeburn 2837: $canshow{'reqcrsotherdom'} = 1;
1.275 raeburn 2838: }
1.286 raeburn 2839: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.334 raeburn 2840: $canshow{'inststatus'} = 1;
1.286 raeburn 2841: }
1.362 raeburn 2842: if (&Apache::lonnet::allowed('cau',$env{'form.ccdomain'})) {
2843: $canshow{'requestauthor'} = 1;
2844: }
1.267 raeburn 2845: my (%changeHash,%changed);
1.286 raeburn 2846: if ($oldinststatus eq '') {
1.334 raeburn 2847: $oldsettings{'inststatus'} = $othertitle;
1.286 raeburn 2848: } else {
2849: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 2850: $oldsettings{'inststatus'} = join(', ',map{ $usertypes->{ &unescape($_) }; } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 2851: } else {
1.334 raeburn 2852: $oldsettings{'inststatus'} = join(', ',map{ &unescape($_); } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 2853: }
2854: }
2855: $changeHash{'inststatus'} = $userenv{'inststatus'};
1.334 raeburn 2856: if ($canmodify_status{'inststatus'}) {
2857: $canshow{'inststatus'} = 1;
1.286 raeburn 2858: if (exists($env{'form.inststatus'})) {
2859: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
2860: if (@inststatuses > 0) {
2861: $newinststatus = join(':',map { &escape($_); } @inststatuses);
2862: $changeHash{'inststatus'} = $newinststatus;
2863: if ($newinststatus ne $oldinststatus) {
2864: $changed{'inststatus'} = $newinststatus;
1.378 raeburn 2865: foreach my $name ('portfolio','author') {
2866: ($newdefquota{$name},$newsettingstatus{$name}) =
2867: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
2868: }
1.286 raeburn 2869: }
2870: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 2871: $newsettings{'inststatus'} = join(', ',map{ $usertypes->{$_}; } (@inststatuses));
1.286 raeburn 2872: } else {
1.337 raeburn 2873: $newsettings{'inststatus'} = join(', ',@inststatuses);
1.286 raeburn 2874: }
1.334 raeburn 2875: }
2876: } else {
2877: $newinststatus = '';
2878: $changeHash{'inststatus'} = $newinststatus;
2879: $newsettings{'inststatus'} = $othertitle;
2880: if ($newinststatus ne $oldinststatus) {
2881: $changed{'inststatus'} = $changeHash{'inststatus'};
1.378 raeburn 2882: foreach my $name ('portfolio','author') {
2883: ($newdefquota{$name},$newsettingstatus{$name}) =
2884: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
2885: }
1.286 raeburn 2886: }
2887: }
1.334 raeburn 2888: } elsif ($context ne 'selfcreate') {
2889: $canshow{'inststatus'} = 1;
1.337 raeburn 2890: $newsettings{'inststatus'} = $oldsettings{'inststatus'};
1.286 raeburn 2891: }
1.378 raeburn 2892: foreach my $name ('portfolio','author') {
2893: $changeHash{$name.'quota'} = $userenv{$name.'quota'};
2894: }
1.334 raeburn 2895: if ($context eq 'domain') {
1.378 raeburn 2896: foreach my $name ('portfolio','author') {
2897: if ($userenv{$name.'quota'} ne '') {
2898: $oldquota{$name} = $userenv{$name.'quota'};
2899: if ($env{'form.custom_'.$name.'quota'} == 1) {
2900: if ($env{'form.'.$name.'quota'} eq '') {
2901: $newquota{$name} = 0;
2902: } else {
2903: $newquota{$name} = $env{'form.'.$name.'quota'};
2904: $newquota{$name} =~ s/[^\d\.]//g;
2905: }
2906: if ($newquota{$name} != $oldquota{$name}) {
2907: if ("a_admin($newquota{$name},\%changeHash,$name)) {
2908: $changed{$name.'quota'} = 1;
2909: }
2910: }
1.334 raeburn 2911: } else {
1.378 raeburn 2912: if ("a_admin('',\%changeHash,$name)) {
2913: $changed{$name.'quota'} = 1;
2914: $newquota{$name} = $newdefquota{$name};
2915: $newisdefault{$name} = 1;
2916: }
1.334 raeburn 2917: }
1.149 raeburn 2918: } else {
1.378 raeburn 2919: $oldisdefault{$name} = 1;
2920: $oldquota{$name} = $olddefquota{$name};
2921: if ($env{'form.custom_'.$name.'quota'} == 1) {
2922: if ($env{'form.'.$name.'quota'} eq '') {
2923: $newquota{$name} = 0;
2924: } else {
2925: $newquota{$name} = $env{'form.'.$name.'quota'};
2926: $newquota{$name} =~ s/[^\d\.]//g;
2927: }
2928: if ("a_admin($newquota{$name},\%changeHash,$name)) {
2929: $changed{$name.'quota'} = 1;
2930: }
1.334 raeburn 2931: } else {
1.378 raeburn 2932: $newquota{$name} = $newdefquota{$name};
2933: $newisdefault{$name} = 1;
1.334 raeburn 2934: }
1.378 raeburn 2935: }
2936: if ($oldisdefault{$name}) {
2937: $oldsettingstext{'quota'}{$name} = &get_defaultquota_text($oldsettingstatus{$name});
1.383 ! raeburn 2938: } else {
! 2939: $oldsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$oldquota{$name});
1.378 raeburn 2940: }
2941: if ($newisdefault{$name}) {
2942: $newsettingstext{'quota'}{$name} = &get_defaultquota_text($newsettingstatus{$name});
1.383 ! raeburn 2943: } else {
! 2944: $newsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$newquota{$name});
1.134 raeburn 2945: }
2946: }
1.334 raeburn 2947: &tool_changes('tools',\@usertools,\%oldsettings,\%oldsettingstext,\%userenv,
2948: \%changeHash,\%changed,\%newsettings,\%newsettingstext);
2949: if ($env{'form.ccdomain'} eq $env{'request.role.domain'}) {
2950: &tool_changes('requestcourses',\@requestcourses,\%oldsettings,\%oldsettingstext,
2951: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.362 raeburn 2952: &tool_changes('requestauthor',\@requestauthor,\%oldsettings,\%oldsettingstext,\%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 2953: } else {
1.334 raeburn 2954: &tool_changes('reqcrsotherdom',\@requestcourses,\%oldsettings,\%oldsettingstext,
2955: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 2956: }
2957: }
1.334 raeburn 2958: foreach my $item (@userinfo) {
2959: if ($env{'form.c'.$item} ne $userenv{$item}) {
2960: $namechanged{$item} = 1;
2961: }
1.204 raeburn 2962: }
1.378 raeburn 2963: foreach my $name ('portfolio','author') {
1.383 ! raeburn 2964: $oldsettings{'quota'}{$name} = $oldquota{$name}.' MB';
! 2965: $newsettings{'quota'}{$name} = $newquota{$name}.' MB';
1.378 raeburn 2966: }
1.334 raeburn 2967: if ((keys(%namechanged) > 0) || (keys(%changed) > 0)) {
1.267 raeburn 2968: my ($chgresult,$namechgresult);
2969: if (keys(%changed) > 0) {
2970: $chgresult =
1.204 raeburn 2971: &Apache::lonnet::put('environment',\%changeHash,
2972: $env{'form.ccdomain'},$env{'form.ccuname'});
1.267 raeburn 2973: if ($chgresult eq 'ok') {
2974: if (($env{'user.name'} eq $env{'form.ccuname'}) &&
2975: ($env{'user.domain'} eq $env{'form.ccdomain'})) {
1.270 raeburn 2976: my %newenvhash;
2977: foreach my $key (keys(%changed)) {
1.299 raeburn 2978: if (($key eq 'official') || ($key eq 'unofficial')
2979: || ($key eq 'community')) {
1.279 raeburn 2980: $newenvhash{'environment.requestcourses.'.$key} =
2981: $changeHash{'requestcourses.'.$key};
1.362 raeburn 2982: if ($changeHash{'requestcourses.'.$key}) {
1.332 raeburn 2983: $newenvhash{'environment.canrequest.'.$key} = 1;
1.279 raeburn 2984: } else {
2985: $newenvhash{'environment.canrequest.'.$key} =
2986: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
2987: $key,'reload','requestcourses');
2988: }
1.362 raeburn 2989: } elsif ($key eq 'requestauthor') {
2990: $newenvhash{'environment.'.$key} = $changeHash{$key};
2991: if ($changeHash{$key}) {
2992: $newenvhash{'environment.canrequest.author'} = 1;
2993: } else {
2994: $newenvhash{'environment.canrequest.author'} =
2995: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
2996: $key,'reload','requestauthor');
2997: }
1.275 raeburn 2998: } elsif ($key ne 'quota') {
1.270 raeburn 2999: $newenvhash{'environment.tools.'.$key} =
3000: $changeHash{'tools.'.$key};
1.279 raeburn 3001: if ($changeHash{'tools.'.$key} ne '') {
3002: $newenvhash{'environment.availabletools.'.$key} =
3003: $changeHash{'tools.'.$key};
3004: } else {
3005: $newenvhash{'environment.availabletools.'.$key} =
1.367 golterma 3006: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3007: $key,'reload','tools');
1.279 raeburn 3008: }
1.270 raeburn 3009: }
3010: }
1.271 raeburn 3011: if (keys(%newenvhash)) {
3012: &Apache::lonnet::appenv(\%newenvhash);
3013: }
1.267 raeburn 3014: }
3015: }
1.204 raeburn 3016: }
1.334 raeburn 3017: if (keys(%namechanged) > 0) {
1.337 raeburn 3018: foreach my $field (@userinfo) {
3019: $changeHash{$field} = $env{'form.c'.$field};
3020: }
3021: # Make the change
1.204 raeburn 3022: $namechgresult =
3023: &Apache::lonnet::modifyuser($env{'form.ccdomain'},
3024: $env{'form.ccuname'},$changeHash{'id'},undef,undef,
3025: $changeHash{'firstname'},$changeHash{'middlename'},
3026: $changeHash{'lastname'},$changeHash{'generation'},
1.337 raeburn 3027: $changeHash{'id'},undef,$changeHash{'permanentemail'},undef,\@userinfo);
1.220 raeburn 3028: %userupdate = (
3029: lastname => $env{'form.clastname'},
3030: middlename => $env{'form.cmiddlename'},
3031: firstname => $env{'form.cfirstname'},
3032: generation => $env{'form.cgeneration'},
3033: id => $env{'form.cid'},
3034: );
1.204 raeburn 3035: }
1.334 raeburn 3036: if (((keys(%namechanged) > 0) && $namechgresult eq 'ok') ||
1.267 raeburn 3037: ((keys(%changed) > 0) && $chgresult eq 'ok')) {
1.28 matthew 3038: # Tell the user we changed the name
1.334 raeburn 3039: &display_userinfo($r,1,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 3040: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,
1.334 raeburn 3041: \%oldsettings, \%oldsettingstext,\%newsettings,
3042: \%newsettingstext);
1.203 raeburn 3043: if ($env{'form.cid'} ne $userenv{'id'}) {
3044: &Apache::lonnet::idput($env{'form.ccdomain'},
3045: ($env{'form.ccuname'} => $env{'form.cid'}));
3046: if (($recurseid) &&
3047: (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}))) {
3048: my $idresult =
3049: &Apache::lonuserutils::propagate_id_change(
3050: $env{'form.ccuname'},$env{'form.ccdomain'},
3051: \%userupdate);
3052: $r->print('<br />'.$idresult.'<br />');
3053: }
1.196 raeburn 3054: }
1.149 raeburn 3055: if (($env{'form.ccdomain'} eq $env{'user.domain'}) &&
3056: ($env{'form.ccuname'} eq $env{'user.name'})) {
3057: my %newenvhash;
3058: foreach my $key (keys(%changeHash)) {
3059: $newenvhash{'environment.'.$key} = $changeHash{$key};
3060: }
1.238 raeburn 3061: &Apache::lonnet::appenv(\%newenvhash);
1.149 raeburn 3062: }
1.28 matthew 3063: } else { # error occurred
1.188 raeburn 3064: $r->print('<span class="LC_error">'.&mt('Unable to successfully change environment for').' '.
3065: $env{'form.ccuname'}.' '.&mt('in domain').' '.
1.206 raeburn 3066: $env{'form.ccdomain'}.'</span><br />');
1.28 matthew 3067: }
1.334 raeburn 3068: } else { # End of if ($env ... ) logic
1.275 raeburn 3069: # They did not want to change the users name, quota, tool availability,
3070: # or ability to request creation of courses,
1.267 raeburn 3071: # but we can still tell them what the name and quota and availabilities are
1.334 raeburn 3072: &display_userinfo($r,undef,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 3073: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,\%oldsettings,
1.334 raeburn 3074: \%oldsettingstext,\%newsettings,\%newsettingstext);
1.28 matthew 3075: }
1.206 raeburn 3076: if (@mod_disallowed) {
3077: my ($rolestr,$contextname);
3078: if (@longroles > 0) {
3079: $rolestr = join(', ',@longroles);
3080: } else {
3081: $rolestr = &mt('No roles');
3082: }
3083: if ($context eq 'course') {
3084: $contextname = &mt('course');
3085: } elsif ($context eq 'author') {
3086: $contextname = &mt('co-author');
3087: }
3088: $r->print(&mt('The following fields were not updated: ').'<ul>');
3089: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
3090: foreach my $field (@mod_disallowed) {
3091: $r->print('<li>'.$fieldtitles{$field}.'</li>'."\n");
3092: }
1.207 raeburn 3093: $r->print('</ul>');
3094: if (@mod_disallowed == 1) {
3095: $r->print(&mt("You do not have the authority to change this field given the user's current set of active/future [_1] roles:",$contextname));
3096: } else {
3097: $r->print(&mt("You do not have the authority to change these fields given the user's current set of active/future [_1] roles:",$contextname));
3098: }
1.292 bisitz 3099: my $helplink = 'javascript:helpMenu('."'display'".')';
3100: $r->print('<span class="LC_cusr_emph">'.$rolestr.'</span><br />'
3101: .&mt('Please contact your [_1]helpdesk[_2] for more information.'
3102: ,'<a href="'.$helplink.'">','</a>')
3103: .'<br />');
1.206 raeburn 3104: }
1.259 bisitz 3105: $r->print('<span class="LC_warning">'
3106: .$no_forceid_alert
3107: .&Apache::lonuserutils::print_namespacing_alerts($env{'form.ccdomain'},\%alerts,\%curr_rules)
3108: .'</span>');
1.4 www 3109: }
1.367 golterma 3110: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1.220 raeburn 3111: if ($env{'form.action'} eq 'singlestudent') {
1.375 raeburn 3112: &enroll_single_student($r,$uhome,$amode,$genpwd,$now,$newuser,$context,
3113: $crstype,$showcredits,$defaultcredits);
1.318 raeburn 3114: $r->print('<p><a href="javascript:backPage(document.userupdate)">');
3115: if ($crstype eq 'Community') {
3116: $r->print(&mt('Enroll Another Member'));
3117: } else {
3118: $r->print(&mt('Enroll Another Student'));
3119: }
3120: $r->print('</a></p>');
1.220 raeburn 3121: } else {
1.375 raeburn 3122: my @rolechanges = &update_roles($r,$context,$showcredits);
1.334 raeburn 3123: if (keys(%namechanged) > 0) {
1.220 raeburn 3124: if ($context eq 'course') {
3125: if (@userroles > 0) {
1.225 raeburn 3126: if ((@rolechanges == 0) ||
3127: (!(grep(/^st$/,@rolechanges)))) {
3128: if (grep(/^st$/,@userroles)) {
3129: my $classlistupdated =
3130: &Apache::lonuserutils::update_classlist($cdom,
1.220 raeburn 3131: $cnum,$env{'form.ccdomain'},
3132: $env{'form.ccuname'},\%userupdate);
1.225 raeburn 3133: }
1.220 raeburn 3134: }
3135: }
3136: }
3137: }
1.226 raeburn 3138: my $userinfo = &Apache::loncommon::plainname($env{'form.ccuname'},
1.233 raeburn 3139: $env{'form.ccdomain'});
3140: if ($env{'form.popup'}) {
3141: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
3142: } else {
1.367 golterma 3143: $r->print('<br />'.&Apache::lonhtmlcommon::actionbox(['<a href="javascript:backPage(document.userupdate,'."'$env{'form.prevphase'}','modify'".')">'
3144: .&mt('Modify this user: [_1]','<span class="LC_cusr_emph">'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.' ('.$userinfo.')</span>').'</a>',
3145: '<a href="javascript:backPage(document.userupdate)">'.&mt('Create/Modify Another User').'</a>']));
1.233 raeburn 3146: }
1.220 raeburn 3147: }
3148: }
3149:
1.334 raeburn 3150: sub display_userinfo {
1.362 raeburn 3151: my ($r,$changed,$order,$canshow,$requestcourses,$usertools,$requestauthor,
3152: $userenv,$changedhash,$namechangedhash,$oldsetting,$oldsettingtext,
1.334 raeburn 3153: $newsetting,$newsettingtext) = @_;
3154: return unless (ref($order) eq 'ARRAY' &&
3155: ref($canshow) eq 'HASH' &&
3156: ref($requestcourses) eq 'ARRAY' &&
1.362 raeburn 3157: ref($requestauthor) eq 'ARRAY' &&
1.334 raeburn 3158: ref($usertools) eq 'ARRAY' &&
3159: ref($userenv) eq 'HASH' &&
3160: ref($changedhash) eq 'HASH' &&
3161: ref($oldsetting) eq 'HASH' &&
3162: ref($oldsettingtext) eq 'HASH' &&
3163: ref($newsetting) eq 'HASH' &&
3164: ref($newsettingtext) eq 'HASH');
3165: my %lt=&Apache::lonlocal::texthash(
1.372 raeburn 3166: 'ui' => 'User Information',
1.334 raeburn 3167: 'uic' => 'User Information Changed',
3168: 'firstname' => 'First Name',
3169: 'middlename' => 'Middle Name',
3170: 'lastname' => 'Last Name',
3171: 'generation' => 'Generation',
3172: 'id' => 'Student/Employee ID',
3173: 'permanentemail' => 'Permanent e-mail address',
1.378 raeburn 3174: 'portfolioquota' => 'Disk space allocated to portfolio files',
3175: 'authorquota' => 'Disk space allocated to authoring space',
1.334 raeburn 3176: 'blog' => 'Blog Availability',
1.361 raeburn 3177: 'webdav' => 'WebDAV Availability',
1.334 raeburn 3178: 'aboutme' => 'Personal Information Page Availability',
3179: 'portfolio' => 'Portfolio Availability',
3180: 'official' => 'Can Request Official Courses',
3181: 'unofficial' => 'Can Request Unofficial Courses',
3182: 'community' => 'Can Request Communities',
1.362 raeburn 3183: 'requestauthor' => 'Can Request Author Role',
1.334 raeburn 3184: 'inststatus' => "Affiliation",
3185: 'prvs' => 'Previous Value:',
3186: 'chto' => 'Changed To:'
3187: );
3188: if ($changed) {
1.372 raeburn 3189: $r->print('<h3>'.$lt{'uic'}.'</h3>'.
1.367 golterma 3190: &Apache::loncommon::start_data_table().
3191: &Apache::loncommon::start_data_table_header_row());
1.334 raeburn 3192: $r->print("<th> </th>\n");
1.367 golterma 3193: $r->print('<th><b>'.$lt{'prvs'}.'</b></th>');
3194: $r->print('<th><span class="LC_nobreak"><b>'.$lt{'chto'}.'</b></span></th>');
3195: $r->print(&Apache::loncommon::end_data_table_header_row());
3196: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
3197:
1.334 raeburn 3198: foreach my $item (@userinfo) {
3199: my $value = $env{'form.c'.$item};
1.367 golterma 3200: #show changes only:
1.383 ! raeburn 3201: unless ($value eq $userenv->{$item}){
1.367 golterma 3202: $r->print(&Apache::loncommon::start_data_table_row());
3203: $r->print("<td>$lt{$item}</td>\n");
1.383 ! raeburn 3204: $r->print("<td>".$userenv->{$item}."</td>\n");
1.367 golterma 3205: $r->print("<td>$value </td>\n");
3206: $r->print(&Apache::loncommon::end_data_table_row());
1.334 raeburn 3207: }
3208: }
3209: foreach my $entry (@{$order}) {
1.383 ! raeburn 3210: if ($canshow->{$entry}) {
! 3211: if (($entry eq 'requestcourses') || ($entry eq 'reqcrsotherdom') || ($entry eq 'requestauthor')) {
! 3212: my @items;
! 3213: if ($entry eq 'requestauthor') {
! 3214: @items = ($entry);
! 3215: } else {
! 3216: @items = @{$requestcourses};
! 3217: }
! 3218: foreach my $item (@items) {
! 3219: if (($newsetting->{$item} ne $oldsetting->{$item}) ||
! 3220: ($newsettingtext->{$item} ne $oldsettingtext->{$item})) {
! 3221: $r->print(&Apache::loncommon::start_data_table_row()."\n");
! 3222: $r->print("<td>$lt{$item}</td>\n");
! 3223: $r->print("<td>".$oldsetting->{$item});
! 3224: if ($oldsettingtext->{$item}) {
! 3225: if ($oldsetting->{$item}) {
! 3226: $r->print(' -- ');
! 3227: }
! 3228: $r->print($oldsettingtext->{$item});
! 3229: }
! 3230: $r->print("</td>\n");
! 3231: $r->print("<td>".$newsetting->{$item});
! 3232: if ($newsettingtext->{$item}) {
! 3233: if ($newsetting->{$item}) {
! 3234: $r->print(' -- ');
! 3235: }
! 3236: $r->print($newsettingtext->{$item});
! 3237: }
! 3238: $r->print("</td>\n");
! 3239: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3240: }
3241: }
3242: } elsif ($entry eq 'tools') {
3243: foreach my $item (@{$usertools}) {
1.383 ! raeburn 3244: if ($newsetting->{$item} ne $oldsetting->{$item}) {
! 3245: $r->print(&Apache::loncommon::start_data_table_row()."\n");
! 3246: $r->print("<td>$lt{$item}</td>\n");
! 3247: $r->print("<td>".$oldsetting->{$item}.' '.$oldsettingtext->{$item}."</td>\n");
! 3248: $r->print("<td>".$newsetting->{$item}.' '.$newsettingtext->{$item}."</td>\n");
! 3249: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3250: }
3251: }
1.378 raeburn 3252: } elsif ($entry eq 'quota') {
3253: if ((ref($oldsetting->{$entry}) eq 'HASH') && (ref($oldsettingtext->{$entry}) eq 'HASH') &&
3254: (ref($newsetting->{$entry}) eq 'HASH') && (ref($newsettingtext->{$entry}) eq 'HASH')) {
3255: foreach my $name ('portfolio','author') {
1.383 ! raeburn 3256: if ($newsetting->{$entry}->{$name} ne $oldsetting->{$entry}->{$name}) {
! 3257: $r->print(&Apache::loncommon::start_data_table_row()."\n");
! 3258: $r->print("<td>$lt{$name.$entry}</td>\n");
! 3259: $r->print("<td>".$oldsettingtext->{$entry}->{$name}."</td>\n");
! 3260: $r->print("<td>".$newsettingtext->{$entry}->{$name}."</td>\n");
! 3261: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.378 raeburn 3262: }
3263: }
3264: }
1.334 raeburn 3265: } else {
1.383 ! raeburn 3266: if ($newsetting->{$entry} ne $oldsetting->{$entry}) {
! 3267: $r->print(&Apache::loncommon::start_data_table_row()."\n");
! 3268: $r->print("<td>$lt{$entry}</td>\n");
! 3269: $r->print("<td>".$oldsetting->{$entry}.' '.$oldsettingtext->{$entry}."</td>\n");
! 3270: $r->print("<td>".$newsetting->{$entry}.' '.$newsettingtext->{$entry}."</td>\n");
! 3271: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3272: }
3273: }
3274: }
3275: }
1.367 golterma 3276: $r->print(&Apache::loncommon::end_data_table().'<br />');
1.372 raeburn 3277: } else {
3278: $r->print('<h3>'.$lt{'ui'}.'</h3>'.
3279: '<p>'.&mt('No changes made to user information').'</p>');
1.334 raeburn 3280: }
3281: return;
3282: }
3283:
1.275 raeburn 3284: sub tool_changes {
3285: my ($context,$usertools,$oldaccess,$oldaccesstext,$userenv,$changeHash,
3286: $changed,$newaccess,$newaccesstext) = @_;
3287: if (!((ref($usertools) eq 'ARRAY') && (ref($oldaccess) eq 'HASH') &&
3288: (ref($oldaccesstext) eq 'HASH') && (ref($userenv) eq 'HASH') &&
3289: (ref($changeHash) eq 'HASH') && (ref($changed) eq 'HASH') &&
3290: (ref($newaccess) eq 'HASH') && (ref($newaccesstext) eq 'HASH'))) {
3291: return;
3292: }
1.383 ! raeburn 3293: my %reqdisplay = &requestchange_display();
1.300 raeburn 3294: if ($context eq 'reqcrsotherdom') {
1.309 raeburn 3295: my @options = ('approval','validate','autolimit');
1.306 raeburn 3296: my $optregex = join('|',@options);
1.300 raeburn 3297: my $cdom = $env{'request.role.domain'};
3298: foreach my $tool (@{$usertools}) {
1.383 ! raeburn 3299: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
1.314 raeburn 3300: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
1.300 raeburn 3301: $changeHash->{$context.'.'.$tool} = $userenv->{$context.'.'.$tool};
1.383 ! raeburn 3302: my ($newop,$limit);
1.314 raeburn 3303: if ($env{'form.'.$context.'_'.$tool}) {
3304: $newop = $env{'form.'.$context.'_'.$tool};
3305: if ($newop eq 'autolimit') {
1.383 ! raeburn 3306: $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
1.314 raeburn 3307: $limit =~ s/\D+//g;
3308: $newop .= '='.$limit;
3309: }
3310: }
1.300 raeburn 3311: if ($userenv->{$context.'.'.$tool} eq '') {
1.314 raeburn 3312: if ($newop) {
3313: $changed->{$tool}=&tool_admin($tool,$cdom.':'.$newop,
1.300 raeburn 3314: $changeHash,$context);
3315: if ($changed->{$tool}) {
1.383 ! raeburn 3316: if ($newop =~ /^autolimit/) {
! 3317: if ($limit) {
! 3318: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
! 3319: } else {
! 3320: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
! 3321: }
! 3322: } else {
! 3323: $newaccesstext->{$tool} = $reqdisplay{$newop};
! 3324: }
1.300 raeburn 3325: } else {
3326: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3327: }
3328: }
3329: } else {
3330: my @curr = split(',',$userenv->{$context.'.'.$tool});
3331: my @new;
3332: my $changedoms;
1.314 raeburn 3333: foreach my $req (@curr) {
3334: if ($req =~ /^\Q$cdom\E\:($optregex\=?\d*)$/) {
3335: my $oldop = $1;
1.383 ! raeburn 3336: if ($oldop =~ /^autolimit=(\d*)/) {
! 3337: my $limit = $1;
! 3338: if ($limit) {
! 3339: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
! 3340: } else {
! 3341: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
! 3342: }
! 3343: } else {
! 3344: $oldaccesstext->{$tool} = $reqdisplay{$oldop};
! 3345: }
1.314 raeburn 3346: if ($oldop ne $newop) {
3347: $changedoms = 1;
3348: foreach my $item (@curr) {
3349: my ($reqdom,$option) = split(':',$item);
3350: unless ($reqdom eq $cdom) {
3351: push(@new,$item);
3352: }
3353: }
3354: if ($newop) {
3355: push(@new,$cdom.':'.$newop);
1.300 raeburn 3356: }
1.314 raeburn 3357: @new = sort(@new);
1.300 raeburn 3358: }
1.314 raeburn 3359: last;
1.300 raeburn 3360: }
1.314 raeburn 3361: }
3362: if ((!$changedoms) && ($newop)) {
1.300 raeburn 3363: $changedoms = 1;
1.306 raeburn 3364: @new = sort(@curr,$cdom.':'.$newop);
1.300 raeburn 3365: }
3366: if ($changedoms) {
1.314 raeburn 3367: my $newdomstr;
1.300 raeburn 3368: if (@new) {
3369: $newdomstr = join(',',@new);
3370: }
3371: $changed->{$tool}=&tool_admin($tool,$newdomstr,$changeHash,
3372: $context);
3373: if ($changed->{$tool}) {
3374: if ($env{'form.'.$context.'_'.$tool}) {
1.306 raeburn 3375: if ($env{'form.'.$context.'_'.$tool} eq 'autolimit') {
1.314 raeburn 3376: my $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
3377: $limit =~ s/\D+//g;
3378: if ($limit) {
1.383 ! raeburn 3379: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
1.314 raeburn 3380: } else {
1.383 ! raeburn 3381: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
1.306 raeburn 3382: }
1.314 raeburn 3383: } else {
1.306 raeburn 3384: $newaccesstext->{$tool} = $reqdisplay{$env{'form.'.$context.'_'.$tool}};
3385: }
1.300 raeburn 3386: } else {
1.383 ! raeburn 3387: $newaccesstext->{$tool} = &mt("availability set to 'off'");
1.300 raeburn 3388: }
3389: }
3390: }
3391: }
3392: }
3393: return;
3394: }
1.275 raeburn 3395: foreach my $tool (@{$usertools}) {
1.383 ! raeburn 3396: my ($newval,$limit,$envkey);
1.362 raeburn 3397: $envkey = $context.'.'.$tool;
1.306 raeburn 3398: if ($context eq 'requestcourses') {
3399: $newval = $env{'form.crsreq_'.$tool};
3400: if ($newval eq 'autolimit') {
1.383 ! raeburn 3401: $limit = $env{'form.crsreq_'.$tool.'_limit'};
! 3402: $limit =~ s/\D+//g;
! 3403: $newval .= '='.$limit;
1.306 raeburn 3404: }
1.362 raeburn 3405: } elsif ($context eq 'requestauthor') {
3406: $newval = $env{'form.'.$context};
3407: $envkey = $context;
1.314 raeburn 3408: } else {
1.306 raeburn 3409: $newval = $env{'form.'.$context.'_'.$tool};
3410: }
1.362 raeburn 3411: if ($userenv->{$envkey} ne '') {
1.275 raeburn 3412: $oldaccess->{$tool} = &mt('custom');
1.383 ! raeburn 3413: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
! 3414: if ($userenv->{$envkey} =~ /^autolimit=(\d*)$/) {
! 3415: my $currlimit = $1;
! 3416: if ($currlimit eq '') {
! 3417: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
! 3418: } else {
! 3419: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$currlimit);
! 3420: }
! 3421: } elsif ($userenv->{$envkey}) {
! 3422: $oldaccesstext->{$tool} = $reqdisplay{$userenv->{$envkey}};
! 3423: } else {
! 3424: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
! 3425: }
1.275 raeburn 3426: } else {
1.383 ! raeburn 3427: if ($userenv->{$envkey}) {
! 3428: $oldaccesstext->{$tool} = &mt("availability set to 'on'");
! 3429: } else {
! 3430: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
! 3431: }
1.275 raeburn 3432: }
1.362 raeburn 3433: $changeHash->{$envkey} = $userenv->{$envkey};
1.275 raeburn 3434: if ($env{'form.custom'.$tool} == 1) {
1.362 raeburn 3435: if ($newval ne $userenv->{$envkey}) {
1.306 raeburn 3436: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
3437: $context);
1.275 raeburn 3438: if ($changed->{$tool}) {
3439: $newaccess->{$tool} = &mt('custom');
1.383 ! raeburn 3440: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
! 3441: if ($newval =~ /^autolimit/) {
! 3442: if ($limit) {
! 3443: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
! 3444: } else {
! 3445: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
! 3446: }
! 3447: } elsif ($newval) {
! 3448: $newaccesstext->{$tool} = $reqdisplay{$newval};
! 3449: } else {
! 3450: $newaccesstext->{$tool} = &mt("availability set to 'off'");
! 3451: }
1.275 raeburn 3452: } else {
1.383 ! raeburn 3453: if ($newval) {
! 3454: $newaccesstext->{$tool} = &mt("availability set to 'on'");
! 3455: } else {
! 3456: $newaccesstext->{$tool} = &mt("availability set to 'off'");
! 3457: }
1.275 raeburn 3458: }
3459: } else {
3460: $newaccess->{$tool} = $oldaccess->{$tool};
1.383 ! raeburn 3461: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
! 3462: if ($newval =~ /^autolimit/) {
! 3463: if ($limit) {
! 3464: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
! 3465: } else {
! 3466: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
! 3467: }
! 3468: } elsif ($newval) {
! 3469: $newaccesstext->{$tool} = $reqdisplay{$newval};
! 3470: } else {
! 3471: $newaccesstext->{$tool} = &mt("availability set to 'off'");
! 3472: }
1.275 raeburn 3473: } else {
1.383 ! raeburn 3474: if ($userenv->{$context.'.'.$tool}) {
! 3475: $newaccesstext->{$tool} = &mt("availability set to 'on'");
! 3476: } else {
! 3477: $newaccesstext->{$tool} = &mt("availability set to 'off'");
! 3478: }
1.275 raeburn 3479: }
3480: }
3481: } else {
3482: $newaccess->{$tool} = $oldaccess->{$tool};
3483: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3484: }
3485: } else {
3486: $changed->{$tool} = &tool_admin($tool,'',$changeHash,$context);
3487: if ($changed->{$tool}) {
3488: $newaccess->{$tool} = &mt('default');
3489: } else {
3490: $newaccess->{$tool} = $oldaccess->{$tool};
1.383 ! raeburn 3491: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
! 3492: if ($newval =~ /^autolimit/) {
! 3493: if ($limit) {
! 3494: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
! 3495: } else {
! 3496: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
! 3497: }
! 3498: } elsif ($newval) {
! 3499: $newaccesstext->{$tool} = $reqdisplay{$newval};
! 3500: } else {
! 3501: $newaccesstext->{$tool} = &mt("availability set to 'off'");
! 3502: }
1.275 raeburn 3503: } else {
1.383 ! raeburn 3504: if ($userenv->{$context.'.'.$tool}) {
! 3505: $newaccesstext->{$tool} = &mt("availability set to 'on'");
! 3506: } else {
! 3507: $newaccesstext->{$tool} = &mt("availability set to 'off'");
! 3508: }
1.275 raeburn 3509: }
3510: }
3511: }
3512: } else {
3513: $oldaccess->{$tool} = &mt('default');
3514: if ($env{'form.custom'.$tool} == 1) {
1.306 raeburn 3515: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
3516: $context);
1.275 raeburn 3517: if ($changed->{$tool}) {
3518: $newaccess->{$tool} = &mt('custom');
1.383 ! raeburn 3519: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
! 3520: if ($newval =~ /^autolimit/) {
! 3521: if ($limit) {
! 3522: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
! 3523: } else {
! 3524: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
! 3525: }
! 3526: } elsif ($newval) {
! 3527: $newaccesstext->{$tool} = $reqdisplay{$newval};
! 3528: } else {
! 3529: $newaccesstext->{$tool} = &mt("availability set to 'off'");
! 3530: }
1.275 raeburn 3531: } else {
1.383 ! raeburn 3532: if ($newval) {
! 3533: $newaccesstext->{$tool} = &mt("availability set to 'on'");
! 3534: } else {
! 3535: $newaccesstext->{$tool} = &mt("availability set to 'off'");
! 3536: }
1.275 raeburn 3537: }
3538: } else {
3539: $newaccess->{$tool} = $oldaccess->{$tool};
3540: }
3541: } else {
3542: $newaccess->{$tool} = $oldaccess->{$tool};
3543: }
3544: }
3545: }
3546: return;
3547: }
3548:
1.220 raeburn 3549: sub update_roles {
1.375 raeburn 3550: my ($r,$context,$showcredits) = @_;
1.4 www 3551: my $now=time;
1.225 raeburn 3552: my @rolechanges;
1.220 raeburn 3553: my %disallowed;
1.73 sakharuk 3554: $r->print('<h3>'.&mt('Modifying Roles').'</h3>');
1.135 raeburn 3555: foreach my $key (keys (%env)) {
3556: next if (! $env{$key});
1.190 raeburn 3557: next if ($key eq 'form.action');
1.27 matthew 3558: # Revoke roles
1.135 raeburn 3559: if ($key=~/^form\.rev/) {
3560: if ($key=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) {
1.64 www 3561: # Revoke standard role
1.170 albertel 3562: my ($scope,$role) = ($1,$2);
3563: my $result =
3564: &Apache::lonnet::revokerole($env{'form.ccdomain'},
3565: $env{'form.ccuname'},
1.239 raeburn 3566: $scope,$role,'','',$context);
1.367 golterma 3567: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 3568: &mt('Revoking [_1] in [_2]',
3569: &Apache::lonnet::plaintext($role),
1.372 raeburn 3570: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 3571: $result ne "ok").'<br />');
3572: if ($result ne "ok") {
3573: $r->print(&mt('Error: [_1]',$result).'<br />');
3574: }
1.170 albertel 3575: if ($role eq 'st') {
1.202 raeburn 3576: my $result =
1.198 raeburn 3577: &Apache::lonuserutils::classlist_drop($scope,
3578: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 3579: $now);
1.367 golterma 3580: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.53 www 3581: }
1.225 raeburn 3582: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3583: push(@rolechanges,$role);
3584: }
1.196 raeburn 3585: }
1.195 raeburn 3586: if ($key=~m{^form\.rev\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}s) {
1.64 www 3587: # Revoke custom role
1.369 bisitz 3588: my $result = &Apache::lonnet::revokecustomrole(
3589: $env{'form.ccdomain'},$env{'form.ccuname'},$1,$2,$3,$4,'','',$context);
1.367 golterma 3590: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 3591: &mt('Revoking custom role [_1] by [_2] in [_3]',
1.372 raeburn 3592: $4,$3.':'.$2,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 3593: $result ne 'ok').'<br />');
3594: if ($result ne "ok") {
3595: $r->print(&mt('Error: [_1]',$result).'<br />');
3596: }
1.225 raeburn 3597: if (!grep(/^cr$/,@rolechanges)) {
3598: push(@rolechanges,'cr');
3599: }
1.64 www 3600: }
1.135 raeburn 3601: } elsif ($key=~/^form\.del/) {
3602: if ($key=~/^form\.del\:([^\_]+)\_([^\_\.]+)$/) {
1.116 raeburn 3603: # Delete standard role
1.170 albertel 3604: my ($scope,$role) = ($1,$2);
3605: my $result =
3606: &Apache::lonnet::assignrole($env{'form.ccdomain'},
3607: $env{'form.ccuname'},
1.239 raeburn 3608: $scope,$role,$now,0,1,'',
3609: $context);
1.367 golterma 3610: $r->print(&Apache::lonhtmlcommon::confirm_success(
3611: &mt('Deleting [_1] in [_2]',
1.369 bisitz 3612: &Apache::lonnet::plaintext($role),
1.372 raeburn 3613: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 3614: $result ne 'ok').'<br />');
3615: if ($result ne "ok") {
3616: $r->print(&mt('Error: [_1]',$result).'<br />');
3617: }
1.367 golterma 3618:
1.170 albertel 3619: if ($role eq 'st') {
1.202 raeburn 3620: my $result =
1.198 raeburn 3621: &Apache::lonuserutils::classlist_drop($scope,
3622: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 3623: $now);
1.369 bisitz 3624: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.81 albertel 3625: }
1.225 raeburn 3626: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3627: push(@rolechanges,$role);
3628: }
1.116 raeburn 3629: }
1.139 albertel 3630: if ($key=~m{^form\.del\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 3631: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
3632: # Delete custom role
1.369 bisitz 3633: my $result =
3634: &Apache::lonnet::assigncustomrole($env{'form.ccdomain'},
3635: $env{'form.ccuname'},$url,$rdom,$rnam,$rolename,$now,
3636: 0,1,$context);
3637: $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('Deleting custom role [_1] by [_2] in [_3]',
1.372 raeburn 3638: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 3639: $result ne "ok").'<br />');
3640: if ($result ne "ok") {
3641: $r->print(&mt('Error: [_1]',$result).'<br />');
3642: }
1.367 golterma 3643:
1.225 raeburn 3644: if (!grep(/^cr$/,@rolechanges)) {
3645: push(@rolechanges,'cr');
3646: }
1.116 raeburn 3647: }
1.135 raeburn 3648: } elsif ($key=~/^form\.ren/) {
1.101 albertel 3649: my $udom = $env{'form.ccdomain'};
3650: my $uname = $env{'form.ccuname'};
1.116 raeburn 3651: # Re-enable standard role
1.135 raeburn 3652: if ($key=~/^form\.ren\:([^\_]+)\_([^\_\.]+)$/) {
1.89 raeburn 3653: my $url = $1;
3654: my $role = $2;
3655: my $logmsg;
3656: my $output;
3657: if ($role eq 'st') {
1.141 albertel 3658: if ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
1.374 raeburn 3659: my ($cdom,$cnum,$csec) = ($1,$2,$3);
1.375 raeburn 3660: my $credits;
3661: if ($showcredits) {
3662: my $defaultcredits =
3663: &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
3664: $credits = &get_user_credits($defaultcredits,$cdom,$cnum);
3665: }
3666: my $result = &Apache::loncommon::commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$cdom,$cnum,$csec,$context,$credits);
1.220 raeburn 3667: if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course') || ($result eq 'refused')) {
1.223 raeburn 3668: if ($result eq 'refused' && $logmsg) {
3669: $output = $logmsg;
3670: } else {
1.369 bisitz 3671: $output = &mt('Error: [_1]',$result)."\n";
1.223 raeburn 3672: }
1.89 raeburn 3673: } else {
1.372 raeburn 3674: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Assigning [_1] in [_2] starting [_3]',
3675: &Apache::lonnet::plaintext($role),
3676: &Apache::loncommon::show_role_extent($url,$context,'st'),
3677: &Apache::lonlocal::locallocaltime($now))).'<br />'.$logmsg.'<br />';
1.89 raeburn 3678: }
3679: }
3680: } else {
1.101 albertel 3681: my $result=&Apache::lonnet::assignrole($env{'form.ccdomain'},
1.239 raeburn 3682: $env{'form.ccuname'},$url,$role,0,$now,'','',
3683: $context);
1.367 golterma 3684: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Re-enabling [_1] in [_2]',
1.372 raeburn 3685: &Apache::lonnet::plaintext($role),
3686: &Apache::loncommon::show_role_extent($url,$context,$role)),$result ne "ok").'<br />';
1.369 bisitz 3687: if ($result ne "ok") {
3688: $output .= &mt('Error: [_1]',$result).'<br />';
3689: }
3690: }
1.89 raeburn 3691: $r->print($output);
1.225 raeburn 3692: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3693: push(@rolechanges,$role);
3694: }
1.113 raeburn 3695: }
1.116 raeburn 3696: # Re-enable custom role
1.139 albertel 3697: if ($key=~m{^form\.ren\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 3698: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
3699: my $result = &Apache::lonnet::assigncustomrole(
3700: $env{'form.ccdomain'}, $env{'form.ccuname'},
1.240 raeburn 3701: $url,$rdom,$rnam,$rolename,0,$now,undef,$context);
1.369 bisitz 3702: $r->print(&Apache::lonhtmlcommon::confirm_success(
3703: &mt('Re-enabling custom role [_1] by [_2] in [_3]',
1.372 raeburn 3704: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 3705: $result ne "ok").'<br />');
3706: if ($result ne "ok") {
3707: $r->print(&mt('Error: [_1]',$result).'<br />');
3708: }
1.225 raeburn 3709: if (!grep(/^cr$/,@rolechanges)) {
3710: push(@rolechanges,'cr');
3711: }
1.116 raeburn 3712: }
1.135 raeburn 3713: } elsif ($key=~/^form\.act/) {
1.101 albertel 3714: my $udom = $env{'form.ccdomain'};
3715: my $uname = $env{'form.ccuname'};
1.141 albertel 3716: if ($key=~/^form\.act\_($match_domain)\_($match_courseid)\_cr_cr_($match_domain)_($match_username)_([^\_]+)$/) {
1.65 www 3717: # Activate a custom role
1.83 albertel 3718: my ($one,$two,$three,$four,$five)=($1,$2,$3,$4,$5);
3719: my $url='/'.$one.'/'.$two;
3720: my $full=$one.'_'.$two.'_cr_cr_'.$three.'_'.$four.'_'.$five;
1.65 www 3721:
1.101 albertel 3722: my $start = ( $env{'form.start_'.$full} ?
3723: $env{'form.start_'.$full} :
1.88 raeburn 3724: $now );
1.101 albertel 3725: my $end = ( $env{'form.end_'.$full} ?
3726: $env{'form.end_'.$full} :
1.88 raeburn 3727: 0 );
3728:
3729: # split multiple sections
3730: my %sections = ();
1.101 albertel 3731: my $num_sections = &build_roles($env{'form.sec_'.$full},\%sections,$5);
1.88 raeburn 3732: if ($num_sections == 0) {
1.240 raeburn 3733: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end,$context));
1.88 raeburn 3734: } else {
1.114 albertel 3735: my %curr_groups =
1.117 raeburn 3736: &Apache::longroup::coursegroups($one,$two);
1.113 raeburn 3737: foreach my $sec (sort {$a cmp $b} keys %sections) {
3738: if (($sec eq 'none') || ($sec eq 'all') ||
3739: exists($curr_groups{$sec})) {
3740: $disallowed{$sec} = $url;
3741: next;
3742: }
3743: my $securl = $url.'/'.$sec;
1.240 raeburn 3744: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end,$context));
1.88 raeburn 3745: }
3746: }
1.225 raeburn 3747: if (!grep(/^cr$/,@rolechanges)) {
3748: push(@rolechanges,'cr');
3749: }
1.142 raeburn 3750: } elsif ($key=~/^form\.act\_($match_domain)\_($match_name)\_([^\_]+)$/) {
1.27 matthew 3751: # Activate roles for sections with 3 id numbers
3752: # set start, end times, and the url for the class
1.83 albertel 3753: my ($one,$two,$three)=($1,$2,$3);
1.101 albertel 3754: my $start = ( $env{'form.start_'.$one.'_'.$two.'_'.$three} ?
3755: $env{'form.start_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 3756: $now );
1.101 albertel 3757: my $end = ( $env{'form.end_'.$one.'_'.$two.'_'.$three} ?
3758: $env{'form.end_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 3759: 0 );
1.83 albertel 3760: my $url='/'.$one.'/'.$two;
1.88 raeburn 3761: my $type = 'three';
3762: # split multiple sections
3763: my %sections = ();
1.101 albertel 3764: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections,$three);
1.375 raeburn 3765: my $credits;
3766: if ($three eq 'st') {
3767: if ($showcredits) {
3768: my $defaultcredits =
3769: &Apache::lonuserutils::get_defaultcredits($one,$two);
3770: $credits = $env{'form.credits_'.$one.'_'.$two.'_'.$three};
3771: $credits =~ s/[^\d\.]//g;
3772: if ($credits eq $defaultcredits) {
3773: undef($credits);
3774: }
3775: }
3776: }
1.88 raeburn 3777: if ($num_sections == 0) {
1.375 raeburn 3778: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 3779: } else {
1.114 albertel 3780: my %curr_groups =
1.117 raeburn 3781: &Apache::longroup::coursegroups($one,$two);
1.88 raeburn 3782: my $emptysec = 0;
3783: foreach my $sec (sort {$a cmp $b} keys %sections) {
3784: $sec =~ s/\W//g;
1.113 raeburn 3785: if ($sec ne '') {
3786: if (($sec eq 'none') || ($sec eq 'all') ||
3787: exists($curr_groups{$sec})) {
3788: $disallowed{$sec} = $url;
3789: next;
3790: }
1.88 raeburn 3791: my $securl = $url.'/'.$sec;
1.375 raeburn 3792: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec,$context,$credits));
1.88 raeburn 3793: } else {
3794: $emptysec = 1;
3795: }
3796: }
3797: if ($emptysec) {
1.375 raeburn 3798: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 3799: }
1.225 raeburn 3800: }
3801: if (!grep(/^\Q$three\E$/,@rolechanges)) {
3802: push(@rolechanges,$three);
3803: }
1.135 raeburn 3804: } elsif ($key=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
1.27 matthew 3805: # Activate roles for sections with two id numbers
3806: # set start, end times, and the url for the class
1.101 albertel 3807: my $start = ( $env{'form.start_'.$1.'_'.$2} ?
3808: $env{'form.start_'.$1.'_'.$2} :
1.27 matthew 3809: $now );
1.101 albertel 3810: my $end = ( $env{'form.end_'.$1.'_'.$2} ?
3811: $env{'form.end_'.$1.'_'.$2} :
1.27 matthew 3812: 0 );
1.225 raeburn 3813: my $one = $1;
3814: my $two = $2;
3815: my $url='/'.$one.'/';
1.88 raeburn 3816: # split multiple sections
3817: my %sections = ();
1.225 raeburn 3818: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two},\%sections,$two);
1.88 raeburn 3819: if ($num_sections == 0) {
1.240 raeburn 3820: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 3821: } else {
3822: my $emptysec = 0;
3823: foreach my $sec (sort {$a cmp $b} keys %sections) {
3824: if ($sec ne '') {
3825: my $securl = $url.'/'.$sec;
1.240 raeburn 3826: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$two,$start,$end,$one,undef,$sec,$context));
1.88 raeburn 3827: } else {
3828: $emptysec = 1;
3829: }
3830: }
3831: if ($emptysec) {
1.240 raeburn 3832: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 3833: }
3834: }
1.225 raeburn 3835: if (!grep(/^\Q$two\E$/,@rolechanges)) {
3836: push(@rolechanges,$two);
3837: }
1.64 www 3838: } else {
1.190 raeburn 3839: $r->print('<p><span class="LC_error">'.&mt('ERROR').': '.&mt('Unknown command').' <tt>'.$key.'</tt></span></p><br />');
1.64 www 3840: }
1.113 raeburn 3841: foreach my $key (sort(keys(%disallowed))) {
1.274 bisitz 3842: $r->print('<p class="LC_warning">');
1.113 raeburn 3843: if (($key eq 'none') || ($key eq 'all')) {
1.274 bisitz 3844: $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 3845: } else {
1.274 bisitz 3846: $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 3847: }
1.274 bisitz 3848: $r->print('</p><p>'
3849: .&mt('Please [_1]go back[_2] and choose a different section name.'
3850: ,'<a href="javascript:history.go(-1)'
3851: ,'</a>')
3852: .'</p><br />'
3853: );
1.113 raeburn 3854: }
3855: }
1.101 albertel 3856: } # End of foreach (keys(%env))
1.75 www 3857: # Flush the course logs so reverse user roles immediately updated
1.349 raeburn 3858: $r->register_cleanup(\&Apache::lonnet::flushcourselogs);
1.225 raeburn 3859: if (@rolechanges == 0) {
1.372 raeburn 3860: $r->print('<p>'.&mt('No roles to modify').'</p>');
1.193 raeburn 3861: }
1.225 raeburn 3862: return @rolechanges;
1.220 raeburn 3863: }
3864:
1.375 raeburn 3865: sub get_user_credits {
3866: my ($uname,$udom,$defaultcredits,$cdom,$cnum) = @_;
3867: if ($cdom eq '' || $cnum eq '') {
3868: return unless ($env{'request.course.id'});
3869: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
3870: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
3871: }
3872: my $credits;
3873: my %currhash =
3874: &Apache::lonnet::get('classlist',[$uname.':'.$udom],$cdom,$cnum);
3875: if (keys(%currhash) > 0) {
3876: my @items = split(/:/,$currhash{$uname.':'.$udom});
3877: my $crdidx = &Apache::loncoursedata::CL_CREDITS() - 3;
3878: $credits = $items[$crdidx];
3879: $credits =~ s/[^\d\.]//g;
3880: }
3881: if ($credits eq $defaultcredits) {
3882: undef($credits);
3883: }
3884: return $credits;
3885: }
3886:
1.220 raeburn 3887: sub enroll_single_student {
1.375 raeburn 3888: my ($r,$uhome,$amode,$genpwd,$now,$newuser,$context,$crstype,
3889: $showcredits,$defaultcredits) = @_;
1.318 raeburn 3890: $r->print('<h3>');
3891: if ($crstype eq 'Community') {
3892: $r->print(&mt('Enrolling Member'));
3893: } else {
3894: $r->print(&mt('Enrolling Student'));
3895: }
3896: $r->print('</h3>');
1.220 raeburn 3897:
3898: # Remove non alphanumeric values from section
3899: $env{'form.sections'}=~s/\W//g;
3900:
1.375 raeburn 3901: my $credits;
3902: if (($showcredits) && ($env{'form.credits'} ne '')) {
3903: $credits = $env{'form.credits'};
3904: $credits =~ s/[^\d\.]//g;
3905: if ($credits ne '') {
3906: if ($credits eq $defaultcredits) {
3907: undef($credits);
3908: }
3909: }
3910: }
3911:
1.220 raeburn 3912: # Clean out any old student roles the user has in this class.
3913: &Apache::lonuserutils::modifystudent($env{'form.ccdomain'},
3914: $env{'form.ccuname'},$env{'request.course.id'},undef,$uhome);
3915: my ($startdate,$enddate) = &Apache::lonuserutils::get_dates_from_form();
3916: my $enroll_result =
3917: &Apache::lonnet::modify_student_enrollment($env{'form.ccdomain'},
3918: $env{'form.ccuname'},$env{'form.cid'},$env{'form.cfirstname'},
3919: $env{'form.cmiddlename'},$env{'form.clastname'},
3920: $env{'form.generation'},$env{'form.sections'},$enddate,
1.375 raeburn 3921: $startdate,'manual',undef,$env{'request.course.id'},'',$context,
3922: $credits);
1.220 raeburn 3923: if ($enroll_result =~ /^ok/) {
1.381 bisitz 3924: $r->print(&mt('[_1] enrolled','<b>'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.'</b>'));
1.220 raeburn 3925: if ($env{'form.sections'} ne '') {
3926: $r->print(' '.&mt('in section [_1]',$env{'form.sections'}));
3927: }
3928: my ($showstart,$showend);
3929: if ($startdate <= $now) {
3930: $showstart = &mt('Access starts immediately');
3931: } else {
3932: $showstart = &mt('Access starts: ').&Apache::lonlocal::locallocaltime($startdate);
3933: }
3934: if ($enddate == 0) {
3935: $showend = &mt('ends: no ending date');
3936: } else {
3937: $showend = &mt('ends: ').&Apache::lonlocal::locallocaltime($enddate);
3938: }
3939: $r->print('.<br />'.$showstart.'; '.$showend);
3940: if ($startdate <= $now && !$newuser) {
1.318 raeburn 3941: $r->print('<p> ');
3942: if ($crstype eq 'Community') {
3943: $r->print(&mt('If the member is currently logged-in to LON-CAPA, the new role will be available when the member next logs in.'));
3944: } else {
3945: $r->print(&mt('If the student is currently logged-in to LON-CAPA, the new role will be available when the student next logs in.'));
3946: }
3947: $r->print('</p>');
1.220 raeburn 3948: }
3949: } else {
3950: $r->print(&mt('unable to enroll').": ".$enroll_result);
3951: }
3952: return;
1.188 raeburn 3953: }
3954:
1.204 raeburn 3955: sub get_defaultquota_text {
3956: my ($settingstatus) = @_;
3957: my $defquotatext;
3958: if ($settingstatus eq '') {
1.383 ! raeburn 3959: $defquotatext = &mt('default');
1.204 raeburn 3960: } else {
3961: my ($usertypes,$order) =
3962: &Apache::lonnet::retrieve_inst_usertypes($env{'form.ccdomain'});
3963: if ($usertypes->{$settingstatus} eq '') {
1.383 ! raeburn 3964: $defquotatext = &mt('default');
1.204 raeburn 3965: } else {
1.383 ! raeburn 3966: $defquotatext = &mt('default for [_1]',$usertypes->{$settingstatus});
1.204 raeburn 3967: }
3968: }
3969: return $defquotatext;
3970: }
3971:
1.188 raeburn 3972: sub update_result_form {
3973: my ($uhome) = @_;
3974: my $outcome =
1.367 golterma 3975: '<form name="userupdate" method="post" action="">'."\n";
1.160 raeburn 3976: foreach my $item ('srchby','srchin','srchtype','srchterm','srchdomain','ccuname','ccdomain') {
1.188 raeburn 3977: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 3978: }
1.207 raeburn 3979: if ($env{'form.origname'} ne '') {
3980: $outcome .= '<input type="hidden" name="origname" value="'.$env{'form.origname'}.'" />'."\n";
3981: }
1.160 raeburn 3982: foreach my $item ('sortby','seluname','seludom') {
3983: if (exists($env{'form.'.$item})) {
1.188 raeburn 3984: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 3985: }
3986: }
1.188 raeburn 3987: if ($uhome eq 'no_host') {
3988: $outcome .= '<input type="hidden" name="forcenewuser" value="1" />'."\n";
3989: }
3990: $outcome .= '<input type="hidden" name="phase" value="" />'."\n".
1.383 ! raeburn 3991: '<input type="hidden" name="currstate" value="" />'."\n".
! 3992: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
1.188 raeburn 3993: '</form>';
3994: return $outcome;
1.4 www 3995: }
3996:
1.149 raeburn 3997: sub quota_admin {
1.378 raeburn 3998: my ($setquota,$changeHash,$name) = @_;
1.149 raeburn 3999: my $quotachanged;
4000: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
4001: # Current user has quota modification privileges
1.267 raeburn 4002: if (ref($changeHash) eq 'HASH') {
4003: $quotachanged = 1;
1.378 raeburn 4004: $changeHash->{$name.'quota'} = $setquota;
1.267 raeburn 4005: }
1.149 raeburn 4006: }
4007: return $quotachanged;
4008: }
4009:
1.267 raeburn 4010: sub tool_admin {
1.275 raeburn 4011: my ($tool,$settool,$changeHash,$context) = @_;
4012: my $canchange = 0;
1.279 raeburn 4013: if ($context eq 'requestcourses') {
1.275 raeburn 4014: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
4015: $canchange = 1;
4016: }
1.300 raeburn 4017: } elsif ($context eq 'reqcrsotherdom') {
4018: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
4019: $canchange = 1;
4020: }
1.362 raeburn 4021: } elsif ($context eq 'requestauthor') {
4022: if (&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) {
4023: $canchange = 1;
4024: }
1.275 raeburn 4025: } elsif (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
4026: # Current user has quota modification privileges
4027: $canchange = 1;
4028: }
1.267 raeburn 4029: my $toolchanged;
1.275 raeburn 4030: if ($canchange) {
1.267 raeburn 4031: if (ref($changeHash) eq 'HASH') {
4032: $toolchanged = 1;
1.362 raeburn 4033: if ($tool eq 'requestauthor') {
4034: $changeHash->{$context} = $settool;
4035: } else {
4036: $changeHash->{$context.'.'.$tool} = $settool;
4037: }
1.267 raeburn 4038: }
4039: }
4040: return $toolchanged;
4041: }
4042:
1.88 raeburn 4043: sub build_roles {
1.89 raeburn 4044: my ($sectionstr,$sections,$role) = @_;
1.88 raeburn 4045: my $num_sections = 0;
4046: if ($sectionstr=~ /,/) {
4047: my @secnums = split/,/,$sectionstr;
1.89 raeburn 4048: if ($role eq 'st') {
4049: $secnums[0] =~ s/\W//g;
4050: $$sections{$secnums[0]} = 1;
4051: $num_sections = 1;
4052: } else {
4053: foreach my $sec (@secnums) {
4054: $sec =~ ~s/\W//g;
1.150 banghart 4055: if (!($sec eq "")) {
1.89 raeburn 4056: if (exists($$sections{$sec})) {
4057: $$sections{$sec} ++;
4058: } else {
4059: $$sections{$sec} = 1;
4060: $num_sections ++;
4061: }
1.88 raeburn 4062: }
4063: }
4064: }
4065: } else {
4066: $sectionstr=~s/\W//g;
4067: unless ($sectionstr eq '') {
4068: $$sections{$sectionstr} = 1;
4069: $num_sections ++;
4070: }
4071: }
1.129 albertel 4072:
1.88 raeburn 4073: return $num_sections;
4074: }
4075:
1.58 www 4076: # ========================================================== Custom Role Editor
4077:
4078: sub custom_role_editor {
1.351 raeburn 4079: my ($r,$brcrum) = @_;
1.324 raeburn 4080: my $action = $env{'form.customroleaction'};
4081: my $rolename;
4082: if ($action eq 'new') {
4083: $rolename=$env{'form.newrolename'};
4084: } else {
4085: $rolename=$env{'form.rolename'};
1.59 www 4086: }
4087:
1.324 raeburn 4088: my ($crstype,$context);
4089: if ($env{'request.course.id'}) {
4090: $crstype = &Apache::loncommon::course_type();
4091: $context = 'course';
4092: } else {
4093: $context = 'domain';
4094: $crstype = $env{'form.templatecrstype'};
4095: }
1.351 raeburn 4096:
4097: $rolename=~s/[^A-Za-z0-9]//gs;
4098: if (!$rolename || $env{'form.phase'} eq 'pickrole') {
4099: &print_username_entry_form($r,undef,undef,undef,undef,$crstype,$brcrum);
4100: return;
4101: }
4102:
1.153 banghart 4103: # ------------------------------------------------------- What can be assigned?
4104: my %full=();
4105: my %courselevel=();
4106: my %courselevelcurrent=();
1.61 www 4107: my $syspriv='';
4108: my $dompriv='';
4109: my $coursepriv='';
1.153 banghart 4110: my $body_top;
1.59 www 4111: my ($rdummy,$roledef)=
4112: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
1.60 www 4113: # ------------------------------------------------------- Does this role exist?
1.153 banghart 4114: $body_top .= '<h2>';
1.59 www 4115: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.153 banghart 4116: $body_top .= &mt('Existing Role').' "';
1.61 www 4117: # ------------------------------------------------- Get current role privileges
4118: ($syspriv,$dompriv,$coursepriv)=split(/\_/,$roledef);
1.324 raeburn 4119: if ($crstype eq 'Community') {
4120: $syspriv =~ s/bre\&S//;
4121: }
1.59 www 4122: } else {
1.153 banghart 4123: $body_top .= &mt('New Role').' "';
1.59 www 4124: $roledef='';
4125: }
1.153 banghart 4126: $body_top .= $rolename.'"</h2>';
1.135 raeburn 4127: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
4128: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 4129: if (!$restrict) { $restrict='F'; }
1.60 www 4130: $courselevel{$priv}=$restrict;
1.61 www 4131: if ($coursepriv=~/\:$priv/) {
4132: $courselevelcurrent{$priv}=1;
4133: }
1.60 www 4134: $full{$priv}=1;
4135: }
4136: my %domainlevel=();
1.61 www 4137: my %domainlevelcurrent=();
1.135 raeburn 4138: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
4139: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 4140: if (!$restrict) { $restrict='F'; }
1.60 www 4141: $domainlevel{$priv}=$restrict;
1.61 www 4142: if ($dompriv=~/\:$priv/) {
4143: $domainlevelcurrent{$priv}=1;
4144: }
1.60 www 4145: $full{$priv}=1;
4146: }
1.61 www 4147: my %systemlevel=();
4148: my %systemlevelcurrent=();
1.135 raeburn 4149: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
4150: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 4151: if (!$restrict) { $restrict='F'; }
1.61 www 4152: $systemlevel{$priv}=$restrict;
4153: if ($syspriv=~/\:$priv/) {
4154: $systemlevelcurrent{$priv}=1;
4155: }
4156: $full{$priv}=1;
4157: }
1.160 raeburn 4158: my ($jsback,$elements) = &crumb_utilities();
1.154 banghart 4159: my $button_code = "\n";
1.153 banghart 4160: my $head_script = "\n";
1.301 bisitz 4161: $head_script .= '<script type="text/javascript">'."\n"
4162: .'// <![CDATA['."\n";
1.324 raeburn 4163: my @template_roles = ("in","ta","ep");
4164: if ($context eq 'domain') {
4165: push(@template_roles,"ad");
1.318 raeburn 4166: }
1.324 raeburn 4167: push(@template_roles,"st");
1.318 raeburn 4168: if ($crstype eq 'Community') {
4169: unshift(@template_roles,'co');
4170: } else {
4171: unshift(@template_roles,'cc');
4172: }
1.154 banghart 4173: foreach my $role (@template_roles) {
1.324 raeburn 4174: $head_script .= &make_script_template($role,$crstype);
1.318 raeburn 4175: $button_code .= &make_button_code($role,$crstype).' ';
1.154 banghart 4176: }
1.324 raeburn 4177: my $context_code;
4178: if ($context eq 'domain') {
4179: my $checkedCommunity = '';
4180: my $checkedCourse = ' checked="checked"';
4181: if ($env{'form.templatecrstype'} eq 'Community') {
4182: $checkedCommunity = $checkedCourse;
4183: $checkedCourse = '';
4184: }
4185: $context_code = '<label>'.
4186: '<input type="radio" name="templatecrstype" value="Course"'.$checkedCourse.' onclick="this.form.submit();">'.
4187: &mt('Course').
4188: '</label>'.(' ' x2).
4189: '<label>'.
4190: '<input type="radio" name="templatecrstype" value="Community"'.$checkedCommunity.' onclick="this.form.submit();">'.
4191: &mt('Community').
4192: '</label>'.
4193: '</fieldset>'.
4194: '<input type="hidden" name="customroleaction" value="'.
4195: $action.'" />';
4196: if ($env{'form.customroleaction'} eq 'new') {
4197: $context_code .= '<input type="hidden" name="newrolename" value="'.
4198: $rolename.'" />';
4199: } else {
4200: $context_code .= '<input type="hidden" name="rolename" value="'.
4201: $rolename.'" />';
4202: }
4203: $context_code .= '<input type="hidden" name="action" value="custom" />'.
4204: '<input type="hidden" name="phase" value="selected_custom_edit" />';
4205: }
4206:
1.301 bisitz 4207: $head_script .= "\n".$jsback."\n"
4208: .'// ]]>'."\n"
4209: .'</script>'."\n";
1.351 raeburn 4210: push (@{$brcrum},
4211: {href => "javascript:backPage(document.form1,'pickrole','')",
4212: text => "Pick custom role",
4213: faq => 282,bug=>'Instructor Interface',},
4214: {href => "javascript:backPage(document.form1,'','')",
4215: text => "Edit custom role",
4216: faq => 282,
4217: bug => 'Instructor Interface',
4218: help => 'Course_Editing_Custom_Roles'}
4219: );
4220: my $args = { bread_crumbs => $brcrum,
4221: bread_crumbs_component => 'User Management'};
4222:
4223: $r->print(&Apache::loncommon::start_page('Custom Role Editor',
4224: $head_script,$args).
4225: $body_top);
1.73 sakharuk 4226: my %lt=&Apache::lonlocal::texthash(
4227: 'prv' => "Privilege",
1.131 raeburn 4228: 'crl' => "Course Level",
1.73 sakharuk 4229: 'dml' => "Domain Level",
1.150 banghart 4230: 'ssl' => "System Level");
1.264 bisitz 4231:
1.324 raeburn 4232: $r->print('<div class="LC_left_float">'
1.264 bisitz 4233: .'<form action=""><fieldset>'
4234: .'<legend>'.&mt('Select a Template').'</legend>'
4235: .$button_code
1.324 raeburn 4236: .'</fieldset></form></div>');
4237: if ($context_code) {
4238: $r->print('<div class="LC_left_float">'
4239: .'<form action="/adm/createuser" method="post"><fieldset>'
4240: .'<legend>'.&mt('Context').'</legend>'
4241: .$context_code
4242: .'</form>'
4243: .'</div>'
4244: );
4245: }
4246: $r->print('<br clear="all" />');
1.264 bisitz 4247:
1.61 www 4248: $r->print(<<ENDCCF);
1.380 bisitz 4249: <form name="form1" method="post" action="">
1.61 www 4250: <input type="hidden" name="phase" value="set_custom_roles" />
4251: <input type="hidden" name="rolename" value="$rolename" />
4252: ENDCCF
1.135 raeburn 4253: $r->print(&Apache::loncommon::start_data_table().
4254: &Apache::loncommon::start_data_table_header_row().
4255: '<th>'.$lt{'prv'}.'</th><th>'.$lt{'crl'}.'</th><th>'.$lt{'dml'}.
4256: '</th><th>'.$lt{'ssl'}.'</th>'.
4257: &Apache::loncommon::end_data_table_header_row());
1.324 raeburn 4258: foreach my $priv (sort(keys(%full))) {
1.318 raeburn 4259: my $privtext = &Apache::lonnet::plaintext($priv,$crstype);
1.135 raeburn 4260: $r->print(&Apache::loncommon::start_data_table_row().
4261: '<td>'.$privtext.'</td><td>'.
1.288 bisitz 4262: ($courselevel{$priv}?'<input type="checkbox" name="'.$priv.'_c"'.
4263: ($courselevelcurrent{$priv}?' checked="checked"':'').' />':' ').
1.61 www 4264: '</td><td>'.
1.288 bisitz 4265: ($domainlevel{$priv}?'<input type="checkbox" name="'.$priv.'_d"'.
4266: ($domainlevelcurrent{$priv}?' checked="checked"':'').' />':' ').
1.324 raeburn 4267: '</td><td>');
4268: if ($priv eq 'bre' && $crstype eq 'Community') {
4269: $r->print(' ');
4270: } else {
4271: $r->print($systemlevel{$priv}?'<input type="checkbox" name="'.$priv.'_s"'.
4272: ($systemlevelcurrent{$priv}?' checked="checked"':'').' />':' ');
4273: }
4274: $r->print('</td>'.
4275: &Apache::loncommon::end_data_table_row());
1.60 www 4276: }
1.135 raeburn 4277: $r->print(&Apache::loncommon::end_data_table().
1.190 raeburn 4278: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
1.160 raeburn 4279: '<input type="hidden" name="startrolename" value="'.$env{'form.rolename'}.
1.179 raeburn 4280: '" />'."\n".'<input type="hidden" name="currstate" value="" />'."\n".
1.160 raeburn 4281: '<input type="reset" value="'.&mt("Reset").'" />'."\n".
1.351 raeburn 4282: '<input type="submit" value="'.&mt('Save').'" /></form>');
1.61 www 4283: }
1.153 banghart 4284: # --------------------------------------------------------
4285: sub make_script_template {
1.324 raeburn 4286: my ($role,$crstype) = @_;
1.153 banghart 4287: my %full_c=();
4288: my %full_d=();
4289: my %full_s=();
4290: my $return_script;
4291: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
4292: my ($priv,$restrict)=split(/\&/,$item);
4293: $full_c{$priv}=1;
4294: }
4295: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
4296: my ($priv,$restrict)=split(/\&/,$item);
4297: $full_d{$priv}=1;
4298: }
1.154 banghart 4299: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
1.324 raeburn 4300: next if (($crstype eq 'Community') && ($item eq 'bre&S'));
1.153 banghart 4301: my ($priv,$restrict)=split(/\&/,$item);
4302: $full_s{$priv}=1;
4303: }
4304: $return_script .= 'function set_'.$role.'() {'."\n";
4305: my @temp = split(/:/,$Apache::lonnet::pr{$role.':c'});
4306: my %role_c;
1.155 banghart 4307: foreach my $priv (@temp) {
1.153 banghart 4308: my ($priv_item, $dummy) = split(/\&/,$priv);
4309: $role_c{$priv_item} = 1;
4310: }
1.269 raeburn 4311: my %role_d;
4312: @temp = split(/:/,$Apache::lonnet::pr{$role.':d'});
4313: foreach my $priv(@temp) {
4314: my ($priv_item, $dummy) = split(/\&/,$priv);
4315: $role_d{$priv_item} = 1;
4316: }
4317: my %role_s;
4318: @temp = split(/:/,$Apache::lonnet::pr{$role.':s'});
4319: foreach my $priv(@temp) {
4320: my ($priv_item, $dummy) = split(/\&/,$priv);
4321: $role_s{$priv_item} = 1;
4322: }
1.153 banghart 4323: foreach my $priv_item (keys(%full_c)) {
4324: my ($priv, $dummy) = split(/\&/,$priv_item);
1.269 raeburn 4325: if ((exists($role_c{$priv})) || (exists($role_d{$priv})) ||
4326: (exists($role_s{$priv}))) {
1.153 banghart 4327: $return_script .= "document.form1.$priv"."_c.checked = true;\n";
4328: } else {
4329: $return_script .= "document.form1.$priv"."_c.checked = false;\n";
4330: }
4331: }
1.154 banghart 4332: foreach my $priv_item (keys(%full_d)) {
4333: my ($priv, $dummy) = split(/\&/,$priv_item);
1.269 raeburn 4334: if ((exists($role_d{$priv})) || (exists($role_s{$priv}))) {
1.154 banghart 4335: $return_script .= "document.form1.$priv"."_d.checked = true;\n";
4336: } else {
4337: $return_script .= "document.form1.$priv"."_d.checked = false;\n";
4338: }
4339: }
4340: foreach my $priv_item (keys(%full_s)) {
1.153 banghart 4341: my ($priv, $dummy) = split(/\&/,$priv_item);
1.154 banghart 4342: if (exists($role_s{$priv})) {
4343: $return_script .= "document.form1.$priv"."_s.checked = true;\n";
4344: } else {
4345: $return_script .= "document.form1.$priv"."_s.checked = false;\n";
4346: }
1.153 banghart 4347: }
4348: $return_script .= '}'."\n";
1.154 banghart 4349: return ($return_script);
4350: }
4351: # ----------------------------------------------------------
4352: sub make_button_code {
1.318 raeburn 4353: my ($role,$crstype) = @_;
4354: my $label = &Apache::lonnet::plaintext($role,$crstype);
1.301 bisitz 4355: my $button_code = '<input type="button" onclick="set_'.$role.'()" value="'.$label.'" />';
1.154 banghart 4356: return ($button_code);
1.153 banghart 4357: }
1.61 www 4358: # ---------------------------------------------------------- Call to definerole
4359: sub set_custom_role {
1.351 raeburn 4360: my ($r,$context,$brcrum) = @_;
1.101 albertel 4361: my $rolename=$env{'form.rolename'};
1.63 www 4362: $rolename=~s/[^A-Za-z0-9]//gs;
1.150 banghart 4363: if (!$rolename) {
1.351 raeburn 4364: &custom_role_editor($r,$brcrum);
1.61 www 4365: return;
4366: }
1.160 raeburn 4367: my ($jsback,$elements) = &crumb_utilities();
1.301 bisitz 4368: my $jscript = '<script type="text/javascript">'
4369: .'// <![CDATA['."\n"
4370: .$jsback."\n"
4371: .'// ]]>'."\n"
4372: .'</script>'."\n";
1.352 raeburn 4373: push(@{$brcrum},
4374: {href => "javascript:backPage(document.customresult,'pickrole','')",
4375: text => "Pick custom role",
4376: faq => 282,
4377: bug => 'Instructor Interface',},
4378: {href => "javascript:backPage(document.customresult,'selected_custom_edit','')",
4379: text => "Edit custom role",
4380: faq => 282,
4381: bug => 'Instructor Interface',},
4382: {href => "javascript:backPage(document.customresult,'set_custom_roles','')",
4383: text => "Result",
4384: faq => 282,
4385: bug => 'Instructor Interface',
4386: help => 'Course_Editing_Custom_Roles'},
4387: );
4388: my $args = { bread_crumbs => $brcrum,
1.351 raeburn 4389: bread_crumbs_component => 'User Management'};
4390: $r->print(&Apache::loncommon::start_page('Save Custom Role',$jscript,$args));
1.160 raeburn 4391:
1.61 www 4392: my ($rdummy,$roledef)=
1.110 albertel 4393: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
4394:
1.61 www 4395: # ------------------------------------------------------- Does this role exist?
1.188 raeburn 4396: $r->print('<h3>');
1.61 www 4397: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.73 sakharuk 4398: $r->print(&mt('Existing Role').' "');
1.61 www 4399: } else {
1.73 sakharuk 4400: $r->print(&mt('New Role').' "');
1.61 www 4401: $roledef='';
4402: }
1.188 raeburn 4403: $r->print($rolename.'"</h3>');
1.61 www 4404: # ------------------------------------------------------- What can be assigned?
4405: my $sysrole='';
4406: my $domrole='';
4407: my $courole='';
4408:
1.135 raeburn 4409: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
4410: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 4411: if (!$restrict) { $restrict=''; }
4412: if ($env{'form.'.$priv.'_c'}) {
1.135 raeburn 4413: $courole.=':'.$item;
1.61 www 4414: }
4415: }
4416:
1.135 raeburn 4417: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
4418: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 4419: if (!$restrict) { $restrict=''; }
4420: if ($env{'form.'.$priv.'_d'}) {
1.135 raeburn 4421: $domrole.=':'.$item;
1.61 www 4422: }
4423: }
4424:
1.135 raeburn 4425: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
4426: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 4427: if (!$restrict) { $restrict=''; }
4428: if ($env{'form.'.$priv.'_s'}) {
1.135 raeburn 4429: $sysrole.=':'.$item;
1.61 www 4430: }
4431: }
1.63 www 4432: $r->print('<br />Defining Role: '.
1.61 www 4433: &Apache::lonnet::definerole($rolename,$sysrole,$domrole,$courole));
1.101 albertel 4434: if ($env{'request.course.id'}) {
4435: my $url='/'.$env{'request.course.id'};
1.63 www 4436: $url=~s/\_/\//g;
1.73 sakharuk 4437: $r->print('<br />'.&mt('Assigning Role to Self').': '.
1.101 albertel 4438: &Apache::lonnet::assigncustomrole($env{'user.domain'},
4439: $env{'user.name'},
1.63 www 4440: $url,
1.101 albertel 4441: $env{'user.domain'},
4442: $env{'user.name'},
1.240 raeburn 4443: $rolename,undef,undef,undef,$context));
1.63 www 4444: }
1.380 bisitz 4445: $r->print(
4446: '<p><a href="javascript:backPage(document.customresult,'."'pickrole'".')">'
4447: .&mt('Create or edit another custom role')
4448: .'</a></p>'
4449: .'<form name="customresult" method="post" action="">'
4450: .&Apache::lonhtmlcommon::echo_form_input([]).'</form>'
4451: );
1.58 www 4452: }
4453:
1.2 www 4454: # ================================================================ Main Handler
4455: sub handler {
4456: my $r = shift;
4457: if ($r->header_only) {
1.68 www 4458: &Apache::loncommon::content_type($r,'text/html');
1.2 www 4459: $r->send_http_header;
4460: return OK;
4461: }
1.318 raeburn 4462: my ($context,$crstype);
1.190 raeburn 4463: if ($env{'request.course.id'}) {
4464: $context = 'course';
1.318 raeburn 4465: $crstype = &Apache::loncommon::course_type();
1.190 raeburn 4466: } elsif ($env{'request.role'} =~ /^au\./) {
1.206 raeburn 4467: $context = 'author';
1.190 raeburn 4468: } else {
4469: $context = 'domain';
4470: }
1.375 raeburn 4471:
1.190 raeburn 4472: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.233 raeburn 4473: ['action','state','callingform','roletype','showrole','bulkaction','popup','phase',
4474: 'username','domain','srchterm','srchdomain','srchin','srchby','srchtype']);
1.190 raeburn 4475: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.351 raeburn 4476: my $args;
4477: my $brcrum = [];
4478: my $bread_crumbs_component = 'User Management';
1.202 raeburn 4479: if ($env{'form.action'} ne 'dateselect') {
1.351 raeburn 4480: $brcrum = [{href=>"/adm/createuser",
4481: text=>"User Management",
4482: 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'}
4483: ];
1.202 raeburn 4484: }
1.289 droeschl 4485: #SD Following files not added to help, because the corresponding .tex-files seem to
4486: #be missing: Course_Approve_Selfenroll,Course_User_Logs,
1.209 raeburn 4487: my ($permission,$allowed) =
1.318 raeburn 4488: &Apache::lonuserutils::get_permission($context,$crstype);
1.190 raeburn 4489: if (!$allowed) {
1.358 raeburn 4490: if ($context eq 'course') {
4491: $r->internal_redirect('/adm/viewclasslist');
4492: return OK;
4493: }
1.190 raeburn 4494: $env{'user.error.msg'}=
4495: "/adm/createuser:cst:0:0:Cannot create/modify user data ".
4496: "or view user status.";
4497: return HTTP_NOT_ACCEPTABLE;
4498: }
4499:
4500: &Apache::loncommon::content_type($r,'text/html');
4501: $r->send_http_header;
4502:
1.375 raeburn 4503: my $showcredits;
4504: if ((($context eq 'course') && ($crstype eq 'Course')) ||
4505: ($context eq 'domain')) {
4506: my %domdefaults =
4507: &Apache::lonnet::get_domain_defaults($env{'request.role.domain'});
4508: if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'}) {
4509: $showcredits = 1;
4510: }
4511: }
4512:
1.190 raeburn 4513: # Main switch on form.action and form.state, as appropriate
4514: if (! exists($env{'form.action'})) {
1.351 raeburn 4515: $args = {bread_crumbs => $brcrum,
4516: bread_crumbs_component => $bread_crumbs_component};
4517: $r->print(&header(undef,$args));
1.318 raeburn 4518: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 4519: } elsif ($env{'form.action'} eq 'upload' && $permission->{'cusr'}) {
1.351 raeburn 4520: push(@{$brcrum},
4521: { href => '/adm/createuser?action=upload&state=',
4522: text => 'Upload Users List',
4523: help => 'Course_Create_Class_List',
4524: });
4525: $bread_crumbs_component = 'Upload Users List';
4526: $args = {bread_crumbs => $brcrum,
4527: bread_crumbs_component => $bread_crumbs_component};
4528: $r->print(&header(undef,$args));
1.190 raeburn 4529: $r->print('<form name="studentform" method="post" '.
4530: 'enctype="multipart/form-data" '.
4531: ' action="/adm/createuser">'."\n");
4532: if (! exists($env{'form.state'})) {
4533: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4534: } elsif ($env{'form.state'} eq 'got_file') {
1.375 raeburn 4535: &Apache::lonuserutils::print_upload_manager_form($r,$context,$permission,
4536: $crstype,$showcredits);
1.190 raeburn 4537: } elsif ($env{'form.state'} eq 'enrolling') {
4538: if ($env{'form.datatoken'}) {
1.375 raeburn 4539: &Apache::lonuserutils::upfile_drop_add($r,$context,$permission,
4540: $showcredits);
1.190 raeburn 4541: }
4542: } else {
4543: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4544: }
1.213 raeburn 4545: } elsif ((($env{'form.action'} eq 'singleuser') || ($env{'form.action'}
4546: eq 'singlestudent')) && ($permission->{'cusr'})) {
1.190 raeburn 4547: my $phase = $env{'form.phase'};
4548: my @search = ('srchterm','srchby','srchin','srchtype','srchdomain');
1.192 albertel 4549: &Apache::loncreateuser::restore_prev_selections();
4550: my $srch;
4551: foreach my $item (@search) {
4552: $srch->{$item} = $env{'form.'.$item};
4553: }
1.207 raeburn 4554: if (($phase eq 'get_user_info') || ($phase eq 'userpicked') ||
4555: ($phase eq 'createnewuser')) {
4556: if ($env{'form.phase'} eq 'createnewuser') {
4557: my $response;
4558: if ($env{'form.srchterm'} !~ /^$match_username$/) {
1.366 bisitz 4559: my $response =
4560: '<span class="LC_warning">'
4561: .&mt('You must specify a valid username. Only the following are allowed:'
4562: .' letters numbers - . @')
4563: .'</span>';
1.221 raeburn 4564: $env{'form.phase'} = '';
1.375 raeburn 4565: &print_username_entry_form($r,$context,$response,$srch,undef,
4566: $crstype,$brcrum,$showcredits);
1.207 raeburn 4567: } else {
4568: my $ccuname =&LONCAPA::clean_username($srch->{'srchterm'});
4569: my $ccdomain=&LONCAPA::clean_domain($srch->{'srchdomain'});
4570: &print_user_modification_page($r,$ccuname,$ccdomain,
1.221 raeburn 4571: $srch,$response,$context,
1.375 raeburn 4572: $permission,$crstype,$brcrum,
4573: $showcredits);
1.207 raeburn 4574: }
4575: } elsif ($env{'form.phase'} eq 'get_user_info') {
1.190 raeburn 4576: my ($currstate,$response,$forcenewuser,$results) =
1.221 raeburn 4577: &user_search_result($context,$srch);
1.190 raeburn 4578: if ($env{'form.currstate'} eq 'modify') {
4579: $currstate = $env{'form.currstate'};
4580: }
4581: if ($currstate eq 'select') {
4582: &print_user_selection_page($r,$response,$srch,$results,
1.351 raeburn 4583: \@search,$context,undef,$crstype,
4584: $brcrum);
1.190 raeburn 4585: } elsif ($currstate eq 'modify') {
4586: my ($ccuname,$ccdomain);
4587: if (($srch->{'srchby'} eq 'uname') &&
4588: ($srch->{'srchtype'} eq 'exact')) {
4589: $ccuname = $srch->{'srchterm'};
4590: $ccdomain= $srch->{'srchdomain'};
4591: } else {
4592: my @matchedunames = keys(%{$results});
4593: ($ccuname,$ccdomain) = split(/:/,$matchedunames[0]);
4594: }
4595: $ccuname =&LONCAPA::clean_username($ccuname);
4596: $ccdomain=&LONCAPA::clean_domain($ccdomain);
4597: if ($env{'form.forcenewuser'}) {
4598: $response = '';
4599: }
4600: &print_user_modification_page($r,$ccuname,$ccdomain,
1.221 raeburn 4601: $srch,$response,$context,
1.351 raeburn 4602: $permission,$crstype,$brcrum);
1.190 raeburn 4603: } elsif ($currstate eq 'query') {
1.351 raeburn 4604: &print_user_query_page($r,'createuser',$brcrum);
1.190 raeburn 4605: } else {
1.229 raeburn 4606: $env{'form.phase'} = '';
1.207 raeburn 4607: &print_username_entry_form($r,$context,$response,$srch,
1.351 raeburn 4608: $forcenewuser,$crstype,$brcrum);
1.190 raeburn 4609: }
4610: } elsif ($env{'form.phase'} eq 'userpicked') {
4611: my $ccuname = &LONCAPA::clean_username($env{'form.seluname'});
4612: my $ccdomain = &LONCAPA::clean_domain($env{'form.seludom'});
1.196 raeburn 4613: &print_user_modification_page($r,$ccuname,$ccdomain,$srch,'',
1.351 raeburn 4614: $context,$permission,$crstype,
4615: $brcrum);
1.190 raeburn 4616: }
4617: } elsif ($env{'form.phase'} eq 'update_user_data') {
1.375 raeburn 4618: &update_user_data($r,$context,$crstype,$brcrum,$showcredits);
1.190 raeburn 4619: } else {
1.351 raeburn 4620: &print_username_entry_form($r,$context,undef,$srch,undef,$crstype,
4621: $brcrum);
1.190 raeburn 4622: }
4623: } elsif ($env{'form.action'} eq 'custom' && $permission->{'custom'}) {
4624: if ($env{'form.phase'} eq 'set_custom_roles') {
1.351 raeburn 4625: &set_custom_role($r,$context,$brcrum);
1.190 raeburn 4626: } else {
1.351 raeburn 4627: &custom_role_editor($r,$brcrum);
1.190 raeburn 4628: }
1.362 raeburn 4629: } elsif (($env{'form.action'} eq 'processauthorreq') &&
4630: ($permission->{'cusr'}) &&
4631: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
4632: push(@{$brcrum},
4633: {href => '/adm/createuser?action=processauthorreq',
4634: text => 'Authoring space requests',
4635: help => 'Domain_Role_Approvals'});
4636: $bread_crumbs_component = 'Authoring requests';
4637: if ($env{'form.state'} eq 'done') {
4638: push(@{$brcrum},
4639: {href => '/adm/createuser?action=authorreqqueue',
4640: text => 'Result',
4641: help => 'Domain_Role_Approvals'});
4642: $bread_crumbs_component = 'Authoring request result';
4643: }
4644: $args = { bread_crumbs => $brcrum,
4645: bread_crumbs_component => $bread_crumbs_component};
4646: $r->print(&header(undef,$args));
4647: if (!exists($env{'form.state'})) {
4648: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestauthor',
4649: $env{'request.role.domain'}));
4650: } elsif ($env{'form.state'} eq 'done') {
4651: $r->print('<h3>'.&mt('Authoring request processing').'</h3>'."\n");
4652: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestauthor',
4653: $env{'request.role.domain'}));
4654: }
1.207 raeburn 4655: } elsif (($env{'form.action'} eq 'listusers') &&
4656: ($permission->{'view'} || $permission->{'cusr'})) {
1.202 raeburn 4657: if ($env{'form.phase'} eq 'bulkchange') {
1.351 raeburn 4658: push(@{$brcrum},
4659: {href => '/adm/createuser?action=listusers',
4660: text => "List Users"},
4661: {href => "/adm/createuser",
4662: text => "Result",
4663: help => 'Course_View_Class_List'});
4664: $bread_crumbs_component = 'Update Users';
4665: $args = {bread_crumbs => $brcrum,
4666: bread_crumbs_component => $bread_crumbs_component};
4667: $r->print(&header(undef,$args));
1.202 raeburn 4668: my $setting = $env{'form.roletype'};
4669: my $choice = $env{'form.bulkaction'};
4670: if ($permission->{'cusr'}) {
1.336 raeburn 4671: &Apache::lonuserutils::update_user_list($r,$context,$setting,$choice,$crstype);
1.221 raeburn 4672: } else {
4673: $r->print(&mt('You are not authorized to make bulk changes to user roles'));
1.223 raeburn 4674: $r->print('<p><a href="/adm/createuser?action=listusers">'.&mt('Display User Lists').'</a>');
1.202 raeburn 4675: }
4676: } else {
1.351 raeburn 4677: push(@{$brcrum},
4678: {href => '/adm/createuser?action=listusers',
4679: text => "List Users",
4680: help => 'Course_View_Class_List'});
4681: $bread_crumbs_component = 'List Users';
4682: $args = {bread_crumbs => $brcrum,
4683: bread_crumbs_component => $bread_crumbs_component};
1.202 raeburn 4684: my ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles);
4685: my $formname = 'studentform';
1.364 raeburn 4686: my $hidecall = "hide_searching();";
1.321 raeburn 4687: if (($context eq 'domain') && (($env{'form.roletype'} eq 'course') ||
4688: ($env{'form.roletype'} eq 'community'))) {
4689: if ($env{'form.roletype'} eq 'course') {
4690: ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles) =
4691: &Apache::lonuserutils::courses_selector($env{'request.role.domain'},
4692: $formname);
4693: } elsif ($env{'form.roletype'} eq 'community') {
4694: $cb_jscript =
4695: &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
4696: my %elements = (
4697: coursepick => 'radio',
4698: coursetotal => 'text',
4699: courselist => 'text',
4700: );
4701: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements);
4702: }
1.364 raeburn 4703: $jscript .= &verify_user_display($context)."\n".
4704: &Apache::loncommon::check_uncheck_jscript();
1.202 raeburn 4705: my $js = &add_script($jscript).$cb_jscript;
4706: my $loadcode =
4707: &Apache::lonuserutils::course_selector_loadcode($formname);
4708: if ($loadcode ne '') {
1.364 raeburn 4709: $args->{add_entries} = {onload => "$loadcode;$hidecall"};
4710: } else {
4711: $args->{add_entries} = {onload => $hidecall};
1.202 raeburn 4712: }
1.351 raeburn 4713: $r->print(&header($js,$args));
1.191 raeburn 4714: } else {
1.364 raeburn 4715: $args->{add_entries} = {onload => $hidecall};
4716: $jscript = &verify_user_display($context).
4717: &Apache::loncommon::check_uncheck_jscript();
4718: $r->print(&header(&add_script($jscript),$args));
1.191 raeburn 4719: }
1.202 raeburn 4720: &Apache::lonuserutils::print_userlist($r,undef,$permission,$context,
1.375 raeburn 4721: $formname,$totcodes,$codetitles,$idlist,$idlist_titles,
4722: $showcredits);
1.191 raeburn 4723: }
1.213 raeburn 4724: } elsif ($env{'form.action'} eq 'drop' && $permission->{'cusr'}) {
1.318 raeburn 4725: my $brtext;
4726: if ($crstype eq 'Community') {
4727: $brtext = 'Drop Members';
4728: } else {
4729: $brtext = 'Drop Students';
4730: }
1.351 raeburn 4731: push(@{$brcrum},
4732: {href => '/adm/createuser?action=drop',
4733: text => $brtext,
4734: help => 'Course_Drop_Student'});
4735: if ($env{'form.state'} eq 'done') {
4736: push(@{$brcrum},
4737: {href=>'/adm/createuser?action=drop',
4738: text=>"Result"});
4739: }
4740: $bread_crumbs_component = $brtext;
4741: $args = {bread_crumbs => $brcrum,
4742: bread_crumbs_component => $bread_crumbs_component};
4743: $r->print(&header(undef,$args));
1.213 raeburn 4744: if (!exists($env{'form.state'})) {
1.318 raeburn 4745: &Apache::lonuserutils::print_drop_menu($r,$context,$permission,$crstype);
1.213 raeburn 4746: } elsif ($env{'form.state'} eq 'done') {
4747: &Apache::lonuserutils::update_user_list($r,$context,undef,
4748: $env{'form.action'});
4749: }
1.202 raeburn 4750: } elsif ($env{'form.action'} eq 'dateselect') {
4751: if ($permission->{'cusr'}) {
1.351 raeburn 4752: $r->print(&header(undef,{'no_nav_bar' => 1}).
1.375 raeburn 4753: &Apache::lonuserutils::date_section_selector($context,$permission,
4754: $crstype,$showcredits));
1.202 raeburn 4755: } else {
1.351 raeburn 4756: $r->print(&header(undef,{'no_nav_bar' => 1}).
4757: '<span class="LC_error">'.&mt('You do not have permission to modify dates or sections for users').'</span>');
1.202 raeburn 4758: }
1.237 raeburn 4759: } elsif ($env{'form.action'} eq 'selfenroll') {
1.351 raeburn 4760: push(@{$brcrum},
4761: {href => '/adm/createuser?action=selfenroll',
4762: text => "Configure Self-enrollment",
4763: help => 'Course_Self_Enrollment'});
1.237 raeburn 4764: if (!exists($env{'form.state'})) {
1.351 raeburn 4765: $args = { bread_crumbs => $brcrum,
4766: bread_crumbs_component => 'Configure Self-enrollment'};
4767: $r->print(&header(undef,$args));
1.241 raeburn 4768: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
1.237 raeburn 4769: &print_selfenroll_menu($r,$context,$permission);
4770: } elsif ($env{'form.state'} eq 'done') {
1.351 raeburn 4771: push (@{$brcrum},
4772: {href=>'/adm/createuser?action=selfenroll',
4773: text=>"Result"});
4774: $args = { bread_crumbs => $brcrum,
4775: bread_crumbs_component => 'Self-enrollment result'};
4776: $r->print(&header(undef,$args));
1.241 raeburn 4777: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
4778: &update_selfenroll_config($r,$context,$permission);
1.237 raeburn 4779: }
1.277 raeburn 4780: } elsif ($env{'form.action'} eq 'selfenrollqueue') {
1.351 raeburn 4781: push(@{$brcrum},
4782: {href => '/adm/createuser?action=selfenrollqueue',
4783: text => 'Enrollment requests',
4784: help => 'Course_Self_Enrollment'});
4785: $bread_crumbs_component = 'Enrollment requests';
4786: if ($env{'form.state'} eq 'done') {
4787: push(@{$brcrum},
4788: {href => '/adm/createuser?action=selfenrollqueue',
4789: text => 'Result',
4790: help => 'Course_Self_Enrollment'});
4791: $bread_crumbs_component = 'Enrollment result';
4792: }
4793: $args = { bread_crumbs => $brcrum,
4794: bread_crumbs_component => $bread_crumbs_component};
4795: $r->print(&header(undef,$args));
1.277 raeburn 4796: my $cid = $env{'request.course.id'};
4797: my $cdom = $env{'course.'.$cid.'.domain'};
4798: my $cnum = $env{'course.'.$cid.'.num'};
1.307 raeburn 4799: my $coursedesc = $env{'course.'.$cid.'.description'};
1.277 raeburn 4800: if (!exists($env{'form.state'})) {
4801: $r->print('<h3>'.&mt('Pending enrollment requests').'</h3>'."\n");
1.307 raeburn 4802: $r->print(&Apache::loncoursequeueadmin::display_queued_requests($context,
4803: $cdom,$cnum));
1.277 raeburn 4804: } elsif ($env{'form.state'} eq 'done') {
4805: $r->print('<h3>'.&mt('Enrollment request processing').'</h3>'."\n");
1.307 raeburn 4806: $r->print(&Apache::loncoursequeueadmin::update_request_queue($context,
4807: $cdom,$cnum,$coursedesc));
1.277 raeburn 4808: }
1.239 raeburn 4809: } elsif ($env{'form.action'} eq 'changelogs') {
1.363 raeburn 4810: my $helpitem;
4811: if ($context eq 'course') {
4812: $helpitem = 'Course_User_Logs';
4813: }
1.351 raeburn 4814: push (@{$brcrum},
4815: {href => '/adm/createuser?action=changelogs',
4816: text => 'User Management Logs',
1.363 raeburn 4817: help => $helpitem});
1.351 raeburn 4818: $bread_crumbs_component = 'User Changes';
4819: $args = { bread_crumbs => $brcrum,
4820: bread_crumbs_component => $bread_crumbs_component};
4821: $r->print(&header(undef,$args));
4822: &print_userchangelogs_display($r,$context,$permission);
1.190 raeburn 4823: } else {
1.351 raeburn 4824: $bread_crumbs_component = 'User Management';
4825: $args = { bread_crumbs => $brcrum,
4826: bread_crumbs_component => $bread_crumbs_component};
4827: $r->print(&header(undef,$args));
1.318 raeburn 4828: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 4829: }
1.351 raeburn 4830: $r->print(&Apache::loncommon::end_page());
1.190 raeburn 4831: return OK;
4832: }
4833:
4834: sub header {
1.351 raeburn 4835: my ($jscript,$args) = @_;
1.190 raeburn 4836: my $start_page;
1.351 raeburn 4837: if (ref($args) eq 'HASH') {
4838: $start_page=&Apache::loncommon::start_page('User Management',$jscript,$args);
1.190 raeburn 4839: } else {
1.351 raeburn 4840: $start_page=&Apache::loncommon::start_page('User Management',$jscript);
1.190 raeburn 4841: }
4842: return $start_page;
4843: }
1.2 www 4844:
1.191 raeburn 4845: sub add_script {
4846: my ($js) = @_;
1.301 bisitz 4847: return '<script type="text/javascript">'."\n"
4848: .'// <![CDATA['."\n"
4849: .$js."\n"
4850: .'// ]]>'."\n"
4851: .'</script>'."\n";
1.191 raeburn 4852: }
4853:
1.202 raeburn 4854: sub verify_user_display {
1.364 raeburn 4855: my ($context) = @_;
1.374 raeburn 4856: my %lt = &Apache::lonlocal::texthash (
4857: course => 'course(s): description, section(s), status',
4858: community => 'community(s): description, section(s), status',
4859: author => 'author',
4860: );
1.364 raeburn 4861: my $photos;
4862: if (($context eq 'course') && $env{'request.course.id'}) {
4863: $photos = $env{'course.'.$env{'request.course.id'}.'.internal.showphoto'};
4864: }
1.202 raeburn 4865: my $output = <<"END";
4866:
1.364 raeburn 4867: function hide_searching() {
4868: if (document.getElementById('searching')) {
4869: document.getElementById('searching').style.display = 'none';
4870: }
4871: return;
4872: }
4873:
1.202 raeburn 4874: function display_update() {
4875: document.studentform.action.value = 'listusers';
4876: document.studentform.phase.value = 'display';
4877: document.studentform.submit();
4878: }
4879:
1.364 raeburn 4880: function updateCols(caller) {
4881: var context = '$context';
4882: var photos = '$photos';
4883: if (caller == 'Status') {
1.374 raeburn 4884: if ((context == 'domain') &&
4885: ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
4886: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community'))) {
1.364 raeburn 4887: document.getElementById('showcolstatus').checked = false;
4888: document.getElementById('showcolstatus').disabled = 'disabled';
4889: document.getElementById('showcolstart').checked = false;
4890: document.getElementById('showcolend').checked = false;
1.374 raeburn 4891: } else {
4892: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
4893: document.getElementById('showcolstatus').checked = true;
4894: document.getElementById('showcolstatus').disabled = '';
4895: document.getElementById('showcolstart').checked = true;
4896: document.getElementById('showcolend').checked = true;
4897: } else {
4898: document.getElementById('showcolstatus').checked = false;
4899: document.getElementById('showcolstatus').disabled = 'disabled';
4900: document.getElementById('showcolstart').checked = false;
4901: document.getElementById('showcolend').checked = false;
4902: }
1.364 raeburn 4903: }
4904: }
4905: if (caller == 'output') {
4906: if (photos == 1) {
4907: if (document.getElementById('showcolphoto')) {
4908: var photoitem = document.getElementById('showcolphoto');
4909: if (document.studentform.output.options[document.studentform.output.selectedIndex].value == 'html') {
4910: photoitem.checked = true;
4911: photoitem.disabled = '';
4912: } else {
4913: photoitem.checked = false;
4914: photoitem.disabled = 'disabled';
4915: }
4916: }
4917: }
4918: }
4919: if (caller == 'showrole') {
1.371 raeburn 4920: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any') ||
4921: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'cr')) {
1.364 raeburn 4922: document.getElementById('showcolrole').checked = true;
4923: document.getElementById('showcolrole').disabled = '';
4924: } else {
4925: document.getElementById('showcolrole').checked = false;
4926: document.getElementById('showcolrole').disabled = 'disabled';
4927: }
1.374 raeburn 4928: if (context == 'domain') {
1.382 raeburn 4929: var quotausageshow = 0;
1.374 raeburn 4930: if ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
4931: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community')) {
4932: document.getElementById('showcolstatus').checked = false;
4933: document.getElementById('showcolstatus').disabled = 'disabled';
4934: document.getElementById('showcolstart').checked = false;
4935: document.getElementById('showcolend').checked = false;
4936: } else {
4937: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
4938: document.getElementById('showcolstatus').checked = true;
4939: document.getElementById('showcolstatus').disabled = '';
4940: document.getElementById('showcolstart').checked = true;
4941: document.getElementById('showcolend').checked = true;
4942: }
4943: }
4944: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'domain') {
4945: document.getElementById('showcolextent').disabled = 'disabled';
4946: document.getElementById('showcolextent').checked = 'false';
4947: document.getElementById('showextent').style.display='none';
4948: document.getElementById('showcoltextextent').innerHTML = '';
1.382 raeburn 4949: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'au') ||
4950: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any')) {
4951: if (document.getElementById('showcolauthorusage')) {
4952: document.getElementById('showcolauthorusage').disabled = '';
4953: }
4954: if (document.getElementById('showcolauthorquota')) {
4955: document.getElementById('showcolauthorquota').disabled = '';
4956: }
4957: quotausageshow = 1;
4958: }
1.374 raeburn 4959: } else {
4960: document.getElementById('showextent').style.display='block';
4961: document.getElementById('showextent').style.textAlign='left';
4962: document.getElementById('showextent').style.textFace='normal';
4963: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'author') {
4964: document.getElementById('showcolextent').disabled = '';
4965: document.getElementById('showcolextent').checked = 'true';
4966: document.getElementById('showcoltextextent').innerHTML="$lt{'author'}";
4967: } else {
4968: document.getElementById('showcolextent').disabled = '';
4969: document.getElementById('showcolextent').checked = 'true';
4970: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community') {
4971: document.getElementById('showcoltextextent').innerHTML="$lt{'community'}";
4972: } else {
4973: document.getElementById('showcoltextextent').innerHTML="$lt{'course'}";
4974: }
4975: }
4976: }
1.382 raeburn 4977: if (quotausageshow == 0) {
4978: if (document.getElementById('showcolauthorusage')) {
4979: document.getElementById('showcolauthorusage').checked = false;
4980: document.getElementById('showcolauthorusage').disabled = 'disabled';
4981: }
4982: if (document.getElementById('showcolauthorquota')) {
4983: document.getElementById('showcolauthorquota').checked = false;
4984: document.getElementById('showcolauthorquota').disabled = 'disabled';
4985: }
4986: }
1.374 raeburn 4987: }
1.364 raeburn 4988: }
4989: return;
4990: }
4991:
1.202 raeburn 4992: END
4993: return $output;
4994:
4995: }
4996:
1.190 raeburn 4997: ###############################################################
4998: ###############################################################
4999: # Menu Phase One
5000: sub print_main_menu {
1.318 raeburn 5001: my ($permission,$context,$crstype) = @_;
5002: my $linkcontext = $context;
5003: my $stuterm = lc(&Apache::lonnet::plaintext('st',$crstype));
5004: if (($context eq 'course') && ($crstype eq 'Community')) {
5005: $linkcontext = lc($crstype);
5006: $stuterm = 'Members';
5007: }
1.208 raeburn 5008: my %links = (
1.298 droeschl 5009: domain => {
5010: upload => 'Upload a File of Users',
5011: singleuser => 'Add/Modify a User',
5012: listusers => 'Manage Users',
5013: },
5014: author => {
5015: upload => 'Upload a File of Co-authors',
5016: singleuser => 'Add/Modify a Co-author',
5017: listusers => 'Manage Co-authors',
5018: },
5019: course => {
5020: upload => 'Upload a File of Course Users',
5021: singleuser => 'Add/Modify a Course User',
1.354 www 5022: listusers => 'List and Modify Multiple Course Users',
1.298 droeschl 5023: },
1.318 raeburn 5024: community => {
5025: upload => 'Upload a File of Community Users',
5026: singleuser => 'Add/Modify a Community User',
1.354 www 5027: listusers => 'List and Modify Multiple Community Users',
1.318 raeburn 5028: },
5029: );
5030: my %linktitles = (
5031: domain => {
5032: singleuser => 'Add a user to the domain, and/or a course or community in the domain.',
5033: listusers => 'Show and manage users in this domain.',
5034: },
5035: author => {
5036: singleuser => 'Add a user with a co- or assistant author role.',
5037: listusers => 'Show and manage co- or assistant authors.',
5038: },
5039: course => {
5040: singleuser => 'Add a user with a certain role to this course.',
5041: listusers => 'Show and manage users in this course.',
5042: },
5043: community => {
5044: singleuser => 'Add a user with a certain role to this community.',
5045: listusers => 'Show and manage users in this community.',
5046: },
1.298 droeschl 5047: );
5048: my @menu = ( {categorytitle => 'Single Users',
5049: items =>
5050: [
5051: {
1.318 raeburn 5052: linktext => $links{$linkcontext}{'singleuser'},
1.298 droeschl 5053: icon => 'edit-redo.png',
5054: #help => 'Course_Change_Privileges',
5055: url => '/adm/createuser?action=singleuser',
5056: permission => $permission->{'cusr'},
1.318 raeburn 5057: linktitle => $linktitles{$linkcontext}{'singleuser'},
1.298 droeschl 5058: },
5059: ]},
5060:
5061: {categorytitle => 'Multiple Users',
5062: items =>
5063: [
5064: {
1.318 raeburn 5065: linktext => $links{$linkcontext}{'upload'},
1.340 wenzelju 5066: icon => 'uplusr.png',
1.298 droeschl 5067: #help => 'Course_Create_Class_List',
5068: url => '/adm/createuser?action=upload',
5069: permission => $permission->{'cusr'},
5070: linktitle => 'Upload a CSV or a text file containing users.',
5071: },
5072: {
1.318 raeburn 5073: linktext => $links{$linkcontext}{'listusers'},
1.340 wenzelju 5074: icon => 'mngcu.png',
1.298 droeschl 5075: #help => 'Course_View_Class_List',
5076: url => '/adm/createuser?action=listusers',
5077: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.318 raeburn 5078: linktitle => $linktitles{$linkcontext}{'listusers'},
1.298 droeschl 5079: },
5080:
5081: ]},
5082:
5083: {categorytitle => 'Administration',
5084: items => [ ]},
5085: );
5086:
1.265 mielkec 5087: if ($context eq 'domain'){
1.298 droeschl 5088:
5089: push(@{ $menu[2]->{items} }, #Category: Administration
5090: {
5091: linktext => 'Custom Roles',
5092: icon => 'emblem-photos.png',
5093: #help => 'Course_Editing_Custom_Roles',
5094: url => '/adm/createuser?action=custom',
5095: permission => $permission->{'custom'},
5096: linktitle => 'Configure a custom role.',
5097: },
1.362 raeburn 5098: {
5099: linktext => 'Authoring Space Requests',
5100: icon => 'selfenrl-queue.png',
5101: #help => 'Domain_Role_Approvals',
5102: url => '/adm/createuser?action=processauthorreq',
5103: permission => $permission->{'cusr'},
5104: linktitle => 'Approve or reject author role requests',
5105: },
1.363 raeburn 5106: {
5107: linktext => 'Change Log',
5108: icon => 'document-properties.png',
5109: #help => 'Course_User_Logs',
5110: url => '/adm/createuser?action=changelogs',
5111: permission => $permission->{'cusr'},
5112: linktitle => 'View change log.',
5113: },
1.298 droeschl 5114: );
5115:
1.265 mielkec 5116: }elsif ($context eq 'course'){
1.298 droeschl 5117: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity();
1.318 raeburn 5118:
5119: my %linktext = (
5120: 'Course' => {
5121: single => 'Add/Modify a Student',
5122: drop => 'Drop Students',
5123: groups => 'Course Groups',
5124: },
5125: 'Community' => {
5126: single => 'Add/Modify a Member',
5127: drop => 'Drop Members',
5128: groups => 'Community Groups',
5129: },
5130: );
5131:
5132: my %linktitle = (
5133: 'Course' => {
5134: single => 'Add a user with the role of student to this course',
5135: drop => 'Remove a student from this course.',
5136: groups => 'Manage course groups',
5137: },
5138: 'Community' => {
5139: single => 'Add a user with the role of member to this community',
5140: drop => 'Remove a member from this community.',
5141: groups => 'Manage community groups',
5142: },
5143: );
5144:
1.298 droeschl 5145: push(@{ $menu[0]->{items} }, #Category: Single Users
5146: {
1.318 raeburn 5147: linktext => $linktext{$crstype}{'single'},
1.298 droeschl 5148: #help => 'Course_Add_Student',
5149: icon => 'list-add.png',
5150: url => '/adm/createuser?action=singlestudent',
5151: permission => $permission->{'cusr'},
1.318 raeburn 5152: linktitle => $linktitle{$crstype}{'single'},
1.298 droeschl 5153: },
5154: );
5155:
5156: push(@{ $menu[1]->{items} }, #Category: Multiple Users
5157: {
1.318 raeburn 5158: linktext => $linktext{$crstype}{'drop'},
1.298 droeschl 5159: icon => 'edit-undo.png',
5160: #help => 'Course_Drop_Student',
5161: url => '/adm/createuser?action=drop',
5162: permission => $permission->{'cusr'},
1.318 raeburn 5163: linktitle => $linktitle{$crstype}{'drop'},
1.298 droeschl 5164: },
5165: );
5166: push(@{ $menu[2]->{items} }, #Category: Administration
5167: {
5168: linktext => 'Custom Roles',
5169: icon => 'emblem-photos.png',
5170: #help => 'Course_Editing_Custom_Roles',
5171: url => '/adm/createuser?action=custom',
5172: permission => $permission->{'custom'},
5173: linktitle => 'Configure a custom role.',
5174: },
5175: {
1.318 raeburn 5176: linktext => $linktext{$crstype}{'groups'},
1.333 wenzelju 5177: icon => 'grps.png',
1.298 droeschl 5178: #help => 'Course_Manage_Group',
5179: url => '/adm/coursegroups?refpage=cusr',
5180: permission => $permission->{'grp_manage'},
1.318 raeburn 5181: linktitle => $linktitle{$crstype}{'groups'},
1.298 droeschl 5182: },
5183: {
1.328 wenzelju 5184: linktext => 'Change Log',
1.298 droeschl 5185: icon => 'document-properties.png',
5186: #help => 'Course_User_Logs',
5187: url => '/adm/createuser?action=changelogs',
5188: permission => $permission->{'cusr'},
5189: linktitle => 'View change log.',
5190: },
5191: );
1.277 raeburn 5192: if ($env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'}) {
1.298 droeschl 5193: push(@{ $menu[2]->{items} },
5194: {
5195: linktext => 'Enrollment Requests',
5196: icon => 'selfenrl-queue.png',
5197: #help => 'Course_Approve_Selfenroll',
5198: url => '/adm/createuser?action=selfenrollqueue',
5199: permission => $permission->{'cusr'},
5200: linktitle =>'Approve or reject enrollment requests.',
5201: },
5202: );
1.277 raeburn 5203: }
1.298 droeschl 5204:
1.265 mielkec 5205: if (!exists($permission->{'cusr_section'})){
1.320 raeburn 5206: if ($crstype ne 'Community') {
5207: push(@{ $menu[2]->{items} },
5208: {
5209: linktext => 'Automated Enrollment',
5210: icon => 'roles.png',
5211: #help => 'Course_Automated_Enrollment',
5212: permission => (&Apache::lonnet::auto_run($cnum,$cdom)
5213: && $permission->{'cusr'}),
5214: url => '/adm/populate',
5215: linktitle => 'Automated enrollment manager.',
5216: }
5217: );
5218: }
5219: push(@{ $menu[2]->{items} },
1.298 droeschl 5220: {
5221: linktext => 'User Self-Enrollment',
1.342 wenzelju 5222: icon => 'self_enroll.png',
1.298 droeschl 5223: #help => 'Course_Self_Enrollment',
5224: url => '/adm/createuser?action=selfenroll',
5225: permission => $permission->{'cusr'},
1.317 bisitz 5226: linktitle => 'Configure user self-enrollment.',
1.298 droeschl 5227: },
5228: );
5229: }
1.363 raeburn 5230: } elsif ($context eq 'author') {
1.370 raeburn 5231: push(@{ $menu[2]->{items} }, #Category: Administration
1.363 raeburn 5232: {
5233: linktext => 'Change Log',
5234: icon => 'document-properties.png',
5235: #help => 'Course_User_Logs',
5236: url => '/adm/createuser?action=changelogs',
5237: permission => $permission->{'cusr'},
5238: linktitle => 'View change log.',
5239: },
1.370 raeburn 5240: );
1.363 raeburn 5241: }
5242: return Apache::lonhtmlcommon::generate_menu(@menu);
1.250 raeburn 5243: # { text => 'View Log-in History',
5244: # help => 'Course_User_Logins',
5245: # action => 'logins',
5246: # permission => $permission->{'cusr'},
5247: # });
1.190 raeburn 5248: }
5249:
1.189 albertel 5250: sub restore_prev_selections {
5251: my %saveable_parameters = ('srchby' => 'scalar',
5252: 'srchin' => 'scalar',
5253: 'srchtype' => 'scalar',
5254: );
5255: &Apache::loncommon::store_settings('user','user_picker',
5256: \%saveable_parameters);
5257: &Apache::loncommon::restore_settings('user','user_picker',
5258: \%saveable_parameters);
5259: }
5260:
1.237 raeburn 5261: sub print_selfenroll_menu {
5262: my ($r,$context,$permission) = @_;
1.322 raeburn 5263: my $crstype = &Apache::loncommon::course_type();
1.237 raeburn 5264: my $formname = 'enrollstudent';
5265: my $nolink = 1;
5266: my ($row,$lt) = &get_selfenroll_titles();
5267: my $groupslist = &Apache::lonuserutils::get_groupslist();
5268: my $setsec_js =
5269: &Apache::lonuserutils::setsections_javascript($formname,$groupslist);
1.249 raeburn 5270: my %alerts = &Apache::lonlocal::texthash(
5271: acto => 'Activation of self-enrollment was selected for the following domain(s)',
5272: butn => 'but no user types have been checked.',
5273: wilf => "Please uncheck 'activate' or check at least one type.",
5274: );
5275: my $selfenroll_js = <<"ENDSCRIPT";
5276: function update_types(caller,num) {
5277: var delidx = getIndexByName('selfenroll_delete');
5278: var actidx = getIndexByName('selfenroll_activate');
5279: if (caller == 'selfenroll_all') {
5280: var selall;
5281: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5282: if (document.$formname.selfenroll_all[i].checked) {
5283: selall = document.$formname.selfenroll_all[i].value;
5284: }
5285: }
5286: if (selall == 1) {
5287: if (delidx != -1) {
5288: if (document.$formname.selfenroll_delete.length) {
5289: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
5290: document.$formname.selfenroll_delete[j].checked = true;
5291: }
5292: } else {
5293: document.$formname.elements[delidx].checked = true;
5294: }
5295: }
5296: if (actidx != -1) {
5297: if (document.$formname.selfenroll_activate.length) {
5298: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5299: document.$formname.selfenroll_activate[j].checked = false;
5300: }
5301: } else {
5302: document.$formname.elements[actidx].checked = false;
5303: }
5304: }
5305: document.$formname.selfenroll_newdom.selectedIndex = 0;
5306: }
5307: }
5308: if (caller == 'selfenroll_activate') {
5309: if (document.$formname.selfenroll_activate.length) {
5310: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5311: if (document.$formname.selfenroll_activate[j].value == num) {
5312: if (document.$formname.selfenroll_activate[j].checked) {
5313: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5314: if (document.$formname.selfenroll_all[i].value == '1') {
5315: document.$formname.selfenroll_all[i].checked = false;
5316: }
5317: if (document.$formname.selfenroll_all[i].value == '0') {
5318: document.$formname.selfenroll_all[i].checked = true;
5319: }
5320: }
5321: }
5322: }
5323: }
5324: } else {
5325: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5326: if (document.$formname.selfenroll_all[i].value == '1') {
5327: document.$formname.selfenroll_all[i].checked = false;
5328: }
5329: if (document.$formname.selfenroll_all[i].value == '0') {
5330: document.$formname.selfenroll_all[i].checked = true;
5331: }
5332: }
5333: }
5334: }
5335: if (caller == 'selfenroll_delete') {
5336: if (document.$formname.selfenroll_delete.length) {
5337: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
5338: if (document.$formname.selfenroll_delete[j].value == num) {
5339: if (document.$formname.selfenroll_delete[j].checked) {
5340: var delindex = getIndexByName('selfenroll_types_'+num);
5341: if (delindex != -1) {
5342: if (document.$formname.elements[delindex].length) {
5343: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
5344: document.$formname.elements[delindex][k].checked = false;
5345: }
5346: } else {
5347: document.$formname.elements[delindex].checked = false;
5348: }
5349: }
5350: }
5351: }
5352: }
5353: } else {
5354: if (document.$formname.selfenroll_delete.checked) {
5355: var delindex = getIndexByName('selfenroll_types_'+num);
5356: if (delindex != -1) {
5357: if (document.$formname.elements[delindex].length) {
5358: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
5359: document.$formname.elements[delindex][k].checked = false;
5360: }
5361: } else {
5362: document.$formname.elements[delindex].checked = false;
5363: }
5364: }
5365: }
5366: }
5367: }
5368: return;
5369: }
5370:
5371: function validate_types(form) {
5372: var needaction = new Array();
5373: var countfail = 0;
5374: var actidx = getIndexByName('selfenroll_activate');
5375: if (actidx != -1) {
5376: if (document.$formname.selfenroll_activate.length) {
5377: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5378: var num = document.$formname.selfenroll_activate[j].value;
5379: if (document.$formname.selfenroll_activate[j].checked) {
5380: countfail = check_types(num,countfail,needaction)
5381: }
5382: }
5383: } else {
5384: if (document.$formname.selfenroll_activate.checked) {
5385: var num = document.enrollstudent.selfenroll_activate.value;
5386: countfail = check_types(num,countfail,needaction)
5387: }
5388: }
5389: }
5390: if (countfail > 0) {
5391: var msg = "$alerts{'acto'}\\n";
5392: var loopend = needaction.length -1;
5393: if (loopend > 0) {
5394: for (var m=0; m<loopend; m++) {
5395: msg += needaction[m]+", ";
5396: }
5397: }
5398: msg += needaction[loopend]+"\\n$alerts{'butn'}\\n$alerts{'wilf'}";
5399: alert(msg);
5400: return;
5401: }
5402: setSections(form);
5403: }
5404:
5405: function check_types(num,countfail,needaction) {
5406: var typeidx = getIndexByName('selfenroll_types_'+num);
5407: var count = 0;
5408: if (typeidx != -1) {
5409: if (document.$formname.elements[typeidx].length) {
5410: for (var k=0; k<document.$formname.elements[typeidx].length; k++) {
5411: if (document.$formname.elements[typeidx][k].checked) {
5412: count ++;
5413: }
5414: }
5415: } else {
5416: if (document.$formname.elements[typeidx].checked) {
5417: count ++;
5418: }
5419: }
5420: if (count == 0) {
5421: var domidx = getIndexByName('selfenroll_dom_'+num);
5422: if (domidx != -1) {
5423: var domname = document.$formname.elements[domidx].value;
5424: needaction[countfail] = domname;
5425: countfail ++;
5426: }
5427: }
5428: }
5429: return countfail;
5430: }
5431:
5432: function getIndexByName(item) {
5433: for (var i=0;i<document.$formname.elements.length;i++) {
5434: if (document.$formname.elements[i].name == item) {
5435: return i;
5436: }
5437: }
5438: return -1;
5439: }
5440: ENDSCRIPT
1.256 raeburn 5441: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
5442: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
5443:
1.237 raeburn 5444: my $output = '<script type="text/javascript">'."\n".
1.301 bisitz 5445: '// <![CDATA['."\n".
1.249 raeburn 5446: $setsec_js."\n".$selfenroll_js."\n".
1.301 bisitz 5447: '// ]]>'."\n".
1.237 raeburn 5448: '</script>'."\n".
1.256 raeburn 5449: '<h3>'.$lt->{'selfenroll'}.'</h3>'."\n";
5450: my ($visible,$cansetvis,$vismsgs,$visactions) = &visible_in_cat($cdom,$cnum);
5451: if (ref($visactions) eq 'HASH') {
5452: if ($visible) {
1.283 bisitz 5453: $output .= '<p class="LC_info">'.$visactions->{'vis'}.'</p>';
1.256 raeburn 5454: } else {
1.283 bisitz 5455: $output .= '<p class="LC_warning">'.$visactions->{'miss'}.'</p>'
5456: .$visactions->{'yous'}.
1.256 raeburn 5457: '<p>'.$visactions->{'gen'}.'<br />'.$visactions->{'coca'};
5458: if (ref($vismsgs) eq 'ARRAY') {
5459: $output .= '<br />'.$visactions->{'make'}.'<ul>';
5460: foreach my $item (@{$vismsgs}) {
5461: $output .= '<li>'.$visactions->{$item}.'</li>';
5462: }
5463: $output .= '</ul>';
5464: }
5465: $output .= '</p>';
5466: }
5467: }
5468: $output .= '<form name="'.$formname.'" method="post" action="/adm/createuser">'."\n".
5469: &Apache::lonhtmlcommon::start_pick_box();
1.237 raeburn 5470: if (ref($row) eq 'ARRAY') {
5471: foreach my $item (@{$row}) {
5472: my $title = $item;
5473: if (ref($lt) eq 'HASH') {
5474: $title = $lt->{$item};
5475: }
1.297 bisitz 5476: $output .= &Apache::lonhtmlcommon::row_title($title);
1.237 raeburn 5477: if ($item eq 'types') {
5478: my $curr_types = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_types'};
1.241 raeburn 5479: my $showdomdesc = 1;
5480: my $includeempty = 1;
5481: my $num = 0;
5482: $output .= &Apache::loncommon::start_data_table().
5483: &Apache::loncommon::start_data_table_row()
5484: .'<td colspan="2"><span class="LC_nobreak"><label>'
5485: .&mt('Any user in any domain:')
5486: .' <input type="radio" name="selfenroll_all" value="1" ';
5487: if ($curr_types eq '*') {
5488: $output .= ' checked="checked" ';
5489: }
1.249 raeburn 5490: $output .= 'onchange="javascript:update_types('.
5491: "'selfenroll_all'".');" />'.&mt('Yes').'</label>'.
5492: ' <input type="radio" name="selfenroll_all" value="0" ';
1.241 raeburn 5493: if ($curr_types ne '*') {
5494: $output .= ' checked="checked" ';
5495: }
1.249 raeburn 5496: $output .= ' onchange="javascript:update_types('.
5497: "'selfenroll_all'".');"/>'.&mt('No').'</label></td>'.
5498: &Apache::loncommon::end_data_table_row().
5499: &Apache::loncommon::end_data_table().
5500: &mt('Or').'<br />'.
5501: &Apache::loncommon::start_data_table();
1.241 raeburn 5502: my %currdoms;
1.249 raeburn 5503: if ($curr_types eq '') {
1.241 raeburn 5504: $output .= &new_selfenroll_dom_row($cdom,'0');
5505: } elsif ($curr_types ne '*') {
5506: my @entries = split(/;/,$curr_types);
5507: if (@entries > 0) {
5508: foreach my $entry (@entries) {
5509: my ($currdom,$typestr) = split(/:/,$entry);
5510: $currdoms{$currdom} = 1;
5511: my $domdesc = &Apache::lonnet::domain($currdom);
1.249 raeburn 5512: my @currinsttypes = split(',',$typestr);
1.241 raeburn 5513: $output .= &Apache::loncommon::start_data_table_row()
5514: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').'<b>'
5515: .' '.$domdesc.' ('.$currdom.')'
5516: .'</b><input type="hidden" name="selfenroll_dom_'.$num
5517: .'" value="'.$currdom.'" /></span><br />'
5518: .'<span class="LC_nobreak"><label><input type="checkbox" '
1.249 raeburn 5519: .'name="selfenroll_delete" value="'.$num.'" onchange="javascript:update_types('."'selfenroll_delete','$num'".');" />'
1.241 raeburn 5520: .&mt('Delete').'</label></span></td>';
1.249 raeburn 5521: $output .= '<td valign="top"> '.&mt('User types:').'<br />'
1.241 raeburn 5522: .&selfenroll_inst_types($num,$currdom,\@currinsttypes).'</td>'
5523: .&Apache::loncommon::end_data_table_row();
5524: $num ++;
5525: }
5526: }
5527: }
1.249 raeburn 5528: my $add_domtitle = &mt('Users in additional domain:');
1.241 raeburn 5529: if ($curr_types eq '*') {
1.249 raeburn 5530: $add_domtitle = &mt('Users in specific domain:');
1.241 raeburn 5531: } elsif ($curr_types eq '') {
1.249 raeburn 5532: $add_domtitle = &mt('Users in other domain:');
1.241 raeburn 5533: }
5534: $output .= &Apache::loncommon::start_data_table_row()
5535: .'<td colspan="2"><span class="LC_nobreak">'.$add_domtitle.'</span><br />'
5536: .&Apache::loncommon::select_dom_form('','selfenroll_newdom',
5537: $includeempty,$showdomdesc)
5538: .'<input type="hidden" name="selfenroll_types_total" value="'.$num.'" />'
5539: .'</td>'.&Apache::loncommon::end_data_table_row()
5540: .&Apache::loncommon::end_data_table();
1.237 raeburn 5541: } elsif ($item eq 'registered') {
5542: my ($regon,$regoff);
5543: if ($env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_registered'}) {
5544: $regon = ' checked="checked" ';
5545: $regoff = ' ';
5546: } else {
5547: $regon = ' ';
5548: $regoff = ' checked="checked" ';
5549: }
5550: $output .= '<label>'.
1.245 raeburn 5551: '<input type="radio" name="selfenroll_registered" value="1"'.$regon.'/>'.
1.244 bisitz 5552: &mt('Yes').'</label> <label>'.
1.245 raeburn 5553: '<input type="radio" name="selfenroll_registered" value="0"'.$regoff.'/>'.
1.244 bisitz 5554: &mt('No').'</label>';
1.237 raeburn 5555: } elsif ($item eq 'enroll_dates') {
5556: my $starttime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_start_date'};
5557: my $endtime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_end_date'};
5558: if ($starttime eq '') {
5559: $starttime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_start_date'};
5560: }
5561: if ($endtime eq '') {
5562: $endtime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_end_date'};
5563: }
5564: my $startform =
5565: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_date',$starttime,
5566: undef,undef,undef,undef,undef,undef,undef,$nolink);
5567: my $endform =
5568: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_date',$endtime,
5569: undef,undef,undef,undef,undef,undef,undef,$nolink);
5570: $output .= &selfenroll_date_forms($startform,$endform);
5571: } elsif ($item eq 'access_dates') {
5572: my $starttime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_start_access'};
5573: my $endtime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_end_access'};
5574: if ($starttime eq '') {
5575: $starttime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_start_date'};
5576: }
5577: if ($endtime eq '') {
5578: $endtime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_end_date'};
5579: }
5580: my $startform =
5581: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_access',$starttime,
5582: undef,undef,undef,undef,undef,undef,undef,$nolink);
5583: my $endform =
5584: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_access',$endtime,
5585: undef,undef,undef,undef,undef,undef,undef,$nolink);
5586: $output .= &selfenroll_date_forms($startform,$endform);
5587: } elsif ($item eq 'section') {
5588: my $currsec = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_section'};
5589: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
5590: my $newsecval;
5591: if ($currsec ne 'none' && $currsec ne '') {
5592: if (!defined($sections_count{$currsec})) {
5593: $newsecval = $currsec;
5594: }
5595: }
5596: my $sections_select =
5597: &Apache::lonuserutils::course_sections(\%sections_count,'st',$currsec);
5598: $output .= '<table class="LC_createuser">'."\n".
5599: '<tr class="LC_section_row">'."\n".
5600: '<td align="center">'.&mt('Existing sections')."\n".
5601: '<br />'.$sections_select.'</td><td align="center">'.
5602: &mt('New section').'<br />'."\n".
5603: '<input type="text" name="newsec" size="15" value="'.$newsecval.'" />'."\n".
5604: '<input type="hidden" name="sections" value="" />'."\n".
5605: '<input type="hidden" name="state" value="done" />'."\n".
5606: '</td></tr></table>'."\n";
1.276 raeburn 5607: } elsif ($item eq 'approval') {
5608: my ($appon,$appoff);
5609: my $cid = $env{'request.course.id'};
5610: my $currnotified = $env{'course.'.$cid.'.internal.selfenroll_notifylist'};
5611: if ($env{'course.'.$cid.'.internal.selfenroll_approval'}) {
5612: $appon = ' checked="checked" ';
5613: $appoff = ' ';
5614: } else {
5615: $appon = ' ';
5616: $appoff = ' checked="checked" ';
5617: }
5618: $output .= '<label>'.
5619: '<input type="radio" name="selfenroll_approval" value="1"'.$appon.'/>'.
5620: &mt('Yes').'</label> <label>'.
5621: '<input type="radio" name="selfenroll_approval" value="0"'.$appoff.'/>'.
5622: &mt('No').'</label>';
5623: my %advhash = &Apache::lonnet::get_course_adv_roles($cid,1);
5624: my (@ccs,%notified);
1.322 raeburn 5625: my $ccrole = 'cc';
5626: if ($crstype eq 'Community') {
5627: $ccrole = 'co';
5628: }
5629: if ($advhash{$ccrole}) {
5630: @ccs = split(/,/,$advhash{$ccrole});
1.276 raeburn 5631: }
5632: if ($currnotified) {
5633: foreach my $current (split(/,/,$currnotified)) {
5634: $notified{$current} = 1;
5635: if (!grep(/^\Q$current\E$/,@ccs)) {
5636: push(@ccs,$current);
5637: }
5638: }
5639: }
5640: if (@ccs) {
1.277 raeburn 5641: $output .= '<br />'.&mt('Personnel to be notified when an enrollment request needs approval, or has been approved:').' '.&Apache::loncommon::start_data_table().
1.276 raeburn 5642: &Apache::loncommon::start_data_table_row();
5643: my $count = 0;
5644: my $numcols = 4;
5645: foreach my $cc (sort(@ccs)) {
5646: my $notifyon;
5647: my ($ccuname,$ccudom) = split(/:/,$cc);
5648: if ($notified{$cc}) {
5649: $notifyon = ' checked="checked" ';
5650: }
5651: if ($count && !$count%$numcols) {
5652: $output .= &Apache::loncommon::end_data_table_row().
5653: &Apache::loncommon::start_data_table_row()
5654: }
5655: $output .= '<td><span class="LC_nobreak"><label>'.
5656: '<input type="checkbox" name="selfenroll_notify"'.$notifyon.' value="'.$cc.'" />'.
5657: &Apache::loncommon::plainname($ccuname,$ccudom).
5658: '</label></span></td>';
1.343 raeburn 5659: $count ++;
1.276 raeburn 5660: }
5661: my $rem = $count%$numcols;
5662: if ($rem) {
5663: my $emptycols = $numcols - $rem;
5664: for (my $i=0; $i<$emptycols; $i++) {
5665: $output .= '<td> </td>';
5666: }
5667: }
5668: $output .= &Apache::loncommon::end_data_table_row().
5669: &Apache::loncommon::end_data_table();
5670: }
5671: } elsif ($item eq 'limit') {
5672: my ($crslimit,$selflimit,$nolimit);
5673: my $cid = $env{'request.course.id'};
5674: my $currlim = $env{'course.'.$cid.'.internal.selfenroll_limit'};
5675: my $currcap = $env{'course.'.$cid.'.internal.selfenroll_cap'};
1.343 raeburn 5676: $nolimit = ' checked="checked" ';
1.276 raeburn 5677: if ($currlim eq 'allstudents') {
5678: $crslimit = ' checked="checked" ';
5679: $selflimit = ' ';
5680: $nolimit = ' ';
5681: } elsif ($currlim eq 'selfenrolled') {
5682: $crslimit = ' ';
5683: $selflimit = ' checked="checked" ';
5684: $nolimit = ' ';
5685: } else {
5686: $crslimit = ' ';
5687: $selflimit = ' ';
5688: }
5689: $output .= '<table><tr><td><label>'.
1.278 raeburn 5690: '<input type="radio" name="selfenroll_limit" value="none"'.$nolimit.'/>'.
1.276 raeburn 5691: &mt('No limit').'</label></td><td><label>'.
5692: '<input type="radio" name="selfenroll_limit" value="allstudents"'.$crslimit.'/>'.
5693: &mt('Limit by total students').'</label></td><td><label>'.
5694: '<input type="radio" name="selfenroll_limit" value="selfenrolled"'.$selflimit.'/>'.
5695: &mt('Limit by total self-enrolled students').
5696: '</td></tr><tr>'.
5697: '<td> </td><td colspan="2"><span class="LC_nobreak">'.
5698: (' 'x3).&mt('Maximum number allowed: ').
5699: '<input type="text" name="selfenroll_cap" size = "5" value="'.$currcap.'" /></td></tr></table>';
1.237 raeburn 5700: }
5701: $output .= &Apache::lonhtmlcommon::row_closure(1);
5702: }
5703: }
5704: $output .= &Apache::lonhtmlcommon::end_pick_box().
1.241 raeburn 5705: '<br /><input type="button" name="selfenrollconf" value="'
1.282 schafran 5706: .&mt('Save').'" onclick="validate_types(this.form);" />'
1.241 raeburn 5707: .'<input type="hidden" name="action" value="selfenroll" /></form>';
1.237 raeburn 5708: $r->print($output);
5709: return;
5710: }
5711:
1.256 raeburn 5712: sub visible_in_cat {
5713: my ($cdom,$cnum) = @_;
5714: my %domconf = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
5715: my ($cathash,%settable,@vismsgs,$cansetvis);
5716: my %visactions = &Apache::lonlocal::texthash(
1.316 bisitz 5717: vis => 'Your course/community currently appears in the Course/Community Catalog for this domain.',
1.256 raeburn 5718: 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.',
1.316 bisitz 5719: miss => 'Your course/community does not currently appear in the Course/Community Catalog for this domain.',
1.256 raeburn 5720: yous => 'You should remedy this if you plan to allow self-enrollment, otherwise students will have difficulty finding your course.',
5721: 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.',
1.282 schafran 5722: make => 'Make any changes to self-enrollment settings below, click "Save", then take action to include the course in the Catalog:',
1.256 raeburn 5723: take => 'Take the following action to ensure the course appears in the Catalog:',
5724: dc_unhide => 'Ask a domain coordinator to change the "Exclude from course catalog" setting.',
5725: dc_addinst => 'Ask a domain coordinator to enable display the catalog of "Official courses (with institutional codes)".',
5726: dc_instcode => 'Ask a domain coordinator to assign an institutional code (if this is an official course).',
5727: dc_catalog => 'Ask a domain coordinator to enable or create at least one course category in the domain.',
5728: dc_categories => 'Ask a domain coordinator to create a hierarchy of categories and sub categories for courses in the domain.',
5729: 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',
5730: dc_addcat => 'Ask a domain coordinator to assign a category to the course.',
5731: );
1.347 raeburn 5732: $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>"');
5733: $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>"');
5734: $visactions{'addcat'} = &mt('Use [_1]Categorize course[_2] to assign a category to the course.','"<a href="/adm/courseprefs?phase=display&actions=courseinfo">','</a>"');
1.256 raeburn 5735: if (ref($domconf{'coursecategories'}) eq 'HASH') {
5736: if ($domconf{'coursecategories'}{'togglecats'} eq 'crs') {
5737: $settable{'togglecats'} = 1;
5738: }
5739: if ($domconf{'coursecategories'}{'categorize'} eq 'crs') {
5740: $settable{'categorize'} = 1;
5741: }
5742: $cathash = $domconf{'coursecategories'}{'cats'};
5743: }
1.260 raeburn 5744: if ($settable{'togglecats'} && $settable{'categorize'}) {
1.256 raeburn 5745: $cansetvis = &mt('You are able to both assign a course category and choose to exclude this course from the catalog.');
5746: } elsif ($settable{'togglecats'}) {
5747: $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 5748: } elsif ($settable{'categorize'}) {
1.256 raeburn 5749: $cansetvis = &mt('You may assign a course category, but only a Domain Coordinator may choose to exclude this course from the catalog.');
5750: } else {
5751: $cansetvis = &mt('Only a Domain Coordinator may assign a course category or choose to exclude this course from the catalog.');
5752: }
5753:
5754: my %currsettings =
5755: &Apache::lonnet::get('environment',['hidefromcat','categories','internal.coursecode'],
5756: $cdom,$cnum);
5757: my $visible = 0;
5758: if ($currsettings{'internal.coursecode'} ne '') {
5759: if (ref($domconf{'coursecategories'}) eq 'HASH') {
5760: $cathash = $domconf{'coursecategories'}{'cats'};
5761: if (ref($cathash) eq 'HASH') {
5762: if ($cathash->{'instcode::0'} eq '') {
5763: push(@vismsgs,'dc_addinst');
5764: } else {
5765: $visible = 1;
5766: }
5767: } else {
5768: $visible = 1;
5769: }
5770: } else {
5771: $visible = 1;
5772: }
5773: } else {
5774: if (ref($cathash) eq 'HASH') {
5775: if ($cathash->{'instcode::0'} ne '') {
5776: push(@vismsgs,'dc_instcode');
5777: }
5778: } else {
5779: push(@vismsgs,'dc_instcode');
5780: }
5781: }
5782: if ($currsettings{'categories'} ne '') {
5783: my $cathash;
5784: if (ref($domconf{'coursecategories'}) eq 'HASH') {
5785: $cathash = $domconf{'coursecategories'}{'cats'};
5786: if (ref($cathash) eq 'HASH') {
5787: if (keys(%{$cathash}) == 0) {
5788: push(@vismsgs,'dc_catalog');
5789: } elsif ((keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} ne '')) {
5790: push(@vismsgs,'dc_categories');
5791: } else {
5792: my @currcategories = split('&',$currsettings{'categories'});
5793: my $matched = 0;
5794: foreach my $cat (@currcategories) {
5795: if ($cathash->{$cat} ne '') {
5796: $visible = 1;
5797: $matched = 1;
5798: last;
5799: }
5800: }
5801: if (!$matched) {
1.260 raeburn 5802: if ($settable{'categorize'}) {
1.256 raeburn 5803: push(@vismsgs,'chgcat');
5804: } else {
5805: push(@vismsgs,'dc_chgcat');
5806: }
5807: }
5808: }
5809: }
5810: }
5811: } else {
5812: if (ref($cathash) eq 'HASH') {
5813: if ((keys(%{$cathash}) > 1) ||
5814: (keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} eq '')) {
1.260 raeburn 5815: if ($settable{'categorize'}) {
1.256 raeburn 5816: push(@vismsgs,'addcat');
5817: } else {
5818: push(@vismsgs,'dc_addcat');
5819: }
5820: }
5821: }
5822: }
5823: if ($currsettings{'hidefromcat'} eq 'yes') {
5824: $visible = 0;
5825: if ($settable{'togglecats'}) {
5826: unshift(@vismsgs,'unhide');
5827: } else {
5828: unshift(@vismsgs,'dc_unhide')
5829: }
5830: }
5831: return ($visible,$cansetvis,\@vismsgs,\%visactions);
5832: }
5833:
1.241 raeburn 5834: sub new_selfenroll_dom_row {
5835: my ($newdom,$num) = @_;
5836: my $domdesc = &Apache::lonnet::domain($newdom);
5837: my $output;
5838: if ($domdesc ne '') {
5839: $output .= &Apache::loncommon::start_data_table_row()
5840: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').' <b>'.$domdesc
5841: .' ('.$newdom.')</b><input type="hidden" name="selfenroll_dom_'.$num
1.249 raeburn 5842: .'" value="'.$newdom.'" /></span><br />'
5843: .'<span class="LC_nobreak"><label><input type="checkbox" '
5844: .'name="selfenroll_activate" value="'.$num.'" '
5845: .'onchange="javascript:update_types('
5846: ."'selfenroll_activate','$num'".');" />'
5847: .&mt('Activate').'</label></span></td>';
1.241 raeburn 5848: my @currinsttypes;
5849: $output .= '<td>'.&mt('User types:').'<br />'
5850: .&selfenroll_inst_types($num,$newdom,\@currinsttypes).'</td>'
5851: .&Apache::loncommon::end_data_table_row();
5852: }
5853: return $output;
5854: }
5855:
5856: sub selfenroll_inst_types {
5857: my ($num,$currdom,$currinsttypes) = @_;
5858: my $output;
5859: my $numinrow = 4;
5860: my $count = 0;
5861: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($currdom);
1.247 raeburn 5862: my $othervalue = 'any';
1.241 raeburn 5863: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
1.251 raeburn 5864: if (keys(%{$usertypes}) > 0) {
1.247 raeburn 5865: $othervalue = 'other';
5866: }
1.241 raeburn 5867: $output .= '<table><tr>';
5868: foreach my $type (@{$types}) {
5869: if (($count > 0) && ($count%$numinrow == 0)) {
5870: $output .= '</tr><tr>';
5871: }
5872: if (defined($usertypes->{$type})) {
1.257 raeburn 5873: my $esc_type = &escape($type);
1.241 raeburn 5874: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.
1.257 raeburn 5875: $esc_type.'" ';
1.241 raeburn 5876: if (ref($currinsttypes) eq 'ARRAY') {
5877: if (@{$currinsttypes} > 0) {
1.249 raeburn 5878: if (grep(/^any$/,@{$currinsttypes})) {
5879: $output .= 'checked="checked"';
1.257 raeburn 5880: } elsif (grep(/^\Q$esc_type\E$/,@{$currinsttypes})) {
1.241 raeburn 5881: $output .= 'checked="checked"';
5882: }
1.249 raeburn 5883: } else {
5884: $output .= 'checked="checked"';
1.241 raeburn 5885: }
5886: }
5887: $output .= ' name="selfenroll_types_'.$num.'" />'.$usertypes->{$type}.'</label></span></td>';
5888: }
5889: $count ++;
5890: }
5891: if (($count > 0) && ($count%$numinrow == 0)) {
5892: $output .= '</tr><tr>';
5893: }
1.249 raeburn 5894: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.$othervalue.'"';
1.241 raeburn 5895: if (ref($currinsttypes) eq 'ARRAY') {
5896: if (@{$currinsttypes} > 0) {
1.249 raeburn 5897: if (grep(/^any$/,@{$currinsttypes})) {
5898: $output .= ' checked="checked"';
5899: } elsif ($othervalue eq 'other') {
5900: if (grep(/^\Q$othervalue\E$/,@{$currinsttypes})) {
5901: $output .= ' checked="checked"';
5902: }
1.241 raeburn 5903: }
1.249 raeburn 5904: } else {
5905: $output .= ' checked="checked"';
1.241 raeburn 5906: }
1.249 raeburn 5907: } else {
5908: $output .= ' checked="checked"';
1.241 raeburn 5909: }
5910: $output .= ' name="selfenroll_types_'.$num.'" />'.$othertitle.'</label></span></td></tr></table>';
5911: }
5912: return $output;
5913: }
5914:
1.237 raeburn 5915: sub selfenroll_date_forms {
5916: my ($startform,$endform) = @_;
5917: my $output .= &Apache::lonhtmlcommon::start_pick_box()."\n".
1.244 bisitz 5918: &Apache::lonhtmlcommon::row_title(&mt('Start date'),
1.237 raeburn 5919: 'LC_oddrow_value')."\n".
5920: $startform."\n".
5921: &Apache::lonhtmlcommon::row_closure(1).
1.244 bisitz 5922: &Apache::lonhtmlcommon::row_title(&mt('End date'),
1.237 raeburn 5923: 'LC_oddrow_value')."\n".
5924: $endform."\n".
5925: &Apache::lonhtmlcommon::row_closure(1).
5926: &Apache::lonhtmlcommon::end_pick_box();
5927: return $output;
5928: }
5929:
1.239 raeburn 5930: sub print_userchangelogs_display {
5931: my ($r,$context,$permission) = @_;
1.363 raeburn 5932: my $formname = 'rolelog';
5933: my ($username,$domain,$crstype,%roleslog);
5934: if ($context eq 'domain') {
5935: $domain = $env{'request.role.domain'};
5936: %roleslog=&Apache::lonnet::dump_dom('nohist_rolelog',$domain);
5937: } else {
5938: if ($context eq 'course') {
5939: $domain = $env{'course.'.$env{'request.course.id'}.'.domain'};
5940: $username = $env{'course.'.$env{'request.course.id'}.'.num'};
5941: $crstype = &Apache::loncommon::course_type();
5942: my %saveable_parameters = ('show' => 'scalar',);
5943: &Apache::loncommon::store_course_settings('roles_log',
5944: \%saveable_parameters);
5945: &Apache::loncommon::restore_course_settings('roles_log',
5946: \%saveable_parameters);
5947: } elsif ($context eq 'author') {
5948: $domain = $env{'user.domain'};
5949: if ($env{'request.role'} =~ m{^au\./\Q$domain\E/$}) {
5950: $username = $env{'user.name'};
5951: } else {
5952: undef($domain);
5953: }
5954: }
5955: if ($domain ne '' && $username ne '') {
5956: %roleslog=&Apache::lonnet::dump('nohist_rolelog',$domain,$username);
5957: }
5958: }
1.239 raeburn 5959: if ((keys(%roleslog))[0]=~/^error\:/) { undef(%roleslog); }
5960:
5961: # set defaults
5962: my $now = time();
5963: my $defstart = $now - (7*24*3600); #7 days ago
5964: my %defaults = (
5965: page => '1',
5966: show => '10',
5967: role => 'any',
5968: chgcontext => 'any',
5969: rolelog_start_date => $defstart,
5970: rolelog_end_date => $now,
5971: );
5972: my $more_records = 0;
5973:
5974: # set current
5975: my %curr;
5976: foreach my $item ('show','page','role','chgcontext') {
5977: $curr{$item} = $env{'form.'.$item};
5978: }
5979: my ($startdate,$enddate) =
5980: &Apache::lonuserutils::get_dates_from_form('rolelog_start_date','rolelog_end_date');
5981: $curr{'rolelog_start_date'} = $startdate;
5982: $curr{'rolelog_end_date'} = $enddate;
5983: foreach my $key (keys(%defaults)) {
5984: if ($curr{$key} eq '') {
5985: $curr{$key} = $defaults{$key};
5986: }
5987: }
1.248 raeburn 5988: my (%whodunit,%changed,$version);
5989: ($version) = ($r->dir_config('lonVersion') =~ /^([\d\.]+)\-/);
1.239 raeburn 5990: my ($minshown,$maxshown);
1.255 raeburn 5991: $minshown = 1;
1.239 raeburn 5992: my $count = 0;
5993: if ($curr{'show'} ne &mt('all')) {
5994: $maxshown = $curr{'page'} * $curr{'show'};
5995: if ($curr{'page'} > 1) {
5996: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
5997: }
5998: }
1.301 bisitz 5999:
1.327 raeburn 6000: # Form Header
6001: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
1.363 raeburn 6002: &role_display_filter($context,$formname,$domain,$username,\%curr,
6003: $version,$crstype));
1.327 raeburn 6004:
6005: # Create navigation
6006: my ($nav_script,$nav_links) = &userlogdisplay_nav($formname,\%curr,$more_records);
6007: my $showntableheader = 0;
6008:
6009: # Table Header
6010: my $tableheader =
6011: &Apache::loncommon::start_data_table_header_row()
6012: .'<th> </th>'
6013: .'<th>'.&mt('When').'</th>'
6014: .'<th>'.&mt('Who made the change').'</th>'
6015: .'<th>'.&mt('Changed User').'</th>'
1.363 raeburn 6016: .'<th>'.&mt('Role').'</th>';
6017:
6018: if ($context eq 'course') {
6019: $tableheader .= '<th>'.&mt('Section').'</th>';
6020: }
6021: $tableheader .=
6022: '<th>'.&mt('Context').'</th>'
1.327 raeburn 6023: .'<th>'.&mt('Start').'</th>'
6024: .'<th>'.&mt('End').'</th>'
6025: .&Apache::loncommon::end_data_table_header_row();
6026:
6027: # Display user change log data
1.239 raeburn 6028: foreach my $id (sort { $roleslog{$b}{'exe_time'}<=>$roleslog{$a}{'exe_time'} } (keys(%roleslog))) {
6029: next if (($roleslog{$id}{'exe_time'} < $curr{'rolelog_start_date'}) ||
6030: ($roleslog{$id}{'exe_time'} > $curr{'rolelog_end_date'}));
6031: if ($curr{'show'} ne &mt('all')) {
6032: if ($count >= $curr{'page'} * $curr{'show'}) {
6033: $more_records = 1;
6034: last;
6035: }
6036: }
6037: if ($curr{'role'} ne 'any') {
6038: next if ($roleslog{$id}{'logentry'}{'role'} ne $curr{'role'});
6039: }
6040: if ($curr{'chgcontext'} ne 'any') {
6041: if ($curr{'chgcontext'} eq 'selfenroll') {
6042: next if (!$roleslog{$id}{'logentry'}{'selfenroll'});
6043: } else {
6044: next if ($roleslog{$id}{'logentry'}{'context'} ne $curr{'chgcontext'});
6045: }
6046: }
6047: $count ++;
6048: next if ($count < $minshown);
1.327 raeburn 6049: unless ($showntableheader) {
6050: $r->print($nav_script
6051: .$nav_links
6052: .&Apache::loncommon::start_data_table()
6053: .$tableheader);
6054: $r->rflush();
6055: $showntableheader = 1;
6056: }
1.239 raeburn 6057: if ($whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} eq '') {
6058: $whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} =
6059: &Apache::loncommon::plainname($roleslog{$id}{'exe_uname'},$roleslog{$id}{'exe_udom'});
6060: }
6061: if ($changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} eq '') {
6062: $changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} =
6063: &Apache::loncommon::plainname($roleslog{$id}{'uname'},$roleslog{$id}{'udom'});
6064: }
6065: my $sec = $roleslog{$id}{'logentry'}{'section'};
6066: if ($sec eq '') {
6067: $sec = &mt('None');
6068: }
6069: my ($rolestart,$roleend);
6070: if ($roleslog{$id}{'delflag'}) {
6071: $rolestart = &mt('deleted');
6072: $roleend = &mt('deleted');
6073: } else {
6074: $rolestart = $roleslog{$id}{'logentry'}{'start'};
6075: $roleend = $roleslog{$id}{'logentry'}{'end'};
6076: if ($rolestart eq '' || $rolestart == 0) {
6077: $rolestart = &mt('No start date');
6078: } else {
6079: $rolestart = &Apache::lonlocal::locallocaltime($rolestart);
6080: }
6081: if ($roleend eq '' || $roleend == 0) {
6082: $roleend = &mt('No end date');
6083: } else {
6084: $roleend = &Apache::lonlocal::locallocaltime($roleend);
6085: }
6086: }
6087: my $chgcontext = $roleslog{$id}{'logentry'}{'context'};
6088: if ($roleslog{$id}{'logentry'}{'selfenroll'}) {
6089: $chgcontext = 'selfenroll';
6090: }
1.363 raeburn 6091: my %lt = &rolechg_contexts($context,$crstype);
1.239 raeburn 6092: if ($chgcontext ne '' && $lt{$chgcontext} ne '') {
6093: $chgcontext = $lt{$chgcontext};
6094: }
1.327 raeburn 6095: $r->print(
1.301 bisitz 6096: &Apache::loncommon::start_data_table_row()
6097: .'<td>'.$count.'</td>'
6098: .'<td>'.&Apache::lonlocal::locallocaltime($roleslog{$id}{'exe_time'}).'</td>'
6099: .'<td>'.$whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}}.'</td>'
6100: .'<td>'.$changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}}.'</td>'
1.363 raeburn 6101: .'<td>'.&Apache::lonnet::plaintext($roleslog{$id}{'logentry'}{'role'},$crstype).'</td>');
6102: if ($context eq 'course') {
6103: $r->print('<td>'.$sec.'</td>');
6104: }
6105: $r->print(
6106: '<td>'.$chgcontext.'</td>'
1.301 bisitz 6107: .'<td>'.$rolestart.'</td>'
6108: .'<td>'.$roleend.'</td>'
1.327 raeburn 6109: .&Apache::loncommon::end_data_table_row()."\n");
1.301 bisitz 6110: }
6111:
1.327 raeburn 6112: if ($showntableheader) { # Table footer, if content displayed above
6113: $r->print(&Apache::loncommon::end_data_table()
6114: .$nav_links);
6115: } else { # No content displayed above
1.301 bisitz 6116: $r->print('<p class="LC_info">'
6117: .&mt('There are no records to display.')
6118: .'</p>'
6119: );
1.239 raeburn 6120: }
1.301 bisitz 6121:
1.327 raeburn 6122: # Form Footer
6123: $r->print(
6124: '<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
6125: .'<input type="hidden" name="action" value="changelogs" />'
6126: .'</form>');
6127: return;
6128: }
1.301 bisitz 6129:
1.327 raeburn 6130: sub userlogdisplay_nav {
6131: my ($formname,$curr,$more_records) = @_;
6132: my ($nav_script,$nav_links);
6133: if (ref($curr) eq 'HASH') {
6134: # Create Navigation:
6135: # Navigation Script
6136: $nav_script = <<"ENDSCRIPT";
1.239 raeburn 6137: <script type="text/javascript">
1.301 bisitz 6138: // <![CDATA[
1.239 raeburn 6139: function chgPage(caller) {
6140: if (caller == 'previous') {
6141: document.$formname.page.value --;
6142: }
6143: if (caller == 'next') {
6144: document.$formname.page.value ++;
6145: }
1.327 raeburn 6146: document.$formname.submit();
1.239 raeburn 6147: return;
6148: }
1.301 bisitz 6149: // ]]>
1.239 raeburn 6150: </script>
6151: ENDSCRIPT
1.327 raeburn 6152: # Navigation Buttons
6153: $nav_links = '<p>';
6154: if (($curr->{'page'} > 1) || ($more_records)) {
6155: if ($curr->{'page'} > 1) {
6156: $nav_links .= '<input type="button"'
6157: .' onclick="javascript:chgPage('."'previous'".');"'
6158: .' value="'.&mt('Previous [_1] changes',$curr->{'show'})
6159: .'" /> ';
6160: }
6161: if ($more_records) {
6162: $nav_links .= '<input type="button"'
6163: .' onclick="javascript:chgPage('."'next'".');"'
6164: .' value="'.&mt('Next [_1] changes',$curr->{'show'})
6165: .'" />';
6166: }
1.301 bisitz 6167: }
1.327 raeburn 6168: $nav_links .= '</p>';
1.301 bisitz 6169: }
1.327 raeburn 6170: return ($nav_script,$nav_links);
1.239 raeburn 6171: }
6172:
6173: sub role_display_filter {
1.363 raeburn 6174: my ($context,$formname,$cdom,$cnum,$curr,$version,$crstype) = @_;
6175: my $lctype;
6176: if ($context eq 'course') {
6177: $lctype = lc($crstype);
6178: }
1.239 raeburn 6179: my $nolink = 1;
6180: my $output = '<table><tr><td valign="top">'.
1.301 bisitz 6181: '<span class="LC_nobreak"><b>'.&mt('Changes/page:').'</b></span><br />'.
1.239 raeburn 6182: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
6183: (&mt('all'),5,10,20,50,100,1000,10000)).
6184: '</td><td> </td>';
6185: my $startform =
6186: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_start_date',
6187: $curr->{'rolelog_start_date'},undef,
6188: undef,undef,undef,undef,undef,undef,$nolink);
6189: my $endform =
6190: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_end_date',
6191: $curr->{'rolelog_end_date'},undef,
6192: undef,undef,undef,undef,undef,undef,$nolink);
1.363 raeburn 6193: my %lt = &rolechg_contexts($context,$crstype);
1.301 bisitz 6194: $output .= '<td valign="top"><b>'.&mt('Window during which changes occurred:').'</b><br />'.
6195: '<table><tr><td>'.&mt('After:').
6196: '</td><td>'.$startform.'</td></tr>'.
6197: '<tr><td>'.&mt('Before:').'</td>'.
6198: '<td>'.$endform.'</td></tr></table>'.
6199: '</td>'.
6200: '<td> </td>'.
1.239 raeburn 6201: '<td valign="top"><b>'.&mt('Role:').'</b><br />'.
6202: '<select name="role"><option value="any"';
6203: if ($curr->{'role'} eq 'any') {
6204: $output .= ' selected="selected"';
6205: }
6206: $output .= '>'.&mt('Any').'</option>'."\n";
1.363 raeburn 6207: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
1.239 raeburn 6208: foreach my $role (@roles) {
6209: my $plrole;
6210: if ($role eq 'cr') {
6211: $plrole = &mt('Custom Role');
6212: } else {
1.318 raeburn 6213: $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.239 raeburn 6214: }
6215: my $selstr = '';
6216: if ($role eq $curr->{'role'}) {
6217: $selstr = ' selected="selected"';
6218: }
6219: $output .= ' <option value="'.$role.'"'.$selstr.'>'.$plrole.'</option>';
6220: }
1.301 bisitz 6221: $output .= '</select></td>'.
6222: '<td> </td>'.
6223: '<td valign="top"><b>'.
1.239 raeburn 6224: &mt('Context:').'</b><br /><select name="chgcontext">';
1.363 raeburn 6225: my @posscontexts;
6226: if ($context eq 'course') {
1.376 raeburn 6227: @posscontexts = ('any','automated','updatenow','createcourse','course','domain','selfenroll','requestcourses');
1.363 raeburn 6228: } elsif ($context eq 'domain') {
6229: @posscontexts = ('any','domain','requestauthor','domconfig','server');
6230: } else {
6231: @posscontexts = ('any','author','domain');
6232: }
6233: foreach my $chgtype (@posscontexts) {
1.239 raeburn 6234: my $selstr = '';
6235: if ($curr->{'chgcontext'} eq $chgtype) {
1.301 bisitz 6236: $selstr = ' selected="selected"';
1.239 raeburn 6237: }
1.363 raeburn 6238: if ($context eq 'course') {
1.376 raeburn 6239: if (($chgtype eq 'automated') || ($chgtype eq 'updatenow')) {
1.363 raeburn 6240: next if (!&Apache::lonnet::auto_run($cnum,$cdom));
6241: }
1.239 raeburn 6242: }
6243: $output .= '<option value="'.$chgtype.'"'.$selstr.'>'.$lt{$chgtype}.'</option>'."\n";
1.248 raeburn 6244: }
1.303 bisitz 6245: $output .= '</select></td>'
6246: .'</tr></table>';
6247:
6248: # Update Display button
6249: $output .= '<p>'
6250: .'<input type="submit" value="'.&mt('Update Display').'" />'
6251: .'</p>';
6252:
6253: # Server version info
1.363 raeburn 6254: my $needsrev = '2.11.0';
6255: if ($context eq 'course') {
6256: $needsrev = '2.7.0';
6257: }
6258:
1.303 bisitz 6259: $output .= '<p class="LC_info">'
6260: .&mt('Only changes made from servers running LON-CAPA [_1] or later are displayed.'
1.363 raeburn 6261: ,$needsrev);
1.248 raeburn 6262: if ($version) {
1.303 bisitz 6263: $output .= ' '.&mt('This LON-CAPA server is version [_1]',$version);
6264: }
6265: $output .= '</p><hr />';
1.239 raeburn 6266: return $output;
6267: }
6268:
6269: sub rolechg_contexts {
1.363 raeburn 6270: my ($context,$crstype) = @_;
6271: my %lt;
6272: if ($context eq 'course') {
6273: %lt = &Apache::lonlocal::texthash (
1.239 raeburn 6274: any => 'Any',
1.376 raeburn 6275: automated => 'Automated Enrollment',
1.239 raeburn 6276: updatenow => 'Roster Update',
6277: createcourse => 'Course Creation',
6278: course => 'User Management in course',
6279: domain => 'User Management in domain',
1.313 raeburn 6280: selfenroll => 'Self-enrolled',
1.318 raeburn 6281: requestcourses => 'Course Request',
1.239 raeburn 6282: );
1.363 raeburn 6283: if ($crstype eq 'Community') {
6284: $lt{'createcourse'} = &mt('Community Creation');
6285: $lt{'course'} = &mt('User Management in community');
6286: $lt{'requestcourses'} = &mt('Community Request');
6287: }
6288: } elsif ($context eq 'domain') {
6289: %lt = &Apache::lonlocal::texthash (
6290: any => 'Any',
6291: domain => 'User Management in domain',
6292: requestauthor => 'Authoring Request',
6293: server => 'Command line script (DC role)',
6294: domconfig => 'Self-enrolled',
6295: );
6296: } else {
6297: %lt = &Apache::lonlocal::texthash (
6298: any => 'Any',
6299: domain => 'User Management in domain',
6300: author => 'User Management by author',
6301: );
6302: }
1.239 raeburn 6303: return %lt;
6304: }
6305:
1.27 matthew 6306: #-------------------------------------------------- functions for &phase_two
1.160 raeburn 6307: sub user_search_result {
1.221 raeburn 6308: my ($context,$srch) = @_;
1.160 raeburn 6309: my %allhomes;
6310: my %inst_matches;
6311: my %srch_results;
1.181 raeburn 6312: my ($response,$currstate,$forcenewuser,$dirsrchres);
1.183 raeburn 6313: $srch->{'srchterm'} =~ s/\s+/ /g;
1.176 raeburn 6314: if ($srch->{'srchby'} !~ /^(uname|lastname|lastfirst)$/) {
1.160 raeburn 6315: $response = &mt('Invalid search.');
6316: }
6317: if ($srch->{'srchin'} !~ /^(crs|dom|alc|instd)$/) {
6318: $response = &mt('Invalid search.');
6319: }
1.177 raeburn 6320: if ($srch->{'srchtype'} !~ /^(exact|contains|begins)$/) {
1.160 raeburn 6321: $response = &mt('Invalid search.');
6322: }
6323: if ($srch->{'srchterm'} eq '') {
6324: $response = &mt('You must enter a search term.');
6325: }
1.183 raeburn 6326: if ($srch->{'srchterm'} =~ /^\s+$/) {
6327: $response = &mt('Your search term must contain more than just spaces.');
6328: }
1.160 raeburn 6329: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'instd')) {
6330: if (($srch->{'srchdomain'} eq '') ||
1.163 albertel 6331: ! (&Apache::lonnet::domain($srch->{'srchdomain'}))) {
1.160 raeburn 6332: $response = &mt('You must specify a valid domain when searching in a domain or institutional directory.')
6333: }
6334: }
6335: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs') ||
6336: ($srch->{'srchin'} eq 'alc')) {
1.176 raeburn 6337: if ($srch->{'srchby'} eq 'uname') {
1.243 raeburn 6338: my $unamecheck = $srch->{'srchterm'};
6339: if ($srch->{'srchtype'} eq 'contains') {
6340: if ($unamecheck !~ /^\w/) {
6341: $unamecheck = 'a'.$unamecheck;
6342: }
6343: }
6344: if ($unamecheck !~ /^$match_username$/) {
1.176 raeburn 6345: $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
6346: }
1.160 raeburn 6347: }
6348: }
1.180 raeburn 6349: if ($response ne '') {
6350: $response = '<span class="LC_warning">'.$response.'</span>';
6351: }
1.160 raeburn 6352: if ($srch->{'srchin'} eq 'instd') {
6353: my $instd_chk = &directorysrch_check($srch);
6354: if ($instd_chk ne 'ok') {
1.180 raeburn 6355: $response = '<span class="LC_warning">'.$instd_chk.'</span>'.
6356: '<br />'.&mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').'<br /><br />';
1.160 raeburn 6357: }
6358: }
6359: if ($response ne '') {
1.180 raeburn 6360: return ($currstate,$response);
1.160 raeburn 6361: }
6362: if ($srch->{'srchby'} eq 'uname') {
6363: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs')) {
6364: if ($env{'form.forcenew'}) {
6365: if ($srch->{'srchdomain'} ne $env{'request.role.domain'}) {
6366: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
6367: if ($uhome eq 'no_host') {
6368: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
1.180 raeburn 6369: my $showdom = &display_domain_info($env{'request.role.domain'});
6370: $response = &mt('New users can only be created in the domain to which your current role belongs - [_1].',$showdom);
1.160 raeburn 6371: } else {
1.179 raeburn 6372: $currstate = 'modify';
1.160 raeburn 6373: }
6374: } else {
1.179 raeburn 6375: $currstate = 'modify';
1.160 raeburn 6376: }
6377: } else {
6378: if ($srch->{'srchin'} eq 'dom') {
1.162 raeburn 6379: if ($srch->{'srchtype'} eq 'exact') {
6380: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
6381: if ($uhome eq 'no_host') {
1.179 raeburn 6382: ($currstate,$response,$forcenewuser) =
1.221 raeburn 6383: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 6384: } else {
1.179 raeburn 6385: $currstate = 'modify';
1.310 raeburn 6386: my $uname = $srch->{'srchterm'};
6387: my $udom = $srch->{'srchdomain'};
6388: $srch_results{$uname.':'.$udom} =
6389: { &Apache::lonnet::get('environment',
6390: ['firstname',
6391: 'lastname',
6392: 'permanentemail'],
6393: $udom,$uname)
6394: };
1.162 raeburn 6395: }
6396: } else {
6397: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 6398: ($currstate,$response,$forcenewuser) =
1.221 raeburn 6399: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 6400: }
6401: } else {
1.167 albertel 6402: my $courseusers = &get_courseusers();
1.162 raeburn 6403: if ($srch->{'srchtype'} eq 'exact') {
1.167 albertel 6404: if (exists($courseusers->{$srch->{'srchterm'}.':'.$srch->{'srchdomain'}})) {
1.179 raeburn 6405: $currstate = 'modify';
1.162 raeburn 6406: } else {
1.179 raeburn 6407: ($currstate,$response,$forcenewuser) =
1.221 raeburn 6408: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 6409: }
1.160 raeburn 6410: } else {
1.167 albertel 6411: foreach my $user (keys(%$courseusers)) {
1.162 raeburn 6412: my ($cuname,$cudomain) = split(/:/,$user);
6413: if ($cudomain eq $srch->{'srchdomain'}) {
1.177 raeburn 6414: my $matched = 0;
6415: if ($srch->{'srchtype'} eq 'begins') {
6416: if ($cuname =~ /^\Q$srch->{'srchterm'}\E/i) {
6417: $matched = 1;
6418: }
6419: } else {
6420: if ($cuname =~ /\Q$srch->{'srchterm'}\E/i) {
6421: $matched = 1;
6422: }
6423: }
6424: if ($matched) {
1.167 albertel 6425: $srch_results{$user} =
6426: {&Apache::lonnet::get('environment',
6427: ['firstname',
6428: 'lastname',
1.194 albertel 6429: 'permanentemail'],
6430: $cudomain,$cuname)};
1.162 raeburn 6431: }
6432: }
6433: }
1.179 raeburn 6434: ($currstate,$response,$forcenewuser) =
1.221 raeburn 6435: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 6436: }
6437: }
6438: }
6439: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 6440: $currstate = 'query';
1.160 raeburn 6441: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 6442: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
6443: if ($dirsrchres eq 'ok') {
6444: ($currstate,$response,$forcenewuser) =
1.221 raeburn 6445: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 6446: } else {
6447: my $showdom = &display_domain_info($srch->{'srchdomain'});
6448: $response = '<span class="LC_warning">'.
6449: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
6450: '</span><br />'.
6451: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
6452: '<br /><br />';
6453: }
1.160 raeburn 6454: }
6455: } else {
6456: if ($srch->{'srchin'} eq 'dom') {
6457: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 6458: ($currstate,$response,$forcenewuser) =
1.221 raeburn 6459: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 6460: } elsif ($srch->{'srchin'} eq 'crs') {
1.167 albertel 6461: my $courseusers = &get_courseusers();
6462: foreach my $user (keys(%$courseusers)) {
1.160 raeburn 6463: my ($uname,$udom) = split(/:/,$user);
6464: my %names = &Apache::loncommon::getnames($uname,$udom);
6465: my %emails = &Apache::loncommon::getemails($uname,$udom);
6466: if ($srch->{'srchby'} eq 'lastname') {
6467: if ((($srch->{'srchtype'} eq 'exact') &&
6468: ($names{'lastname'} eq $srch->{'srchterm'})) ||
1.177 raeburn 6469: (($srch->{'srchtype'} eq 'begins') &&
6470: ($names{'lastname'} =~ /^\Q$srch->{'srchterm'}\E/i)) ||
1.160 raeburn 6471: (($srch->{'srchtype'} eq 'contains') &&
6472: ($names{'lastname'} =~ /\Q$srch->{'srchterm'}\E/i))) {
6473: $srch_results{$user} = {firstname => $names{'firstname'},
6474: lastname => $names{'lastname'},
6475: permanentemail => $emails{'permanentemail'},
6476: };
6477: }
6478: } elsif ($srch->{'srchby'} eq 'lastfirst') {
6479: my ($srchlast,$srchfirst) = split(/,/,$srch->{'srchterm'});
1.177 raeburn 6480: $srchlast =~ s/\s+$//;
6481: $srchfirst =~ s/^\s+//;
1.160 raeburn 6482: if ($srch->{'srchtype'} eq 'exact') {
6483: if (($names{'lastname'} eq $srchlast) &&
6484: ($names{'firstname'} eq $srchfirst)) {
6485: $srch_results{$user} = {firstname => $names{'firstname'},
6486: lastname => $names{'lastname'},
6487: permanentemail => $emails{'permanentemail'},
6488:
6489: };
6490: }
1.177 raeburn 6491: } elsif ($srch->{'srchtype'} eq 'begins') {
6492: if (($names{'lastname'} =~ /^\Q$srchlast\E/i) &&
6493: ($names{'firstname'} =~ /^\Q$srchfirst\E/i)) {
6494: $srch_results{$user} = {firstname => $names{'firstname'},
6495: lastname => $names{'lastname'},
6496: permanentemail => $emails{'permanentemail'},
6497: };
6498: }
6499: } else {
1.160 raeburn 6500: if (($names{'lastname'} =~ /\Q$srchlast\E/i) &&
6501: ($names{'firstname'} =~ /\Q$srchfirst\E/i)) {
6502: $srch_results{$user} = {firstname => $names{'firstname'},
6503: lastname => $names{'lastname'},
6504: permanentemail => $emails{'permanentemail'},
6505: };
6506: }
6507: }
6508: }
6509: }
1.179 raeburn 6510: ($currstate,$response,$forcenewuser) =
1.221 raeburn 6511: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 6512: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 6513: $currstate = 'query';
1.160 raeburn 6514: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 6515: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
6516: if ($dirsrchres eq 'ok') {
6517: ($currstate,$response,$forcenewuser) =
1.221 raeburn 6518: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 6519: } else {
6520: my $showdom = &display_domain_info($srch->{'srchdomain'}); $response = '<span class="LC_warning">'.
6521: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
6522: '</span><br />'.
6523: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
6524: '<br /><br />';
6525: }
1.160 raeburn 6526: }
6527: }
1.179 raeburn 6528: return ($currstate,$response,$forcenewuser,\%srch_results);
1.160 raeburn 6529: }
6530:
6531: sub directorysrch_check {
6532: my ($srch) = @_;
6533: my $can_search = 0;
6534: my $response;
6535: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
6536: ['directorysrch'],$srch->{'srchdomain'});
1.180 raeburn 6537: my $showdom = &display_domain_info($srch->{'srchdomain'});
1.160 raeburn 6538: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
6539: if (!$dom_inst_srch{'directorysrch'}{'available'}) {
1.180 raeburn 6540: return &mt('Institutional directory search is not available in domain: [_1]',$showdom);
1.160 raeburn 6541: }
6542: if ($dom_inst_srch{'directorysrch'}{'localonly'}) {
6543: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
1.180 raeburn 6544: return &mt('Institutional directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
1.160 raeburn 6545: }
6546: my @usertypes = split(/:/,$env{'environment.inststatus'});
6547: if (!@usertypes) {
6548: push(@usertypes,'default');
6549: }
6550: if (ref($dom_inst_srch{'directorysrch'}{'cansearch'}) eq 'ARRAY') {
6551: foreach my $type (@usertypes) {
6552: if (grep(/^\Q$type\E$/,@{$dom_inst_srch{'directorysrch'}{'cansearch'}})) {
6553: $can_search = 1;
6554: last;
6555: }
6556: }
6557: }
6558: if (!$can_search) {
6559: my ($insttypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($srch->{'srchdomain'});
6560: my @longtypes;
6561: foreach my $item (@usertypes) {
1.229 raeburn 6562: if (defined($insttypes->{$item})) {
6563: push (@longtypes,$insttypes->{$item});
6564: } elsif ($item eq 'default') {
6565: push (@longtypes,&mt('other'));
6566: }
1.160 raeburn 6567: }
6568: my $insttype_str = join(', ',@longtypes);
1.180 raeburn 6569: return &mt('Institutional directory search in domain: [_1] is not available to your user type: ',$showdom).$insttype_str;
1.229 raeburn 6570: }
1.160 raeburn 6571: } else {
6572: $can_search = 1;
6573: }
6574: } else {
1.180 raeburn 6575: return &mt('Institutional directory search has not been configured for domain: [_1]',$showdom);
1.160 raeburn 6576: }
6577: my %longtext = &Apache::lonlocal::texthash (
1.167 albertel 6578: uname => 'username',
1.160 raeburn 6579: lastfirst => 'last name, first name',
1.167 albertel 6580: lastname => 'last name',
1.172 raeburn 6581: contains => 'contains',
1.178 raeburn 6582: exact => 'as exact match to',
6583: begins => 'begins with',
1.160 raeburn 6584: );
6585: if ($can_search) {
6586: if (ref($dom_inst_srch{'directorysrch'}{'searchby'}) eq 'ARRAY') {
6587: if (!grep(/^\Q$srch->{'srchby'}\E$/,@{$dom_inst_srch{'directorysrch'}{'searchby'}})) {
1.180 raeburn 6588: return &mt('Institutional directory search in domain: [_1] is not available for searching by "[_2]"',$showdom,$longtext{$srch->{'srchby'}});
1.160 raeburn 6589: }
6590: } else {
1.180 raeburn 6591: return &mt('Institutional directory search in domain: [_1] is not available.', $showdom);
1.160 raeburn 6592: }
6593: }
6594: if ($can_search) {
1.178 raeburn 6595: if (ref($dom_inst_srch{'directorysrch'}{'searchtypes'}) eq 'ARRAY') {
6596: if (grep(/^\Q$srch->{'srchtype'}\E/,@{$dom_inst_srch{'directorysrch'}{'searchtypes'}})) {
6597: return 'ok';
6598: } else {
1.180 raeburn 6599: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 6600: }
6601: } else {
6602: if ((($dom_inst_srch{'directorysrch'}{'searchtypes'} eq 'specify') &&
6603: ($srch->{'srchtype'} eq 'exact' || $srch->{'srchtype'} eq 'contains')) ||
6604: ($dom_inst_srch{'directorysrch'}{'searchtypes'} eq $srch->{'srchtype'})) {
6605: return 'ok';
6606: } else {
1.180 raeburn 6607: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 6608: }
1.160 raeburn 6609: }
6610: }
6611: }
6612:
6613: sub get_courseusers {
6614: my %advhash;
1.167 albertel 6615: my $classlist = &Apache::loncoursedata::get_classlist();
1.160 raeburn 6616: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles();
6617: foreach my $role (sort(keys(%coursepersonnel))) {
6618: foreach my $user (split(/\,/,$coursepersonnel{$role})) {
1.167 albertel 6619: if (!exists($classlist->{$user})) {
6620: $classlist->{$user} = [];
6621: }
1.160 raeburn 6622: }
6623: }
1.167 albertel 6624: return $classlist;
1.160 raeburn 6625: }
6626:
6627: sub build_search_response {
1.221 raeburn 6628: my ($context,$srch,%srch_results) = @_;
1.179 raeburn 6629: my ($currstate,$response,$forcenewuser);
1.160 raeburn 6630: my %names = (
1.330 bisitz 6631: 'uname' => 'username',
6632: 'lastname' => 'last name',
1.160 raeburn 6633: 'lastfirst' => 'last name, first name',
1.330 bisitz 6634: 'crs' => 'this course',
6635: 'dom' => 'LON-CAPA domain',
6636: 'instd' => 'the institutional directory for domain',
1.160 raeburn 6637: );
6638:
6639: my %single = (
1.180 raeburn 6640: begins => 'A match',
1.160 raeburn 6641: contains => 'A match',
1.180 raeburn 6642: exact => 'An exact match',
1.160 raeburn 6643: );
6644: my %nomatch = (
1.180 raeburn 6645: begins => 'No match',
1.160 raeburn 6646: contains => 'No match',
1.180 raeburn 6647: exact => 'No exact match',
1.160 raeburn 6648: );
6649: if (keys(%srch_results) > 1) {
1.179 raeburn 6650: $currstate = 'select';
1.160 raeburn 6651: } else {
6652: if (keys(%srch_results) == 1) {
1.179 raeburn 6653: $currstate = 'modify';
1.180 raeburn 6654: $response = &mt("$single{$srch->{'srchtype'}} was found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}.",$srch->{'srchterm'});
6655: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 6656: $response .= ': '.&display_domain_info($srch->{'srchdomain'});
1.180 raeburn 6657: }
1.330 bisitz 6658: } else { # Search has nothing found. Prepare message to user.
6659: $response = '<span class="LC_warning">';
1.180 raeburn 6660: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 6661: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}: [_2]",
6662: '<b>'.$srch->{'srchterm'}.'</b>',
6663: &display_domain_info($srch->{'srchdomain'}));
6664: } else {
6665: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}.",
6666: '<b>'.$srch->{'srchterm'}.'</b>');
1.180 raeburn 6667: }
6668: $response .= '</span>';
1.330 bisitz 6669:
1.160 raeburn 6670: if ($srch->{'srchin'} ne 'alc') {
6671: $forcenewuser = 1;
6672: my $cansrchinst = 0;
6673: if ($srch->{'srchdomain'}) {
6674: my %domconfig = &Apache::lonnet::get_dom('configuration',['directorysrch'],$srch->{'srchdomain'});
6675: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
6676: if ($domconfig{'directorysrch'}{'available'}) {
6677: $cansrchinst = 1;
6678: }
6679: }
6680: }
1.180 raeburn 6681: if ((($srch->{'srchby'} eq 'lastfirst') ||
6682: ($srch->{'srchby'} eq 'lastname')) &&
6683: ($srch->{'srchin'} eq 'dom')) {
6684: if ($cansrchinst) {
6685: $response .= '<br />'.&mt('You may want to broaden your search to a search of the institutional directory for the domain.');
1.160 raeburn 6686: }
6687: }
1.180 raeburn 6688: if ($srch->{'srchin'} eq 'crs') {
6689: $response .= '<br />'.&mt('You may want to broaden your search to the selected LON-CAPA domain.');
6690: }
6691: }
1.305 raeburn 6692: my $createdom = $env{'request.role.domain'};
6693: if ($context eq 'requestcrs') {
6694: if ($env{'form.coursedom'} ne '') {
6695: $createdom = $env{'form.coursedom'};
6696: }
6697: }
6698: if (!($srch->{'srchby'} eq 'uname' && $srch->{'srchin'} eq 'dom' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchdomain'} eq $createdom)) {
1.221 raeburn 6699: my $cancreate =
1.305 raeburn 6700: &Apache::lonuserutils::can_create_user($createdom,$context);
6701: my $targetdom = '<span class="LC_cusr_emph">'.$createdom.'</span>';
1.221 raeburn 6702: if ($cancreate) {
1.305 raeburn 6703: my $showdom = &display_domain_info($createdom);
1.266 bisitz 6704: $response .= '<br /><br />'
6705: .'<b>'.&mt('To add a new user:').'</b>'
1.305 raeburn 6706: .'<br />';
6707: if ($context eq 'requestcrs') {
6708: $response .= &mt("(You can only define new users in the new course's domain - [_1])",$targetdom);
6709: } else {
6710: $response .= &mt("(You can only create new users in your current role's domain - [_1])",$targetdom);
6711: }
6712: $response .='<ul><li>'
1.266 bisitz 6713: .&mt("Set 'Domain/institution to search' to: [_1]",'<span class="LC_cusr_emph">'.$showdom.'</span>')
6714: .'</li><li>'
6715: .&mt("Set 'Search criteria' to: [_1]username is ..... in selected LON-CAPA domain[_2]",'<span class="LC_cusr_emph">','</span>')
6716: .'</li><li>'
6717: .&mt('Provide the proposed username')
6718: .'</li><li>'
6719: .&mt("Click 'Search'")
6720: .'</li></ul><br />';
1.221 raeburn 6721: } else {
6722: my $helplink = ' href="javascript:helpMenu('."'display'".')"';
1.305 raeburn 6723: $response .= '<br /><br />';
6724: if ($context eq 'requestcrs') {
1.314 raeburn 6725: $response .= &mt("You are not authorized to define new users in the new course's domain - [_1].",$targetdom);
1.305 raeburn 6726: } else {
6727: $response .= &mt("You are not authorized to create new users in your current role's domain - [_1].",$targetdom);
6728: }
6729: $response .= '<br />'
6730: .&mt('Please contact the [_1]helpdesk[_2] if you need to create a new user.'
1.266 bisitz 6731: ,' <a'.$helplink.'>'
6732: ,'</a>')
1.305 raeburn 6733: .'<br /><br />';
1.221 raeburn 6734: }
1.160 raeburn 6735: }
6736: }
6737: }
1.179 raeburn 6738: return ($currstate,$response,$forcenewuser);
1.160 raeburn 6739: }
6740:
1.180 raeburn 6741: sub display_domain_info {
6742: my ($dom) = @_;
6743: my $output = $dom;
6744: if ($dom ne '') {
6745: my $domdesc = &Apache::lonnet::domain($dom,'description');
6746: if ($domdesc ne '') {
6747: $output .= ' <span class="LC_cusr_emph">('.$domdesc.')</span>';
6748: }
6749: }
6750: return $output;
6751: }
6752:
1.160 raeburn 6753: sub crumb_utilities {
6754: my %elements = (
6755: crtuser => {
6756: srchterm => 'text',
1.172 raeburn 6757: srchin => 'selectbox',
1.160 raeburn 6758: srchby => 'selectbox',
6759: srchtype => 'selectbox',
6760: srchdomain => 'selectbox',
6761: },
1.207 raeburn 6762: crtusername => {
6763: srchterm => 'text',
6764: srchdomain => 'selectbox',
6765: },
1.160 raeburn 6766: docustom => {
6767: rolename => 'selectbox',
6768: newrolename => 'textbox',
6769: },
1.179 raeburn 6770: studentform => {
6771: srchterm => 'text',
6772: srchin => 'selectbox',
6773: srchby => 'selectbox',
6774: srchtype => 'selectbox',
6775: srchdomain => 'selectbox',
6776: },
1.160 raeburn 6777: );
6778:
6779: my $jsback .= qq|
6780: function backPage(formname,prevphase,prevstate) {
1.211 raeburn 6781: if (typeof prevphase == 'undefined') {
6782: formname.phase.value = '';
6783: }
6784: else {
6785: formname.phase.value = prevphase;
6786: }
6787: if (typeof prevstate == 'undefined') {
6788: formname.currstate.value = '';
6789: }
6790: else {
6791: formname.currstate.value = prevstate;
6792: }
1.160 raeburn 6793: formname.submit();
6794: }
6795: |;
6796: return ($jsback,\%elements);
6797: }
6798:
1.26 matthew 6799: sub course_level_table {
1.375 raeburn 6800: my ($inccourses,$showcredits,$defaultcredits) = @_;
6801: return unless (ref($inccourses) eq 'HASH');
1.26 matthew 6802: my $table = '';
1.62 www 6803: # Custom Roles?
6804:
1.190 raeburn 6805: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.89 raeburn 6806: my %lt=&Apache::lonlocal::texthash(
6807: 'exs' => "Existing sections",
6808: 'new' => "Define new section",
6809: 'ssd' => "Set Start Date",
6810: 'sed' => "Set End Date",
1.131 raeburn 6811: 'crl' => "Course Level",
1.89 raeburn 6812: 'act' => "Activate",
6813: 'rol' => "Role",
6814: 'ext' => "Extent",
1.113 raeburn 6815: 'grs' => "Section",
1.375 raeburn 6816: 'crd' => "Credits",
1.89 raeburn 6817: 'sta' => "Start",
6818: 'end' => "End"
6819: );
1.62 www 6820:
1.375 raeburn 6821: foreach my $protectedcourse (sort(keys(%{$inccourses}))) {
1.135 raeburn 6822: my $thiscourse=$protectedcourse;
1.26 matthew 6823: $thiscourse=~s:_:/:g;
6824: my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
1.365 raeburn 6825: my $isowner = &Apache::lonuserutils::is_courseowner($protectedcourse,$coursedata{'internal.courseowner'});
1.26 matthew 6826: my $area=$coursedata{'description'};
1.321 raeburn 6827: my $crstype=$coursedata{'type'};
1.135 raeburn 6828: if (!defined($area)) { $area=&mt('Unavailable course').': '.$protectedcourse; }
1.89 raeburn 6829: my ($domain,$cnum)=split(/\//,$thiscourse);
1.115 albertel 6830: my %sections_count;
1.101 albertel 6831: if (defined($env{'request.course.id'})) {
6832: if ($env{'request.course.id'} eq $domain.'_'.$cnum) {
1.115 albertel 6833: %sections_count =
6834: &Apache::loncommon::get_sections($domain,$cnum);
1.92 raeburn 6835: }
6836: }
1.321 raeburn 6837: my @roles = &Apache::lonuserutils::roles_by_context('course','',$crstype);
1.213 raeburn 6838: foreach my $role (@roles) {
1.321 raeburn 6839: my $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.329 raeburn 6840: if ((&Apache::lonnet::allowed('c'.$role,$thiscourse)) ||
6841: ((($role eq 'cc') || ($role eq 'co')) && ($isowner))) {
1.221 raeburn 6842: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 6843: $plrole,\%sections_count,\%lt,
6844: $defaultcredits,$crstype);
1.221 raeburn 6845: } elsif ($env{'request.course.sec'} ne '') {
6846: if (&Apache::lonnet::allowed('c'.$role,$thiscourse.'/'.
6847: $env{'request.course.sec'})) {
6848: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 6849: $plrole,\%sections_count,\%lt,
6850: $defaultcredits,$crstype);
1.26 matthew 6851: }
6852: }
6853: }
1.221 raeburn 6854: if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
1.324 raeburn 6855: foreach my $cust (sort(keys(%customroles))) {
6856: next if ($crstype eq 'Community' && $customroles{$cust} =~ /bre\&S/);
1.221 raeburn 6857: my $role = 'cr_cr_'.$env{'user.domain'}.'_'.$env{'user.name'}.'_'.$cust;
6858: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
6859: $cust,\%sections_count,\%lt);
6860: }
1.62 www 6861: }
1.26 matthew 6862: }
6863: return '' if ($table eq ''); # return nothing if there is nothing
6864: # in the table
1.188 raeburn 6865: my $result;
6866: if (!$env{'request.course.id'}) {
6867: $result = '<h4>'.$lt{'crl'}.'</h4>'."\n";
6868: }
6869: $result .=
1.136 raeburn 6870: &Apache::loncommon::start_data_table().
6871: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 6872: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
6873: '<th>'.$lt{'ext'}.'</th><th>'.$lt{'crd'}.'</th>'."\n".
6874: '<th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th>'."\n".
6875: '<th>'.$lt{'end'}.'</th>'.
1.136 raeburn 6876: &Apache::loncommon::end_data_table_header_row().
6877: $table.
6878: &Apache::loncommon::end_data_table();
1.26 matthew 6879: return $result;
6880: }
1.88 raeburn 6881:
1.221 raeburn 6882: sub course_level_row {
1.375 raeburn 6883: my ($protectedcourse,$role,$area,$domain,$plrole,$sections_count,
6884: $lt,$defaultcredits,$crstype) = @_;
6885: my $creditem;
1.222 raeburn 6886: my $row = &Apache::loncommon::start_data_table_row().
6887: ' <td><input type="checkbox" name="act_'.
6888: $protectedcourse.'_'.$role.'" /></td>'."\n".
6889: ' <td>'.$plrole.'</td>'."\n".
6890: ' <td>'.$area.'<br />Domain: '.$domain.'</td>'."\n";
1.375 raeburn 6891: if (($role eq 'st') && ($crstype eq 'Course')) {
6892: $row .=
6893: '<td><input type="text" name="credits_'.$protectedcourse.'_'.
6894: $role.'" size="3" value="'.$defaultcredits.'" /></td>';
6895: } else {
6896: $row .= '<td> </td>';
6897: }
1.322 raeburn 6898: if (($role eq 'cc') || ($role eq 'co')) {
1.222 raeburn 6899: $row .= '<td> </td>';
1.221 raeburn 6900: } elsif ($env{'request.course.sec'} ne '') {
1.222 raeburn 6901: $row .= ' <td><input type="hidden" value="'.
6902: $env{'request.course.sec'}.'" '.
6903: 'name="sec_'.$protectedcourse.'_'.$role.'" />'.
6904: $env{'request.course.sec'}.'</td>';
1.221 raeburn 6905: } else {
6906: if (ref($sections_count) eq 'HASH') {
6907: my $currsec =
6908: &Apache::lonuserutils::course_sections($sections_count,
6909: $protectedcourse.'_'.$role);
1.222 raeburn 6910: $row .= '<td><table class="LC_createuser">'."\n".
6911: '<tr class="LC_section_row">'."\n".
6912: ' <td valign="top">'.$lt->{'exs'}.'<br />'.
6913: $currsec.'</td>'."\n".
6914: ' <td> </td>'."\n".
6915: ' <td valign="top"> '.$lt->{'new'}.'<br />'.
1.221 raeburn 6916: '<input type="text" name="newsec_'.$protectedcourse.'_'.$role.
6917: '" value="" />'.
6918: '<input type="hidden" '.
6919: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n".
1.222 raeburn 6920: '</tr></table></td>'."\n";
1.221 raeburn 6921: } else {
1.222 raeburn 6922: $row .= '<td><input type="text" size="10" '.
1.375 raeburn 6923: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n";
1.221 raeburn 6924: }
6925: }
1.222 raeburn 6926: $row .= <<ENDTIMEENTRY;
6927: <td><input type="hidden" name="start_$protectedcourse\_$role" value="" />
1.221 raeburn 6928: <a href=
6929: "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 6930: <td><input type="hidden" name="end_$protectedcourse\_$role" value="" />
1.221 raeburn 6931: <a href=
6932: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$role.value,'end_$protectedcourse\_$role','cu.pres','dateset')">$lt->{'sed'}</a></td>
6933: ENDTIMEENTRY
1.222 raeburn 6934: $row .= &Apache::loncommon::end_data_table_row();
6935: return $row;
1.221 raeburn 6936: }
6937:
1.88 raeburn 6938: sub course_level_dc {
1.375 raeburn 6939: my ($dcdom,$showcredits) = @_;
1.190 raeburn 6940: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.213 raeburn 6941: my @roles = &Apache::lonuserutils::roles_by_context('course');
1.88 raeburn 6942: my $hiddenitems = '<input type="hidden" name="dcdomain" value="'.$dcdom.'" />'.
6943: '<input type="hidden" name="origdom" value="'.$dcdom.'" />'.
1.133 raeburn 6944: '<input type="hidden" name="dccourse" value="" />';
1.355 www 6945: my $courseform=&Apache::loncommon::selectcourse_link
1.356 raeburn 6946: ('cu','dccourse','dcdomain','coursedesc',undef,undef,'Select','crstype');
1.375 raeburn 6947: my $credit_elem;
6948: if ($showcredits) {
6949: $credit_elem = 'credits';
6950: }
6951: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,'currsec','cu','role','Course/Community Browser',$credit_elem);
1.88 raeburn 6952: my %lt=&Apache::lonlocal::texthash(
6953: 'rol' => "Role",
1.113 raeburn 6954: 'grs' => "Section",
1.88 raeburn 6955: 'exs' => "Existing sections",
6956: 'new' => "Define new section",
6957: 'sta' => "Start",
6958: 'end' => "End",
6959: 'ssd' => "Set Start Date",
1.355 www 6960: 'sed' => "Set End Date",
1.375 raeburn 6961: 'scc' => "Course/Community",
6962: 'crd' => "Credits",
1.88 raeburn 6963: );
1.323 raeburn 6964: my $header = '<h4>'.&mt('Course/Community Level').'</h4>'.
1.136 raeburn 6965: &Apache::loncommon::start_data_table().
6966: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 6967: '<th>'.$lt{'scc'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
6968: '<th>'.$lt{'grs'}.'</th><th>'.$lt{'crd'}.'</th>'."\n".
6969: '<th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'."\n".
1.136 raeburn 6970: &Apache::loncommon::end_data_table_header_row();
1.143 raeburn 6971: my $otheritems = &Apache::loncommon::start_data_table_row()."\n".
1.356 raeburn 6972: '<td><br /><span class="LC_nobreak"><input type="text" name="coursedesc" value="" onfocus="this.blur();opencrsbrowser('."'cu','dccourse','dcdomain','coursedesc','','','','crstype'".')" />'.
6973: $courseform.(' ' x4).'</span></td>'."\n".
1.323 raeburn 6974: '<td valign><br /><select name="role">'."\n";
1.213 raeburn 6975: foreach my $role (@roles) {
1.135 raeburn 6976: my $plrole=&Apache::lonnet::plaintext($role);
6977: $otheritems .= ' <option value="'.$role.'">'.$plrole;
1.88 raeburn 6978: }
6979: if ( keys %customroles > 0) {
1.135 raeburn 6980: foreach my $cust (sort keys %customroles) {
1.101 albertel 6981: my $custrole='cr_cr_'.$env{'user.domain'}.
1.135 raeburn 6982: '_'.$env{'user.name'}.'_'.$cust;
6983: $otheritems .= ' <option value="'.$custrole.'">'.$cust;
1.88 raeburn 6984: }
6985: }
6986: $otheritems .= '</select></td><td>'.
6987: '<table border="0" cellspacing="0" cellpadding="0">'.
6988: '<tr><td valign="top"><b>'.$lt{'exs'}.'</b><br /><select name="currsec">'.
6989: ' <option value=""><--'.&mt('Pick course first').'</select></td>'.
6990: '<td> </td>'.
6991: '<td valign="top"> <b>'.$lt{'new'}.'</b><br />'.
1.113 raeburn 6992: '<input type="text" name="newsec" value="" />'.
1.237 raeburn 6993: '<input type="hidden" name="section" value="" />'.
1.323 raeburn 6994: '<input type="hidden" name="groups" value="" />'.
6995: '<input type="hidden" name="crstype" value="" /></td>'.
1.375 raeburn 6996: '</tr></table></td>'."\n";
6997: if ($showcredits) {
6998: $otheritems .= '<td><br />'."\n".
6999: '<input type="text" size="3" name="credits" value="" />'."\n";
7000: }
1.88 raeburn 7001: $otheritems .= <<ENDTIMEENTRY;
1.323 raeburn 7002: <td><br /><input type="hidden" name="start" value='' />
1.88 raeburn 7003: <a href=
7004: "javascript:pjump('date_start','Start Date',document.cu.start.value,'start','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.323 raeburn 7005: <td><br /><input type="hidden" name="end" value='' />
1.88 raeburn 7006: <a href=
7007: "javascript:pjump('date_end','End Date',document.cu.end.value,'end','cu.pres','dateset')">$lt{'sed'}</a></td>
7008: ENDTIMEENTRY
1.136 raeburn 7009: $otheritems .= &Apache::loncommon::end_data_table_row().
7010: &Apache::loncommon::end_data_table()."\n";
1.88 raeburn 7011: return $cb_jscript.$header.$hiddenitems.$otheritems;
7012: }
7013:
1.237 raeburn 7014: sub update_selfenroll_config {
1.241 raeburn 7015: my ($r,$context,$permission) = @_;
1.237 raeburn 7016: my ($row,$lt) = &get_selfenroll_titles();
1.241 raeburn 7017: my %curr_groups = &Apache::longroup::coursegroups();
1.237 raeburn 7018: my (%changes,%warning);
7019: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
7020: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.241 raeburn 7021: my $curr_types;
1.237 raeburn 7022: if (ref($row) eq 'ARRAY') {
7023: foreach my $item (@{$row}) {
7024: if ($item eq 'enroll_dates') {
7025: my (%currenrolldate,%newenrolldate);
7026: foreach my $type ('start','end') {
7027: $currenrolldate{$type} = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$type.'_date'};
7028: $newenrolldate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_date');
7029: if ($newenrolldate{$type} ne $currenrolldate{$type}) {
7030: $changes{'internal.selfenroll_'.$type.'_date'} = $newenrolldate{$type};
7031: }
7032: }
7033: } elsif ($item eq 'access_dates') {
7034: my (%currdate,%newdate);
7035: foreach my $type ('start','end') {
7036: $currdate{$type} = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$type.'_access'};
7037: $newdate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_access');
7038: if ($newdate{$type} ne $currdate{$type}) {
7039: $changes{'internal.selfenroll_'.$type.'_access'} = $newdate{$type};
7040: }
7041: }
1.241 raeburn 7042: } elsif ($item eq 'types') {
7043: $curr_types =
7044: $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$item};
7045: if ($env{'form.selfenroll_all'}) {
7046: if ($curr_types ne '*') {
7047: $changes{'internal.selfenroll_types'} = '*';
7048: } else {
7049: next;
7050: }
7051: } else {
1.249 raeburn 7052: my %currdoms;
1.241 raeburn 7053: my @entries = split(/;/,$curr_types);
7054: my @deletedoms = &Apache::loncommon::get_env_multiple('form.selfenroll_delete');
1.249 raeburn 7055: my @activations = &Apache::loncommon::get_env_multiple('form.selfenroll_activate');
1.241 raeburn 7056: my $newnum = 0;
1.249 raeburn 7057: my @latesttypes;
7058: foreach my $num (@activations) {
7059: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$num);
7060: if (@types > 0) {
1.241 raeburn 7061: @types = sort(@types);
7062: my $typestr = join(',',@types);
1.249 raeburn 7063: my $typedom = $env{'form.selfenroll_dom_'.$num};
7064: $latesttypes[$newnum] = $typedom.':'.$typestr;
7065: $currdoms{$typedom} = 1;
1.241 raeburn 7066: $newnum ++;
7067: }
7068: }
1.338 raeburn 7069: for (my $j=0; $j<$env{'form.selfenroll_types_total'}; $j++) {
7070: if ((!grep(/^$j$/,@deletedoms)) && (!grep(/^$j$/,@activations))) {
1.249 raeburn 7071: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$j);
7072: if (@types > 0) {
7073: @types = sort(@types);
7074: my $typestr = join(',',@types);
7075: my $typedom = $env{'form.selfenroll_dom_'.$j};
7076: $latesttypes[$newnum] = $typedom.':'.$typestr;
7077: $currdoms{$typedom} = 1;
7078: $newnum ++;
7079: }
7080: }
7081: }
7082: if ($env{'form.selfenroll_newdom'} ne '') {
7083: my $typedom = $env{'form.selfenroll_newdom'};
7084: if ((!defined($currdoms{$typedom})) &&
7085: (&Apache::lonnet::domain($typedom) ne '')) {
7086: my $typestr;
7087: my ($othertitle,$usertypes,$types) =
7088: &Apache::loncommon::sorted_inst_types($typedom);
7089: my $othervalue = 'any';
7090: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7091: if (@{$types} > 0) {
1.257 raeburn 7092: my @esc_types = map { &escape($_); } @{$types};
1.249 raeburn 7093: $othervalue = 'other';
1.258 raeburn 7094: $typestr = join(',',(@esc_types,$othervalue));
1.249 raeburn 7095: }
7096: $typestr = $othervalue;
7097: } else {
7098: $typestr = $othervalue;
7099: }
7100: $latesttypes[$newnum] = $typedom.':'.$typestr;
7101: $newnum ++ ;
7102: }
7103: }
1.241 raeburn 7104: my $selfenroll_types = join(';',@latesttypes);
7105: if ($selfenroll_types ne $curr_types) {
7106: $changes{'internal.selfenroll_types'} = $selfenroll_types;
7107: }
7108: }
1.276 raeburn 7109: } elsif ($item eq 'limit') {
7110: my $newlimit = $env{'form.selfenroll_limit'};
7111: my $newcap = $env{'form.selfenroll_cap'};
7112: $newcap =~s/\s+//g;
7113: my $currlimit = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_limit'};
7114: $currlimit = 'none' if ($currlimit eq '');
7115: my $currcap = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_cap'};
7116: if ($newlimit ne $currlimit) {
7117: if ($newlimit ne 'none') {
7118: if ($newcap =~ /^\d+$/) {
7119: if ($newcap ne $currcap) {
7120: $changes{'internal.selfenroll_cap'} = $newcap;
7121: }
7122: $changes{'internal.selfenroll_limit'} = $newlimit;
7123: } else {
7124: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.&mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
7125: }
7126: } elsif ($currcap ne '') {
7127: $changes{'internal.selfenroll_cap'} = '';
7128: $changes{'internal.selfenroll_limit'} = $newlimit;
7129: }
7130: } elsif ($currlimit ne 'none') {
7131: if ($newcap =~ /^\d+$/) {
7132: if ($newcap ne $currcap) {
7133: $changes{'internal.selfenroll_cap'} = $newcap;
7134: }
7135: } else {
7136: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.&mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
7137: }
7138: }
7139: } elsif ($item eq 'approval') {
7140: my (@currnotified,@newnotified);
7141: my $currapproval = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'};
7142: my $currnotifylist = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_notifylist'};
7143: if ($currnotifylist ne '') {
7144: @currnotified = split(/,/,$currnotifylist);
7145: @currnotified = sort(@currnotified);
7146: }
7147: my $newapproval = $env{'form.selfenroll_approval'};
7148: @newnotified = &Apache::loncommon::get_env_multiple('form.selfenroll_notify');
7149: @newnotified = sort(@newnotified);
7150: if ($newapproval ne $currapproval) {
7151: $changes{'internal.selfenroll_approval'} = $newapproval;
7152: if (!$newapproval) {
7153: if ($currnotifylist ne '') {
7154: $changes{'internal.selfenroll_notifylist'} = '';
7155: }
7156: } else {
7157: my @differences =
1.295 raeburn 7158: &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 7159: if (@differences > 0) {
7160: if (@newnotified > 0) {
7161: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
7162: } else {
7163: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
7164: }
7165: }
7166: }
7167: } else {
1.295 raeburn 7168: my @differences = &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 7169: if (@differences > 0) {
7170: if (@newnotified > 0) {
7171: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
7172: } else {
7173: $changes{'internal.selfenroll_notifylist'} = '';
7174: }
7175: }
7176: }
1.237 raeburn 7177: } else {
7178: my $curr_val =
7179: $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$item};
7180: my $newval = $env{'form.selfenroll_'.$item};
7181: if ($item eq 'section') {
7182: $newval = $env{'form.sections'};
1.241 raeburn 7183: if (defined($curr_groups{$newval})) {
1.237 raeburn 7184: $newval = $curr_val;
7185: $warning{$item} = &mt('Section for self-enrolled users unchanged as the proposed section is a group').'<br />'.&mt('Group names and section names must be distinct');
7186: } elsif ($newval eq 'all') {
7187: $newval = $curr_val;
1.274 bisitz 7188: $warning{$item} = &mt('Section for self-enrolled users unchanged, as "all" is a reserved section name.');
1.237 raeburn 7189: }
7190: if ($newval eq '') {
7191: $newval = 'none';
7192: }
7193: }
7194: if ($newval ne $curr_val) {
7195: $changes{'internal.selfenroll_'.$item} = $newval;
7196: }
1.241 raeburn 7197: }
1.237 raeburn 7198: }
7199: if (keys(%warning) > 0) {
7200: foreach my $item (@{$row}) {
7201: if (exists($warning{$item})) {
7202: $r->print($warning{$item}.'<br />');
7203: }
7204: }
7205: }
7206: if (keys(%changes) > 0) {
7207: my $putresult = &Apache::lonnet::put('environment',\%changes,$cdom,$cnum);
7208: if ($putresult eq 'ok') {
7209: if ((exists($changes{'internal.selfenroll_types'})) ||
7210: (exists($changes{'internal.selfenroll_start_date'})) ||
7211: (exists($changes{'internal.selfenroll_end_date'}))) {
7212: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',
7213: $cnum,undef,undef,'Course');
7214: my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
7215: if (ref($crsinfo{$env{'request.course.id'}}) eq 'HASH') {
7216: foreach my $item ('selfenroll_types','selfenroll_start_date','selfenroll_end_date') {
7217: if (exists($changes{'internal.'.$item})) {
7218: $crsinfo{$env{'request.course.id'}}{$item} =
7219: $changes{'internal.'.$item};
7220: }
7221: }
7222: my $crsputresult =
7223: &Apache::lonnet::courseidput($cdom,\%crsinfo,
7224: $chome,'notime');
7225: }
7226: }
7227: $r->print(&mt('The following changes were made to self-enrollment settings:').'<ul>');
7228: foreach my $item (@{$row}) {
7229: my $title = $item;
7230: if (ref($lt) eq 'HASH') {
7231: $title = $lt->{$item};
7232: }
7233: if ($item eq 'enroll_dates') {
7234: foreach my $type ('start','end') {
7235: if (exists($changes{'internal.selfenroll_'.$type.'_date'})) {
7236: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_date'});
1.244 bisitz 7237: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 7238: $title,$type,$newdate).'</li>');
7239: }
7240: }
7241: } elsif ($item eq 'access_dates') {
7242: foreach my $type ('start','end') {
7243: if (exists($changes{'internal.selfenroll_'.$type.'_access'})) {
7244: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_access'});
1.244 bisitz 7245: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 7246: $title,$type,$newdate).'</li>');
7247: }
7248: }
1.276 raeburn 7249: } elsif ($item eq 'limit') {
7250: if ((exists($changes{'internal.selfenroll_limit'})) ||
7251: (exists($changes{'internal.selfenroll_cap'}))) {
7252: my ($newval,$newcap);
7253: if ($changes{'internal.selfenroll_cap'} ne '') {
7254: $newcap = $changes{'internal.selfenroll_cap'}
7255: } else {
7256: $newcap = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_cap'};
7257: }
7258: if ($changes{'internal.selfenroll_limit'} eq 'none') {
7259: $newval = &mt('No limit');
7260: } elsif ($changes{'internal.selfenroll_limit'} eq
7261: 'allstudents') {
7262: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
7263: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
7264: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
7265: } else {
7266: my $currlimit = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_limit'};
7267: if ($currlimit eq 'allstudents') {
7268: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
7269: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
1.308 raeburn 7270: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
1.276 raeburn 7271: }
7272: }
7273: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
7274: }
7275: } elsif ($item eq 'approval') {
7276: if ((exists($changes{'internal.selfenroll_approval'})) ||
7277: (exists($changes{'internal.selfenroll_notifylist'}))) {
7278: my ($newval,$newnotify);
7279: if (exists($changes{'internal.selfenroll_notifylist'})) {
7280: $newnotify = $changes{'internal.selfenroll_notifylist'};
7281: } else {
7282: $newnotify = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_notifylist'};
7283: }
7284: if ($changes{'internal.selfenroll_approval'}) {
7285: $newval = &mt('Yes');
7286: } elsif ($changes{'internal.selfenroll_approval'} eq '0') {
7287: $newval = &mt('No');
7288: } else {
7289: my $currapproval =
7290: $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'};
7291: if ($currapproval) {
7292: $newval = &mt('Yes');
7293: } else {
7294: $newval = &mt('No');
7295: }
7296: }
7297: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval));
7298: if ($newnotify) {
1.277 raeburn 7299: $r->print('<br />'.&mt('The following will be notified when an enrollment request needs approval, or has been approved: [_1].',$newnotify));
1.276 raeburn 7300: } else {
1.277 raeburn 7301: $r->print('<br />'.&mt('No notifications sent when an enrollment request needs approval, or has been approved.'));
1.276 raeburn 7302: }
7303: $r->print('</li>'."\n");
7304: }
1.237 raeburn 7305: } else {
7306: if (exists($changes{'internal.selfenroll_'.$item})) {
1.241 raeburn 7307: my $newval = $changes{'internal.selfenroll_'.$item};
7308: if ($item eq 'types') {
7309: if ($newval eq '') {
7310: $newval = &mt('None');
7311: } elsif ($newval eq '*') {
7312: $newval = &mt('Any user in any domain');
7313: }
1.245 raeburn 7314: } elsif ($item eq 'registered') {
7315: if ($newval eq '1') {
7316: $newval = &mt('Yes');
7317: } elsif ($newval eq '0') {
7318: $newval = &mt('No');
7319: }
1.241 raeburn 7320: }
1.244 bisitz 7321: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
1.237 raeburn 7322: }
7323: }
7324: }
7325: $r->print('</ul>');
7326: my %newenvhash;
7327: foreach my $key (keys(%changes)) {
7328: $newenvhash{'course.'.$env{'request.course.id'}.'.'.$key} = $changes{$key};
7329: }
1.238 raeburn 7330: &Apache::lonnet::appenv(\%newenvhash);
1.237 raeburn 7331: } else {
7332: $r->print(&mt('An error occurred when saving changes to self-enrollment settings in this course.').'<br />'.&mt('The error was: [_1].',$putresult));
7333: }
7334: } else {
1.249 raeburn 7335: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.237 raeburn 7336: }
7337: } else {
1.249 raeburn 7338: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.241 raeburn 7339: }
1.256 raeburn 7340: my ($visible,$cansetvis,$vismsgs,$visactions) = &visible_in_cat($cdom,$cnum);
7341: if (ref($visactions) eq 'HASH') {
7342: if (!$visible) {
1.366 bisitz 7343: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
1.256 raeburn 7344: '<br />');
7345: if (ref($vismsgs) eq 'ARRAY') {
7346: $r->print('<br />'.$visactions->{'take'}.'<ul>');
7347: foreach my $item (@{$vismsgs}) {
7348: $r->print('<li>'.$visactions->{$item}.'</li>');
7349: }
7350: $r->print('</ul>');
7351: }
7352: $r->print($cansetvis);
7353: }
7354: }
1.237 raeburn 7355: return;
7356: }
7357:
7358: sub get_selfenroll_titles {
1.276 raeburn 7359: my @row = ('types','registered','enroll_dates','access_dates','section',
7360: 'approval','limit');
1.237 raeburn 7361: my %lt = &Apache::lonlocal::texthash (
7362: types => 'Users allowed to self-enroll in this course',
1.245 raeburn 7363: registered => 'Restrict self-enrollment to students officially registered for the course',
1.237 raeburn 7364: enroll_dates => 'Dates self-enrollment available',
1.256 raeburn 7365: access_dates => 'Course access dates assigned to self-enrolling users',
7366: section => 'Section assigned to self-enrolling users',
1.276 raeburn 7367: approval => 'Self-enrollment requests need approval?',
7368: limit => 'Enrollment limit',
1.237 raeburn 7369: );
7370: return (\@row,\%lt);
7371: }
7372:
1.27 matthew 7373: #---------------------------------------------- end functions for &phase_two
1.29 matthew 7374:
7375: #--------------------------------- functions for &phase_two and &phase_three
7376:
7377: #--------------------------end of functions for &phase_two and &phase_three
1.372 raeburn 7378:
1.1 www 7379: 1;
7380: __END__
1.2 www 7381:
7382:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>