Annotation of loncom/interface/loncreateuser.pm, revision 1.385
1.20 harris41 1: # The LearningOnline Network with CAPA
1.1 www 2: # Create a user
3: #
1.385 ! bisitz 4: # $Id: loncreateuser.pm,v 1.384 2013/12/24 19:15:10 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",
1.385 ! bisitz 171: author => "Disk space allocated to user's Authoring Space (if role assigned)",
1.378 raeburn 172: );
173: foreach my $name ('portfolio','author') {
174: my ($currquota,$quotatype,$inststatus,$defquota) =
175: &Apache::loncommon::get_user_quota($ccuname,$ccdomain,$name);
176: if ($longinsttype eq '') {
177: if ($inststatus ne '') {
178: if ($usertypes->{$inststatus} ne '') {
179: $longinsttype = $usertypes->{$inststatus};
180: }
181: }
182: }
183: my ($showquota,$custom_on,$custom_off,$defaultinfo);
184: $custom_on = ' ';
185: $custom_off = ' checked="checked" ';
186: if ($quotatype eq 'custom') {
187: $custom_on = $custom_off;
188: $custom_off = ' ';
189: $showquota = $currquota;
190: if ($longinsttype eq '') {
191: $defaultinfo = &mt('For this user, the default quota would be [_1]'
1.383 raeburn 192: .' MB.',$defquota);
1.378 raeburn 193: } else {
194: $defaultinfo = &mt("For this user, the default quota would be [_1]".
1.383 raeburn 195: " MB, as determined by the user's institutional".
1.378 raeburn 196: " affiliation ([_2]).",$defquota,$longinsttype);
197: }
198: } else {
199: if ($longinsttype eq '') {
200: $defaultinfo = &mt('For this user, the default quota is [_1]'
1.383 raeburn 201: .' MB.',$defquota);
1.378 raeburn 202: } else {
203: $defaultinfo = &mt("For this user, the default quota of [_1]".
1.383 raeburn 204: " MB, is determined by the user's institutional".
1.378 raeburn 205: " affiliation ([_2]).",$defquota,$longinsttype);
206: }
207: }
208:
209: if (&Apache::lonnet::allowed('mpq',$ccdomain)) {
210: $output .= '<tr class="LC_info_row">'."\n".
211: ' <td>'.$titles{$name}.'</td>'."\n".
212: ' </tr>'."\n".
213: &Apache::loncommon::start_data_table_row()."\n".
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.385 ! bisitz 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.384 raeburn 254: 'textbook' => 'Can request creation of textbook courses',
1.362 raeburn 255: 'requestauthor' => 'Can request author space',
1.275 raeburn 256: );
1.279 raeburn 257: if ($context eq 'requestcourses') {
1.275 raeburn 258: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
1.299 raeburn 259: 'requestcourses.official','requestcourses.unofficial',
1.384 raeburn 260: 'requestcourses.community','requestcourses.textbook');
261: @usertools = ('official','unofficial','community','textbook');
1.309 raeburn 262: @options =('norequest','approval','autolimit','validate');
1.306 raeburn 263: %validations = &Apache::lonnet::auto_courserequest_checks($ccdomain);
264: %reqtitles = &courserequest_titles();
265: %reqdisplay = &courserequest_display();
266: $colspan = ' colspan="2"';
1.332 raeburn 267: %domconfig =
268: &Apache::lonnet::get_dom('configuration',['requestcourses'],$ccdomain);
269: $isadv = &Apache::lonnet::is_advanced_user($ccuname,$ccdomain);
1.362 raeburn 270: } elsif ($context eq 'requestauthor') {
271: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
272: 'requestauthor');
273: @usertools = ('requestauthor');
274: @options =('norequest','approval','automatic');
275: %reqtitles = &requestauthor_titles();
276: %reqdisplay = &requestauthor_display();
277: $colspan = ' colspan="2"';
278: %domconfig =
279: &Apache::lonnet::get_dom('configuration',['requestauthor'],$ccdomain);
1.275 raeburn 280: } else {
281: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
1.361 raeburn 282: 'tools.aboutme','tools.portfolio','tools.blog',
283: 'tools.webdav');
284: @usertools = ('aboutme','blog','webdav','portfolio');
1.275 raeburn 285: }
286: foreach my $item (@usertools) {
1.306 raeburn 287: my ($custom_access,$curr_access,$cust_on,$cust_off,$tool_on,$tool_off,
288: $currdisp,$custdisp,$custradio);
1.275 raeburn 289: $cust_off = 'checked="checked" ';
290: $tool_on = 'checked="checked" ';
291: $curr_access =
292: &Apache::lonnet::usertools_access($ccuname,$ccdomain,$item,undef,
293: $context);
1.362 raeburn 294: if ($context eq 'requestauthor') {
295: if ($userenv{$context} ne '') {
296: $cust_on = ' checked="checked" ';
297: $cust_off = '';
298: }
299: } elsif ($userenv{$context.'.'.$item} ne '') {
1.306 raeburn 300: $cust_on = ' checked="checked" ';
301: $cust_off = '';
302: }
303: if ($context eq 'requestcourses') {
304: if ($userenv{$context.'.'.$item} eq '') {
1.314 raeburn 305: $custom_access = &mt('Currently from default setting.');
1.306 raeburn 306: } else {
307: $custom_access = &mt('Currently from custom setting.');
1.275 raeburn 308: }
1.362 raeburn 309: } elsif ($context eq 'requestauthor') {
310: if ($userenv{$context} eq '') {
311: $custom_access = &mt('Currently from default setting.');
312: } else {
313: $custom_access = &mt('Currently from custom setting.');
314: }
1.275 raeburn 315: } else {
1.306 raeburn 316: if ($userenv{$context.'.'.$item} eq '') {
1.314 raeburn 317: $custom_access =
1.306 raeburn 318: &mt('Availability determined currently from default setting.');
319: if (!$curr_access) {
320: $tool_off = 'checked="checked" ';
321: $tool_on = '';
322: }
323: } else {
1.314 raeburn 324: $custom_access =
1.306 raeburn 325: &mt('Availability determined currently from custom setting.');
326: if ($userenv{$context.'.'.$item} == 0) {
327: $tool_off = 'checked="checked" ';
328: $tool_on = '';
329: }
1.275 raeburn 330: }
331: }
332: $output .= ' <tr class="LC_info_row">'."\n".
1.306 raeburn 333: ' <td'.$colspan.'>'.$lt{$item}.'</td>'."\n".
1.275 raeburn 334: ' </tr>'."\n".
1.306 raeburn 335: &Apache::loncommon::start_data_table_row()."\n";
1.362 raeburn 336: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.306 raeburn 337: my ($curroption,$currlimit);
1.362 raeburn 338: my $envkey = $context.'.'.$item;
339: if ($context eq 'requestauthor') {
340: $envkey = $context;
341: }
342: if ($userenv{$envkey} ne '') {
343: $curroption = $userenv{$envkey};
1.332 raeburn 344: } else {
345: my (@inststatuses);
1.362 raeburn 346: if ($context eq 'requestcourses') {
347: $curroption =
348: &Apache::loncoursequeueadmin::get_processtype('course',$ccuname,$ccdomain,
349: $isadv,$ccdomain,$item,
350: \@inststatuses,\%domconfig);
351: } else {
352: $curroption =
353: &Apache::loncoursequeueadmin::get_processtype('requestauthor',$ccuname,$ccdomain,
354: $isadv,$ccdomain,undef,
355: \@inststatuses,\%domconfig);
356: }
1.332 raeburn 357: }
1.306 raeburn 358: if (!$curroption) {
359: $curroption = 'norequest';
360: }
361: if ($curroption =~ /^autolimit=(\d*)$/) {
362: $currlimit = $1;
1.314 raeburn 363: if ($currlimit eq '') {
364: $currdisp = &mt('Yes, automatic creation');
365: } else {
366: $currdisp = &mt('Yes, up to [quant,_1,request]/user',$currlimit);
367: }
1.306 raeburn 368: } else {
369: $currdisp = $reqdisplay{$curroption};
370: }
371: $custdisp = '<table>';
372: foreach my $option (@options) {
373: my $val = $option;
374: if ($option eq 'norequest') {
375: $val = 0;
376: }
377: if ($option eq 'validate') {
378: my $canvalidate = 0;
379: if (ref($validations{$item}) eq 'HASH') {
380: if ($validations{$item}{'_custom_'}) {
381: $canvalidate = 1;
382: }
383: }
384: next if (!$canvalidate);
385: }
386: my $checked = '';
387: if ($option eq $curroption) {
388: $checked = ' checked="checked"';
389: } elsif ($option eq 'autolimit') {
390: if ($curroption =~ /^autolimit/) {
391: $checked = ' checked="checked"';
392: }
393: }
1.362 raeburn 394: my $name = 'crsreq_'.$item;
395: if ($context eq 'requestauthor') {
396: $name = $item;
397: }
1.306 raeburn 398: $custdisp .= '<tr><td><span class="LC_nobreak"><label>'.
1.362 raeburn 399: '<input type="radio" name="'.$name.'" '.
400: 'value="'.$val.'"'.$checked.' />'.
1.306 raeburn 401: $reqtitles{$option}.'</label> ';
402: if ($option eq 'autolimit') {
1.362 raeburn 403: $custdisp .= '<input type="text" name="'.$name.
404: '_limit" size="1" '.
1.314 raeburn 405: 'value="'.$currlimit.'" /></span><br />'.
406: $reqtitles{'unlimited'};
1.362 raeburn 407: } else {
408: $custdisp .= '</span>';
409: }
410: $custdisp .= '</td></tr>';
1.306 raeburn 411: }
412: $custdisp .= '</table>';
413: $custradio = '</span></td><td>'.&mt('Custom setting').'<br />'.$custdisp;
414: } else {
415: $currdisp = ($curr_access?&mt('Yes'):&mt('No'));
1.362 raeburn 416: my $name = $context.'_'.$item;
417: if ($context eq 'requestauthor') {
418: $name = $context;
419: }
1.306 raeburn 420: $custdisp = '<span class="LC_nobreak"><label>'.
1.362 raeburn 421: '<input type="radio" name="'.$name.'"'.
1.361 raeburn 422: ' value="1" '.$tool_on.'/>'.&mt('On').'</label> <label>'.
1.362 raeburn 423: '<input type="radio" name="'.$name.'" value="0" '.
1.306 raeburn 424: $tool_off.'/>'.&mt('Off').'</label></span>';
425: $custradio = (' 'x2).'--'.$lt{'cusa'}.': '.$custdisp.
426: '</span>';
427: }
428: $output .= ' <td'.$colspan.'>'.$custom_access.(' 'x4).
429: $lt{'avai'}.': '.$currdisp.'</td>'."\n".
1.275 raeburn 430: &Apache::loncommon::end_data_table_row()."\n".
431: &Apache::loncommon::start_data_table_row()."\n".
1.306 raeburn 432: ' <td style="vertical-align:top;"><span class="LC_nobreak">'.
433: $lt{'chse'}.': <label>'.
1.275 raeburn 434: '<input type="radio" name="custom'.$item.'" value="0" '.
1.306 raeburn 435: $cust_off.'/>'.$lt{'usde'}.'</label>'.(' ' x3).
436: '<label><input type="radio" name="custom'.$item.'" value="1" '.
437: $cust_on.'/>'.$lt{'uscu'}.'</label>'.$custradio.'</td>'.
1.275 raeburn 438: &Apache::loncommon::end_data_table_row()."\n";
439: }
440: return $output;
441: }
442:
1.300 raeburn 443: sub coursereq_externaluser {
444: my ($ccuname,$ccdomain,$cdom) = @_;
1.306 raeburn 445: my (@usertools,@options,%validations,%userenv,$output);
1.300 raeburn 446: my %lt = &Apache::lonlocal::texthash (
447: 'official' => 'Can request creation of official courses',
448: 'unofficial' => 'Can request creation of unofficial courses',
449: 'community' => 'Can request creation of communities',
1.384 raeburn 450: 'textbook' => 'Can request creation of textbook courses',
1.300 raeburn 451: );
452:
453: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
454: 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
1.384 raeburn 455: 'reqcrsotherdom.community','reqcrsotherdom.textbook');
456: @usertools = ('official','unofficial','community','textbook');
1.309 raeburn 457: @options = ('approval','validate','autolimit');
1.306 raeburn 458: %validations = &Apache::lonnet::auto_courserequest_checks($cdom);
459: my $optregex = join('|',@options);
460: my %reqtitles = &courserequest_titles();
1.300 raeburn 461: foreach my $item (@usertools) {
1.306 raeburn 462: my ($curroption,$currlimit,$tooloff);
1.300 raeburn 463: if ($userenv{'reqcrsotherdom.'.$item} ne '') {
464: my @curr = split(',',$userenv{'reqcrsotherdom.'.$item});
1.314 raeburn 465: foreach my $req (@curr) {
466: if ($req =~ /^\Q$cdom\E\:($optregex)=?(\d*)$/) {
467: $curroption = $1;
468: $currlimit = $2;
469: last;
1.306 raeburn 470: }
471: }
1.314 raeburn 472: if (!$curroption) {
473: $curroption = 'norequest';
474: $tooloff = ' checked="checked"';
475: }
1.306 raeburn 476: } else {
477: $curroption = 'norequest';
478: $tooloff = ' checked="checked"';
479: }
480: $output.= &Apache::loncommon::start_data_table_row()."\n".
1.314 raeburn 481: ' <td><span class="LC_nobreak">'.$lt{$item}.': </span></td><td>'.
482: '<table><tr><td valign="top">'."\n".
1.306 raeburn 483: '<label><input type="radio" name="reqcrsotherdom_'.$item.
1.314 raeburn 484: '" value=""'.$tooloff.' />'.$reqtitles{'norequest'}.
485: '</label></td>';
1.306 raeburn 486: foreach my $option (@options) {
487: if ($option eq 'validate') {
488: my $canvalidate = 0;
489: if (ref($validations{$item}) eq 'HASH') {
490: if ($validations{$item}{'_external_'}) {
491: $canvalidate = 1;
492: }
493: }
494: next if (!$canvalidate);
495: }
496: my $checked = '';
497: if ($option eq $curroption) {
498: $checked = ' checked="checked"';
499: }
1.314 raeburn 500: $output .= '<td valign="top"><span class="LC_nobreak"><label>'.
1.306 raeburn 501: '<input type="radio" name="reqcrsotherdom_'.$item.
502: '" value="'.$option.'"'.$checked.' />'.
1.314 raeburn 503: $reqtitles{$option}.'</label>';
1.306 raeburn 504: if ($option eq 'autolimit') {
1.314 raeburn 505: $output .= ' <input type="text" name="reqcrsotherdom_'.
1.306 raeburn 506: $item.'_limit" size="1" '.
1.314 raeburn 507: 'value="'.$currlimit.'" /></span>'.
508: '<br />'.$reqtitles{'unlimited'};
509: } else {
510: $output .= '</span>';
1.300 raeburn 511: }
1.314 raeburn 512: $output .= '</td>';
1.300 raeburn 513: }
1.314 raeburn 514: $output .= '</td></tr></table></td>'."\n".
1.300 raeburn 515: &Apache::loncommon::end_data_table_row()."\n";
516: }
517: return $output;
518: }
519:
1.362 raeburn 520: sub domainrole_req {
521: my ($ccuname,$ccdomain) = @_;
522: return '<br /><h3>'.
523: &mt('User Can Request Assignment of Domain Roles?').
524: '</h3>'."\n".
525: &Apache::loncommon::start_data_table().
526: &build_tools_display($ccuname,$ccdomain,
527: 'requestauthor').
528: &Apache::loncommon::end_data_table();
529: }
530:
1.306 raeburn 531: sub courserequest_titles {
532: my %titles = &Apache::lonlocal::texthash (
533: official => 'Official',
534: unofficial => 'Unofficial',
535: community => 'Communities',
1.384 raeburn 536: textbook => 'Textbook',
1.306 raeburn 537: norequest => 'Not allowed',
1.309 raeburn 538: approval => 'Approval by Dom. Coord.',
1.306 raeburn 539: validate => 'With validation',
540: autolimit => 'Numerical limit',
1.314 raeburn 541: unlimited => '(blank for unlimited)',
1.306 raeburn 542: );
543: return %titles;
544: }
545:
546: sub courserequest_display {
547: my %titles = &Apache::lonlocal::texthash (
1.309 raeburn 548: approval => 'Yes, need approval',
1.306 raeburn 549: validate => 'Yes, with validation',
550: norequest => 'No',
551: );
552: return %titles;
553: }
554:
1.362 raeburn 555: sub requestauthor_titles {
556: my %titles = &Apache::lonlocal::texthash (
557: norequest => 'Not allowed',
558: approval => 'Approval by Dom. Coord.',
559: automatic => 'Automatic approval',
560: );
561: return %titles;
562:
563: }
564:
565: sub requestauthor_display {
566: my %titles = &Apache::lonlocal::texthash (
567: approval => 'Yes, need approval',
568: automatic => 'Yes, automatic approval',
569: norequest => 'No',
570: );
571: return %titles;
572: }
573:
1.383 raeburn 574: sub requestchange_display {
575: my %titles = &Apache::lonlocal::texthash (
576: approval => "availability set to 'on' (approval required)",
577: automatic => "availability set to 'on' (automatic approval)",
578: norequest => "availability set to 'off'",
579: );
580: return %titles;
581: }
582:
1.362 raeburn 583: sub curr_requestauthor {
584: my ($uname,$udom,$isadv,$inststatuses,$domconfig) = @_;
585: return unless ((ref($inststatuses) eq 'ARRAY') && (ref($domconfig) eq 'HASH'));
586: if ($uname eq '' || $udom eq '') {
587: $uname = $env{'user.name'};
588: $udom = $env{'user.domain'};
589: $isadv = $env{'user.adv'};
590: }
591: my (%userenv,%settings,$val);
592: my @options = ('automatic','approval');
593: %userenv =
594: &Apache::lonnet::userenvironment($udom,$uname,'requestauthor','inststatus');
595: if ($userenv{'requestauthor'}) {
596: $val = $userenv{'requestauthor'};
597: @{$inststatuses} = ('_custom_');
598: } else {
599: my %alltasks;
600: if (ref($domconfig->{'requestauthor'}) eq 'HASH') {
601: %settings = %{$domconfig->{'requestauthor'}};
602: if (($isadv) && ($settings{'_LC_adv'} ne '')) {
603: $val = $settings{'_LC_adv'};
604: @{$inststatuses} = ('_LC_adv_');
605: } else {
606: if ($userenv{'inststatus'} ne '') {
607: @{$inststatuses} = split(',',$userenv{'inststatus'});
608: } else {
609: @{$inststatuses} = ('default');
610: }
611: foreach my $status (@{$inststatuses}) {
612: if (exists($settings{$status})) {
613: my $value = $settings{$status};
614: next unless ($value);
615: unless (exists($alltasks{$value})) {
616: if (ref($alltasks{$value}) eq 'ARRAY') {
617: unless(grep(/^\Q$status\E$/,@{$alltasks{$value}})) {
618: push(@{$alltasks{$value}},$status);
619: }
620: } else {
621: @{$alltasks{$value}} = ($status);
622: }
623: }
624: }
625: }
626: foreach my $option (@options) {
627: if ($alltasks{$option}) {
628: $val = $option;
629: last;
630: }
631: }
632: }
633: }
634: }
635: return $val;
636: }
637:
1.2 www 638: # =================================================================== Phase one
1.1 www 639:
1.42 matthew 640: sub print_username_entry_form {
1.351 raeburn 641: my ($r,$context,$response,$srch,$forcenewuser,$crstype,$brcrum) = @_;
1.101 albertel 642: my $defdom=$env{'request.role.domain'};
1.160 raeburn 643: my $formtoset = 'crtuser';
644: if (exists($env{'form.startrolename'})) {
645: $formtoset = 'docustom';
646: $env{'form.rolename'} = $env{'form.startrolename'};
1.207 raeburn 647: } elsif ($env{'form.origform'} eq 'crtusername') {
648: $formtoset = $env{'form.origform'};
1.160 raeburn 649: }
650:
651: my ($jsback,$elements) = &crumb_utilities();
652:
653: my $jscript = &Apache::loncommon::studentbrowser_javascript()."\n".
1.165 albertel 654: '<script type="text/javascript">'."\n".
1.301 bisitz 655: '// <![CDATA['."\n".
656: &Apache::lonhtmlcommon::set_form_elements($elements->{$formtoset})."\n".
657: '// ]]>'."\n".
1.162 raeburn 658: '</script>'."\n";
1.160 raeburn 659:
1.324 raeburn 660: my %existingroles=&Apache::lonuserutils::my_custom_roles($crstype);
661: if (($env{'form.action'} eq 'custom') && (keys(%existingroles) > 0)
662: && (&Apache::lonnet::allowed('mcr','/'))) {
663: $jscript .= &customrole_javascript();
664: }
1.224 raeburn 665: my $helpitem = 'Course_Change_Privileges';
666: if ($env{'form.action'} eq 'custom') {
667: $helpitem = 'Course_Editing_Custom_Roles';
668: } elsif ($env{'form.action'} eq 'singlestudent') {
669: $helpitem = 'Course_Add_Student';
670: }
1.351 raeburn 671: my %breadcrumb_text = &singleuser_breadcrumb($crstype);
672: if ($env{'form.action'} eq 'custom') {
673: push(@{$brcrum},
674: {href=>"javascript:backPage(document.crtuser)",
675: text=>"Pick custom role",
676: help => $helpitem,}
677: );
678: } else {
679: push (@{$brcrum},
680: {href => "javascript:backPage(document.crtuser)",
681: text => $breadcrumb_text{'search'},
682: help => $helpitem,
683: faq => 282,
684: bug => 'Instructor Interface',}
685: );
686: }
687: my %loaditems = (
688: 'onload' => "javascript:setFormElements(document.$formtoset)",
689: );
690: my $args = {bread_crumbs => $brcrum,
691: bread_crumbs_component => 'User Management',
692: add_entries => \%loaditems,};
693: $r->print(&Apache::loncommon::start_page('User Management',$jscript,$args));
694:
1.71 sakharuk 695: my %lt=&Apache::lonlocal::texthash(
1.229 raeburn 696: 'srst' => 'Search for a user and enroll as a student',
1.318 raeburn 697: 'srme' => 'Search for a user and enroll as a member',
1.229 raeburn 698: 'srad' => 'Search for a user and modify/add user information or roles',
1.71 sakharuk 699: 'usr' => "Username",
700: 'dom' => "Domain",
1.324 raeburn 701: 'ecrp' => "Define or Edit Custom Role",
702: 'nr' => "role name",
1.282 schafran 703: 'cre' => "Next",
1.71 sakharuk 704: );
1.351 raeburn 705:
1.214 raeburn 706: if ($env{'form.action'} eq 'custom') {
1.190 raeburn 707: if (&Apache::lonnet::allowed('mcr','/')) {
1.324 raeburn 708: my $newroletext = &mt('Define new custom role:');
709: $r->print('<form action="/adm/createuser" method="post" name="docustom">'.
710: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
711: '<input type="hidden" name="phase" value="selected_custom_edit" />'.
712: '<h3>'.$lt{'ecrp'}.'</h3>'.
713: &Apache::loncommon::start_data_table().
714: &Apache::loncommon::start_data_table_row().
715: '<td>');
716: if (keys(%existingroles) > 0) {
717: $r->print('<br /><label><input type="radio" name="customroleaction" value="new" checked="checked" onclick="setCustomFields();" /><b>'.$newroletext.'</b></label>');
718: } else {
719: $r->print('<br /><input type="hidden" name="customroleaction" value="new" /><b>'.$newroletext.'</b>');
720: }
721: $r->print('</td><td align="center">'.$lt{'nr'}.'<br /><input type="text" size="15" name="newrolename" onfocus="setCustomAction('."'new'".');" /></td>'.
722: &Apache::loncommon::end_data_table_row());
723: if (keys(%existingroles) > 0) {
724: $r->print(&Apache::loncommon::start_data_table_row().'<td><br />'.
725: '<label><input type="radio" name="customroleaction" value="edit" onclick="setCustomFields();"/><b>'.
726: &mt('View/Modify existing role:').'</b></label></td>'.
727: '<td align="center"><br />'.
728: '<select name="rolename" onchange="setCustomAction('."'edit'".');">'.
1.326 raeburn 729: '<option value="" selected="selected">'.
1.324 raeburn 730: &mt('Select'));
731: foreach my $role (sort(keys(%existingroles))) {
1.326 raeburn 732: $r->print('<option value="'.$role.'">'.$role.'</option>');
1.324 raeburn 733: }
734: $r->print('</select>'.
735: '</td>'.
736: &Apache::loncommon::end_data_table_row());
737: }
738: $r->print(&Apache::loncommon::end_data_table().'<p>'.
739: '<input name="customeditor" type="submit" value="'.
740: $lt{'cre'}.'" /></p>'.
741: '</form>');
1.190 raeburn 742: }
1.213 raeburn 743: } else {
1.229 raeburn 744: my $actiontext = $lt{'srad'};
1.213 raeburn 745: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 746: if ($crstype eq 'Community') {
747: $actiontext = $lt{'srme'};
748: } else {
749: $actiontext = $lt{'srst'};
750: }
1.213 raeburn 751: }
1.324 raeburn 752: $r->print("<h3>$actiontext</h3>");
1.213 raeburn 753: if ($env{'form.origform'} ne 'crtusername') {
754: $r->print("\n".$response);
755: }
1.318 raeburn 756: $r->print(&entry_form($defdom,$srch,$forcenewuser,$context,$response,$crstype));
1.107 www 757: }
1.110 albertel 758: }
759:
1.324 raeburn 760: sub customrole_javascript {
761: my $js = <<"END";
762: <script type="text/javascript">
763: // <![CDATA[
764:
765: function setCustomFields() {
766: if (document.docustom.customroleaction.length > 0) {
767: for (var i=0; i<document.docustom.customroleaction.length; i++) {
768: if (document.docustom.customroleaction[i].checked) {
769: if (document.docustom.customroleaction[i].value == 'new') {
770: document.docustom.rolename.selectedIndex = 0;
771: } else {
772: document.docustom.newrolename.value = '';
773: }
774: }
775: }
776: }
777: return;
778: }
779:
780: function setCustomAction(caller) {
781: if (document.docustom.customroleaction.length > 0) {
782: for (var i=0; i<document.docustom.customroleaction.length; i++) {
783: if (document.docustom.customroleaction[i].value == caller) {
784: document.docustom.customroleaction[i].checked = true;
785: }
786: }
787: }
788: setCustomFields();
789: return;
790: }
791:
792: // ]]>
793: </script>
794: END
795: return $js;
796: }
797:
1.160 raeburn 798: sub entry_form {
1.318 raeburn 799: my ($dom,$srch,$forcenewuser,$context,$responsemsg,$crstype) = @_;
1.229 raeburn 800: my ($usertype,$inexact);
1.214 raeburn 801: if (ref($srch) eq 'HASH') {
802: if (($srch->{'srchin'} eq 'dom') &&
803: ($srch->{'srchby'} eq 'uname') &&
804: ($srch->{'srchtype'} eq 'exact') &&
805: ($srch->{'srchdomain'} ne '') &&
806: ($srch->{'srchterm'} ne '')) {
1.353 raeburn 807: my (%curr_rules,%got_rules);
1.214 raeburn 808: my ($rules,$ruleorder) =
809: &Apache::lonnet::inst_userrules($srch->{'srchdomain'},'username');
1.353 raeburn 810: $usertype = &Apache::lonuserutils::check_usertype($srch->{'srchdomain'},$srch->{'srchterm'},$rules,\%curr_rules,\%got_rules);
1.229 raeburn 811: } else {
812: $inexact = 1;
1.214 raeburn 813: }
1.207 raeburn 814: }
1.214 raeburn 815: my $cancreate =
816: &Apache::lonuserutils::can_create_user($dom,$context,$usertype);
1.160 raeburn 817: my $userpicker =
1.179 raeburn 818: &Apache::loncommon::user_picker($dom,$srch,$forcenewuser,
1.214 raeburn 819: 'document.crtuser',$cancreate,$usertype);
1.160 raeburn 820: my $srchbutton = &mt('Search');
1.229 raeburn 821: if ($env{'form.action'} eq 'singlestudent') {
822: $srchbutton = &mt('Search and Enroll');
823: } elsif ($cancreate && $responsemsg ne '' && $inexact) {
824: $srchbutton = &mt('Search or Add New User');
825: }
1.207 raeburn 826: my $output = <<"ENDBLOCK";
1.160 raeburn 827: <form action="/adm/createuser" method="post" name="crtuser">
1.190 raeburn 828: <input type="hidden" name="action" value="$env{'form.action'}" />
1.160 raeburn 829: <input type="hidden" name="phase" value="get_user_info" />
830: $userpicker
1.179 raeburn 831: <input name="userrole" type="button" value="$srchbutton" onclick="javascript:validateEntry(document.crtuser)" />
1.160 raeburn 832: </form>
1.207 raeburn 833: ENDBLOCK
1.229 raeburn 834: if ($env{'form.phase'} eq '') {
1.207 raeburn 835: my $defdom=$env{'request.role.domain'};
836: my $domform = &Apache::loncommon::select_dom_form($defdom,'srchdomain');
837: my %lt=&Apache::lonlocal::texthash(
1.229 raeburn 838: 'enro' => 'Enroll one student',
1.318 raeburn 839: 'enrm' => 'Enroll one member',
1.229 raeburn 840: 'admo' => 'Add/modify a single user',
841: 'crea' => 'create new user if required',
842: 'uskn' => "username is known",
1.207 raeburn 843: 'crnu' => 'Create a new user',
844: 'usr' => 'Username',
845: 'dom' => 'in domain',
1.229 raeburn 846: 'enrl' => 'Enroll',
847: 'cram' => 'Create/Modify user',
1.207 raeburn 848: );
1.229 raeburn 849: my $sellink=&Apache::loncommon::selectstudent_link('crtusername','srchterm','srchdomain');
850: my ($title,$buttontext,$showresponse);
1.318 raeburn 851: if ($env{'form.action'} eq 'singlestudent') {
852: if ($crstype eq 'Community') {
853: $title = $lt{'enrm'};
854: } else {
855: $title = $lt{'enro'};
856: }
1.229 raeburn 857: $buttontext = $lt{'enrl'};
858: } else {
859: $title = $lt{'admo'};
860: $buttontext = $lt{'cram'};
861: }
862: if ($cancreate) {
863: $title .= ' <span class="LC_cusr_subheading">('.$lt{'crea'}.')</span>';
864: } else {
865: $title .= ' <span class="LC_cusr_subheading">('.$lt{'uskn'}.')</span>';
866: }
867: if ($env{'form.origform'} eq 'crtusername') {
868: $showresponse = $responsemsg;
869: }
1.207 raeburn 870: $output .= <<"ENDDOCUMENT";
1.229 raeburn 871: <br />
1.207 raeburn 872: <form action="/adm/createuser" method="post" name="crtusername">
873: <input type="hidden" name="action" value="$env{'form.action'}" />
874: <input type="hidden" name="phase" value="createnewuser" />
875: <input type="hidden" name="srchtype" value="exact" />
1.233 raeburn 876: <input type="hidden" name="srchby" value="uname" />
1.207 raeburn 877: <input type="hidden" name="srchin" value="dom" />
878: <input type="hidden" name="forcenewuser" value="1" />
879: <input type="hidden" name="origform" value="crtusername" />
1.229 raeburn 880: <h3>$title</h3>
881: $showresponse
1.207 raeburn 882: <table>
883: <tr>
884: <td>$lt{'usr'}:</td>
885: <td><input type="text" size="15" name="srchterm" /></td>
886: <td> $lt{'dom'}:</td><td>$domform</td>
1.229 raeburn 887: <td> $sellink </td>
888: <td> <input name="userrole" type="submit" value="$buttontext" /></td>
1.207 raeburn 889: </tr>
890: </table>
891: </form>
1.160 raeburn 892: ENDDOCUMENT
1.207 raeburn 893: }
1.160 raeburn 894: return $output;
895: }
1.110 albertel 896:
897: sub user_modification_js {
1.113 raeburn 898: my ($pjump_def,$dc_setcourse_code,$nondc_setsection_code,$groupslist)=@_;
899:
1.110 albertel 900: return <<END;
901: <script type="text/javascript" language="Javascript">
1.301 bisitz 902: // <![CDATA[
1.314 raeburn 903:
1.110 albertel 904: $pjump_def
905: $dc_setcourse_code
906:
907: function dateset() {
908: eval("document.cu."+document.cu.pres_marker.value+
909: ".value=document.cu.pres_value.value");
1.359 www 910: modalWindow.close();
1.110 albertel 911: }
912:
1.113 raeburn 913: $nondc_setsection_code
1.301 bisitz 914: // ]]>
1.110 albertel 915: </script>
916: END
1.2 www 917: }
918:
919: # =================================================================== Phase two
1.160 raeburn 920: sub print_user_selection_page {
1.351 raeburn 921: my ($r,$response,$srch,$srch_results,$srcharray,$context,$opener_elements,$crstype,$brcrum) = @_;
1.160 raeburn 922: my @fields = ('username','domain','lastname','firstname','permanentemail');
923: my $sortby = $env{'form.sortby'};
924:
925: if (!grep(/^\Q$sortby\E$/,@fields)) {
926: $sortby = 'lastname';
927: }
928:
929: my ($jsback,$elements) = &crumb_utilities();
930:
931: my $jscript = (<<ENDSCRIPT);
932: <script type="text/javascript">
1.301 bisitz 933: // <![CDATA[
1.160 raeburn 934: function pickuser(uname,udom) {
935: document.usersrchform.seluname.value=uname;
936: document.usersrchform.seludom.value=udom;
937: document.usersrchform.phase.value="userpicked";
938: document.usersrchform.submit();
939: }
940:
941: $jsback
1.301 bisitz 942: // ]]>
1.160 raeburn 943: </script>
944: ENDSCRIPT
945:
946: my %lt=&Apache::lonlocal::texthash(
1.179 raeburn 947: 'usrch' => "User Search to add/modify roles",
948: 'stusrch' => "User Search to enroll student",
1.318 raeburn 949: 'memsrch' => "User Search to enroll member",
1.179 raeburn 950: 'usel' => "Select a user to add/modify roles",
1.318 raeburn 951: 'stusel' => "Select a user to enroll as a student",
952: 'memsel' => "Select a user to enroll as a member",
1.160 raeburn 953: 'username' => "username",
954: 'domain' => "domain",
955: 'lastname' => "last name",
956: 'firstname' => "first name",
957: 'permanentemail' => "permanent e-mail",
958: );
1.302 raeburn 959: if ($context eq 'requestcrs') {
960: $r->print('<div>');
961: } else {
1.318 raeburn 962: my %breadcrumb_text = &singleuser_breadcrumb($crstype);
1.351 raeburn 963: my $helpitem;
964: if ($env{'form.action'} eq 'singleuser') {
965: $helpitem = 'Course_Change_Privileges';
966: } elsif ($env{'form.action'} eq 'singlestudent') {
967: $helpitem = 'Course_Add_Student';
968: }
969: push (@{$brcrum},
970: {href => "javascript:backPage(document.usersrchform,'','')",
971: text => $breadcrumb_text{'search'},
972: faq => 282,
973: bug => 'Instructor Interface',},
974: {href => "javascript:backPage(document.usersrchform,'get_user_info','select')",
975: text => $breadcrumb_text{'userpicked'},
976: faq => 282,
977: bug => 'Instructor Interface',
978: help => $helpitem}
979: );
980: $r->print(&Apache::loncommon::start_page('User Management',$jscript,{bread_crumbs => $brcrum}));
1.302 raeburn 981: if ($env{'form.action'} eq 'singleuser') {
982: $r->print("<b>$lt{'usrch'}</b><br />");
1.318 raeburn 983: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,$crstype));
1.302 raeburn 984: $r->print('<h3>'.$lt{'usel'}.'</h3>');
985: } elsif ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 986: $r->print($jscript."<b>");
987: if ($crstype eq 'Community') {
988: $r->print($lt{'memsrch'});
989: } else {
990: $r->print($lt{'stusrch'});
991: }
992: $r->print("</b><br />");
993: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,$crstype));
994: $r->print('</form><h3>');
995: if ($crstype eq 'Community') {
996: $r->print($lt{'memsel'});
997: } else {
998: $r->print($lt{'stusel'});
999: }
1000: $r->print('</h3>');
1.302 raeburn 1001: }
1.179 raeburn 1002: }
1.380 bisitz 1003: $r->print('<form name="usersrchform" method="post" action="">'.
1.160 raeburn 1004: &Apache::loncommon::start_data_table()."\n".
1005: &Apache::loncommon::start_data_table_header_row()."\n".
1006: ' <th> </th>'."\n");
1007: foreach my $field (@fields) {
1008: $r->print(' <th><a href="javascript:document.usersrchform.sortby.value='.
1009: "'".$field."'".';document.usersrchform.submit();">'.
1010: $lt{$field}.'</a></th>'."\n");
1011: }
1012: $r->print(&Apache::loncommon::end_data_table_header_row());
1013:
1014: my @sorted_users = sort {
1.167 albertel 1015: lc($srch_results->{$a}->{$sortby}) cmp lc($srch_results->{$b}->{$sortby})
1.160 raeburn 1016: ||
1.167 albertel 1017: lc($srch_results->{$a}->{lastname}) cmp lc($srch_results->{$b}->{lastname})
1.160 raeburn 1018: ||
1019: lc($srch_results->{$a}->{firstname}) cmp lc($srch_results->{$b}->{firstname})
1.167 albertel 1020: ||
1021: lc($a) cmp lc($b)
1.160 raeburn 1022: } (keys(%$srch_results));
1023:
1024: foreach my $user (@sorted_users) {
1025: my ($uname,$udom) = split(/:/,$user);
1.302 raeburn 1026: my $onclick;
1027: if ($context eq 'requestcrs') {
1.314 raeburn 1028: $onclick =
1.302 raeburn 1029: 'onclick="javascript:gochoose('."'$uname','$udom',".
1030: "'$srch_results->{$user}->{firstname}',".
1031: "'$srch_results->{$user}->{lastname}',".
1032: "'$srch_results->{$user}->{permanentemail}'".');"';
1033: } else {
1.314 raeburn 1034: $onclick =
1.302 raeburn 1035: ' onclick="javascript:pickuser('."'".$uname."'".','."'".$udom."'".');"';
1036: }
1.160 raeburn 1037: $r->print(&Apache::loncommon::start_data_table_row().
1.302 raeburn 1038: '<td><input type="button" name="seluser" value="'.&mt('Select').'" '.
1039: $onclick.' /></td>'.
1.160 raeburn 1040: '<td><tt>'.$uname.'</tt></td>'.
1041: '<td><tt>'.$udom.'</tt></td>');
1042: foreach my $field ('lastname','firstname','permanentemail') {
1043: $r->print('<td>'.$srch_results->{$user}->{$field}.'</td>');
1044: }
1045: $r->print(&Apache::loncommon::end_data_table_row());
1046: }
1047: $r->print(&Apache::loncommon::end_data_table().'<br /><br />');
1.179 raeburn 1048: if (ref($srcharray) eq 'ARRAY') {
1049: foreach my $item (@{$srcharray}) {
1050: $r->print('<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n");
1051: }
1052: }
1.160 raeburn 1053: $r->print(' <input type="hidden" name="sortby" value="'.$sortby.'" />'."\n".
1054: ' <input type="hidden" name="seluname" value="" />'."\n".
1055: ' <input type="hidden" name="seludom" value="" />'."\n".
1.179 raeburn 1056: ' <input type="hidden" name="currstate" value="select" />'."\n".
1.190 raeburn 1057: ' <input type="hidden" name="phase" value="get_user_info" />'."\n".
1.214 raeburn 1058: ' <input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n");
1.302 raeburn 1059: if ($context eq 'requestcrs') {
1060: $r->print($opener_elements.'</form></div>');
1061: } else {
1.351 raeburn 1062: $r->print($response.'</form>');
1.302 raeburn 1063: }
1.160 raeburn 1064: }
1065:
1066: sub print_user_query_page {
1.351 raeburn 1067: my ($r,$caller,$brcrum) = @_;
1.160 raeburn 1068: # FIXME - this is for a network-wide name search (similar to catalog search)
1069: # To use frames with similar behavior to catalog/portfolio search.
1070: # To be implemented.
1071: return;
1072: }
1073:
1.42 matthew 1074: sub print_user_modification_page {
1.375 raeburn 1075: my ($r,$ccuname,$ccdomain,$srch,$response,$context,$permission,$crstype,
1076: $brcrum,$showcredits) = @_;
1.185 raeburn 1077: if (($ccuname eq '') || ($ccdomain eq '')) {
1.215 raeburn 1078: my $usermsg = &mt('No username and/or domain provided.');
1079: $env{'form.phase'} = '';
1.351 raeburn 1080: &print_username_entry_form($r,$context,$usermsg,'','',$crstype,$brcrum);
1.58 www 1081: return;
1082: }
1.213 raeburn 1083: my ($form,$formname);
1084: if ($env{'form.action'} eq 'singlestudent') {
1085: $form = 'document.enrollstudent';
1086: $formname = 'enrollstudent';
1087: } else {
1088: $form = 'document.cu';
1089: $formname = 'cu';
1090: }
1.188 raeburn 1091: my %abv_auth = &auth_abbrev();
1.227 raeburn 1092: my (%rulematch,%inst_results,$newuser,%alerts,%curr_rules,%got_rules);
1.185 raeburn 1093: my $uhome=&Apache::lonnet::homeserver($ccuname,$ccdomain);
1094: if ($uhome eq 'no_host') {
1.215 raeburn 1095: my $usertype;
1096: my ($rules,$ruleorder) =
1097: &Apache::lonnet::inst_userrules($ccdomain,'username');
1098: $usertype =
1.353 raeburn 1099: &Apache::lonuserutils::check_usertype($ccdomain,$ccuname,$rules,
1.362 raeburn 1100: \%curr_rules,\%got_rules);
1.215 raeburn 1101: my $cancreate =
1102: &Apache::lonuserutils::can_create_user($ccdomain,$context,
1103: $usertype);
1104: if (!$cancreate) {
1.292 bisitz 1105: my $helplink = 'javascript:helpMenu('."'display'".')';
1.215 raeburn 1106: my %usertypetext = (
1107: official => 'institutional',
1108: unofficial => 'non-institutional',
1109: );
1110: my $response;
1111: if ($env{'form.origform'} eq 'crtusername') {
1.362 raeburn 1112: $response = '<span class="LC_warning">'.
1113: &mt('No match found for the username [_1] in LON-CAPA domain: [_2]',
1114: '<b>'.$ccuname.'</b>',$ccdomain).
1.215 raeburn 1115: '</span><br />';
1116: }
1.292 bisitz 1117: $response .= '<p class="LC_warning">'
1118: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
1119: .' '
1120: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
1121: ,'<a href="'.$helplink.'">','</a>')
1122: .'</p><br />';
1.215 raeburn 1123: $env{'form.phase'} = '';
1.351 raeburn 1124: &print_username_entry_form($r,$context,$response,undef,undef,$crstype,$brcrum);
1.215 raeburn 1125: return;
1126: }
1.188 raeburn 1127: $newuser = 1;
1.193 raeburn 1128: my $checkhash;
1129: my $checks = { 'username' => 1 };
1.196 raeburn 1130: $checkhash->{$ccuname.':'.$ccdomain} = { 'newuser' => $newuser };
1.193 raeburn 1131: &Apache::loncommon::user_rule_check($checkhash,$checks,
1.196 raeburn 1132: \%alerts,\%rulematch,\%inst_results,\%curr_rules,\%got_rules);
1133: if (ref($alerts{'username'}) eq 'HASH') {
1134: if (ref($alerts{'username'}{$ccdomain}) eq 'HASH') {
1135: my $domdesc =
1.193 raeburn 1136: &Apache::lonnet::domain($ccdomain,'description');
1.196 raeburn 1137: if ($alerts{'username'}{$ccdomain}{$ccuname}) {
1138: my $userchkmsg;
1139: if (ref($curr_rules{$ccdomain}) eq 'HASH') {
1140: $userchkmsg =
1141: &Apache::loncommon::instrule_disallow_msg('username',
1.193 raeburn 1142: $domdesc,1).
1143: &Apache::loncommon::user_rule_formats($ccdomain,
1144: $domdesc,$curr_rules{$ccdomain}{'username'},
1145: 'username');
1.196 raeburn 1146: }
1.215 raeburn 1147: $env{'form.phase'} = '';
1.351 raeburn 1148: &print_username_entry_form($r,$context,$userchkmsg,undef,undef,$crstype,$brcrum);
1.196 raeburn 1149: return;
1.215 raeburn 1150: }
1.193 raeburn 1151: }
1.185 raeburn 1152: }
1.187 raeburn 1153: } else {
1.188 raeburn 1154: $newuser = 0;
1.185 raeburn 1155: }
1.160 raeburn 1156: if ($response) {
1.215 raeburn 1157: $response = '<br />'.$response;
1.160 raeburn 1158: }
1.149 raeburn 1159:
1.52 matthew 1160: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
1.88 raeburn 1161: my $dc_setcourse_code = '';
1.119 raeburn 1162: my $nondc_setsection_code = '';
1.112 albertel 1163: my %loaditem;
1.114 albertel 1164:
1.216 raeburn 1165: my $groupslist = &Apache::lonuserutils::get_groupslist();
1.88 raeburn 1166:
1.375 raeburn 1167: my $js = &validation_javascript($context,$ccdomain,$pjump_def,$crstype,
1.216 raeburn 1168: $groupslist,$newuser,$formname,\%loaditem);
1.318 raeburn 1169: my %breadcrumb_text = &singleuser_breadcrumb($crstype);
1.224 raeburn 1170: my $helpitem = 'Course_Change_Privileges';
1171: if ($env{'form.action'} eq 'singlestudent') {
1172: $helpitem = 'Course_Add_Student';
1173: }
1.351 raeburn 1174: push (@{$brcrum},
1175: {href => "javascript:backPage($form)",
1176: text => $breadcrumb_text{'search'},
1177: faq => 282,
1178: bug => 'Instructor Interface',});
1179: if ($env{'form.phase'} eq 'userpicked') {
1180: push(@{$brcrum},
1181: {href => "javascript:backPage($form,'get_user_info','select')",
1182: text => $breadcrumb_text{'userpicked'},
1183: faq => 282,
1184: bug => 'Instructor Interface',});
1185: }
1186: push(@{$brcrum},
1187: {href => "javascript:backPage($form,'$env{'form.phase'}','modify')",
1188: text => $breadcrumb_text{'modify'},
1189: faq => 282,
1190: bug => 'Instructor Interface',
1191: help => $helpitem});
1192: my $args = {'add_entries' => \%loaditem,
1193: 'bread_crumbs' => $brcrum,
1194: 'bread_crumbs_component' => 'User Management'};
1195: if ($env{'form.popup'}) {
1196: $args->{'no_nav_bar'} = 1;
1197: }
1198: my $start_page =
1199: &Apache::loncommon::start_page('User Management',$js,$args);
1.3 www 1200:
1.25 matthew 1201: my $forminfo =<<"ENDFORMINFO";
1.216 raeburn 1202: <form action="/adm/createuser" method="post" name="$formname">
1.190 raeburn 1203: <input type="hidden" name="phase" value="update_user_data" />
1.188 raeburn 1204: <input type="hidden" name="ccuname" value="$ccuname" />
1205: <input type="hidden" name="ccdomain" value="$ccdomain" />
1.157 albertel 1206: <input type="hidden" name="pres_value" value="" />
1207: <input type="hidden" name="pres_type" value="" />
1208: <input type="hidden" name="pres_marker" value="" />
1.25 matthew 1209: ENDFORMINFO
1.375 raeburn 1210: my (%inccourses,$roledom,$defaultcredits);
1.329 raeburn 1211: if ($context eq 'course') {
1212: $inccourses{$env{'request.course.id'}}=1;
1213: $roledom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1.375 raeburn 1214: if ($showcredits) {
1215: $defaultcredits = &Apache::lonuserutils::get_defaultcredits();
1216: }
1.329 raeburn 1217: } elsif ($context eq 'author') {
1218: $roledom = $env{'request.role.domain'};
1219: } elsif ($context eq 'domain') {
1220: foreach my $key (keys(%env)) {
1221: $roledom = $env{'request.role.domain'};
1222: if ($key=~/^user\.priv\.cm\.\/($roledom)\/($match_username)/) {
1223: $inccourses{$1.'_'.$2}=1;
1224: }
1225: }
1226: } else {
1227: foreach my $key (keys(%env)) {
1228: if ($key=~/^user\.priv\.cm\.\/($match_domain)\/($match_username)/) {
1229: $inccourses{$1.'_'.$2}=1;
1230: }
1.2 www 1231: }
1.24 matthew 1232: }
1.216 raeburn 1233: if ($newuser) {
1.362 raeburn 1234: my ($portfolioform,$domroleform);
1.267 raeburn 1235: if ((&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) ||
1236: (&Apache::lonnet::allowed('mut',$env{'request.role.domain'}))) {
1237: # Current user has quota or user tools modification privileges
1.378 raeburn 1238: $portfolioform = '<br />'.&user_quotas($ccuname,$ccdomain);
1.134 raeburn 1239: }
1.383 raeburn 1240: if ((&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) &&
1241: ($ccdomain eq $env{'request.role.domain'})) {
1.362 raeburn 1242: $domroleform = '<br />'.&domainrole_req($ccuname,$ccdomain);
1243: }
1.227 raeburn 1244: &initialize_authen_forms($ccdomain,$formname);
1.188 raeburn 1245: my %lt=&Apache::lonlocal::texthash(
1246: 'cnu' => 'Create New User',
1.213 raeburn 1247: 'ast' => 'as a student',
1.318 raeburn 1248: 'ame' => 'as a member',
1.188 raeburn 1249: 'ind' => 'in domain',
1250: 'lg' => 'Login Data',
1.190 raeburn 1251: 'hs' => "Home Server",
1.188 raeburn 1252: );
1.185 raeburn 1253: $r->print(<<ENDTITLE);
1.110 albertel 1254: $start_page
1.160 raeburn 1255: $response
1.25 matthew 1256: $forminfo
1.31 matthew 1257: <script type="text/javascript" language="Javascript">
1.301 bisitz 1258: // <![CDATA[
1.20 harris41 1259: $loginscript
1.301 bisitz 1260: // ]]>
1.31 matthew 1261: </script>
1.20 harris41 1262: <input type='hidden' name='makeuser' value='1' />
1.216 raeburn 1263: <h2>$lt{'cnu'} "$ccuname" $lt{'ind'} $ccdomain
1.185 raeburn 1264: ENDTITLE
1.213 raeburn 1265: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1266: if ($crstype eq 'Community') {
1267: $r->print(' ('.$lt{'ame'}.')');
1268: } else {
1269: $r->print(' ('.$lt{'ast'}.')');
1270: }
1.213 raeburn 1271: }
1272: $r->print('</h2>'."\n".'<div class="LC_left_float">');
1.206 raeburn 1273: my $personal_table =
1.210 raeburn 1274: &personal_data_display($ccuname,$ccdomain,$newuser,$context,
1275: $inst_results{$ccuname.':'.$ccdomain});
1.206 raeburn 1276: $r->print($personal_table);
1.187 raeburn 1277: my ($home_server_pick,$numlib) =
1278: &Apache::loncommon::home_server_form_item($ccdomain,'hserver',
1279: 'default','hide');
1280: if ($numlib > 1) {
1281: $r->print("
1.185 raeburn 1282: <br />
1.187 raeburn 1283: $lt{'hs'}: $home_server_pick
1284: <br />");
1285: } else {
1286: $r->print($home_server_pick);
1287: }
1.304 raeburn 1288: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.362 raeburn 1289: $r->print('<br /><h3>'.
1290: &mt('User Can Request Creation of Courses/Communities in this Domain?').'</h3>'.
1.304 raeburn 1291: &Apache::loncommon::start_data_table().
1292: &build_tools_display($ccuname,$ccdomain,
1293: 'requestcourses').
1294: &Apache::loncommon::end_data_table());
1295: }
1.188 raeburn 1296: $r->print('</div>'."\n".'<div class="LC_left_float"><h3>'.
1297: $lt{'lg'}.'</h3>');
1.185 raeburn 1298: my ($fixedauth,$varauth,$authmsg);
1.193 raeburn 1299: if (ref($rulematch{$ccuname.':'.$ccdomain}) eq 'HASH') {
1300: my $matchedrule = $rulematch{$ccuname.':'.$ccdomain}{'username'};
1301: my ($rules,$ruleorder) =
1302: &Apache::lonnet::inst_userrules($ccdomain,'username');
1.185 raeburn 1303: if (ref($rules) eq 'HASH') {
1.193 raeburn 1304: if (ref($rules->{$matchedrule}) eq 'HASH') {
1305: my $authtype = $rules->{$matchedrule}{'authtype'};
1.185 raeburn 1306: if ($authtype !~ /^(krb4|krb5|int|fsys|loc)$/) {
1.190 raeburn 1307: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.275 raeburn 1308: } else {
1.193 raeburn 1309: my $authparm = $rules->{$matchedrule}{'authparm'};
1.273 raeburn 1310: $authmsg = $rules->{$matchedrule}{'authmsg'};
1.185 raeburn 1311: if ($authtype =~ /^krb(4|5)$/) {
1312: my $ver = $1;
1313: if ($authparm ne '') {
1314: $fixedauth = <<"KERB";
1315: <input type="hidden" name="login" value="krb" />
1316: <input type="hidden" name="krbver" value="$ver" />
1317: <input type="hidden" name="krbarg" value="$authparm" />
1318: KERB
1319: }
1320: } else {
1321: $fixedauth =
1322: '<input type="hidden" name="login" value="'.$authtype.'" />'."\n";
1.193 raeburn 1323: if ($rules->{$matchedrule}{'authparmfixed'}) {
1.185 raeburn 1324: $fixedauth .=
1325: '<input type="hidden" name="'.$authtype.'arg" value="'.$authparm.'" />'."\n";
1326: } else {
1.273 raeburn 1327: if ($authtype eq 'int') {
1328: $varauth = '<br />'.
1.301 bisitz 1329: &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 1330: } elsif ($authtype eq 'loc') {
1331: $varauth = '<br />'.
1332: &mt('[_1] Local Authentication with argument [_2]','','<input type="text" name="'.$authtype.'arg" value="" />')."\n";
1333: } else {
1334: $varauth =
1.185 raeburn 1335: '<input type="text" name="'.$authtype.'arg" value="" />'."\n";
1.273 raeburn 1336: }
1.185 raeburn 1337: }
1338: }
1339: }
1340: } else {
1.190 raeburn 1341: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.185 raeburn 1342: }
1343: }
1344: if ($authmsg) {
1345: $r->print(<<ENDAUTH);
1346: $fixedauth
1347: $authmsg
1348: $varauth
1349: ENDAUTH
1350: }
1351: } else {
1.190 raeburn 1352: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.187 raeburn 1353: }
1.362 raeburn 1354: $r->print($portfolioform.$domroleform);
1.215 raeburn 1355: if ($env{'form.action'} eq 'singlestudent') {
1356: $r->print(&date_sections_select($context,$newuser,$formname,
1.375 raeburn 1357: $permission,$crstype,$ccuname,
1358: $ccdomain,$showcredits));
1.215 raeburn 1359: }
1360: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.216 raeburn 1361: } else { # user already exists
1.79 albertel 1362: my %lt=&Apache::lonlocal::texthash(
1.191 raeburn 1363: 'cup' => "Modify existing user: ",
1.213 raeburn 1364: 'ens' => "Enroll one student: ",
1.318 raeburn 1365: 'enm' => "Enroll one member: ",
1.72 sakharuk 1366: 'id' => "in domain",
1367: );
1.26 matthew 1368: $r->print(<<ENDCHANGEUSER);
1.110 albertel 1369: $start_page
1.25 matthew 1370: $forminfo
1.213 raeburn 1371: <h2>
1.26 matthew 1372: ENDCHANGEUSER
1.213 raeburn 1373: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1374: if ($crstype eq 'Community') {
1375: $r->print($lt{'enm'});
1376: } else {
1377: $r->print($lt{'ens'});
1378: }
1.213 raeburn 1379: } else {
1380: $r->print($lt{'cup'});
1381: }
1382: $r->print(' "'.$ccuname.'" '.$lt{'id'}.' "'.$ccdomain.'"</h2>'.
1383: "\n".'<div class="LC_left_float">');
1.206 raeburn 1384: my ($personal_table,$showforceid) =
1.210 raeburn 1385: &personal_data_display($ccuname,$ccdomain,$newuser,$context,
1386: $inst_results{$ccuname.':'.$ccdomain});
1.206 raeburn 1387: $r->print($personal_table);
1388: if ($showforceid) {
1.362 raeburn 1389: $r->print('<table>'.&Apache::lonuserutils::forceid_change($context).'</table>');
1.199 raeburn 1390: }
1.275 raeburn 1391: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.362 raeburn 1392: $r->print('<br /><h3>'.&mt('User Can Request Creation of Courses/Communities in this Domain?').'</h3>'.
1.300 raeburn 1393: &Apache::loncommon::start_data_table());
1.314 raeburn 1394: if ($env{'request.role.domain'} eq $ccdomain) {
1.300 raeburn 1395: $r->print(&build_tools_display($ccuname,$ccdomain,'requestcourses'));
1396: } else {
1397: $r->print(&coursereq_externaluser($ccuname,$ccdomain,
1398: $env{'request.role.domain'}));
1399: }
1400: $r->print(&Apache::loncommon::end_data_table());
1.275 raeburn 1401: }
1.199 raeburn 1402: $r->print('</div>');
1.362 raeburn 1403: my @order = ('auth','quota','tools','requestauthor');
1404: my %user_text;
1405: my ($isadv,$isauthor) =
1406: &Apache::lonnet::is_advanced_user($ccuname,$ccdomain);
1407: if ((!$isauthor) &&
1.383 raeburn 1408: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))
1409: && ($env{'request.role.domain'} eq $ccdomain)) {
1.362 raeburn 1410: $user_text{'requestauthor'} = &domainrole_req($ccuname,$ccdomain);
1411: }
1412: $user_text{'auth'} = &user_authentication($ccuname,$ccdomain,$formname);
1.267 raeburn 1413: if ((&Apache::lonnet::allowed('mpq',$ccdomain)) ||
1414: (&Apache::lonnet::allowed('mut',$ccdomain))) {
1.188 raeburn 1415: # Current user has quota modification privileges
1.378 raeburn 1416: $user_text{'quota'} = &user_quotas($ccuname,$ccdomain);
1.267 raeburn 1417: }
1418: if (!&Apache::lonnet::allowed('mpq',$ccdomain)) {
1419: if (&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) {
1420: my %lt=&Apache::lonlocal::texthash(
1.385 ! bisitz 1421: 'dska' => "Disk quotas for user's portfolio and Authoring Space",
! 1422: 'youd' => "You do not have privileges to modify the portfolio and/or Authoring Space quotas for this user.",
1.267 raeburn 1423: 'ichr' => "If a change is required, contact a domain coordinator for the domain",
1424: );
1.362 raeburn 1425: $user_text{'quota'} = <<ENDNOPORTPRIV;
1.188 raeburn 1426: <h3>$lt{'dska'}</h3>
1427: $lt{'youd'} $lt{'ichr'}: $ccdomain
1428: ENDNOPORTPRIV
1.267 raeburn 1429: }
1430: }
1431: if (!&Apache::lonnet::allowed('mut',$ccdomain)) {
1432: if (&Apache::lonnet::allowed('mut',$env{'request.role.domain'})) {
1433: my %lt=&Apache::lonlocal::texthash(
1434: 'utav' => "User Tools Availability",
1.361 raeburn 1435: 'yodo' => "You do not have privileges to modify Portfolio, Blog, WebDAV, or Personal Information Page settings for this user.",
1.267 raeburn 1436: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
1437: );
1.362 raeburn 1438: $user_text{'tools'} = <<ENDNOTOOLSPRIV;
1.267 raeburn 1439: <h3>$lt{'utav'}</h3>
1440: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1441: ENDNOTOOLSPRIV
1442: }
1.188 raeburn 1443: }
1.362 raeburn 1444: my $gotdiv = 0;
1445: foreach my $item (@order) {
1446: if ($user_text{$item} ne '') {
1447: unless ($gotdiv) {
1448: $r->print('<div class="LC_left_float">');
1449: $gotdiv = 1;
1450: }
1451: $r->print('<br />'.$user_text{$item});
1452: }
1453: }
1454: if ($env{'form.action'} eq 'singlestudent') {
1455: unless ($gotdiv) {
1456: $r->print('<div class="LC_left_float">');
1.213 raeburn 1457: }
1.375 raeburn 1458: my $credits;
1459: if ($showcredits) {
1460: $credits = &get_user_credits($ccuname,$ccdomain,$defaultcredits);
1461: if ($credits eq '') {
1462: $credits = $defaultcredits;
1463: }
1464: }
1.374 raeburn 1465: $r->print(&date_sections_select($context,$newuser,$formname,
1.375 raeburn 1466: $permission,$crstype,$ccuname,
1467: $ccdomain,$showcredits));
1.374 raeburn 1468: }
1.362 raeburn 1469: if ($gotdiv) {
1470: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.188 raeburn 1471: }
1.217 raeburn 1472: if ($env{'form.action'} ne 'singlestudent') {
1.329 raeburn 1473: &display_existing_roles($r,$ccuname,$ccdomain,\%inccourses,$context,
1474: $roledom,$crstype);
1.217 raeburn 1475: }
1.25 matthew 1476: } ## End of new user/old user logic
1.218 raeburn 1477: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1478: my $btntxt;
1479: if ($crstype eq 'Community') {
1480: $btntxt = &mt('Enroll Member');
1481: } else {
1482: $btntxt = &mt('Enroll Student');
1483: }
1484: $r->print('<br /><input type="button" value="'.$btntxt.'" onclick="setSections(this.form)" />'."\n");
1.218 raeburn 1485: } else {
1.375 raeburn 1486: $r->print('<fieldset><legend>'.&mt('Add Roles').'</legend>');
1.218 raeburn 1487: my $addrolesdisplay = 0;
1488: if ($context eq 'domain' || $context eq 'author') {
1489: $addrolesdisplay = &new_coauthor_roles($r,$ccuname,$ccdomain);
1490: }
1491: if ($context eq 'domain') {
1.357 raeburn 1492: my $add_domainroles = &new_domain_roles($r,$ccdomain);
1.218 raeburn 1493: if (!$addrolesdisplay) {
1494: $addrolesdisplay = $add_domainroles;
1.2 www 1495: }
1.375 raeburn 1496: $r->print(&course_level_dc($env{'request.role.domain'},$showcredits));
1497: $r->print('</fieldset><br /><input type="button" value="'.&mt('Save').'" onclick="setCourse()" />'."\n");
1.218 raeburn 1498: } elsif ($context eq 'author') {
1499: if ($addrolesdisplay) {
1.375 raeburn 1500: $r->print('</fieldset><br /><input type="button" value="'.&mt('Save').'"');
1.218 raeburn 1501: if ($newuser) {
1.301 bisitz 1502: $r->print(' onclick="auth_check()" \>'."\n");
1.218 raeburn 1503: } else {
1.301 bisitz 1504: $r->print('onclick="this.form.submit()" \>'."\n");
1.218 raeburn 1505: }
1.188 raeburn 1506: } else {
1.375 raeburn 1507: $r->print('</fieldset><br /><a href="javascript:backPage(document.cu)">'.
1.218 raeburn 1508: &mt('Back to previous page').'</a>');
1.188 raeburn 1509: }
1510: } else {
1.375 raeburn 1511: $r->print(&course_level_table(\%inccourses,$showcredits,$defaultcredits));
1512: $r->print('</fieldset><br /><input type="button" value="'.&mt('Save').'" onclick="setSections(this.form)" />'."\n");
1.188 raeburn 1513: }
1.88 raeburn 1514: }
1.188 raeburn 1515: $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','userrole','ccdomain','prevphase','currstate','ccuname','ccdomain']));
1.179 raeburn 1516: $r->print('<input type="hidden" name="currstate" value="" />');
1.352 raeburn 1517: $r->print('<input type="hidden" name="prevphase" value="'.$env{'form.phase'}.'" /></form>');
1.218 raeburn 1518: return;
1.2 www 1519: }
1.1 www 1520:
1.213 raeburn 1521: sub singleuser_breadcrumb {
1.318 raeburn 1522: my ($crstype) = @_;
1.213 raeburn 1523: my %breadcrumb_text;
1524: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1525: if ($crstype eq 'Community') {
1526: $breadcrumb_text{'search'} = 'Enroll a member';
1527: } else {
1528: $breadcrumb_text{'search'} = 'Enroll a student';
1529: }
1.213 raeburn 1530: $breadcrumb_text{'userpicked'} = 'Select a user',
1531: $breadcrumb_text{'modify'} = 'Set section/dates',
1532: } else {
1.229 raeburn 1533: $breadcrumb_text{'search'} = 'Create/modify a user';
1.213 raeburn 1534: $breadcrumb_text{'userpicked'} = 'Select a user',
1535: $breadcrumb_text{'modify'} = 'Set user role',
1536: }
1537: return %breadcrumb_text;
1538: }
1539:
1540: sub date_sections_select {
1.375 raeburn 1541: my ($context,$newuser,$formname,$permission,$crstype,$ccuname,$ccdomain,
1542: $showcredits) = @_;
1543: my $credits;
1544: if ($showcredits) {
1545: my $defaultcredits = &Apache::lonuserutils::get_defaultcredits();
1546: $credits = &get_user_credits($ccuname,$ccdomain,$defaultcredits);
1547: if ($credits eq '') {
1548: $credits = $defaultcredits;
1549: }
1550: }
1.213 raeburn 1551: my $cid = $env{'request.course.id'};
1552: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity($cid);
1553: my $date_table = '<h3>'.&mt('Starting and Ending Dates').'</h3>'."\n".
1554: &Apache::lonuserutils::date_setting_table(undef,undef,$context,
1555: undef,$formname,$permission);
1556: my $rowtitle = 'Section';
1.375 raeburn 1557: my $secbox = '<h3>'.&mt('Section and Credits').'</h3>'."\n".
1.213 raeburn 1558: &Apache::lonuserutils::section_picker($cdom,$cnum,'st',$rowtitle,
1.375 raeburn 1559: $permission,$context,'',$crstype,
1560: $showcredits,$credits);
1.213 raeburn 1561: my $output = $date_table.$secbox;
1562: return $output;
1563: }
1564:
1.216 raeburn 1565: sub validation_javascript {
1.375 raeburn 1566: my ($context,$ccdomain,$pjump_def,$crstype,$groupslist,$newuser,$formname,
1.216 raeburn 1567: $loaditem) = @_;
1568: my $dc_setcourse_code = '';
1569: my $nondc_setsection_code = '';
1570: if ($context eq 'domain') {
1571: my $dcdom = $env{'request.role.domain'};
1572: $loaditem->{'onload'} = "document.cu.coursedesc.value='';";
1.227 raeburn 1573: $dc_setcourse_code =
1574: &Apache::lonuserutils::dc_setcourse_js('cu','singleuser',$context);
1.216 raeburn 1575: } else {
1.227 raeburn 1576: my $checkauth;
1577: if (($newuser) || (&Apache::lonnet::allowed('mau',$ccdomain))) {
1578: $checkauth = 1;
1579: }
1580: if ($context eq 'course') {
1581: $nondc_setsection_code =
1582: &Apache::lonuserutils::setsections_javascript($formname,$groupslist,
1.375 raeburn 1583: undef,$checkauth,
1584: $crstype);
1.227 raeburn 1585: }
1586: if ($checkauth) {
1587: $nondc_setsection_code .=
1588: &Apache::lonuserutils::verify_authen($formname,$context);
1589: }
1.216 raeburn 1590: }
1591: my $js = &user_modification_js($pjump_def,$dc_setcourse_code,
1592: $nondc_setsection_code,$groupslist);
1593: my ($jsback,$elements) = &crumb_utilities();
1594: $js .= "\n".
1.301 bisitz 1595: '<script type="text/javascript">'."\n".
1596: '// <![CDATA['."\n".
1597: $jsback."\n".
1598: '// ]]>'."\n".
1599: '</script>'."\n";
1.216 raeburn 1600: return $js;
1601: }
1602:
1.217 raeburn 1603: sub display_existing_roles {
1.375 raeburn 1604: my ($r,$ccuname,$ccdomain,$inccourses,$context,$roledom,$crstype,
1605: $showcredits) = @_;
1.329 raeburn 1606: my $now=time;
1607: my %lt=&Apache::lonlocal::texthash(
1.217 raeburn 1608: 'rer' => "Existing Roles",
1609: 'rev' => "Revoke",
1610: 'del' => "Delete",
1611: 'ren' => "Re-Enable",
1612: 'rol' => "Role",
1613: 'ext' => "Extent",
1.375 raeburn 1614: 'crd' => "Credits",
1.217 raeburn 1615: 'sta' => "Start",
1616: 'end' => "End",
1617: );
1.329 raeburn 1618: my (%rolesdump,%roletext,%sortrole,%roleclass,%rolepriv);
1619: if ($context eq 'course' || $context eq 'author') {
1620: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
1621: my %roleshash =
1622: &Apache::lonnet::get_my_roles($ccuname,$ccdomain,'userroles',
1623: ['active','previous','future'],\@roles,$roledom,1);
1624: foreach my $key (keys(%roleshash)) {
1625: my ($start,$end) = split(':',$roleshash{$key});
1626: next if ($start eq '-1' || $end eq '-1');
1627: my ($rnum,$rdom,$role,$sec) = split(':',$key);
1628: if ($context eq 'course') {
1629: next unless (($rnum eq $env{'course.'.$env{'request.course.id'}.'.num'})
1630: && ($rdom eq $env{'course.'.$env{'request.course.id'}.'.domain'}));
1631: } elsif ($context eq 'author') {
1632: next unless (($rnum eq $env{'user.name'}) && ($rdom eq $env{'request.role.domain'}));
1633: }
1634: my ($newkey,$newvalue,$newrole);
1635: $newkey = '/'.$rdom.'/'.$rnum;
1636: if ($sec ne '') {
1637: $newkey .= '/'.$sec;
1638: }
1639: $newvalue = $role;
1640: if ($role =~ /^cr/) {
1641: $newrole = 'cr';
1642: } else {
1643: $newrole = $role;
1644: }
1645: $newkey .= '_'.$newrole;
1646: if ($start ne '' && $end ne '') {
1647: $newvalue .= '_'.$end.'_'.$start;
1.335 raeburn 1648: } elsif ($end ne '') {
1649: $newvalue .= '_'.$end;
1.329 raeburn 1650: }
1651: $rolesdump{$newkey} = $newvalue;
1652: }
1653: } else {
1.360 raeburn 1654: %rolesdump=&Apache::lonnet::dump('roles',$ccdomain,$ccuname);
1.329 raeburn 1655: }
1656: # Build up table of user roles to allow revocation and re-enabling of roles.
1657: my ($tmp) = keys(%rolesdump);
1658: return if ($tmp =~ /^(con_lost|error)/i);
1659: foreach my $area (sort { my $a1=join('_',(split('_',$a))[1,0]);
1660: my $b1=join('_',(split('_',$b))[1,0]);
1661: return $a1 cmp $b1;
1662: } keys(%rolesdump)) {
1663: next if ($area =~ /^rolesdef/);
1664: my $envkey=$area;
1665: my $role = $rolesdump{$area};
1666: my $thisrole=$area;
1667: $area =~ s/\_\w\w$//;
1668: my ($role_code,$role_end_time,$role_start_time) =
1669: split(/_/,$role);
1.217 raeburn 1670: # Is this a custom role? Get role owner and title.
1.329 raeburn 1671: my ($croleudom,$croleuname,$croletitle)=
1672: ($role_code=~m{^cr/($match_domain)/($match_username)/(\w+)$});
1673: my $allowed=0;
1674: my $delallowed=0;
1675: my $sortkey=$role_code;
1676: my $class='Unknown';
1.375 raeburn 1677: my $credits='';
1.329 raeburn 1678: if ($area =~ m{^/($match_domain)/($match_courseid)} ) {
1679: $class='Course';
1680: my ($coursedom,$coursedir) = ($1,$2);
1681: my $cid = $1.'_'.$2;
1682: # $1.'_'.$2 is the course id (eg. 103_12345abcef103l3).
1683: my %coursedata=
1684: &Apache::lonnet::coursedescription($cid);
1685: if ($coursedir =~ /^$match_community$/) {
1686: $class='Community';
1687: }
1688: $sortkey.="\0$coursedom";
1689: my $carea;
1690: if (defined($coursedata{'description'})) {
1691: $carea=$coursedata{'description'}.
1692: '<br />'.&mt('Domain').': '.$coursedom.(' 'x8).
1693: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$coursedir,$coursedom);
1694: $sortkey.="\0".$coursedata{'description'};
1695: } else {
1696: if ($class eq 'Community') {
1697: $carea=&mt('Unavailable community').': '.$area;
1698: $sortkey.="\0".&mt('Unavailable community').': '.$area;
1.217 raeburn 1699: } else {
1700: $carea=&mt('Unavailable course').': '.$area;
1701: $sortkey.="\0".&mt('Unavailable course').': '.$area;
1702: }
1.329 raeburn 1703: }
1704: $sortkey.="\0$coursedir";
1705: $inccourses->{$cid}=1;
1.375 raeburn 1706: if (($showcredits) && ($class eq 'Course') && ($role_code eq 'st')) {
1707: my $defaultcredits = $coursedata{'internal.defaultcredits'};
1708: $credits =
1709: &get_user_credits($ccuname,$ccdomain,$defaultcredits,
1710: $coursedom,$coursedir);
1711: if ($credits eq '') {
1712: $credits = $defaultcredits;
1713: }
1714: }
1.329 raeburn 1715: if ((&Apache::lonnet::allowed('c'.$role_code,$coursedom.'/'.$coursedir)) ||
1716: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
1717: $allowed=1;
1718: }
1719: unless ($allowed) {
1.365 raeburn 1720: my $isowner = &Apache::lonuserutils::is_courseowner($cid,$coursedata{'internal.courseowner'});
1.329 raeburn 1721: if ($isowner) {
1722: if (($role_code eq 'co') && ($class eq 'Community')) {
1723: $allowed = 1;
1724: } elsif (($role_code eq 'cc') && ($class eq 'Course')) {
1725: $allowed = 1;
1726: }
1.217 raeburn 1727: }
1.329 raeburn 1728: }
1729: if ((&Apache::lonnet::allowed('dro',$coursedom)) ||
1730: (&Apache::lonnet::allowed('dro',$ccdomain))) {
1731: $delallowed=1;
1732: }
1.217 raeburn 1733: # - custom role. Needs more info, too
1.329 raeburn 1734: if ($croletitle) {
1735: if (&Apache::lonnet::allowed('ccr',$coursedom.'/'.$coursedir)) {
1736: $allowed=1;
1737: $thisrole.='.'.$role_code;
1.217 raeburn 1738: }
1.329 raeburn 1739: }
1740: if ($area=~m{^/($match_domain)/($match_courseid)/(\w+)}) {
1.373 bisitz 1741: $carea.='<br />'.&mt('Section: [_1]',$3);
1.329 raeburn 1742: $sortkey.="\0$3";
1743: if (!$allowed) {
1744: if ($env{'request.course.sec'} eq $3) {
1745: if (&Apache::lonnet::allowed('c'.$role_code,$1.'/'.$2.'/'.$3)) {
1746: $allowed = 1;
1.217 raeburn 1747: }
1748: }
1749: }
1.329 raeburn 1750: }
1751: $area=$carea;
1752: } else {
1753: $sortkey.="\0".$area;
1754: # Determine if current user is able to revoke privileges
1755: if ($area=~m{^/($match_domain)/}) {
1756: if ((&Apache::lonnet::allowed('c'.$role_code,$1)) ||
1757: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
1758: $allowed=1;
1.217 raeburn 1759: }
1.329 raeburn 1760: if (((&Apache::lonnet::allowed('dro',$1)) ||
1761: (&Apache::lonnet::allowed('dro',$ccdomain))) &&
1762: ($role_code ne 'dc')) {
1763: $delallowed=1;
1.217 raeburn 1764: }
1.329 raeburn 1765: } else {
1766: if (&Apache::lonnet::allowed('c'.$role_code,'/')) {
1.217 raeburn 1767: $allowed=1;
1768: }
1769: }
1.363 raeburn 1770: if ($role_code eq 'ca' || $role_code eq 'au' || $role_code eq 'aa') {
1.377 raeburn 1771: $class='Authoring Space';
1.329 raeburn 1772: } elsif ($role_code eq 'su') {
1773: $class='System';
1.217 raeburn 1774: } else {
1.329 raeburn 1775: $class='Domain';
1.217 raeburn 1776: }
1.329 raeburn 1777: }
1778: if (($role_code eq 'ca') || ($role_code eq 'aa')) {
1779: $area=~m{/($match_domain)/($match_username)};
1780: if (&Apache::lonuserutils::authorpriv($2,$1)) {
1781: $allowed=1;
1.217 raeburn 1782: } else {
1.329 raeburn 1783: $allowed=0;
1.217 raeburn 1784: }
1.329 raeburn 1785: }
1786: my $row = '';
1787: $row.= '<td>';
1788: my $active=1;
1789: $active=0 if (($role_end_time) && ($now>$role_end_time));
1790: if (($active) && ($allowed)) {
1791: $row.= '<input type="checkbox" name="rev:'.$thisrole.'" />';
1792: } else {
1793: if ($active) {
1794: $row.=' ';
1.217 raeburn 1795: } else {
1.329 raeburn 1796: $row.=&mt('expired or revoked');
1.217 raeburn 1797: }
1.329 raeburn 1798: }
1799: $row.='</td><td>';
1800: if ($allowed && !$active) {
1801: $row.= '<input type="checkbox" name="ren:'.$thisrole.'" />';
1802: } else {
1803: $row.=' ';
1804: }
1805: $row.='</td><td>';
1806: if ($delallowed) {
1807: $row.= '<input type="checkbox" name="del:'.$thisrole.'" />';
1808: } else {
1809: $row.=' ';
1810: }
1811: my $plaintext='';
1812: if (!$croletitle) {
1.375 raeburn 1813: $plaintext=&Apache::lonnet::plaintext($role_code,$class);
1814: if (($showcredits) && ($credits ne '')) {
1815: $plaintext .= '<br/ ><span class="LC_nobreak">'.
1816: '<span class="LC_fontsize_small">'.
1817: &mt('Credits: [_1]',$credits).
1818: '</span></span>';
1819: }
1.329 raeburn 1820: } else {
1821: $plaintext=
1.346 bisitz 1822: &mt('Customrole [_1][_2]defined by [_3]',
1823: '"'.$croletitle.'"',
1824: '<br />',
1825: $croleuname.':'.$croleudom);
1.329 raeburn 1826: }
1827: $row.= '</td><td>'.$plaintext.
1828: '</td><td>'.$area.
1829: '</td><td>'.($role_start_time?&Apache::lonlocal::locallocaltime($role_start_time)
1830: : ' ' ).
1831: '</td><td>'.($role_end_time ?&Apache::lonlocal::locallocaltime($role_end_time)
1832: : ' ' )
1833: ."</td>";
1834: $sortrole{$sortkey}=$envkey;
1835: $roletext{$envkey}=$row;
1836: $roleclass{$envkey}=$class;
1837: $rolepriv{$envkey}=$allowed;
1838: } # end of foreach (table building loop)
1839:
1840: my $rolesdisplay = 0;
1841: my %output = ();
1.377 raeburn 1842: foreach my $type ('Authoring Space','Course','Community','Domain','System','Unknown') {
1.329 raeburn 1843: $output{$type} = '';
1844: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
1845: if ( ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/ ) && ($rolepriv{$sortrole{$which}}) ) {
1846: $output{$type}.=
1847: &Apache::loncommon::start_data_table_row().
1848: $roletext{$sortrole{$which}}.
1849: &Apache::loncommon::end_data_table_row();
1.217 raeburn 1850: }
1.329 raeburn 1851: }
1852: unless($output{$type} eq '') {
1853: $output{$type} = '<tr class="LC_info_row">'.
1854: "<td align='center' colspan='7'>".&mt($type)."</td></tr>".
1855: $output{$type};
1856: $rolesdisplay = 1;
1857: }
1858: }
1859: if ($rolesdisplay == 1) {
1860: my $contextrole='';
1861: if ($env{'request.course.id'}) {
1862: if (&Apache::loncommon::course_type() eq 'Community') {
1863: $contextrole = &mt('Existing Roles in this Community');
1.290 bisitz 1864: } else {
1.329 raeburn 1865: $contextrole = &mt('Existing Roles in this Course');
1.290 bisitz 1866: }
1.329 raeburn 1867: } elsif ($env{'request.role'} =~ /^au\./) {
1.377 raeburn 1868: $contextrole = &mt('Existing Co-Author Roles in your Authoring Space');
1.329 raeburn 1869: } else {
1870: $contextrole = &mt('Existing Roles in this Domain');
1871: }
1.375 raeburn 1872: $r->print('<div>'.
1873: '<fieldset><legend>'.$contextrole.'</legend>'.
1.217 raeburn 1874: &Apache::loncommon::start_data_table("LC_createuser").
1875: &Apache::loncommon::start_data_table_header_row().
1876: '<th>'.$lt{'rev'}.'</th><th>'.$lt{'ren'}.'</th><th>'.$lt{'del'}.
1877: '</th><th>'.$lt{'rol'}.'</th><th>'.$lt{'ext'}.
1878: '</th><th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
1879: &Apache::loncommon::end_data_table_header_row());
1.377 raeburn 1880: foreach my $type ('Authoring Space','Course','Community','Domain','System','Unknown') {
1.329 raeburn 1881: if ($output{$type}) {
1882: $r->print($output{$type}."\n");
1.217 raeburn 1883: }
1884: }
1.375 raeburn 1885: $r->print(&Apache::loncommon::end_data_table().
1886: '</fieldset></div>');
1.329 raeburn 1887: }
1.217 raeburn 1888: return;
1889: }
1890:
1.218 raeburn 1891: sub new_coauthor_roles {
1892: my ($r,$ccuname,$ccdomain) = @_;
1893: my $addrolesdisplay = 0;
1894: #
1895: # Co-Author
1896: #
1897: if (&Apache::lonuserutils::authorpriv($env{'user.name'},
1898: $env{'request.role.domain'}) &&
1899: ($env{'user.name'} ne $ccuname || $env{'user.domain'} ne $ccdomain)) {
1900: # No sense in assigning co-author role to yourself
1901: $addrolesdisplay = 1;
1902: my $cuname=$env{'user.name'};
1903: my $cudom=$env{'request.role.domain'};
1904: my %lt=&Apache::lonlocal::texthash(
1.377 raeburn 1905: 'cs' => "Authoring Space",
1.218 raeburn 1906: 'act' => "Activate",
1907: 'rol' => "Role",
1908: 'ext' => "Extent",
1909: 'sta' => "Start",
1910: 'end' => "End",
1911: 'cau' => "Co-Author",
1912: 'caa' => "Assistant Co-Author",
1913: 'ssd' => "Set Start Date",
1914: 'sed' => "Set End Date"
1915: );
1916: $r->print('<h4>'.$lt{'cs'}.'</h4>'."\n".
1917: &Apache::loncommon::start_data_table()."\n".
1918: &Apache::loncommon::start_data_table_header_row()."\n".
1919: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'.
1920: '<th>'.$lt{'ext'}.'</th><th>'.$lt{'sta'}.'</th>'.
1921: '<th>'.$lt{'end'}.'</th>'."\n".
1922: &Apache::loncommon::end_data_table_header_row()."\n".
1923: &Apache::loncommon::start_data_table_row().'
1924: <td>
1.291 bisitz 1925: <input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_ca" />
1.218 raeburn 1926: </td>
1927: <td>'.$lt{'cau'}.'</td>
1928: <td>'.$cudom.'_'.$cuname.'</td>
1929: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_ca" value="" />
1930: <a href=
1931: "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>
1932: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_ca" value="" />
1933: <a href=
1934: "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".
1935: &Apache::loncommon::end_data_table_row()."\n".
1936: &Apache::loncommon::start_data_table_row()."\n".
1.291 bisitz 1937: '<td><input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_aa" /></td>
1.218 raeburn 1938: <td>'.$lt{'caa'}.'</td>
1939: <td>'.$cudom.'_'.$cuname.'</td>
1940: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_aa" value="" />
1941: <a href=
1942: "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>
1943: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_aa" value="" />
1944: <a href=
1945: "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".
1946: &Apache::loncommon::end_data_table_row()."\n".
1947: &Apache::loncommon::end_data_table());
1948: } elsif ($env{'request.role'} =~ /^au\./) {
1949: if (!(&Apache::lonuserutils::authorpriv($env{'user.name'},
1950: $env{'request.role.domain'}))) {
1951: $r->print('<span class="LC_error">'.
1952: &mt('You do not have privileges to assign co-author roles.').
1953: '</span>');
1954: } elsif (($env{'user.name'} eq $ccuname) &&
1955: ($env{'user.domain'} eq $ccdomain)) {
1.377 raeburn 1956: $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 1957: }
1958: }
1959: return $addrolesdisplay;;
1960: }
1961:
1962: sub new_domain_roles {
1.357 raeburn 1963: my ($r,$ccdomain) = @_;
1.218 raeburn 1964: my $addrolesdisplay = 0;
1965: #
1966: # Domain level
1967: #
1968: my $num_domain_level = 0;
1969: my $domaintext =
1970: '<h4>'.&mt('Domain Level').'</h4>'.
1971: &Apache::loncommon::start_data_table().
1972: &Apache::loncommon::start_data_table_header_row().
1973: '<th>'.&mt('Activate').'</th><th>'.&mt('Role').'</th><th>'.
1974: &mt('Extent').'</th>'.
1975: '<th>'.&mt('Start').'</th><th>'.&mt('End').'</th>'.
1976: &Apache::loncommon::end_data_table_header_row();
1.312 raeburn 1977: my @allroles = &Apache::lonuserutils::roles_by_context('domain');
1.218 raeburn 1978: foreach my $thisdomain (sort(&Apache::lonnet::all_domains())) {
1.312 raeburn 1979: foreach my $role (@allroles) {
1980: next if ($role eq 'ad');
1.357 raeburn 1981: next if (($role eq 'au') && ($ccdomain ne $thisdomain));
1.218 raeburn 1982: if (&Apache::lonnet::allowed('c'.$role,$thisdomain)) {
1983: my $plrole=&Apache::lonnet::plaintext($role);
1984: my %lt=&Apache::lonlocal::texthash(
1985: 'ssd' => "Set Start Date",
1986: 'sed' => "Set End Date"
1987: );
1988: $num_domain_level ++;
1989: $domaintext .=
1990: &Apache::loncommon::start_data_table_row().
1.291 bisitz 1991: '<td><input type="checkbox" name="act_'.$thisdomain.'_'.$role.'" /></td>
1.218 raeburn 1992: <td>'.$plrole.'</td>
1993: <td>'.$thisdomain.'</td>
1994: <td><input type="hidden" name="start_'.$thisdomain.'_'.$role.'" value="" />
1995: <a href=
1996: "javascript:pjump('."'date_start','Start Date $plrole',document.cu.start_$thisdomain\_$role.value,'start_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'ssd'}.'</a></td>
1997: <td><input type="hidden" name="end_'.$thisdomain.'_'.$role.'" value="" />
1998: <a href=
1999: "javascript:pjump('."'date_end','End Date $plrole',document.cu.end_$thisdomain\_$role.value,'end_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'sed'}.'</a></td>'.
2000: &Apache::loncommon::end_data_table_row();
2001: }
2002: }
2003: }
2004: $domaintext.= &Apache::loncommon::end_data_table();
2005: if ($num_domain_level > 0) {
2006: $r->print($domaintext);
2007: $addrolesdisplay = 1;
2008: }
2009: return $addrolesdisplay;
2010: }
2011:
1.188 raeburn 2012: sub user_authentication {
1.227 raeburn 2013: my ($ccuname,$ccdomain,$formname) = @_;
1.188 raeburn 2014: my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
1.227 raeburn 2015: my $outcome;
1.188 raeburn 2016: # Check for a bad authentication type
2017: if ($currentauth !~ /^(krb4|krb5|unix|internal|localauth):/) {
2018: # bad authentication scheme
2019: my %lt=&Apache::lonlocal::texthash(
2020: 'err' => "ERROR",
2021: 'uuas' => "This user has an unrecognized authentication scheme",
2022: 'adcs' => "Please alert a domain coordinator of this situation",
2023: 'sldb' => "Please specify login data below",
2024: 'ld' => "Login Data"
2025: );
2026: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
1.227 raeburn 2027: &initialize_authen_forms($ccdomain,$formname);
2028:
1.190 raeburn 2029: my $choices = &Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc);
1.188 raeburn 2030: $outcome = <<ENDBADAUTH;
2031: <script type="text/javascript" language="Javascript">
1.301 bisitz 2032: // <![CDATA[
1.188 raeburn 2033: $loginscript
1.301 bisitz 2034: // ]]>
1.188 raeburn 2035: </script>
2036: <span class="LC_error">$lt{'err'}:
2037: $lt{'uuas'} ($currentauth). $lt{'sldb'}.</span>
2038: <h3>$lt{'ld'}</h3>
2039: $choices
2040: ENDBADAUTH
2041: } else {
2042: # This user is not allowed to modify the user's
2043: # authentication scheme, so just notify them of the problem
2044: $outcome = <<ENDBADAUTH;
2045: <span class="LC_error"> $lt{'err'}:
2046: $lt{'uuas'} ($currentauth). $lt{'adcs'}.
2047: </span>
2048: ENDBADAUTH
2049: }
2050: } else { # Authentication type is valid
1.227 raeburn 2051: &initialize_authen_forms($ccdomain,$formname,$currentauth,'modifyuser');
1.205 raeburn 2052: my ($authformcurrent,$can_modify,@authform_others) =
1.188 raeburn 2053: &modify_login_block($ccdomain,$currentauth);
2054: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
2055: # Current user has login modification privileges
2056: my %lt=&Apache::lonlocal::texthash (
2057: 'ld' => "Login Data",
2058: 'ccld' => "Change Current Login Data",
2059: 'enld' => "Enter New Login Data"
2060: );
2061: $outcome =
2062: '<script type="text/javascript" language="Javascript">'."\n".
1.301 bisitz 2063: '// <![CDATA['."\n".
1.188 raeburn 2064: $loginscript."\n".
1.301 bisitz 2065: '// ]]>'."\n".
1.188 raeburn 2066: '</script>'."\n".
2067: '<h3>'.$lt{'ld'}.'</h3>'.
2068: &Apache::loncommon::start_data_table().
1.205 raeburn 2069: &Apache::loncommon::start_data_table_row().
1.188 raeburn 2070: '<td>'.$authformnop;
2071: if ($can_modify) {
2072: $outcome .= '</td>'."\n".
2073: &Apache::loncommon::end_data_table_row().
2074: &Apache::loncommon::start_data_table_row().
2075: '<td>'.$authformcurrent.'</td>'.
2076: &Apache::loncommon::end_data_table_row()."\n";
2077: } else {
1.200 raeburn 2078: $outcome .= ' ('.$authformcurrent.')</td>'.
2079: &Apache::loncommon::end_data_table_row()."\n";
1.188 raeburn 2080: }
1.205 raeburn 2081: foreach my $item (@authform_others) {
2082: $outcome .= &Apache::loncommon::start_data_table_row().
2083: '<td>'.$item.'</td>'.
2084: &Apache::loncommon::end_data_table_row()."\n";
1.188 raeburn 2085: }
1.205 raeburn 2086: $outcome .= &Apache::loncommon::end_data_table();
1.188 raeburn 2087: } else {
2088: if (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
2089: my %lt=&Apache::lonlocal::texthash(
2090: 'ccld' => "Change Current Login Data",
2091: 'yodo' => "You do not have privileges to modify the authentication configuration for this user.",
2092: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
2093: );
2094: $outcome .= <<ENDNOPRIV;
2095: <h3>$lt{'ccld'}</h3>
2096: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1.235 raeburn 2097: <input type="hidden" name="login" value="nochange" />
1.188 raeburn 2098: ENDNOPRIV
2099: }
2100: }
2101: } ## End of "check for bad authentication type" logic
2102: return $outcome;
2103: }
2104:
1.187 raeburn 2105: sub modify_login_block {
2106: my ($dom,$currentauth) = @_;
2107: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2108: my ($authnum,%can_assign) =
2109: &Apache::loncommon::get_assignable_auth($dom);
1.205 raeburn 2110: my ($authformcurrent,@authform_others,$show_override_msg);
1.187 raeburn 2111: if ($currentauth=~/^krb(4|5):/) {
2112: $authformcurrent=$authformkrb;
2113: if ($can_assign{'int'}) {
1.205 raeburn 2114: push(@authform_others,$authformint);
1.187 raeburn 2115: }
2116: if ($can_assign{'loc'}) {
1.205 raeburn 2117: push(@authform_others,$authformloc);
1.187 raeburn 2118: }
2119: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
2120: $show_override_msg = 1;
2121: }
2122: } elsif ($currentauth=~/^internal:/) {
2123: $authformcurrent=$authformint;
2124: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2125: push(@authform_others,$authformkrb);
1.187 raeburn 2126: }
2127: if ($can_assign{'loc'}) {
1.205 raeburn 2128: push(@authform_others,$authformloc);
1.187 raeburn 2129: }
2130: if ($can_assign{'int'}) {
2131: $show_override_msg = 1;
2132: }
2133: } elsif ($currentauth=~/^unix:/) {
2134: $authformcurrent=$authformfsys;
2135: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2136: push(@authform_others,$authformkrb);
1.187 raeburn 2137: }
2138: if ($can_assign{'int'}) {
1.205 raeburn 2139: push(@authform_others,$authformint);
1.187 raeburn 2140: }
2141: if ($can_assign{'loc'}) {
1.205 raeburn 2142: push(@authform_others,$authformloc);
1.187 raeburn 2143: }
2144: if ($can_assign{'fsys'}) {
2145: $show_override_msg = 1;
2146: }
2147: } elsif ($currentauth=~/^localauth:/) {
2148: $authformcurrent=$authformloc;
2149: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2150: push(@authform_others,$authformkrb);
1.187 raeburn 2151: }
2152: if ($can_assign{'int'}) {
1.205 raeburn 2153: push(@authform_others,$authformint);
1.187 raeburn 2154: }
2155: if ($can_assign{'loc'}) {
2156: $show_override_msg = 1;
2157: }
2158: }
2159: if ($show_override_msg) {
1.205 raeburn 2160: $authformcurrent = '<table><tr><td colspan="3">'.$authformcurrent.
2161: '</td></tr>'."\n".
2162: '<tr><td> </td>'.
2163: '<td><b>'.&mt('Currently in use').'</b></td>'.
2164: '<td align="right"><span class="LC_cusr_emph">'.
1.187 raeburn 2165: &mt('will override current values').
1.205 raeburn 2166: '</span></td></tr></table>';
1.187 raeburn 2167: }
1.205 raeburn 2168: return ($authformcurrent,$show_override_msg,@authform_others);
1.187 raeburn 2169: }
2170:
1.188 raeburn 2171: sub personal_data_display {
1.252 raeburn 2172: my ($ccuname,$ccdomain,$newuser,$context,$inst_results,$rolesarray) = @_;
1.286 raeburn 2173: my ($output,$showforceid,%userenv,%canmodify,%canmodify_status);
1.219 raeburn 2174: my @userinfo = ('firstname','middlename','lastname','generation',
2175: 'permanentemail','id');
1.252 raeburn 2176: my $rowcount = 0;
2177: my $editable = 0;
1.286 raeburn 2178: %canmodify_status =
2179: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
2180: ['inststatus'],$rolesarray);
1.253 raeburn 2181: if (!$newuser) {
1.188 raeburn 2182: # Get the users information
2183: %userenv = &Apache::lonnet::get('environment',
2184: ['firstname','middlename','lastname','generation',
1.286 raeburn 2185: 'permanentemail','id','inststatus'],$ccdomain,$ccuname);
1.219 raeburn 2186: %canmodify =
2187: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
1.252 raeburn 2188: \@userinfo,$rolesarray);
1.257 raeburn 2189: } elsif ($context eq 'selfcreate') {
2190: %canmodify = &selfcreate_canmodify($context,$ccdomain,\@userinfo,
2191: $inst_results,$rolesarray);
1.188 raeburn 2192: }
2193: my %lt=&Apache::lonlocal::texthash(
2194: 'pd' => "Personal Data",
2195: 'firstname' => "First Name",
2196: 'middlename' => "Middle Name",
2197: 'lastname' => "Last Name",
2198: 'generation' => "Generation",
2199: 'permanentemail' => "Permanent e-mail address",
1.259 bisitz 2200: 'id' => "Student/Employee ID",
1.286 raeburn 2201: 'lg' => "Login Data",
2202: 'inststatus' => "Affiliation",
1.188 raeburn 2203: );
2204: my %textboxsize = (
2205: firstname => '15',
2206: middlename => '15',
2207: lastname => '15',
2208: generation => '5',
2209: permanentemail => '25',
2210: id => '15',
2211: );
2212: my $genhelp=&Apache::loncommon::help_open_topic('Generation');
2213: $output = '<h3>'.$lt{'pd'}.'</h3>'.
2214: &Apache::lonhtmlcommon::start_pick_box();
2215: foreach my $item (@userinfo) {
2216: my $rowtitle = $lt{$item};
1.252 raeburn 2217: my $hiderow = 0;
1.188 raeburn 2218: if ($item eq 'generation') {
2219: $rowtitle = $genhelp.$rowtitle;
2220: }
1.252 raeburn 2221: my $row = &Apache::lonhtmlcommon::row_title($rowtitle,undef,'LC_oddrow_value')."\n";
1.188 raeburn 2222: if ($newuser) {
1.210 raeburn 2223: if (ref($inst_results) eq 'HASH') {
2224: if ($inst_results->{$item} ne '') {
1.252 raeburn 2225: $row .= '<input type="hidden" name="c'.$item.'" value="'.$inst_results->{$item}.'" />'.$inst_results->{$item};
1.210 raeburn 2226: } else {
1.252 raeburn 2227: if ($context eq 'selfcreate') {
2228: if ($canmodify{$item}) {
2229: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
2230: $editable ++;
2231: } else {
2232: $hiderow = 1;
2233: }
1.253 raeburn 2234: } else {
2235: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1.252 raeburn 2236: }
1.210 raeburn 2237: }
1.188 raeburn 2238: } else {
1.252 raeburn 2239: if ($context eq 'selfcreate') {
1.287 raeburn 2240: if (($item eq 'permanentemail') && ($newuser eq 'email')) {
2241: $row .= $ccuname;
1.252 raeburn 2242: } else {
1.287 raeburn 2243: if ($canmodify{$item}) {
2244: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
2245: $editable ++;
2246: } else {
2247: $hiderow = 1;
2248: }
1.252 raeburn 2249: }
1.253 raeburn 2250: } else {
2251: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1.252 raeburn 2252: }
1.188 raeburn 2253: }
2254: } else {
1.219 raeburn 2255: if ($canmodify{$item}) {
1.252 raeburn 2256: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="'.$userenv{$item}.'" />';
1.188 raeburn 2257: } else {
1.252 raeburn 2258: $row .= $userenv{$item};
1.188 raeburn 2259: }
1.206 raeburn 2260: if ($item eq 'id') {
1.219 raeburn 2261: $showforceid = $canmodify{$item};
2262: }
1.188 raeburn 2263: }
1.252 raeburn 2264: $row .= &Apache::lonhtmlcommon::row_closure(1);
2265: if (!$hiderow) {
2266: $output .= $row;
2267: $rowcount ++;
2268: }
1.188 raeburn 2269: }
1.286 raeburn 2270: if (($canmodify_status{'inststatus'}) || ($context ne 'selfcreate')) {
2271: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($ccdomain);
2272: if (ref($types) eq 'ARRAY') {
2273: if (@{$types} > 0) {
2274: my ($hiderow,$shown);
2275: if ($canmodify_status{'inststatus'}) {
2276: $shown = &pick_inst_statuses($userenv{'inststatus'},$usertypes,$types);
2277: } else {
2278: if ($userenv{'inststatus'} eq '') {
2279: $hiderow = 1;
1.334 raeburn 2280: } else {
2281: my @showitems;
2282: foreach my $item ( map { &unescape($_); } split(':',$userenv{'inststatus'})) {
2283: if (exists($usertypes->{$item})) {
2284: push(@showitems,$usertypes->{$item});
2285: } else {
2286: push(@showitems,$item);
2287: }
2288: }
2289: if (@showitems) {
2290: $shown = join(', ',@showitems);
2291: } else {
2292: $hiderow = 1;
2293: }
1.286 raeburn 2294: }
2295: }
2296: if (!$hiderow) {
2297: my $row = &Apache::lonhtmlcommon::row_title(&mt('Affliations'),undef,'LC_oddrow_value')."\n".
2298: $shown.&Apache::lonhtmlcommon::row_closure(1);
2299: if ($context eq 'selfcreate') {
2300: $rowcount ++;
2301: }
2302: $output .= $row;
2303: }
2304: }
2305: }
2306: }
1.188 raeburn 2307: $output .= &Apache::lonhtmlcommon::end_pick_box();
1.206 raeburn 2308: if (wantarray) {
1.252 raeburn 2309: if ($context eq 'selfcreate') {
2310: return($output,$rowcount,$editable);
2311: } else {
2312: return ($output,$showforceid);
2313: }
1.206 raeburn 2314: } else {
2315: return $output;
2316: }
1.188 raeburn 2317: }
2318:
1.286 raeburn 2319: sub pick_inst_statuses {
2320: my ($curr,$usertypes,$types) = @_;
2321: my ($output,$rem,@currtypes);
2322: if ($curr ne '') {
2323: @currtypes = map { &unescape($_); } split(/:/,$curr);
2324: }
2325: my $numinrow = 2;
2326: if (ref($types) eq 'ARRAY') {
2327: $output = '<table>';
2328: my $lastcolspan;
2329: for (my $i=0; $i<@{$types}; $i++) {
2330: if (defined($usertypes->{$types->[$i]})) {
2331: my $rem = $i%($numinrow);
2332: if ($rem == 0) {
2333: if ($i<@{$types}-1) {
2334: if ($i > 0) {
2335: $output .= '</tr>';
2336: }
2337: $output .= '<tr>';
2338: }
2339: } elsif ($i==@{$types}-1) {
2340: my $colsleft = $numinrow - $rem;
2341: if ($colsleft > 1) {
2342: $lastcolspan = ' colspan="'.$colsleft.'"';
2343: }
2344: }
2345: my $check = ' ';
2346: if (grep(/^\Q$types->[$i]\E$/,@currtypes)) {
2347: $check = ' checked="checked" ';
2348: }
2349: $output .= '<td class="LC_left_item"'.$lastcolspan.'>'.
2350: '<span class="LC_nobreak"><label>'.
2351: '<input type="checkbox" name="inststatus" '.
2352: 'value="'.$types->[$i].'"'.$check.'/>'.
2353: $usertypes->{$types->[$i]}.'</label></span></td>';
2354: }
2355: }
2356: $output .= '</tr></table>';
2357: }
2358: return $output;
2359: }
2360:
1.257 raeburn 2361: sub selfcreate_canmodify {
2362: my ($context,$dom,$userinfo,$inst_results,$rolesarray) = @_;
2363: if (ref($inst_results) eq 'HASH') {
2364: my @inststatuses = &get_inststatuses($inst_results);
2365: if (@inststatuses == 0) {
2366: @inststatuses = ('default');
2367: }
2368: $rolesarray = \@inststatuses;
2369: }
2370: my %canmodify =
2371: &Apache::lonuserutils::can_modify_userinfo($context,$dom,$userinfo,
2372: $rolesarray);
2373: return %canmodify;
2374: }
2375:
1.252 raeburn 2376: sub get_inststatuses {
2377: my ($insthashref) = @_;
2378: my @inststatuses = ();
2379: if (ref($insthashref) eq 'HASH') {
2380: if (ref($insthashref->{'inststatus'}) eq 'ARRAY') {
2381: @inststatuses = @{$insthashref->{'inststatus'}};
2382: }
2383: }
2384: return @inststatuses;
2385: }
2386:
1.4 www 2387: # ================================================================= Phase Three
1.42 matthew 2388: sub update_user_data {
1.375 raeburn 2389: my ($r,$context,$crstype,$brcrum,$showcredits) = @_;
1.101 albertel 2390: my $uhome=&Apache::lonnet::homeserver($env{'form.ccuname'},
2391: $env{'form.ccdomain'});
1.27 matthew 2392: # Error messages
1.188 raeburn 2393: my $error = '<span class="LC_error">'.&mt('Error').': ';
1.193 raeburn 2394: my $end = '</span><br /><br />';
2395: my $rtnlink = '<a href="javascript:backPage(document.userupdate,'.
1.188 raeburn 2396: "'$env{'form.prevphase'}','modify')".'" />'.
1.219 raeburn 2397: &mt('Return to previous page').'</a>'.
2398: &Apache::loncommon::end_page();
2399: my $now = time;
1.40 www 2400: my $title;
1.101 albertel 2401: if (exists($env{'form.makeuser'})) {
1.40 www 2402: $title='Set Privileges for New User';
2403: } else {
2404: $title='Modify User Privileges';
2405: }
1.213 raeburn 2406: my $newuser = 0;
1.160 raeburn 2407: my ($jsback,$elements) = &crumb_utilities();
2408: my $jscript = '<script type="text/javascript">'."\n".
1.301 bisitz 2409: '// <![CDATA['."\n".
2410: $jsback."\n".
2411: '// ]]>'."\n".
2412: '</script>'."\n";
1.318 raeburn 2413: my %breadcrumb_text = &singleuser_breadcrumb($crstype);
1.351 raeburn 2414: push (@{$brcrum},
2415: {href => "javascript:backPage(document.userupdate)",
2416: text => $breadcrumb_text{'search'},
2417: faq => 282,
2418: bug => 'Instructor Interface',}
2419: );
2420: if ($env{'form.prevphase'} eq 'userpicked') {
2421: push(@{$brcrum},
2422: {href => "javascript:backPage(document.userupdate,'get_user_info','select')",
2423: text => $breadcrumb_text{'userpicked'},
2424: faq => 282,
2425: bug => 'Instructor Interface',});
1.233 raeburn 2426: }
1.224 raeburn 2427: my $helpitem = 'Course_Change_Privileges';
2428: if ($env{'form.action'} eq 'singlestudent') {
2429: $helpitem = 'Course_Add_Student';
2430: }
1.351 raeburn 2431: push(@{$brcrum},
2432: {href => "javascript:backPage(document.userupdate,'$env{'form.prevphase'}','modify')",
2433: text => $breadcrumb_text{'modify'},
2434: faq => 282,
2435: bug => 'Instructor Interface',},
2436: {href => "/adm/createuser",
2437: text => "Result",
2438: faq => 282,
2439: bug => 'Instructor Interface',
2440: help => $helpitem});
2441: my $args = {bread_crumbs => $brcrum,
2442: bread_crumbs_component => 'User Management'};
2443: if ($env{'form.popup'}) {
2444: $args->{'no_nav_bar'} = 1;
2445: }
2446: $r->print(&Apache::loncommon::start_page($title,$jscript,$args));
1.188 raeburn 2447: $r->print(&update_result_form($uhome));
1.27 matthew 2448: # Check Inputs
1.101 albertel 2449: if (! $env{'form.ccuname'} ) {
1.193 raeburn 2450: $r->print($error.&mt('No login name specified').'.'.$end.$rtnlink);
1.27 matthew 2451: return;
2452: }
1.138 albertel 2453: if ( $env{'form.ccuname'} ne
2454: &LONCAPA::clean_username($env{'form.ccuname'}) ) {
1.281 bisitz 2455: $r->print($error.&mt('Invalid login name.').' '.
2456: &mt('Only letters, numbers, periods, dashes, @, and underscores are valid.').
1.193 raeburn 2457: $end.$rtnlink);
1.27 matthew 2458: return;
2459: }
1.101 albertel 2460: if (! $env{'form.ccdomain'} ) {
1.193 raeburn 2461: $r->print($error.&mt('No domain specified').'.'.$end.$rtnlink);
1.27 matthew 2462: return;
2463: }
1.138 albertel 2464: if ( $env{'form.ccdomain'} ne
2465: &LONCAPA::clean_domain($env{'form.ccdomain'}) ) {
1.281 bisitz 2466: $r->print($error.&mt('Invalid domain name.').' '.
2467: &mt('Only letters, numbers, periods, dashes, and underscores are valid.').
1.193 raeburn 2468: $end.$rtnlink);
1.27 matthew 2469: return;
2470: }
1.219 raeburn 2471: if ($uhome eq 'no_host') {
2472: $newuser = 1;
2473: }
1.101 albertel 2474: if (! exists($env{'form.makeuser'})) {
1.29 matthew 2475: # Modifying an existing user, so check the validity of the name
2476: if ($uhome eq 'no_host') {
1.73 sakharuk 2477: $r->print($error.&mt('Unable to determine home server for ').
1.101 albertel 2478: $env{'form.ccuname'}.&mt(' in domain ').
2479: $env{'form.ccdomain'}.'.');
1.29 matthew 2480: return;
2481: }
2482: }
1.27 matthew 2483: # Determine authentication method and password for the user being modified
2484: my $amode='';
2485: my $genpwd='';
1.101 albertel 2486: if ($env{'form.login'} eq 'krb') {
1.41 albertel 2487: $amode='krb';
1.101 albertel 2488: $amode.=$env{'form.krbver'};
2489: $genpwd=$env{'form.krbarg'};
2490: } elsif ($env{'form.login'} eq 'int') {
1.27 matthew 2491: $amode='internal';
1.101 albertel 2492: $genpwd=$env{'form.intarg'};
2493: } elsif ($env{'form.login'} eq 'fsys') {
1.27 matthew 2494: $amode='unix';
1.101 albertel 2495: $genpwd=$env{'form.fsysarg'};
2496: } elsif ($env{'form.login'} eq 'loc') {
1.27 matthew 2497: $amode='localauth';
1.101 albertel 2498: $genpwd=$env{'form.locarg'};
1.27 matthew 2499: $genpwd=" " if (!$genpwd);
1.101 albertel 2500: } elsif (($env{'form.login'} eq 'nochange') ||
2501: ($env{'form.login'} eq '' )) {
1.34 matthew 2502: # There is no need to tell the user we did not change what they
2503: # did not ask us to change.
1.35 matthew 2504: # If they are creating a new user but have not specified login
2505: # information this will be caught below.
1.30 matthew 2506: } else {
1.367 golterma 2507: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
2508: return;
1.27 matthew 2509: }
1.164 albertel 2510:
1.188 raeburn 2511: $r->print('<h3>'.&mt('User [_1] in domain [_2]',
1.367 golterma 2512: $env{'form.ccuname'}.' ('.&Apache::loncommon::plainname($env{'form.ccuname'},
2513: $env{'form.ccdomain'}).')', $env{'form.ccdomain'}).'</h3>');
2514: my %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($r,2);
1.344 bisitz 2515:
1.193 raeburn 2516: my (%alerts,%rulematch,%inst_results,%curr_rules);
1.334 raeburn 2517: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
1.361 raeburn 2518: my @usertools = ('aboutme','blog','webdav','portfolio');
1.384 raeburn 2519: my @requestcourses = ('official','unofficial','community','textbook');
1.362 raeburn 2520: my @requestauthor = ('requestauthor');
1.286 raeburn 2521: my ($othertitle,$usertypes,$types) =
2522: &Apache::loncommon::sorted_inst_types($env{'form.ccdomain'});
1.334 raeburn 2523: my %canmodify_status =
2524: &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},
2525: ['inststatus']);
1.101 albertel 2526: if ($env{'form.makeuser'}) {
1.164 albertel 2527: $r->print('<h3>'.&mt('Creating new account.').'</h3>');
1.27 matthew 2528: # Check for the authentication mode and password
2529: if (! $amode || ! $genpwd) {
1.193 raeburn 2530: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
1.27 matthew 2531: return;
1.18 albertel 2532: }
1.29 matthew 2533: # Determine desired host
1.101 albertel 2534: my $desiredhost = $env{'form.hserver'};
1.29 matthew 2535: if (lc($desiredhost) eq 'default') {
2536: $desiredhost = undef;
2537: } else {
1.147 albertel 2538: my %home_servers =
2539: &Apache::lonnet::get_servers($env{'form.ccdomain'},'library');
1.29 matthew 2540: if (! exists($home_servers{$desiredhost})) {
1.193 raeburn 2541: $r->print($error.&mt('Invalid home server specified').$end.$rtnlink);
2542: return;
2543: }
2544: }
2545: # Check ID format
2546: my %checkhash;
2547: my %checks = ('id' => 1);
2548: %{$checkhash{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}}} = (
1.219 raeburn 2549: 'newuser' => $newuser,
1.196 raeburn 2550: 'id' => $env{'form.cid'},
1.193 raeburn 2551: );
1.196 raeburn 2552: if ($env{'form.cid'} ne '') {
2553: &Apache::loncommon::user_rule_check(\%checkhash,\%checks,\%alerts,
2554: \%rulematch,\%inst_results,\%curr_rules);
2555: if (ref($alerts{'id'}) eq 'HASH') {
2556: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
2557: my $domdesc =
2558: &Apache::lonnet::domain($env{'form.ccdomain'},'description');
2559: if ($alerts{'id'}{$env{'form.ccdomain'}}{$env{'form.cid'}}) {
2560: my $userchkmsg;
2561: if (ref($curr_rules{$env{'form.ccdomain'}}) eq 'HASH') {
2562: $userchkmsg =
2563: &Apache::loncommon::instrule_disallow_msg('id',
2564: $domdesc,1).
2565: &Apache::loncommon::user_rule_formats($env{'form.ccdomain'},
2566: $domdesc,$curr_rules{$env{'form.ccdomain'}}{'id'},'id');
2567: }
2568: $r->print($error.&mt('Invalid ID format').$end.
2569: $userchkmsg.$rtnlink);
2570: return;
2571: }
2572: }
1.29 matthew 2573: }
2574: }
1.367 golterma 2575: &Apache::lonhtmlcommon::Increment_PrgWin($r, \%prog_state);
1.27 matthew 2576: # Call modifyuser
2577: my $result = &Apache::lonnet::modifyuser
1.193 raeburn 2578: ($env{'form.ccdomain'},$env{'form.ccuname'},$env{'form.cid'},
1.188 raeburn 2579: $amode,$genpwd,$env{'form.cfirstname'},
2580: $env{'form.cmiddlename'},$env{'form.clastname'},
2581: $env{'form.cgeneration'},undef,$desiredhost,
2582: $env{'form.cpermanentemail'});
1.77 www 2583: $r->print(&mt('Generating user').': '.$result);
1.219 raeburn 2584: $uhome = &Apache::lonnet::homeserver($env{'form.ccuname'},
1.101 albertel 2585: $env{'form.ccdomain'});
1.334 raeburn 2586: my (%changeHash,%newcustom,%changed,%changedinfo);
1.267 raeburn 2587: if ($uhome ne 'no_host') {
1.334 raeburn 2588: if ($context eq 'domain') {
1.378 raeburn 2589: foreach my $name ('portfolio','author') {
2590: if ($env{'form.custom_'.$name.'quota'} == 1) {
2591: if ($env{'form.'.$name.'quota'} eq '') {
2592: $newcustom{$name.'quota'} = 0;
2593: } else {
2594: $newcustom{$name.'quota'} = $env{'form.'.$name.'quota'};
2595: $newcustom{$name.'quota'} =~ s/[^\d\.]//g;
2596: }
2597: if ("a_admin($newcustom{$name.'quota'},\%changeHash,$name)) {
2598: $changed{$name.'quota'} = 1;
2599: }
1.334 raeburn 2600: }
2601: }
2602: foreach my $item (@usertools) {
2603: if ($env{'form.custom'.$item} == 1) {
2604: $newcustom{$item} = $env{'form.tools_'.$item};
2605: $changed{$item} = &tool_admin($item,$newcustom{$item},
2606: \%changeHash,'tools');
2607: }
1.267 raeburn 2608: }
1.334 raeburn 2609: foreach my $item (@requestcourses) {
1.341 raeburn 2610: if ($env{'form.custom'.$item} == 1) {
2611: $newcustom{$item} = $env{'form.crsreq_'.$item};
2612: if ($env{'form.crsreq_'.$item} eq 'autolimit') {
2613: $newcustom{$item} .= '=';
1.383 raeburn 2614: $env{'form.crsreq_'.$item.'_limit'} =~ s/\D+//g;
2615: if ($env{'form.crsreq_'.$item.'_limit'}) {
1.341 raeburn 2616: $newcustom{$item} .= $env{'form.crsreq_'.$item.'_limit'};
2617: }
1.334 raeburn 2618: }
1.341 raeburn 2619: $changed{$item} = &tool_admin($item,$newcustom{$item},
2620: \%changeHash,'requestcourses');
1.334 raeburn 2621: }
1.275 raeburn 2622: }
1.362 raeburn 2623: if ($env{'form.customrequestauthor'} == 1) {
2624: $newcustom{'requestauthor'} = $env{'form.requestauthor'};
2625: $changed{'requestauthor'} = &tool_admin('requestauthor',
2626: $newcustom{'requestauthor'},
2627: \%changeHash,'requestauthor');
2628: }
1.275 raeburn 2629: }
1.334 raeburn 2630: if ($canmodify_status{'inststatus'}) {
2631: if (exists($env{'form.inststatus'})) {
2632: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
2633: if (@inststatuses > 0) {
2634: $changeHash{'inststatus'} = join(',',@inststatuses);
2635: $changed{'inststatus'} = $changeHash{'inststatus'};
1.306 raeburn 2636: }
2637: }
1.232 raeburn 2638: }
1.334 raeburn 2639: if (keys(%changed)) {
2640: foreach my $item (@userinfo) {
2641: $changeHash{$item} = $env{'form.c'.$item};
1.286 raeburn 2642: }
1.267 raeburn 2643: my $chgresult =
2644: &Apache::lonnet::put('environment',\%changeHash,
2645: $env{'form.ccdomain'},$env{'form.ccuname'});
2646: }
1.232 raeburn 2647: }
1.219 raeburn 2648: $r->print('<br />'.&mt('Home server').': '.$uhome.' '.
2649: &Apache::lonnet::hostname($uhome));
1.101 albertel 2650: } elsif (($env{'form.login'} ne 'nochange') &&
2651: ($env{'form.login'} ne '' )) {
1.27 matthew 2652: # Modify user privileges
2653: if (! $amode || ! $genpwd) {
1.193 raeburn 2654: $r->print($error.'Invalid login mode or password'.$end.$rtnlink);
1.27 matthew 2655: return;
1.20 harris41 2656: }
1.27 matthew 2657: # Only allow authentification modification if the person has authority
1.101 albertel 2658: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.20 harris41 2659: $r->print('Modifying authentication: '.
1.31 matthew 2660: &Apache::lonnet::modifyuserauth(
1.101 albertel 2661: $env{'form.ccdomain'},$env{'form.ccuname'},
1.21 harris41 2662: $amode,$genpwd));
1.102 albertel 2663: $r->print('<br />'.&mt('Home server').': '.&Apache::lonnet::homeserver
1.101 albertel 2664: ($env{'form.ccuname'},$env{'form.ccdomain'}));
1.4 www 2665: } else {
1.27 matthew 2666: # Okay, this is a non-fatal error.
1.193 raeburn 2667: $r->print($error.&mt('You do not have the authority to modify this users authentification information').'.'.$end);
1.27 matthew 2668: }
1.28 matthew 2669: }
1.344 bisitz 2670: $r->rflush(); # Finish display of header before time consuming actions start
1.367 golterma 2671: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state);
1.28 matthew 2672: ##
1.375 raeburn 2673: my (@userroles,%userupdate,$cnum,$cdom,$defaultcredits,%namechanged);
1.213 raeburn 2674: if ($context eq 'course') {
1.375 raeburn 2675: ($cnum,$cdom) =
2676: &Apache::lonuserutils::get_course_identity();
1.318 raeburn 2677: $crstype = &Apache::loncommon::course_type($cdom.'_'.$cnum);
1.375 raeburn 2678: if ($showcredits) {
2679: $defaultcredits = &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
2680: }
1.213 raeburn 2681: }
1.101 albertel 2682: if (! $env{'form.makeuser'} ) {
1.28 matthew 2683: # Check for need to change
2684: my %userenv = &Apache::lonnet::get
1.134 raeburn 2685: ('environment',['firstname','middlename','lastname','generation',
1.378 raeburn 2686: 'id','permanentemail','portfolioquota','authorquota','inststatus',
2687: 'tools.aboutme','tools.blog','tools.webdav','tools.portfolio',
1.361 raeburn 2688: 'requestcourses.official','requestcourses.unofficial',
1.384 raeburn 2689: 'requestcourses.community','requestcourses.textbook',
2690: 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
2691: 'reqcrsotherdom.community','reqcrsotherdom.textbook',
1.362 raeburn 2692: 'requestauthor'],
1.160 raeburn 2693: $env{'form.ccdomain'},$env{'form.ccuname'});
1.28 matthew 2694: my ($tmp) = keys(%userenv);
2695: if ($tmp =~ /^(con_lost|error)/i) {
2696: %userenv = ();
2697: }
1.206 raeburn 2698: my $no_forceid_alert;
2699: # Check to see if user information can be changed
2700: my %domconfig =
2701: &Apache::lonnet::get_dom('configuration',['usermodification'],
2702: $env{'form.ccdomain'});
1.213 raeburn 2703: my @statuses = ('active','future');
2704: my %roles = &Apache::lonnet::get_my_roles($env{'form.ccuname'},$env{'form.ccdomain'},'userroles',\@statuses,undef,$env{'request.role.domain'});
2705: my ($auname,$audom);
1.220 raeburn 2706: if ($context eq 'author') {
1.206 raeburn 2707: $auname = $env{'user.name'};
2708: $audom = $env{'user.domain'};
2709: }
2710: foreach my $item (keys(%roles)) {
1.220 raeburn 2711: my ($rolenum,$roledom,$role) = split(/:/,$item,-1);
1.206 raeburn 2712: if ($context eq 'course') {
2713: if ($cnum ne '' && $cdom ne '') {
2714: if ($rolenum eq $cnum && $roledom eq $cdom) {
2715: if (!grep(/^\Q$role\E$/,@userroles)) {
2716: push(@userroles,$role);
2717: }
2718: }
2719: }
2720: } elsif ($context eq 'author') {
2721: if ($rolenum eq $auname && $roledom eq $audom) {
2722: if (!grep(/^\Q$role\E$/,@userroles)) {
2723: push(@userroles,$role);
2724: }
2725: }
2726: }
2727: }
1.220 raeburn 2728: if ($env{'form.action'} eq 'singlestudent') {
2729: if (!grep(/^st$/,@userroles)) {
2730: push(@userroles,'st');
2731: }
2732: } else {
2733: # Check for course or co-author roles being activated or re-enabled
2734: if ($context eq 'author' || $context eq 'course') {
2735: foreach my $key (keys(%env)) {
2736: if ($context eq 'author') {
2737: if ($key=~/^form\.act_\Q$audom\E_\Q$auname\E_([^_]+)/) {
2738: if (!grep(/^\Q$1\E$/,@userroles)) {
2739: push(@userroles,$1);
2740: }
2741: } elsif ($key =~/^form\.ren\:\Q$audom\E\/\Q$auname\E_([^_]+)/) {
2742: if (!grep(/^\Q$1\E$/,@userroles)) {
2743: push(@userroles,$1);
2744: }
1.206 raeburn 2745: }
1.220 raeburn 2746: } elsif ($context eq 'course') {
2747: if ($key=~/^form\.act_\Q$cdom\E_\Q$cnum\E_([^_]+)/) {
2748: if (!grep(/^\Q$1\E$/,@userroles)) {
2749: push(@userroles,$1);
2750: }
2751: } elsif ($key =~/^form\.ren\:\Q$cdom\E\/\Q$cnum\E(\/?\w*)_([^_]+)/) {
2752: if (!grep(/^\Q$1\E$/,@userroles)) {
2753: push(@userroles,$1);
2754: }
1.206 raeburn 2755: }
2756: }
2757: }
2758: }
2759: }
2760: #Check to see if we can change personal data for the user
2761: my (@mod_disallowed,@longroles);
2762: foreach my $role (@userroles) {
2763: if ($role eq 'cr') {
2764: push(@longroles,'Custom');
2765: } else {
1.318 raeburn 2766: push(@longroles,&Apache::lonnet::plaintext($role,$crstype));
1.206 raeburn 2767: }
2768: }
1.219 raeburn 2769: my %canmodify = &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},\@userinfo,\@userroles);
2770: foreach my $item (@userinfo) {
1.28 matthew 2771: # Strip leading and trailing whitespace
1.203 raeburn 2772: $env{'form.c'.$item} =~ s/(\s+$|^\s+)//g;
1.219 raeburn 2773: if (!$canmodify{$item}) {
1.207 raeburn 2774: if (defined($env{'form.c'.$item})) {
2775: if ($env{'form.c'.$item} ne $userenv{$item}) {
2776: push(@mod_disallowed,$item);
2777: }
1.206 raeburn 2778: }
2779: $env{'form.c'.$item} = $userenv{$item};
2780: }
1.28 matthew 2781: }
1.259 bisitz 2782: # Check to see if we can change the Student/Employee ID
1.196 raeburn 2783: my $forceid = $env{'form.forceid'};
2784: my $recurseid = $env{'form.recurseid'};
2785: my (%alerts,%rulematch,%idinst_results,%curr_rules,%got_rules);
1.203 raeburn 2786: my %uidhash = &Apache::lonnet::idrget($env{'form.ccdomain'},
2787: $env{'form.ccuname'});
2788: if (($uidhash{$env{'form.ccuname'}}) &&
2789: ($uidhash{$env{'form.ccuname'}}!~/error\:/) &&
2790: (!$forceid)) {
2791: if ($env{'form.cid'} ne $uidhash{$env{'form.ccuname'}}) {
2792: $env{'form.cid'} = $userenv{'id'};
1.293 bisitz 2793: $no_forceid_alert = &mt('New student/employee ID does not match existing ID for this user.')
1.259 bisitz 2794: .'<br />'
2795: .&mt("Change is not permitted without checking the 'Force ID change' checkbox on the previous page.")
2796: .'<br />'."\n";
1.203 raeburn 2797: }
2798: }
2799: if ($env{'form.cid'} ne $userenv{'id'}) {
1.196 raeburn 2800: my $checkhash;
2801: my $checks = { 'id' => 1 };
2802: $checkhash->{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}} =
2803: { 'newuser' => $newuser,
2804: 'id' => $env{'form.cid'},
2805: };
2806: &Apache::loncommon::user_rule_check($checkhash,$checks,
2807: \%alerts,\%rulematch,\%idinst_results,\%curr_rules,\%got_rules);
2808: if (ref($alerts{'id'}) eq 'HASH') {
2809: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
1.203 raeburn 2810: $env{'form.cid'} = $userenv{'id'};
1.196 raeburn 2811: }
2812: }
2813: }
1.378 raeburn 2814: my (%quotachanged,%oldquota,%newquota,%olddefquota,%newdefquota,
2815: $oldinststatus,$newinststatus,%oldisdefault,%newisdefault,%oldsettings,
1.339 raeburn 2816: %oldsettingstext,%newsettings,%newsettingstext,@disporder,
1.378 raeburn 2817: %oldsettingstatus,%newsettingstatus);
1.334 raeburn 2818: @disporder = ('inststatus');
2819: if ($env{'request.role.domain'} eq $env{'form.ccdomain'}) {
1.362 raeburn 2820: push(@disporder,'requestcourses','requestauthor');
1.334 raeburn 2821: } else {
2822: push(@disporder,'reqcrsotherdom');
2823: }
2824: push(@disporder,('quota','tools'));
1.338 raeburn 2825: $oldinststatus = $userenv{'inststatus'};
1.378 raeburn 2826: foreach my $name ('portfolio','author') {
2827: ($olddefquota{$name},$oldsettingstatus{$name}) =
2828: &Apache::loncommon::default_quota($env{'form.ccdomain'},$oldinststatus,$name);
2829: ($newdefquota{$name},$newsettingstatus{$name}) = ($olddefquota{$name},$oldsettingstatus{$name});
2830: }
1.334 raeburn 2831: my %canshow;
1.220 raeburn 2832: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
1.334 raeburn 2833: $canshow{'quota'} = 1;
1.220 raeburn 2834: }
1.267 raeburn 2835: if (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
1.334 raeburn 2836: $canshow{'tools'} = 1;
1.267 raeburn 2837: }
1.275 raeburn 2838: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
1.334 raeburn 2839: $canshow{'requestcourses'} = 1;
1.300 raeburn 2840: } elsif (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.334 raeburn 2841: $canshow{'reqcrsotherdom'} = 1;
1.275 raeburn 2842: }
1.286 raeburn 2843: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.334 raeburn 2844: $canshow{'inststatus'} = 1;
1.286 raeburn 2845: }
1.362 raeburn 2846: if (&Apache::lonnet::allowed('cau',$env{'form.ccdomain'})) {
2847: $canshow{'requestauthor'} = 1;
2848: }
1.267 raeburn 2849: my (%changeHash,%changed);
1.286 raeburn 2850: if ($oldinststatus eq '') {
1.334 raeburn 2851: $oldsettings{'inststatus'} = $othertitle;
1.286 raeburn 2852: } else {
2853: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 2854: $oldsettings{'inststatus'} = join(', ',map{ $usertypes->{ &unescape($_) }; } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 2855: } else {
1.334 raeburn 2856: $oldsettings{'inststatus'} = join(', ',map{ &unescape($_); } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 2857: }
2858: }
2859: $changeHash{'inststatus'} = $userenv{'inststatus'};
1.334 raeburn 2860: if ($canmodify_status{'inststatus'}) {
2861: $canshow{'inststatus'} = 1;
1.286 raeburn 2862: if (exists($env{'form.inststatus'})) {
2863: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
2864: if (@inststatuses > 0) {
2865: $newinststatus = join(':',map { &escape($_); } @inststatuses);
2866: $changeHash{'inststatus'} = $newinststatus;
2867: if ($newinststatus ne $oldinststatus) {
2868: $changed{'inststatus'} = $newinststatus;
1.378 raeburn 2869: foreach my $name ('portfolio','author') {
2870: ($newdefquota{$name},$newsettingstatus{$name}) =
2871: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
2872: }
1.286 raeburn 2873: }
2874: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 2875: $newsettings{'inststatus'} = join(', ',map{ $usertypes->{$_}; } (@inststatuses));
1.286 raeburn 2876: } else {
1.337 raeburn 2877: $newsettings{'inststatus'} = join(', ',@inststatuses);
1.286 raeburn 2878: }
1.334 raeburn 2879: }
2880: } else {
2881: $newinststatus = '';
2882: $changeHash{'inststatus'} = $newinststatus;
2883: $newsettings{'inststatus'} = $othertitle;
2884: if ($newinststatus ne $oldinststatus) {
2885: $changed{'inststatus'} = $changeHash{'inststatus'};
1.378 raeburn 2886: foreach my $name ('portfolio','author') {
2887: ($newdefquota{$name},$newsettingstatus{$name}) =
2888: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
2889: }
1.286 raeburn 2890: }
2891: }
1.334 raeburn 2892: } elsif ($context ne 'selfcreate') {
2893: $canshow{'inststatus'} = 1;
1.337 raeburn 2894: $newsettings{'inststatus'} = $oldsettings{'inststatus'};
1.286 raeburn 2895: }
1.378 raeburn 2896: foreach my $name ('portfolio','author') {
2897: $changeHash{$name.'quota'} = $userenv{$name.'quota'};
2898: }
1.334 raeburn 2899: if ($context eq 'domain') {
1.378 raeburn 2900: foreach my $name ('portfolio','author') {
2901: if ($userenv{$name.'quota'} ne '') {
2902: $oldquota{$name} = $userenv{$name.'quota'};
2903: if ($env{'form.custom_'.$name.'quota'} == 1) {
2904: if ($env{'form.'.$name.'quota'} eq '') {
2905: $newquota{$name} = 0;
2906: } else {
2907: $newquota{$name} = $env{'form.'.$name.'quota'};
2908: $newquota{$name} =~ s/[^\d\.]//g;
2909: }
2910: if ($newquota{$name} != $oldquota{$name}) {
2911: if ("a_admin($newquota{$name},\%changeHash,$name)) {
2912: $changed{$name.'quota'} = 1;
2913: }
2914: }
1.334 raeburn 2915: } else {
1.378 raeburn 2916: if ("a_admin('',\%changeHash,$name)) {
2917: $changed{$name.'quota'} = 1;
2918: $newquota{$name} = $newdefquota{$name};
2919: $newisdefault{$name} = 1;
2920: }
1.334 raeburn 2921: }
1.149 raeburn 2922: } else {
1.378 raeburn 2923: $oldisdefault{$name} = 1;
2924: $oldquota{$name} = $olddefquota{$name};
2925: if ($env{'form.custom_'.$name.'quota'} == 1) {
2926: if ($env{'form.'.$name.'quota'} eq '') {
2927: $newquota{$name} = 0;
2928: } else {
2929: $newquota{$name} = $env{'form.'.$name.'quota'};
2930: $newquota{$name} =~ s/[^\d\.]//g;
2931: }
2932: if ("a_admin($newquota{$name},\%changeHash,$name)) {
2933: $changed{$name.'quota'} = 1;
2934: }
1.334 raeburn 2935: } else {
1.378 raeburn 2936: $newquota{$name} = $newdefquota{$name};
2937: $newisdefault{$name} = 1;
1.334 raeburn 2938: }
1.378 raeburn 2939: }
2940: if ($oldisdefault{$name}) {
2941: $oldsettingstext{'quota'}{$name} = &get_defaultquota_text($oldsettingstatus{$name});
1.383 raeburn 2942: } else {
2943: $oldsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$oldquota{$name});
1.378 raeburn 2944: }
2945: if ($newisdefault{$name}) {
2946: $newsettingstext{'quota'}{$name} = &get_defaultquota_text($newsettingstatus{$name});
1.383 raeburn 2947: } else {
2948: $newsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$newquota{$name});
1.134 raeburn 2949: }
2950: }
1.334 raeburn 2951: &tool_changes('tools',\@usertools,\%oldsettings,\%oldsettingstext,\%userenv,
2952: \%changeHash,\%changed,\%newsettings,\%newsettingstext);
2953: if ($env{'form.ccdomain'} eq $env{'request.role.domain'}) {
2954: &tool_changes('requestcourses',\@requestcourses,\%oldsettings,\%oldsettingstext,
2955: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.384 raeburn 2956: &tool_changes('requestauthor',\@requestauthor,\%oldsettings,\%oldsettingstext,
2957: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 2958: } else {
1.334 raeburn 2959: &tool_changes('reqcrsotherdom',\@requestcourses,\%oldsettings,\%oldsettingstext,
2960: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 2961: }
2962: }
1.334 raeburn 2963: foreach my $item (@userinfo) {
2964: if ($env{'form.c'.$item} ne $userenv{$item}) {
2965: $namechanged{$item} = 1;
2966: }
1.204 raeburn 2967: }
1.378 raeburn 2968: foreach my $name ('portfolio','author') {
1.383 raeburn 2969: $oldsettings{'quota'}{$name} = $oldquota{$name}.' MB';
2970: $newsettings{'quota'}{$name} = $newquota{$name}.' MB';
1.378 raeburn 2971: }
1.334 raeburn 2972: if ((keys(%namechanged) > 0) || (keys(%changed) > 0)) {
1.267 raeburn 2973: my ($chgresult,$namechgresult);
2974: if (keys(%changed) > 0) {
2975: $chgresult =
1.204 raeburn 2976: &Apache::lonnet::put('environment',\%changeHash,
2977: $env{'form.ccdomain'},$env{'form.ccuname'});
1.267 raeburn 2978: if ($chgresult eq 'ok') {
2979: if (($env{'user.name'} eq $env{'form.ccuname'}) &&
2980: ($env{'user.domain'} eq $env{'form.ccdomain'})) {
1.270 raeburn 2981: my %newenvhash;
2982: foreach my $key (keys(%changed)) {
1.299 raeburn 2983: if (($key eq 'official') || ($key eq 'unofficial')
2984: || ($key eq 'community')) {
1.279 raeburn 2985: $newenvhash{'environment.requestcourses.'.$key} =
2986: $changeHash{'requestcourses.'.$key};
1.362 raeburn 2987: if ($changeHash{'requestcourses.'.$key}) {
1.332 raeburn 2988: $newenvhash{'environment.canrequest.'.$key} = 1;
1.279 raeburn 2989: } else {
2990: $newenvhash{'environment.canrequest.'.$key} =
2991: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
2992: $key,'reload','requestcourses');
2993: }
1.362 raeburn 2994: } elsif ($key eq 'requestauthor') {
2995: $newenvhash{'environment.'.$key} = $changeHash{$key};
2996: if ($changeHash{$key}) {
2997: $newenvhash{'environment.canrequest.author'} = 1;
2998: } else {
2999: $newenvhash{'environment.canrequest.author'} =
3000: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3001: $key,'reload','requestauthor');
3002: }
1.275 raeburn 3003: } elsif ($key ne 'quota') {
1.270 raeburn 3004: $newenvhash{'environment.tools.'.$key} =
3005: $changeHash{'tools.'.$key};
1.279 raeburn 3006: if ($changeHash{'tools.'.$key} ne '') {
3007: $newenvhash{'environment.availabletools.'.$key} =
3008: $changeHash{'tools.'.$key};
3009: } else {
3010: $newenvhash{'environment.availabletools.'.$key} =
1.367 golterma 3011: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3012: $key,'reload','tools');
1.279 raeburn 3013: }
1.270 raeburn 3014: }
3015: }
1.271 raeburn 3016: if (keys(%newenvhash)) {
3017: &Apache::lonnet::appenv(\%newenvhash);
3018: }
1.267 raeburn 3019: }
3020: }
1.204 raeburn 3021: }
1.334 raeburn 3022: if (keys(%namechanged) > 0) {
1.337 raeburn 3023: foreach my $field (@userinfo) {
3024: $changeHash{$field} = $env{'form.c'.$field};
3025: }
3026: # Make the change
1.204 raeburn 3027: $namechgresult =
3028: &Apache::lonnet::modifyuser($env{'form.ccdomain'},
3029: $env{'form.ccuname'},$changeHash{'id'},undef,undef,
3030: $changeHash{'firstname'},$changeHash{'middlename'},
3031: $changeHash{'lastname'},$changeHash{'generation'},
1.337 raeburn 3032: $changeHash{'id'},undef,$changeHash{'permanentemail'},undef,\@userinfo);
1.220 raeburn 3033: %userupdate = (
3034: lastname => $env{'form.clastname'},
3035: middlename => $env{'form.cmiddlename'},
3036: firstname => $env{'form.cfirstname'},
3037: generation => $env{'form.cgeneration'},
3038: id => $env{'form.cid'},
3039: );
1.204 raeburn 3040: }
1.334 raeburn 3041: if (((keys(%namechanged) > 0) && $namechgresult eq 'ok') ||
1.267 raeburn 3042: ((keys(%changed) > 0) && $chgresult eq 'ok')) {
1.28 matthew 3043: # Tell the user we changed the name
1.334 raeburn 3044: &display_userinfo($r,1,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 3045: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,
1.334 raeburn 3046: \%oldsettings, \%oldsettingstext,\%newsettings,
3047: \%newsettingstext);
1.203 raeburn 3048: if ($env{'form.cid'} ne $userenv{'id'}) {
3049: &Apache::lonnet::idput($env{'form.ccdomain'},
3050: ($env{'form.ccuname'} => $env{'form.cid'}));
3051: if (($recurseid) &&
3052: (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}))) {
3053: my $idresult =
3054: &Apache::lonuserutils::propagate_id_change(
3055: $env{'form.ccuname'},$env{'form.ccdomain'},
3056: \%userupdate);
3057: $r->print('<br />'.$idresult.'<br />');
3058: }
1.196 raeburn 3059: }
1.149 raeburn 3060: if (($env{'form.ccdomain'} eq $env{'user.domain'}) &&
3061: ($env{'form.ccuname'} eq $env{'user.name'})) {
3062: my %newenvhash;
3063: foreach my $key (keys(%changeHash)) {
3064: $newenvhash{'environment.'.$key} = $changeHash{$key};
3065: }
1.238 raeburn 3066: &Apache::lonnet::appenv(\%newenvhash);
1.149 raeburn 3067: }
1.28 matthew 3068: } else { # error occurred
1.188 raeburn 3069: $r->print('<span class="LC_error">'.&mt('Unable to successfully change environment for').' '.
3070: $env{'form.ccuname'}.' '.&mt('in domain').' '.
1.206 raeburn 3071: $env{'form.ccdomain'}.'</span><br />');
1.28 matthew 3072: }
1.334 raeburn 3073: } else { # End of if ($env ... ) logic
1.275 raeburn 3074: # They did not want to change the users name, quota, tool availability,
3075: # or ability to request creation of courses,
1.267 raeburn 3076: # but we can still tell them what the name and quota and availabilities are
1.334 raeburn 3077: &display_userinfo($r,undef,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 3078: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,\%oldsettings,
1.334 raeburn 3079: \%oldsettingstext,\%newsettings,\%newsettingstext);
1.28 matthew 3080: }
1.206 raeburn 3081: if (@mod_disallowed) {
3082: my ($rolestr,$contextname);
3083: if (@longroles > 0) {
3084: $rolestr = join(', ',@longroles);
3085: } else {
3086: $rolestr = &mt('No roles');
3087: }
3088: if ($context eq 'course') {
3089: $contextname = &mt('course');
3090: } elsif ($context eq 'author') {
3091: $contextname = &mt('co-author');
3092: }
3093: $r->print(&mt('The following fields were not updated: ').'<ul>');
3094: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
3095: foreach my $field (@mod_disallowed) {
3096: $r->print('<li>'.$fieldtitles{$field}.'</li>'."\n");
3097: }
1.207 raeburn 3098: $r->print('</ul>');
3099: if (@mod_disallowed == 1) {
3100: $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));
3101: } else {
3102: $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));
3103: }
1.292 bisitz 3104: my $helplink = 'javascript:helpMenu('."'display'".')';
3105: $r->print('<span class="LC_cusr_emph">'.$rolestr.'</span><br />'
3106: .&mt('Please contact your [_1]helpdesk[_2] for more information.'
3107: ,'<a href="'.$helplink.'">','</a>')
3108: .'<br />');
1.206 raeburn 3109: }
1.259 bisitz 3110: $r->print('<span class="LC_warning">'
3111: .$no_forceid_alert
3112: .&Apache::lonuserutils::print_namespacing_alerts($env{'form.ccdomain'},\%alerts,\%curr_rules)
3113: .'</span>');
1.4 www 3114: }
1.367 golterma 3115: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1.220 raeburn 3116: if ($env{'form.action'} eq 'singlestudent') {
1.375 raeburn 3117: &enroll_single_student($r,$uhome,$amode,$genpwd,$now,$newuser,$context,
3118: $crstype,$showcredits,$defaultcredits);
1.318 raeburn 3119: $r->print('<p><a href="javascript:backPage(document.userupdate)">');
3120: if ($crstype eq 'Community') {
3121: $r->print(&mt('Enroll Another Member'));
3122: } else {
3123: $r->print(&mt('Enroll Another Student'));
3124: }
3125: $r->print('</a></p>');
1.220 raeburn 3126: } else {
1.375 raeburn 3127: my @rolechanges = &update_roles($r,$context,$showcredits);
1.334 raeburn 3128: if (keys(%namechanged) > 0) {
1.220 raeburn 3129: if ($context eq 'course') {
3130: if (@userroles > 0) {
1.225 raeburn 3131: if ((@rolechanges == 0) ||
3132: (!(grep(/^st$/,@rolechanges)))) {
3133: if (grep(/^st$/,@userroles)) {
3134: my $classlistupdated =
3135: &Apache::lonuserutils::update_classlist($cdom,
1.220 raeburn 3136: $cnum,$env{'form.ccdomain'},
3137: $env{'form.ccuname'},\%userupdate);
1.225 raeburn 3138: }
1.220 raeburn 3139: }
3140: }
3141: }
3142: }
1.226 raeburn 3143: my $userinfo = &Apache::loncommon::plainname($env{'form.ccuname'},
1.233 raeburn 3144: $env{'form.ccdomain'});
3145: if ($env{'form.popup'}) {
3146: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
3147: } else {
1.367 golterma 3148: $r->print('<br />'.&Apache::lonhtmlcommon::actionbox(['<a href="javascript:backPage(document.userupdate,'."'$env{'form.prevphase'}','modify'".')">'
3149: .&mt('Modify this user: [_1]','<span class="LC_cusr_emph">'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.' ('.$userinfo.')</span>').'</a>',
3150: '<a href="javascript:backPage(document.userupdate)">'.&mt('Create/Modify Another User').'</a>']));
1.233 raeburn 3151: }
1.220 raeburn 3152: }
3153: }
3154:
1.334 raeburn 3155: sub display_userinfo {
1.362 raeburn 3156: my ($r,$changed,$order,$canshow,$requestcourses,$usertools,$requestauthor,
3157: $userenv,$changedhash,$namechangedhash,$oldsetting,$oldsettingtext,
1.334 raeburn 3158: $newsetting,$newsettingtext) = @_;
3159: return unless (ref($order) eq 'ARRAY' &&
3160: ref($canshow) eq 'HASH' &&
3161: ref($requestcourses) eq 'ARRAY' &&
1.362 raeburn 3162: ref($requestauthor) eq 'ARRAY' &&
1.334 raeburn 3163: ref($usertools) eq 'ARRAY' &&
3164: ref($userenv) eq 'HASH' &&
3165: ref($changedhash) eq 'HASH' &&
3166: ref($oldsetting) eq 'HASH' &&
3167: ref($oldsettingtext) eq 'HASH' &&
3168: ref($newsetting) eq 'HASH' &&
3169: ref($newsettingtext) eq 'HASH');
3170: my %lt=&Apache::lonlocal::texthash(
1.372 raeburn 3171: 'ui' => 'User Information',
1.334 raeburn 3172: 'uic' => 'User Information Changed',
3173: 'firstname' => 'First Name',
3174: 'middlename' => 'Middle Name',
3175: 'lastname' => 'Last Name',
3176: 'generation' => 'Generation',
3177: 'id' => 'Student/Employee ID',
3178: 'permanentemail' => 'Permanent e-mail address',
1.378 raeburn 3179: 'portfolioquota' => 'Disk space allocated to portfolio files',
1.385 ! bisitz 3180: 'authorquota' => 'Disk space allocated to Authoring Space',
1.334 raeburn 3181: 'blog' => 'Blog Availability',
1.361 raeburn 3182: 'webdav' => 'WebDAV Availability',
1.334 raeburn 3183: 'aboutme' => 'Personal Information Page Availability',
3184: 'portfolio' => 'Portfolio Availability',
3185: 'official' => 'Can Request Official Courses',
3186: 'unofficial' => 'Can Request Unofficial Courses',
3187: 'community' => 'Can Request Communities',
1.384 raeburn 3188: 'textbook' => 'Can Request Textbook Courses',
1.362 raeburn 3189: 'requestauthor' => 'Can Request Author Role',
1.334 raeburn 3190: 'inststatus' => "Affiliation",
3191: 'prvs' => 'Previous Value:',
3192: 'chto' => 'Changed To:'
3193: );
3194: if ($changed) {
1.372 raeburn 3195: $r->print('<h3>'.$lt{'uic'}.'</h3>'.
1.367 golterma 3196: &Apache::loncommon::start_data_table().
3197: &Apache::loncommon::start_data_table_header_row());
1.334 raeburn 3198: $r->print("<th> </th>\n");
1.367 golterma 3199: $r->print('<th><b>'.$lt{'prvs'}.'</b></th>');
3200: $r->print('<th><span class="LC_nobreak"><b>'.$lt{'chto'}.'</b></span></th>');
3201: $r->print(&Apache::loncommon::end_data_table_header_row());
3202: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
3203:
1.334 raeburn 3204: foreach my $item (@userinfo) {
3205: my $value = $env{'form.c'.$item};
1.367 golterma 3206: #show changes only:
1.383 raeburn 3207: unless ($value eq $userenv->{$item}){
1.367 golterma 3208: $r->print(&Apache::loncommon::start_data_table_row());
3209: $r->print("<td>$lt{$item}</td>\n");
1.383 raeburn 3210: $r->print("<td>".$userenv->{$item}."</td>\n");
1.367 golterma 3211: $r->print("<td>$value </td>\n");
3212: $r->print(&Apache::loncommon::end_data_table_row());
1.334 raeburn 3213: }
3214: }
3215: foreach my $entry (@{$order}) {
1.383 raeburn 3216: if ($canshow->{$entry}) {
3217: if (($entry eq 'requestcourses') || ($entry eq 'reqcrsotherdom') || ($entry eq 'requestauthor')) {
3218: my @items;
3219: if ($entry eq 'requestauthor') {
3220: @items = ($entry);
3221: } else {
3222: @items = @{$requestcourses};
1.384 raeburn 3223: }
1.383 raeburn 3224: foreach my $item (@items) {
3225: if (($newsetting->{$item} ne $oldsetting->{$item}) ||
3226: ($newsettingtext->{$item} ne $oldsettingtext->{$item})) {
3227: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3228: $r->print("<td>$lt{$item}</td>\n");
3229: $r->print("<td>".$oldsetting->{$item});
3230: if ($oldsettingtext->{$item}) {
3231: if ($oldsetting->{$item}) {
3232: $r->print(' -- ');
3233: }
3234: $r->print($oldsettingtext->{$item});
3235: }
3236: $r->print("</td>\n");
3237: $r->print("<td>".$newsetting->{$item});
3238: if ($newsettingtext->{$item}) {
3239: if ($newsetting->{$item}) {
3240: $r->print(' -- ');
3241: }
3242: $r->print($newsettingtext->{$item});
3243: }
3244: $r->print("</td>\n");
3245: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3246: }
3247: }
3248: } elsif ($entry eq 'tools') {
3249: foreach my $item (@{$usertools}) {
1.383 raeburn 3250: if ($newsetting->{$item} ne $oldsetting->{$item}) {
3251: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3252: $r->print("<td>$lt{$item}</td>\n");
3253: $r->print("<td>".$oldsetting->{$item}.' '.$oldsettingtext->{$item}."</td>\n");
3254: $r->print("<td>".$newsetting->{$item}.' '.$newsettingtext->{$item}."</td>\n");
3255: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3256: }
3257: }
1.378 raeburn 3258: } elsif ($entry eq 'quota') {
3259: if ((ref($oldsetting->{$entry}) eq 'HASH') && (ref($oldsettingtext->{$entry}) eq 'HASH') &&
3260: (ref($newsetting->{$entry}) eq 'HASH') && (ref($newsettingtext->{$entry}) eq 'HASH')) {
3261: foreach my $name ('portfolio','author') {
1.383 raeburn 3262: if ($newsetting->{$entry}->{$name} ne $oldsetting->{$entry}->{$name}) {
3263: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3264: $r->print("<td>$lt{$name.$entry}</td>\n");
3265: $r->print("<td>".$oldsettingtext->{$entry}->{$name}."</td>\n");
3266: $r->print("<td>".$newsettingtext->{$entry}->{$name}."</td>\n");
3267: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.378 raeburn 3268: }
3269: }
3270: }
1.334 raeburn 3271: } else {
1.383 raeburn 3272: if ($newsetting->{$entry} ne $oldsetting->{$entry}) {
3273: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3274: $r->print("<td>$lt{$entry}</td>\n");
3275: $r->print("<td>".$oldsetting->{$entry}.' '.$oldsettingtext->{$entry}."</td>\n");
3276: $r->print("<td>".$newsetting->{$entry}.' '.$newsettingtext->{$entry}."</td>\n");
3277: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3278: }
3279: }
3280: }
3281: }
1.367 golterma 3282: $r->print(&Apache::loncommon::end_data_table().'<br />');
1.372 raeburn 3283: } else {
3284: $r->print('<h3>'.$lt{'ui'}.'</h3>'.
3285: '<p>'.&mt('No changes made to user information').'</p>');
1.334 raeburn 3286: }
3287: return;
3288: }
3289:
1.275 raeburn 3290: sub tool_changes {
3291: my ($context,$usertools,$oldaccess,$oldaccesstext,$userenv,$changeHash,
3292: $changed,$newaccess,$newaccesstext) = @_;
3293: if (!((ref($usertools) eq 'ARRAY') && (ref($oldaccess) eq 'HASH') &&
3294: (ref($oldaccesstext) eq 'HASH') && (ref($userenv) eq 'HASH') &&
3295: (ref($changeHash) eq 'HASH') && (ref($changed) eq 'HASH') &&
3296: (ref($newaccess) eq 'HASH') && (ref($newaccesstext) eq 'HASH'))) {
3297: return;
3298: }
1.383 raeburn 3299: my %reqdisplay = &requestchange_display();
1.300 raeburn 3300: if ($context eq 'reqcrsotherdom') {
1.309 raeburn 3301: my @options = ('approval','validate','autolimit');
1.306 raeburn 3302: my $optregex = join('|',@options);
1.300 raeburn 3303: my $cdom = $env{'request.role.domain'};
3304: foreach my $tool (@{$usertools}) {
1.383 raeburn 3305: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
1.314 raeburn 3306: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
1.300 raeburn 3307: $changeHash->{$context.'.'.$tool} = $userenv->{$context.'.'.$tool};
1.383 raeburn 3308: my ($newop,$limit);
1.314 raeburn 3309: if ($env{'form.'.$context.'_'.$tool}) {
3310: $newop = $env{'form.'.$context.'_'.$tool};
3311: if ($newop eq 'autolimit') {
1.383 raeburn 3312: $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
1.314 raeburn 3313: $limit =~ s/\D+//g;
3314: $newop .= '='.$limit;
3315: }
3316: }
1.300 raeburn 3317: if ($userenv->{$context.'.'.$tool} eq '') {
1.314 raeburn 3318: if ($newop) {
3319: $changed->{$tool}=&tool_admin($tool,$cdom.':'.$newop,
1.300 raeburn 3320: $changeHash,$context);
3321: if ($changed->{$tool}) {
1.383 raeburn 3322: if ($newop =~ /^autolimit/) {
3323: if ($limit) {
3324: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3325: } else {
3326: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3327: }
3328: } else {
3329: $newaccesstext->{$tool} = $reqdisplay{$newop};
3330: }
1.300 raeburn 3331: } else {
3332: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3333: }
3334: }
3335: } else {
3336: my @curr = split(',',$userenv->{$context.'.'.$tool});
3337: my @new;
3338: my $changedoms;
1.314 raeburn 3339: foreach my $req (@curr) {
3340: if ($req =~ /^\Q$cdom\E\:($optregex\=?\d*)$/) {
3341: my $oldop = $1;
1.383 raeburn 3342: if ($oldop =~ /^autolimit=(\d*)/) {
3343: my $limit = $1;
3344: if ($limit) {
3345: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3346: } else {
3347: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3348: }
3349: } else {
3350: $oldaccesstext->{$tool} = $reqdisplay{$oldop};
3351: }
1.314 raeburn 3352: if ($oldop ne $newop) {
3353: $changedoms = 1;
3354: foreach my $item (@curr) {
3355: my ($reqdom,$option) = split(':',$item);
3356: unless ($reqdom eq $cdom) {
3357: push(@new,$item);
3358: }
3359: }
3360: if ($newop) {
3361: push(@new,$cdom.':'.$newop);
1.300 raeburn 3362: }
1.314 raeburn 3363: @new = sort(@new);
1.300 raeburn 3364: }
1.314 raeburn 3365: last;
1.300 raeburn 3366: }
1.314 raeburn 3367: }
3368: if ((!$changedoms) && ($newop)) {
1.300 raeburn 3369: $changedoms = 1;
1.306 raeburn 3370: @new = sort(@curr,$cdom.':'.$newop);
1.300 raeburn 3371: }
3372: if ($changedoms) {
1.314 raeburn 3373: my $newdomstr;
1.300 raeburn 3374: if (@new) {
3375: $newdomstr = join(',',@new);
3376: }
3377: $changed->{$tool}=&tool_admin($tool,$newdomstr,$changeHash,
3378: $context);
3379: if ($changed->{$tool}) {
3380: if ($env{'form.'.$context.'_'.$tool}) {
1.306 raeburn 3381: if ($env{'form.'.$context.'_'.$tool} eq 'autolimit') {
1.314 raeburn 3382: my $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
3383: $limit =~ s/\D+//g;
3384: if ($limit) {
1.383 raeburn 3385: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
1.314 raeburn 3386: } else {
1.383 raeburn 3387: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
1.306 raeburn 3388: }
1.314 raeburn 3389: } else {
1.306 raeburn 3390: $newaccesstext->{$tool} = $reqdisplay{$env{'form.'.$context.'_'.$tool}};
3391: }
1.300 raeburn 3392: } else {
1.383 raeburn 3393: $newaccesstext->{$tool} = &mt("availability set to 'off'");
1.300 raeburn 3394: }
3395: }
3396: }
3397: }
3398: }
3399: return;
3400: }
1.275 raeburn 3401: foreach my $tool (@{$usertools}) {
1.383 raeburn 3402: my ($newval,$limit,$envkey);
1.362 raeburn 3403: $envkey = $context.'.'.$tool;
1.306 raeburn 3404: if ($context eq 'requestcourses') {
3405: $newval = $env{'form.crsreq_'.$tool};
3406: if ($newval eq 'autolimit') {
1.383 raeburn 3407: $limit = $env{'form.crsreq_'.$tool.'_limit'};
3408: $limit =~ s/\D+//g;
3409: $newval .= '='.$limit;
1.306 raeburn 3410: }
1.362 raeburn 3411: } elsif ($context eq 'requestauthor') {
3412: $newval = $env{'form.'.$context};
3413: $envkey = $context;
1.314 raeburn 3414: } else {
1.306 raeburn 3415: $newval = $env{'form.'.$context.'_'.$tool};
3416: }
1.362 raeburn 3417: if ($userenv->{$envkey} ne '') {
1.275 raeburn 3418: $oldaccess->{$tool} = &mt('custom');
1.383 raeburn 3419: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3420: if ($userenv->{$envkey} =~ /^autolimit=(\d*)$/) {
3421: my $currlimit = $1;
3422: if ($currlimit eq '') {
3423: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3424: } else {
3425: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$currlimit);
3426: }
3427: } elsif ($userenv->{$envkey}) {
3428: $oldaccesstext->{$tool} = $reqdisplay{$userenv->{$envkey}};
3429: } else {
3430: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
3431: }
1.275 raeburn 3432: } else {
1.383 raeburn 3433: if ($userenv->{$envkey}) {
3434: $oldaccesstext->{$tool} = &mt("availability set to 'on'");
3435: } else {
3436: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
3437: }
1.275 raeburn 3438: }
1.362 raeburn 3439: $changeHash->{$envkey} = $userenv->{$envkey};
1.275 raeburn 3440: if ($env{'form.custom'.$tool} == 1) {
1.362 raeburn 3441: if ($newval ne $userenv->{$envkey}) {
1.306 raeburn 3442: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
3443: $context);
1.275 raeburn 3444: if ($changed->{$tool}) {
3445: $newaccess->{$tool} = &mt('custom');
1.383 raeburn 3446: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3447: if ($newval =~ /^autolimit/) {
3448: if ($limit) {
3449: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3450: } else {
3451: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3452: }
3453: } elsif ($newval) {
3454: $newaccesstext->{$tool} = $reqdisplay{$newval};
3455: } else {
3456: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3457: }
1.275 raeburn 3458: } else {
1.383 raeburn 3459: if ($newval) {
3460: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3461: } else {
3462: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3463: }
1.275 raeburn 3464: }
3465: } else {
3466: $newaccess->{$tool} = $oldaccess->{$tool};
1.383 raeburn 3467: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3468: if ($newval =~ /^autolimit/) {
3469: if ($limit) {
3470: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3471: } else {
3472: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3473: }
3474: } elsif ($newval) {
3475: $newaccesstext->{$tool} = $reqdisplay{$newval};
3476: } else {
3477: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3478: }
1.275 raeburn 3479: } else {
1.383 raeburn 3480: if ($userenv->{$context.'.'.$tool}) {
3481: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3482: } else {
3483: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3484: }
1.275 raeburn 3485: }
3486: }
3487: } else {
3488: $newaccess->{$tool} = $oldaccess->{$tool};
3489: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3490: }
3491: } else {
3492: $changed->{$tool} = &tool_admin($tool,'',$changeHash,$context);
3493: if ($changed->{$tool}) {
3494: $newaccess->{$tool} = &mt('default');
3495: } else {
3496: $newaccess->{$tool} = $oldaccess->{$tool};
1.383 raeburn 3497: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3498: if ($newval =~ /^autolimit/) {
3499: if ($limit) {
3500: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3501: } else {
3502: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3503: }
3504: } elsif ($newval) {
3505: $newaccesstext->{$tool} = $reqdisplay{$newval};
3506: } else {
3507: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3508: }
1.275 raeburn 3509: } else {
1.383 raeburn 3510: if ($userenv->{$context.'.'.$tool}) {
3511: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3512: } else {
3513: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3514: }
1.275 raeburn 3515: }
3516: }
3517: }
3518: } else {
3519: $oldaccess->{$tool} = &mt('default');
3520: if ($env{'form.custom'.$tool} == 1) {
1.306 raeburn 3521: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
3522: $context);
1.275 raeburn 3523: if ($changed->{$tool}) {
3524: $newaccess->{$tool} = &mt('custom');
1.383 raeburn 3525: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3526: if ($newval =~ /^autolimit/) {
3527: if ($limit) {
3528: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3529: } else {
3530: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3531: }
3532: } elsif ($newval) {
3533: $newaccesstext->{$tool} = $reqdisplay{$newval};
3534: } else {
3535: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3536: }
1.275 raeburn 3537: } else {
1.383 raeburn 3538: if ($newval) {
3539: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3540: } else {
3541: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3542: }
1.275 raeburn 3543: }
3544: } else {
3545: $newaccess->{$tool} = $oldaccess->{$tool};
3546: }
3547: } else {
3548: $newaccess->{$tool} = $oldaccess->{$tool};
3549: }
3550: }
3551: }
3552: return;
3553: }
3554:
1.220 raeburn 3555: sub update_roles {
1.375 raeburn 3556: my ($r,$context,$showcredits) = @_;
1.4 www 3557: my $now=time;
1.225 raeburn 3558: my @rolechanges;
1.220 raeburn 3559: my %disallowed;
1.73 sakharuk 3560: $r->print('<h3>'.&mt('Modifying Roles').'</h3>');
1.135 raeburn 3561: foreach my $key (keys (%env)) {
3562: next if (! $env{$key});
1.190 raeburn 3563: next if ($key eq 'form.action');
1.27 matthew 3564: # Revoke roles
1.135 raeburn 3565: if ($key=~/^form\.rev/) {
3566: if ($key=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) {
1.64 www 3567: # Revoke standard role
1.170 albertel 3568: my ($scope,$role) = ($1,$2);
3569: my $result =
3570: &Apache::lonnet::revokerole($env{'form.ccdomain'},
3571: $env{'form.ccuname'},
1.239 raeburn 3572: $scope,$role,'','',$context);
1.367 golterma 3573: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 3574: &mt('Revoking [_1] in [_2]',
3575: &Apache::lonnet::plaintext($role),
1.372 raeburn 3576: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 3577: $result ne "ok").'<br />');
3578: if ($result ne "ok") {
3579: $r->print(&mt('Error: [_1]',$result).'<br />');
3580: }
1.170 albertel 3581: if ($role eq 'st') {
1.202 raeburn 3582: my $result =
1.198 raeburn 3583: &Apache::lonuserutils::classlist_drop($scope,
3584: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 3585: $now);
1.367 golterma 3586: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.53 www 3587: }
1.225 raeburn 3588: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3589: push(@rolechanges,$role);
3590: }
1.196 raeburn 3591: }
1.195 raeburn 3592: if ($key=~m{^form\.rev\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}s) {
1.64 www 3593: # Revoke custom role
1.369 bisitz 3594: my $result = &Apache::lonnet::revokecustomrole(
3595: $env{'form.ccdomain'},$env{'form.ccuname'},$1,$2,$3,$4,'','',$context);
1.367 golterma 3596: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 3597: &mt('Revoking custom role [_1] by [_2] in [_3]',
1.372 raeburn 3598: $4,$3.':'.$2,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 3599: $result ne 'ok').'<br />');
3600: if ($result ne "ok") {
3601: $r->print(&mt('Error: [_1]',$result).'<br />');
3602: }
1.225 raeburn 3603: if (!grep(/^cr$/,@rolechanges)) {
3604: push(@rolechanges,'cr');
3605: }
1.64 www 3606: }
1.135 raeburn 3607: } elsif ($key=~/^form\.del/) {
3608: if ($key=~/^form\.del\:([^\_]+)\_([^\_\.]+)$/) {
1.116 raeburn 3609: # Delete standard role
1.170 albertel 3610: my ($scope,$role) = ($1,$2);
3611: my $result =
3612: &Apache::lonnet::assignrole($env{'form.ccdomain'},
3613: $env{'form.ccuname'},
1.239 raeburn 3614: $scope,$role,$now,0,1,'',
3615: $context);
1.367 golterma 3616: $r->print(&Apache::lonhtmlcommon::confirm_success(
3617: &mt('Deleting [_1] in [_2]',
1.369 bisitz 3618: &Apache::lonnet::plaintext($role),
1.372 raeburn 3619: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 3620: $result ne 'ok').'<br />');
3621: if ($result ne "ok") {
3622: $r->print(&mt('Error: [_1]',$result).'<br />');
3623: }
1.367 golterma 3624:
1.170 albertel 3625: if ($role eq 'st') {
1.202 raeburn 3626: my $result =
1.198 raeburn 3627: &Apache::lonuserutils::classlist_drop($scope,
3628: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 3629: $now);
1.369 bisitz 3630: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.81 albertel 3631: }
1.225 raeburn 3632: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3633: push(@rolechanges,$role);
3634: }
1.116 raeburn 3635: }
1.139 albertel 3636: if ($key=~m{^form\.del\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 3637: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
3638: # Delete custom role
1.369 bisitz 3639: my $result =
3640: &Apache::lonnet::assigncustomrole($env{'form.ccdomain'},
3641: $env{'form.ccuname'},$url,$rdom,$rnam,$rolename,$now,
3642: 0,1,$context);
3643: $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('Deleting custom role [_1] by [_2] in [_3]',
1.372 raeburn 3644: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 3645: $result ne "ok").'<br />');
3646: if ($result ne "ok") {
3647: $r->print(&mt('Error: [_1]',$result).'<br />');
3648: }
1.367 golterma 3649:
1.225 raeburn 3650: if (!grep(/^cr$/,@rolechanges)) {
3651: push(@rolechanges,'cr');
3652: }
1.116 raeburn 3653: }
1.135 raeburn 3654: } elsif ($key=~/^form\.ren/) {
1.101 albertel 3655: my $udom = $env{'form.ccdomain'};
3656: my $uname = $env{'form.ccuname'};
1.116 raeburn 3657: # Re-enable standard role
1.135 raeburn 3658: if ($key=~/^form\.ren\:([^\_]+)\_([^\_\.]+)$/) {
1.89 raeburn 3659: my $url = $1;
3660: my $role = $2;
3661: my $logmsg;
3662: my $output;
3663: if ($role eq 'st') {
1.141 albertel 3664: if ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
1.374 raeburn 3665: my ($cdom,$cnum,$csec) = ($1,$2,$3);
1.375 raeburn 3666: my $credits;
3667: if ($showcredits) {
3668: my $defaultcredits =
3669: &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
3670: $credits = &get_user_credits($defaultcredits,$cdom,$cnum);
3671: }
3672: my $result = &Apache::loncommon::commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$cdom,$cnum,$csec,$context,$credits);
1.220 raeburn 3673: if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course') || ($result eq 'refused')) {
1.223 raeburn 3674: if ($result eq 'refused' && $logmsg) {
3675: $output = $logmsg;
3676: } else {
1.369 bisitz 3677: $output = &mt('Error: [_1]',$result)."\n";
1.223 raeburn 3678: }
1.89 raeburn 3679: } else {
1.372 raeburn 3680: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Assigning [_1] in [_2] starting [_3]',
3681: &Apache::lonnet::plaintext($role),
3682: &Apache::loncommon::show_role_extent($url,$context,'st'),
3683: &Apache::lonlocal::locallocaltime($now))).'<br />'.$logmsg.'<br />';
1.89 raeburn 3684: }
3685: }
3686: } else {
1.101 albertel 3687: my $result=&Apache::lonnet::assignrole($env{'form.ccdomain'},
1.239 raeburn 3688: $env{'form.ccuname'},$url,$role,0,$now,'','',
3689: $context);
1.367 golterma 3690: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Re-enabling [_1] in [_2]',
1.372 raeburn 3691: &Apache::lonnet::plaintext($role),
3692: &Apache::loncommon::show_role_extent($url,$context,$role)),$result ne "ok").'<br />';
1.369 bisitz 3693: if ($result ne "ok") {
3694: $output .= &mt('Error: [_1]',$result).'<br />';
3695: }
3696: }
1.89 raeburn 3697: $r->print($output);
1.225 raeburn 3698: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3699: push(@rolechanges,$role);
3700: }
1.113 raeburn 3701: }
1.116 raeburn 3702: # Re-enable custom role
1.139 albertel 3703: if ($key=~m{^form\.ren\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 3704: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
3705: my $result = &Apache::lonnet::assigncustomrole(
3706: $env{'form.ccdomain'}, $env{'form.ccuname'},
1.240 raeburn 3707: $url,$rdom,$rnam,$rolename,0,$now,undef,$context);
1.369 bisitz 3708: $r->print(&Apache::lonhtmlcommon::confirm_success(
3709: &mt('Re-enabling custom role [_1] by [_2] in [_3]',
1.372 raeburn 3710: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 3711: $result ne "ok").'<br />');
3712: if ($result ne "ok") {
3713: $r->print(&mt('Error: [_1]',$result).'<br />');
3714: }
1.225 raeburn 3715: if (!grep(/^cr$/,@rolechanges)) {
3716: push(@rolechanges,'cr');
3717: }
1.116 raeburn 3718: }
1.135 raeburn 3719: } elsif ($key=~/^form\.act/) {
1.101 albertel 3720: my $udom = $env{'form.ccdomain'};
3721: my $uname = $env{'form.ccuname'};
1.141 albertel 3722: if ($key=~/^form\.act\_($match_domain)\_($match_courseid)\_cr_cr_($match_domain)_($match_username)_([^\_]+)$/) {
1.65 www 3723: # Activate a custom role
1.83 albertel 3724: my ($one,$two,$three,$four,$five)=($1,$2,$3,$4,$5);
3725: my $url='/'.$one.'/'.$two;
3726: my $full=$one.'_'.$two.'_cr_cr_'.$three.'_'.$four.'_'.$five;
1.65 www 3727:
1.101 albertel 3728: my $start = ( $env{'form.start_'.$full} ?
3729: $env{'form.start_'.$full} :
1.88 raeburn 3730: $now );
1.101 albertel 3731: my $end = ( $env{'form.end_'.$full} ?
3732: $env{'form.end_'.$full} :
1.88 raeburn 3733: 0 );
3734:
3735: # split multiple sections
3736: my %sections = ();
1.101 albertel 3737: my $num_sections = &build_roles($env{'form.sec_'.$full},\%sections,$5);
1.88 raeburn 3738: if ($num_sections == 0) {
1.240 raeburn 3739: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end,$context));
1.88 raeburn 3740: } else {
1.114 albertel 3741: my %curr_groups =
1.117 raeburn 3742: &Apache::longroup::coursegroups($one,$two);
1.113 raeburn 3743: foreach my $sec (sort {$a cmp $b} keys %sections) {
3744: if (($sec eq 'none') || ($sec eq 'all') ||
3745: exists($curr_groups{$sec})) {
3746: $disallowed{$sec} = $url;
3747: next;
3748: }
3749: my $securl = $url.'/'.$sec;
1.240 raeburn 3750: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end,$context));
1.88 raeburn 3751: }
3752: }
1.225 raeburn 3753: if (!grep(/^cr$/,@rolechanges)) {
3754: push(@rolechanges,'cr');
3755: }
1.142 raeburn 3756: } elsif ($key=~/^form\.act\_($match_domain)\_($match_name)\_([^\_]+)$/) {
1.27 matthew 3757: # Activate roles for sections with 3 id numbers
3758: # set start, end times, and the url for the class
1.83 albertel 3759: my ($one,$two,$three)=($1,$2,$3);
1.101 albertel 3760: my $start = ( $env{'form.start_'.$one.'_'.$two.'_'.$three} ?
3761: $env{'form.start_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 3762: $now );
1.101 albertel 3763: my $end = ( $env{'form.end_'.$one.'_'.$two.'_'.$three} ?
3764: $env{'form.end_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 3765: 0 );
1.83 albertel 3766: my $url='/'.$one.'/'.$two;
1.88 raeburn 3767: my $type = 'three';
3768: # split multiple sections
3769: my %sections = ();
1.101 albertel 3770: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections,$three);
1.375 raeburn 3771: my $credits;
3772: if ($three eq 'st') {
3773: if ($showcredits) {
3774: my $defaultcredits =
3775: &Apache::lonuserutils::get_defaultcredits($one,$two);
3776: $credits = $env{'form.credits_'.$one.'_'.$two.'_'.$three};
3777: $credits =~ s/[^\d\.]//g;
3778: if ($credits eq $defaultcredits) {
3779: undef($credits);
3780: }
3781: }
3782: }
1.88 raeburn 3783: if ($num_sections == 0) {
1.375 raeburn 3784: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 3785: } else {
1.114 albertel 3786: my %curr_groups =
1.117 raeburn 3787: &Apache::longroup::coursegroups($one,$two);
1.88 raeburn 3788: my $emptysec = 0;
3789: foreach my $sec (sort {$a cmp $b} keys %sections) {
3790: $sec =~ s/\W//g;
1.113 raeburn 3791: if ($sec ne '') {
3792: if (($sec eq 'none') || ($sec eq 'all') ||
3793: exists($curr_groups{$sec})) {
3794: $disallowed{$sec} = $url;
3795: next;
3796: }
1.88 raeburn 3797: my $securl = $url.'/'.$sec;
1.375 raeburn 3798: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec,$context,$credits));
1.88 raeburn 3799: } else {
3800: $emptysec = 1;
3801: }
3802: }
3803: if ($emptysec) {
1.375 raeburn 3804: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 3805: }
1.225 raeburn 3806: }
3807: if (!grep(/^\Q$three\E$/,@rolechanges)) {
3808: push(@rolechanges,$three);
3809: }
1.135 raeburn 3810: } elsif ($key=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
1.27 matthew 3811: # Activate roles for sections with two id numbers
3812: # set start, end times, and the url for the class
1.101 albertel 3813: my $start = ( $env{'form.start_'.$1.'_'.$2} ?
3814: $env{'form.start_'.$1.'_'.$2} :
1.27 matthew 3815: $now );
1.101 albertel 3816: my $end = ( $env{'form.end_'.$1.'_'.$2} ?
3817: $env{'form.end_'.$1.'_'.$2} :
1.27 matthew 3818: 0 );
1.225 raeburn 3819: my $one = $1;
3820: my $two = $2;
3821: my $url='/'.$one.'/';
1.88 raeburn 3822: # split multiple sections
3823: my %sections = ();
1.225 raeburn 3824: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two},\%sections,$two);
1.88 raeburn 3825: if ($num_sections == 0) {
1.240 raeburn 3826: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 3827: } else {
3828: my $emptysec = 0;
3829: foreach my $sec (sort {$a cmp $b} keys %sections) {
3830: if ($sec ne '') {
3831: my $securl = $url.'/'.$sec;
1.240 raeburn 3832: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$two,$start,$end,$one,undef,$sec,$context));
1.88 raeburn 3833: } else {
3834: $emptysec = 1;
3835: }
3836: }
3837: if ($emptysec) {
1.240 raeburn 3838: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 3839: }
3840: }
1.225 raeburn 3841: if (!grep(/^\Q$two\E$/,@rolechanges)) {
3842: push(@rolechanges,$two);
3843: }
1.64 www 3844: } else {
1.190 raeburn 3845: $r->print('<p><span class="LC_error">'.&mt('ERROR').': '.&mt('Unknown command').' <tt>'.$key.'</tt></span></p><br />');
1.64 www 3846: }
1.113 raeburn 3847: foreach my $key (sort(keys(%disallowed))) {
1.274 bisitz 3848: $r->print('<p class="LC_warning">');
1.113 raeburn 3849: if (($key eq 'none') || ($key eq 'all')) {
1.274 bisitz 3850: $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 3851: } else {
1.274 bisitz 3852: $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 3853: }
1.274 bisitz 3854: $r->print('</p><p>'
3855: .&mt('Please [_1]go back[_2] and choose a different section name.'
3856: ,'<a href="javascript:history.go(-1)'
3857: ,'</a>')
3858: .'</p><br />'
3859: );
1.113 raeburn 3860: }
3861: }
1.101 albertel 3862: } # End of foreach (keys(%env))
1.75 www 3863: # Flush the course logs so reverse user roles immediately updated
1.349 raeburn 3864: $r->register_cleanup(\&Apache::lonnet::flushcourselogs);
1.225 raeburn 3865: if (@rolechanges == 0) {
1.372 raeburn 3866: $r->print('<p>'.&mt('No roles to modify').'</p>');
1.193 raeburn 3867: }
1.225 raeburn 3868: return @rolechanges;
1.220 raeburn 3869: }
3870:
1.375 raeburn 3871: sub get_user_credits {
3872: my ($uname,$udom,$defaultcredits,$cdom,$cnum) = @_;
3873: if ($cdom eq '' || $cnum eq '') {
3874: return unless ($env{'request.course.id'});
3875: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
3876: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
3877: }
3878: my $credits;
3879: my %currhash =
3880: &Apache::lonnet::get('classlist',[$uname.':'.$udom],$cdom,$cnum);
3881: if (keys(%currhash) > 0) {
3882: my @items = split(/:/,$currhash{$uname.':'.$udom});
3883: my $crdidx = &Apache::loncoursedata::CL_CREDITS() - 3;
3884: $credits = $items[$crdidx];
3885: $credits =~ s/[^\d\.]//g;
3886: }
3887: if ($credits eq $defaultcredits) {
3888: undef($credits);
3889: }
3890: return $credits;
3891: }
3892:
1.220 raeburn 3893: sub enroll_single_student {
1.375 raeburn 3894: my ($r,$uhome,$amode,$genpwd,$now,$newuser,$context,$crstype,
3895: $showcredits,$defaultcredits) = @_;
1.318 raeburn 3896: $r->print('<h3>');
3897: if ($crstype eq 'Community') {
3898: $r->print(&mt('Enrolling Member'));
3899: } else {
3900: $r->print(&mt('Enrolling Student'));
3901: }
3902: $r->print('</h3>');
1.220 raeburn 3903:
3904: # Remove non alphanumeric values from section
3905: $env{'form.sections'}=~s/\W//g;
3906:
1.375 raeburn 3907: my $credits;
3908: if (($showcredits) && ($env{'form.credits'} ne '')) {
3909: $credits = $env{'form.credits'};
3910: $credits =~ s/[^\d\.]//g;
3911: if ($credits ne '') {
3912: if ($credits eq $defaultcredits) {
3913: undef($credits);
3914: }
3915: }
3916: }
3917:
1.220 raeburn 3918: # Clean out any old student roles the user has in this class.
3919: &Apache::lonuserutils::modifystudent($env{'form.ccdomain'},
3920: $env{'form.ccuname'},$env{'request.course.id'},undef,$uhome);
3921: my ($startdate,$enddate) = &Apache::lonuserutils::get_dates_from_form();
3922: my $enroll_result =
3923: &Apache::lonnet::modify_student_enrollment($env{'form.ccdomain'},
3924: $env{'form.ccuname'},$env{'form.cid'},$env{'form.cfirstname'},
3925: $env{'form.cmiddlename'},$env{'form.clastname'},
3926: $env{'form.generation'},$env{'form.sections'},$enddate,
1.375 raeburn 3927: $startdate,'manual',undef,$env{'request.course.id'},'',$context,
3928: $credits);
1.220 raeburn 3929: if ($enroll_result =~ /^ok/) {
1.381 bisitz 3930: $r->print(&mt('[_1] enrolled','<b>'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.'</b>'));
1.220 raeburn 3931: if ($env{'form.sections'} ne '') {
3932: $r->print(' '.&mt('in section [_1]',$env{'form.sections'}));
3933: }
3934: my ($showstart,$showend);
3935: if ($startdate <= $now) {
3936: $showstart = &mt('Access starts immediately');
3937: } else {
3938: $showstart = &mt('Access starts: ').&Apache::lonlocal::locallocaltime($startdate);
3939: }
3940: if ($enddate == 0) {
3941: $showend = &mt('ends: no ending date');
3942: } else {
3943: $showend = &mt('ends: ').&Apache::lonlocal::locallocaltime($enddate);
3944: }
3945: $r->print('.<br />'.$showstart.'; '.$showend);
3946: if ($startdate <= $now && !$newuser) {
1.318 raeburn 3947: $r->print('<p> ');
3948: if ($crstype eq 'Community') {
3949: $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.'));
3950: } else {
3951: $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.'));
3952: }
3953: $r->print('</p>');
1.220 raeburn 3954: }
3955: } else {
3956: $r->print(&mt('unable to enroll').": ".$enroll_result);
3957: }
3958: return;
1.188 raeburn 3959: }
3960:
1.204 raeburn 3961: sub get_defaultquota_text {
3962: my ($settingstatus) = @_;
3963: my $defquotatext;
3964: if ($settingstatus eq '') {
1.383 raeburn 3965: $defquotatext = &mt('default');
1.204 raeburn 3966: } else {
3967: my ($usertypes,$order) =
3968: &Apache::lonnet::retrieve_inst_usertypes($env{'form.ccdomain'});
3969: if ($usertypes->{$settingstatus} eq '') {
1.383 raeburn 3970: $defquotatext = &mt('default');
1.204 raeburn 3971: } else {
1.383 raeburn 3972: $defquotatext = &mt('default for [_1]',$usertypes->{$settingstatus});
1.204 raeburn 3973: }
3974: }
3975: return $defquotatext;
3976: }
3977:
1.188 raeburn 3978: sub update_result_form {
3979: my ($uhome) = @_;
3980: my $outcome =
1.367 golterma 3981: '<form name="userupdate" method="post" action="">'."\n";
1.160 raeburn 3982: foreach my $item ('srchby','srchin','srchtype','srchterm','srchdomain','ccuname','ccdomain') {
1.188 raeburn 3983: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 3984: }
1.207 raeburn 3985: if ($env{'form.origname'} ne '') {
3986: $outcome .= '<input type="hidden" name="origname" value="'.$env{'form.origname'}.'" />'."\n";
3987: }
1.160 raeburn 3988: foreach my $item ('sortby','seluname','seludom') {
3989: if (exists($env{'form.'.$item})) {
1.188 raeburn 3990: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 3991: }
3992: }
1.188 raeburn 3993: if ($uhome eq 'no_host') {
3994: $outcome .= '<input type="hidden" name="forcenewuser" value="1" />'."\n";
3995: }
3996: $outcome .= '<input type="hidden" name="phase" value="" />'."\n".
1.383 raeburn 3997: '<input type="hidden" name="currstate" value="" />'."\n".
3998: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
1.188 raeburn 3999: '</form>';
4000: return $outcome;
1.4 www 4001: }
4002:
1.149 raeburn 4003: sub quota_admin {
1.378 raeburn 4004: my ($setquota,$changeHash,$name) = @_;
1.149 raeburn 4005: my $quotachanged;
4006: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
4007: # Current user has quota modification privileges
1.267 raeburn 4008: if (ref($changeHash) eq 'HASH') {
4009: $quotachanged = 1;
1.378 raeburn 4010: $changeHash->{$name.'quota'} = $setquota;
1.267 raeburn 4011: }
1.149 raeburn 4012: }
4013: return $quotachanged;
4014: }
4015:
1.267 raeburn 4016: sub tool_admin {
1.275 raeburn 4017: my ($tool,$settool,$changeHash,$context) = @_;
4018: my $canchange = 0;
1.279 raeburn 4019: if ($context eq 'requestcourses') {
1.275 raeburn 4020: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
4021: $canchange = 1;
4022: }
1.300 raeburn 4023: } elsif ($context eq 'reqcrsotherdom') {
4024: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
4025: $canchange = 1;
4026: }
1.362 raeburn 4027: } elsif ($context eq 'requestauthor') {
4028: if (&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) {
4029: $canchange = 1;
4030: }
1.275 raeburn 4031: } elsif (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
4032: # Current user has quota modification privileges
4033: $canchange = 1;
4034: }
1.267 raeburn 4035: my $toolchanged;
1.275 raeburn 4036: if ($canchange) {
1.267 raeburn 4037: if (ref($changeHash) eq 'HASH') {
4038: $toolchanged = 1;
1.362 raeburn 4039: if ($tool eq 'requestauthor') {
4040: $changeHash->{$context} = $settool;
4041: } else {
4042: $changeHash->{$context.'.'.$tool} = $settool;
4043: }
1.267 raeburn 4044: }
4045: }
4046: return $toolchanged;
4047: }
4048:
1.88 raeburn 4049: sub build_roles {
1.89 raeburn 4050: my ($sectionstr,$sections,$role) = @_;
1.88 raeburn 4051: my $num_sections = 0;
4052: if ($sectionstr=~ /,/) {
4053: my @secnums = split/,/,$sectionstr;
1.89 raeburn 4054: if ($role eq 'st') {
4055: $secnums[0] =~ s/\W//g;
4056: $$sections{$secnums[0]} = 1;
4057: $num_sections = 1;
4058: } else {
4059: foreach my $sec (@secnums) {
4060: $sec =~ ~s/\W//g;
1.150 banghart 4061: if (!($sec eq "")) {
1.89 raeburn 4062: if (exists($$sections{$sec})) {
4063: $$sections{$sec} ++;
4064: } else {
4065: $$sections{$sec} = 1;
4066: $num_sections ++;
4067: }
1.88 raeburn 4068: }
4069: }
4070: }
4071: } else {
4072: $sectionstr=~s/\W//g;
4073: unless ($sectionstr eq '') {
4074: $$sections{$sectionstr} = 1;
4075: $num_sections ++;
4076: }
4077: }
1.129 albertel 4078:
1.88 raeburn 4079: return $num_sections;
4080: }
4081:
1.58 www 4082: # ========================================================== Custom Role Editor
4083:
4084: sub custom_role_editor {
1.351 raeburn 4085: my ($r,$brcrum) = @_;
1.324 raeburn 4086: my $action = $env{'form.customroleaction'};
4087: my $rolename;
4088: if ($action eq 'new') {
4089: $rolename=$env{'form.newrolename'};
4090: } else {
4091: $rolename=$env{'form.rolename'};
1.59 www 4092: }
4093:
1.324 raeburn 4094: my ($crstype,$context);
4095: if ($env{'request.course.id'}) {
4096: $crstype = &Apache::loncommon::course_type();
4097: $context = 'course';
4098: } else {
4099: $context = 'domain';
4100: $crstype = $env{'form.templatecrstype'};
4101: }
1.351 raeburn 4102:
4103: $rolename=~s/[^A-Za-z0-9]//gs;
4104: if (!$rolename || $env{'form.phase'} eq 'pickrole') {
4105: &print_username_entry_form($r,undef,undef,undef,undef,$crstype,$brcrum);
4106: return;
4107: }
4108:
1.153 banghart 4109: # ------------------------------------------------------- What can be assigned?
4110: my %full=();
4111: my %courselevel=();
4112: my %courselevelcurrent=();
1.61 www 4113: my $syspriv='';
4114: my $dompriv='';
4115: my $coursepriv='';
1.153 banghart 4116: my $body_top;
1.59 www 4117: my ($rdummy,$roledef)=
4118: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
1.60 www 4119: # ------------------------------------------------------- Does this role exist?
1.153 banghart 4120: $body_top .= '<h2>';
1.59 www 4121: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.153 banghart 4122: $body_top .= &mt('Existing Role').' "';
1.61 www 4123: # ------------------------------------------------- Get current role privileges
4124: ($syspriv,$dompriv,$coursepriv)=split(/\_/,$roledef);
1.324 raeburn 4125: if ($crstype eq 'Community') {
4126: $syspriv =~ s/bre\&S//;
4127: }
1.59 www 4128: } else {
1.153 banghart 4129: $body_top .= &mt('New Role').' "';
1.59 www 4130: $roledef='';
4131: }
1.153 banghart 4132: $body_top .= $rolename.'"</h2>';
1.135 raeburn 4133: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
4134: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 4135: if (!$restrict) { $restrict='F'; }
1.60 www 4136: $courselevel{$priv}=$restrict;
1.61 www 4137: if ($coursepriv=~/\:$priv/) {
4138: $courselevelcurrent{$priv}=1;
4139: }
1.60 www 4140: $full{$priv}=1;
4141: }
4142: my %domainlevel=();
1.61 www 4143: my %domainlevelcurrent=();
1.135 raeburn 4144: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
4145: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 4146: if (!$restrict) { $restrict='F'; }
1.60 www 4147: $domainlevel{$priv}=$restrict;
1.61 www 4148: if ($dompriv=~/\:$priv/) {
4149: $domainlevelcurrent{$priv}=1;
4150: }
1.60 www 4151: $full{$priv}=1;
4152: }
1.61 www 4153: my %systemlevel=();
4154: my %systemlevelcurrent=();
1.135 raeburn 4155: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
4156: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 4157: if (!$restrict) { $restrict='F'; }
1.61 www 4158: $systemlevel{$priv}=$restrict;
4159: if ($syspriv=~/\:$priv/) {
4160: $systemlevelcurrent{$priv}=1;
4161: }
4162: $full{$priv}=1;
4163: }
1.160 raeburn 4164: my ($jsback,$elements) = &crumb_utilities();
1.154 banghart 4165: my $button_code = "\n";
1.153 banghart 4166: my $head_script = "\n";
1.301 bisitz 4167: $head_script .= '<script type="text/javascript">'."\n"
4168: .'// <![CDATA['."\n";
1.324 raeburn 4169: my @template_roles = ("in","ta","ep");
4170: if ($context eq 'domain') {
4171: push(@template_roles,"ad");
1.318 raeburn 4172: }
1.324 raeburn 4173: push(@template_roles,"st");
1.318 raeburn 4174: if ($crstype eq 'Community') {
4175: unshift(@template_roles,'co');
4176: } else {
4177: unshift(@template_roles,'cc');
4178: }
1.154 banghart 4179: foreach my $role (@template_roles) {
1.324 raeburn 4180: $head_script .= &make_script_template($role,$crstype);
1.318 raeburn 4181: $button_code .= &make_button_code($role,$crstype).' ';
1.154 banghart 4182: }
1.324 raeburn 4183: my $context_code;
4184: if ($context eq 'domain') {
4185: my $checkedCommunity = '';
4186: my $checkedCourse = ' checked="checked"';
4187: if ($env{'form.templatecrstype'} eq 'Community') {
4188: $checkedCommunity = $checkedCourse;
4189: $checkedCourse = '';
4190: }
4191: $context_code = '<label>'.
4192: '<input type="radio" name="templatecrstype" value="Course"'.$checkedCourse.' onclick="this.form.submit();">'.
4193: &mt('Course').
4194: '</label>'.(' ' x2).
4195: '<label>'.
4196: '<input type="radio" name="templatecrstype" value="Community"'.$checkedCommunity.' onclick="this.form.submit();">'.
4197: &mt('Community').
4198: '</label>'.
4199: '</fieldset>'.
4200: '<input type="hidden" name="customroleaction" value="'.
4201: $action.'" />';
4202: if ($env{'form.customroleaction'} eq 'new') {
4203: $context_code .= '<input type="hidden" name="newrolename" value="'.
4204: $rolename.'" />';
4205: } else {
4206: $context_code .= '<input type="hidden" name="rolename" value="'.
4207: $rolename.'" />';
4208: }
4209: $context_code .= '<input type="hidden" name="action" value="custom" />'.
4210: '<input type="hidden" name="phase" value="selected_custom_edit" />';
4211: }
4212:
1.301 bisitz 4213: $head_script .= "\n".$jsback."\n"
4214: .'// ]]>'."\n"
4215: .'</script>'."\n";
1.351 raeburn 4216: push (@{$brcrum},
4217: {href => "javascript:backPage(document.form1,'pickrole','')",
4218: text => "Pick custom role",
4219: faq => 282,bug=>'Instructor Interface',},
4220: {href => "javascript:backPage(document.form1,'','')",
4221: text => "Edit custom role",
4222: faq => 282,
4223: bug => 'Instructor Interface',
4224: help => 'Course_Editing_Custom_Roles'}
4225: );
4226: my $args = { bread_crumbs => $brcrum,
4227: bread_crumbs_component => 'User Management'};
4228:
4229: $r->print(&Apache::loncommon::start_page('Custom Role Editor',
4230: $head_script,$args).
4231: $body_top);
1.73 sakharuk 4232: my %lt=&Apache::lonlocal::texthash(
4233: 'prv' => "Privilege",
1.131 raeburn 4234: 'crl' => "Course Level",
1.73 sakharuk 4235: 'dml' => "Domain Level",
1.150 banghart 4236: 'ssl' => "System Level");
1.264 bisitz 4237:
1.324 raeburn 4238: $r->print('<div class="LC_left_float">'
1.264 bisitz 4239: .'<form action=""><fieldset>'
4240: .'<legend>'.&mt('Select a Template').'</legend>'
4241: .$button_code
1.324 raeburn 4242: .'</fieldset></form></div>');
4243: if ($context_code) {
4244: $r->print('<div class="LC_left_float">'
4245: .'<form action="/adm/createuser" method="post"><fieldset>'
4246: .'<legend>'.&mt('Context').'</legend>'
4247: .$context_code
4248: .'</form>'
4249: .'</div>'
4250: );
4251: }
4252: $r->print('<br clear="all" />');
1.264 bisitz 4253:
1.61 www 4254: $r->print(<<ENDCCF);
1.380 bisitz 4255: <form name="form1" method="post" action="">
1.61 www 4256: <input type="hidden" name="phase" value="set_custom_roles" />
4257: <input type="hidden" name="rolename" value="$rolename" />
4258: ENDCCF
1.135 raeburn 4259: $r->print(&Apache::loncommon::start_data_table().
4260: &Apache::loncommon::start_data_table_header_row().
4261: '<th>'.$lt{'prv'}.'</th><th>'.$lt{'crl'}.'</th><th>'.$lt{'dml'}.
4262: '</th><th>'.$lt{'ssl'}.'</th>'.
4263: &Apache::loncommon::end_data_table_header_row());
1.324 raeburn 4264: foreach my $priv (sort(keys(%full))) {
1.318 raeburn 4265: my $privtext = &Apache::lonnet::plaintext($priv,$crstype);
1.135 raeburn 4266: $r->print(&Apache::loncommon::start_data_table_row().
4267: '<td>'.$privtext.'</td><td>'.
1.288 bisitz 4268: ($courselevel{$priv}?'<input type="checkbox" name="'.$priv.'_c"'.
4269: ($courselevelcurrent{$priv}?' checked="checked"':'').' />':' ').
1.61 www 4270: '</td><td>'.
1.288 bisitz 4271: ($domainlevel{$priv}?'<input type="checkbox" name="'.$priv.'_d"'.
4272: ($domainlevelcurrent{$priv}?' checked="checked"':'').' />':' ').
1.324 raeburn 4273: '</td><td>');
4274: if ($priv eq 'bre' && $crstype eq 'Community') {
4275: $r->print(' ');
4276: } else {
4277: $r->print($systemlevel{$priv}?'<input type="checkbox" name="'.$priv.'_s"'.
4278: ($systemlevelcurrent{$priv}?' checked="checked"':'').' />':' ');
4279: }
4280: $r->print('</td>'.
4281: &Apache::loncommon::end_data_table_row());
1.60 www 4282: }
1.135 raeburn 4283: $r->print(&Apache::loncommon::end_data_table().
1.190 raeburn 4284: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
1.160 raeburn 4285: '<input type="hidden" name="startrolename" value="'.$env{'form.rolename'}.
1.179 raeburn 4286: '" />'."\n".'<input type="hidden" name="currstate" value="" />'."\n".
1.160 raeburn 4287: '<input type="reset" value="'.&mt("Reset").'" />'."\n".
1.351 raeburn 4288: '<input type="submit" value="'.&mt('Save').'" /></form>');
1.61 www 4289: }
1.153 banghart 4290: # --------------------------------------------------------
4291: sub make_script_template {
1.324 raeburn 4292: my ($role,$crstype) = @_;
1.153 banghart 4293: my %full_c=();
4294: my %full_d=();
4295: my %full_s=();
4296: my $return_script;
4297: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
4298: my ($priv,$restrict)=split(/\&/,$item);
4299: $full_c{$priv}=1;
4300: }
4301: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
4302: my ($priv,$restrict)=split(/\&/,$item);
4303: $full_d{$priv}=1;
4304: }
1.154 banghart 4305: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
1.324 raeburn 4306: next if (($crstype eq 'Community') && ($item eq 'bre&S'));
1.153 banghart 4307: my ($priv,$restrict)=split(/\&/,$item);
4308: $full_s{$priv}=1;
4309: }
4310: $return_script .= 'function set_'.$role.'() {'."\n";
4311: my @temp = split(/:/,$Apache::lonnet::pr{$role.':c'});
4312: my %role_c;
1.155 banghart 4313: foreach my $priv (@temp) {
1.153 banghart 4314: my ($priv_item, $dummy) = split(/\&/,$priv);
4315: $role_c{$priv_item} = 1;
4316: }
1.269 raeburn 4317: my %role_d;
4318: @temp = split(/:/,$Apache::lonnet::pr{$role.':d'});
4319: foreach my $priv(@temp) {
4320: my ($priv_item, $dummy) = split(/\&/,$priv);
4321: $role_d{$priv_item} = 1;
4322: }
4323: my %role_s;
4324: @temp = split(/:/,$Apache::lonnet::pr{$role.':s'});
4325: foreach my $priv(@temp) {
4326: my ($priv_item, $dummy) = split(/\&/,$priv);
4327: $role_s{$priv_item} = 1;
4328: }
1.153 banghart 4329: foreach my $priv_item (keys(%full_c)) {
4330: my ($priv, $dummy) = split(/\&/,$priv_item);
1.269 raeburn 4331: if ((exists($role_c{$priv})) || (exists($role_d{$priv})) ||
4332: (exists($role_s{$priv}))) {
1.153 banghart 4333: $return_script .= "document.form1.$priv"."_c.checked = true;\n";
4334: } else {
4335: $return_script .= "document.form1.$priv"."_c.checked = false;\n";
4336: }
4337: }
1.154 banghart 4338: foreach my $priv_item (keys(%full_d)) {
4339: my ($priv, $dummy) = split(/\&/,$priv_item);
1.269 raeburn 4340: if ((exists($role_d{$priv})) || (exists($role_s{$priv}))) {
1.154 banghart 4341: $return_script .= "document.form1.$priv"."_d.checked = true;\n";
4342: } else {
4343: $return_script .= "document.form1.$priv"."_d.checked = false;\n";
4344: }
4345: }
4346: foreach my $priv_item (keys(%full_s)) {
1.153 banghart 4347: my ($priv, $dummy) = split(/\&/,$priv_item);
1.154 banghart 4348: if (exists($role_s{$priv})) {
4349: $return_script .= "document.form1.$priv"."_s.checked = true;\n";
4350: } else {
4351: $return_script .= "document.form1.$priv"."_s.checked = false;\n";
4352: }
1.153 banghart 4353: }
4354: $return_script .= '}'."\n";
1.154 banghart 4355: return ($return_script);
4356: }
4357: # ----------------------------------------------------------
4358: sub make_button_code {
1.318 raeburn 4359: my ($role,$crstype) = @_;
4360: my $label = &Apache::lonnet::plaintext($role,$crstype);
1.301 bisitz 4361: my $button_code = '<input type="button" onclick="set_'.$role.'()" value="'.$label.'" />';
1.154 banghart 4362: return ($button_code);
1.153 banghart 4363: }
1.61 www 4364: # ---------------------------------------------------------- Call to definerole
4365: sub set_custom_role {
1.351 raeburn 4366: my ($r,$context,$brcrum) = @_;
1.101 albertel 4367: my $rolename=$env{'form.rolename'};
1.63 www 4368: $rolename=~s/[^A-Za-z0-9]//gs;
1.150 banghart 4369: if (!$rolename) {
1.351 raeburn 4370: &custom_role_editor($r,$brcrum);
1.61 www 4371: return;
4372: }
1.160 raeburn 4373: my ($jsback,$elements) = &crumb_utilities();
1.301 bisitz 4374: my $jscript = '<script type="text/javascript">'
4375: .'// <![CDATA['."\n"
4376: .$jsback."\n"
4377: .'// ]]>'."\n"
4378: .'</script>'."\n";
1.352 raeburn 4379: push(@{$brcrum},
4380: {href => "javascript:backPage(document.customresult,'pickrole','')",
4381: text => "Pick custom role",
4382: faq => 282,
4383: bug => 'Instructor Interface',},
4384: {href => "javascript:backPage(document.customresult,'selected_custom_edit','')",
4385: text => "Edit custom role",
4386: faq => 282,
4387: bug => 'Instructor Interface',},
4388: {href => "javascript:backPage(document.customresult,'set_custom_roles','')",
4389: text => "Result",
4390: faq => 282,
4391: bug => 'Instructor Interface',
4392: help => 'Course_Editing_Custom_Roles'},
4393: );
4394: my $args = { bread_crumbs => $brcrum,
1.351 raeburn 4395: bread_crumbs_component => 'User Management'};
4396: $r->print(&Apache::loncommon::start_page('Save Custom Role',$jscript,$args));
1.160 raeburn 4397:
1.61 www 4398: my ($rdummy,$roledef)=
1.110 albertel 4399: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
4400:
1.61 www 4401: # ------------------------------------------------------- Does this role exist?
1.188 raeburn 4402: $r->print('<h3>');
1.61 www 4403: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.73 sakharuk 4404: $r->print(&mt('Existing Role').' "');
1.61 www 4405: } else {
1.73 sakharuk 4406: $r->print(&mt('New Role').' "');
1.61 www 4407: $roledef='';
4408: }
1.188 raeburn 4409: $r->print($rolename.'"</h3>');
1.61 www 4410: # ------------------------------------------------------- What can be assigned?
4411: my $sysrole='';
4412: my $domrole='';
4413: my $courole='';
4414:
1.135 raeburn 4415: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
4416: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 4417: if (!$restrict) { $restrict=''; }
4418: if ($env{'form.'.$priv.'_c'}) {
1.135 raeburn 4419: $courole.=':'.$item;
1.61 www 4420: }
4421: }
4422:
1.135 raeburn 4423: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
4424: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 4425: if (!$restrict) { $restrict=''; }
4426: if ($env{'form.'.$priv.'_d'}) {
1.135 raeburn 4427: $domrole.=':'.$item;
1.61 www 4428: }
4429: }
4430:
1.135 raeburn 4431: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
4432: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 4433: if (!$restrict) { $restrict=''; }
4434: if ($env{'form.'.$priv.'_s'}) {
1.135 raeburn 4435: $sysrole.=':'.$item;
1.61 www 4436: }
4437: }
1.63 www 4438: $r->print('<br />Defining Role: '.
1.61 www 4439: &Apache::lonnet::definerole($rolename,$sysrole,$domrole,$courole));
1.101 albertel 4440: if ($env{'request.course.id'}) {
4441: my $url='/'.$env{'request.course.id'};
1.63 www 4442: $url=~s/\_/\//g;
1.73 sakharuk 4443: $r->print('<br />'.&mt('Assigning Role to Self').': '.
1.101 albertel 4444: &Apache::lonnet::assigncustomrole($env{'user.domain'},
4445: $env{'user.name'},
1.63 www 4446: $url,
1.101 albertel 4447: $env{'user.domain'},
4448: $env{'user.name'},
1.240 raeburn 4449: $rolename,undef,undef,undef,$context));
1.63 www 4450: }
1.380 bisitz 4451: $r->print(
4452: '<p><a href="javascript:backPage(document.customresult,'."'pickrole'".')">'
4453: .&mt('Create or edit another custom role')
4454: .'</a></p>'
4455: .'<form name="customresult" method="post" action="">'
4456: .&Apache::lonhtmlcommon::echo_form_input([]).'</form>'
4457: );
1.58 www 4458: }
4459:
1.2 www 4460: # ================================================================ Main Handler
4461: sub handler {
4462: my $r = shift;
4463: if ($r->header_only) {
1.68 www 4464: &Apache::loncommon::content_type($r,'text/html');
1.2 www 4465: $r->send_http_header;
4466: return OK;
4467: }
1.318 raeburn 4468: my ($context,$crstype);
1.190 raeburn 4469: if ($env{'request.course.id'}) {
4470: $context = 'course';
1.318 raeburn 4471: $crstype = &Apache::loncommon::course_type();
1.190 raeburn 4472: } elsif ($env{'request.role'} =~ /^au\./) {
1.206 raeburn 4473: $context = 'author';
1.190 raeburn 4474: } else {
4475: $context = 'domain';
4476: }
1.375 raeburn 4477:
1.190 raeburn 4478: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.233 raeburn 4479: ['action','state','callingform','roletype','showrole','bulkaction','popup','phase',
4480: 'username','domain','srchterm','srchdomain','srchin','srchby','srchtype']);
1.190 raeburn 4481: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.351 raeburn 4482: my $args;
4483: my $brcrum = [];
4484: my $bread_crumbs_component = 'User Management';
1.202 raeburn 4485: if ($env{'form.action'} ne 'dateselect') {
1.351 raeburn 4486: $brcrum = [{href=>"/adm/createuser",
4487: text=>"User Management",
4488: 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'}
4489: ];
1.202 raeburn 4490: }
1.289 droeschl 4491: #SD Following files not added to help, because the corresponding .tex-files seem to
4492: #be missing: Course_Approve_Selfenroll,Course_User_Logs,
1.209 raeburn 4493: my ($permission,$allowed) =
1.318 raeburn 4494: &Apache::lonuserutils::get_permission($context,$crstype);
1.190 raeburn 4495: if (!$allowed) {
1.358 raeburn 4496: if ($context eq 'course') {
4497: $r->internal_redirect('/adm/viewclasslist');
4498: return OK;
4499: }
1.190 raeburn 4500: $env{'user.error.msg'}=
4501: "/adm/createuser:cst:0:0:Cannot create/modify user data ".
4502: "or view user status.";
4503: return HTTP_NOT_ACCEPTABLE;
4504: }
4505:
4506: &Apache::loncommon::content_type($r,'text/html');
4507: $r->send_http_header;
4508:
1.375 raeburn 4509: my $showcredits;
4510: if ((($context eq 'course') && ($crstype eq 'Course')) ||
4511: ($context eq 'domain')) {
4512: my %domdefaults =
4513: &Apache::lonnet::get_domain_defaults($env{'request.role.domain'});
4514: if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'}) {
4515: $showcredits = 1;
4516: }
4517: }
4518:
1.190 raeburn 4519: # Main switch on form.action and form.state, as appropriate
4520: if (! exists($env{'form.action'})) {
1.351 raeburn 4521: $args = {bread_crumbs => $brcrum,
4522: bread_crumbs_component => $bread_crumbs_component};
4523: $r->print(&header(undef,$args));
1.318 raeburn 4524: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 4525: } elsif ($env{'form.action'} eq 'upload' && $permission->{'cusr'}) {
1.351 raeburn 4526: push(@{$brcrum},
4527: { href => '/adm/createuser?action=upload&state=',
4528: text => 'Upload Users List',
4529: help => 'Course_Create_Class_List',
4530: });
4531: $bread_crumbs_component = 'Upload Users List';
4532: $args = {bread_crumbs => $brcrum,
4533: bread_crumbs_component => $bread_crumbs_component};
4534: $r->print(&header(undef,$args));
1.190 raeburn 4535: $r->print('<form name="studentform" method="post" '.
4536: 'enctype="multipart/form-data" '.
4537: ' action="/adm/createuser">'."\n");
4538: if (! exists($env{'form.state'})) {
4539: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4540: } elsif ($env{'form.state'} eq 'got_file') {
1.375 raeburn 4541: &Apache::lonuserutils::print_upload_manager_form($r,$context,$permission,
4542: $crstype,$showcredits);
1.190 raeburn 4543: } elsif ($env{'form.state'} eq 'enrolling') {
4544: if ($env{'form.datatoken'}) {
1.375 raeburn 4545: &Apache::lonuserutils::upfile_drop_add($r,$context,$permission,
4546: $showcredits);
1.190 raeburn 4547: }
4548: } else {
4549: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4550: }
1.213 raeburn 4551: } elsif ((($env{'form.action'} eq 'singleuser') || ($env{'form.action'}
4552: eq 'singlestudent')) && ($permission->{'cusr'})) {
1.190 raeburn 4553: my $phase = $env{'form.phase'};
4554: my @search = ('srchterm','srchby','srchin','srchtype','srchdomain');
1.192 albertel 4555: &Apache::loncreateuser::restore_prev_selections();
4556: my $srch;
4557: foreach my $item (@search) {
4558: $srch->{$item} = $env{'form.'.$item};
4559: }
1.207 raeburn 4560: if (($phase eq 'get_user_info') || ($phase eq 'userpicked') ||
4561: ($phase eq 'createnewuser')) {
4562: if ($env{'form.phase'} eq 'createnewuser') {
4563: my $response;
4564: if ($env{'form.srchterm'} !~ /^$match_username$/) {
1.366 bisitz 4565: my $response =
4566: '<span class="LC_warning">'
4567: .&mt('You must specify a valid username. Only the following are allowed:'
4568: .' letters numbers - . @')
4569: .'</span>';
1.221 raeburn 4570: $env{'form.phase'} = '';
1.375 raeburn 4571: &print_username_entry_form($r,$context,$response,$srch,undef,
4572: $crstype,$brcrum,$showcredits);
1.207 raeburn 4573: } else {
4574: my $ccuname =&LONCAPA::clean_username($srch->{'srchterm'});
4575: my $ccdomain=&LONCAPA::clean_domain($srch->{'srchdomain'});
4576: &print_user_modification_page($r,$ccuname,$ccdomain,
1.221 raeburn 4577: $srch,$response,$context,
1.375 raeburn 4578: $permission,$crstype,$brcrum,
4579: $showcredits);
1.207 raeburn 4580: }
4581: } elsif ($env{'form.phase'} eq 'get_user_info') {
1.190 raeburn 4582: my ($currstate,$response,$forcenewuser,$results) =
1.221 raeburn 4583: &user_search_result($context,$srch);
1.190 raeburn 4584: if ($env{'form.currstate'} eq 'modify') {
4585: $currstate = $env{'form.currstate'};
4586: }
4587: if ($currstate eq 'select') {
4588: &print_user_selection_page($r,$response,$srch,$results,
1.351 raeburn 4589: \@search,$context,undef,$crstype,
4590: $brcrum);
1.190 raeburn 4591: } elsif ($currstate eq 'modify') {
4592: my ($ccuname,$ccdomain);
4593: if (($srch->{'srchby'} eq 'uname') &&
4594: ($srch->{'srchtype'} eq 'exact')) {
4595: $ccuname = $srch->{'srchterm'};
4596: $ccdomain= $srch->{'srchdomain'};
4597: } else {
4598: my @matchedunames = keys(%{$results});
4599: ($ccuname,$ccdomain) = split(/:/,$matchedunames[0]);
4600: }
4601: $ccuname =&LONCAPA::clean_username($ccuname);
4602: $ccdomain=&LONCAPA::clean_domain($ccdomain);
4603: if ($env{'form.forcenewuser'}) {
4604: $response = '';
4605: }
4606: &print_user_modification_page($r,$ccuname,$ccdomain,
1.221 raeburn 4607: $srch,$response,$context,
1.351 raeburn 4608: $permission,$crstype,$brcrum);
1.190 raeburn 4609: } elsif ($currstate eq 'query') {
1.351 raeburn 4610: &print_user_query_page($r,'createuser',$brcrum);
1.190 raeburn 4611: } else {
1.229 raeburn 4612: $env{'form.phase'} = '';
1.207 raeburn 4613: &print_username_entry_form($r,$context,$response,$srch,
1.351 raeburn 4614: $forcenewuser,$crstype,$brcrum);
1.190 raeburn 4615: }
4616: } elsif ($env{'form.phase'} eq 'userpicked') {
4617: my $ccuname = &LONCAPA::clean_username($env{'form.seluname'});
4618: my $ccdomain = &LONCAPA::clean_domain($env{'form.seludom'});
1.196 raeburn 4619: &print_user_modification_page($r,$ccuname,$ccdomain,$srch,'',
1.351 raeburn 4620: $context,$permission,$crstype,
4621: $brcrum);
1.190 raeburn 4622: }
4623: } elsif ($env{'form.phase'} eq 'update_user_data') {
1.375 raeburn 4624: &update_user_data($r,$context,$crstype,$brcrum,$showcredits);
1.190 raeburn 4625: } else {
1.351 raeburn 4626: &print_username_entry_form($r,$context,undef,$srch,undef,$crstype,
4627: $brcrum);
1.190 raeburn 4628: }
4629: } elsif ($env{'form.action'} eq 'custom' && $permission->{'custom'}) {
4630: if ($env{'form.phase'} eq 'set_custom_roles') {
1.351 raeburn 4631: &set_custom_role($r,$context,$brcrum);
1.190 raeburn 4632: } else {
1.351 raeburn 4633: &custom_role_editor($r,$brcrum);
1.190 raeburn 4634: }
1.362 raeburn 4635: } elsif (($env{'form.action'} eq 'processauthorreq') &&
4636: ($permission->{'cusr'}) &&
4637: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
4638: push(@{$brcrum},
4639: {href => '/adm/createuser?action=processauthorreq',
1.385 ! bisitz 4640: text => 'Authoring Space requests',
1.362 raeburn 4641: help => 'Domain_Role_Approvals'});
4642: $bread_crumbs_component = 'Authoring requests';
4643: if ($env{'form.state'} eq 'done') {
4644: push(@{$brcrum},
4645: {href => '/adm/createuser?action=authorreqqueue',
4646: text => 'Result',
4647: help => 'Domain_Role_Approvals'});
4648: $bread_crumbs_component = 'Authoring request result';
4649: }
4650: $args = { bread_crumbs => $brcrum,
4651: bread_crumbs_component => $bread_crumbs_component};
4652: $r->print(&header(undef,$args));
4653: if (!exists($env{'form.state'})) {
4654: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestauthor',
4655: $env{'request.role.domain'}));
4656: } elsif ($env{'form.state'} eq 'done') {
4657: $r->print('<h3>'.&mt('Authoring request processing').'</h3>'."\n");
4658: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestauthor',
4659: $env{'request.role.domain'}));
4660: }
1.207 raeburn 4661: } elsif (($env{'form.action'} eq 'listusers') &&
4662: ($permission->{'view'} || $permission->{'cusr'})) {
1.202 raeburn 4663: if ($env{'form.phase'} eq 'bulkchange') {
1.351 raeburn 4664: push(@{$brcrum},
4665: {href => '/adm/createuser?action=listusers',
4666: text => "List Users"},
4667: {href => "/adm/createuser",
4668: text => "Result",
4669: help => 'Course_View_Class_List'});
4670: $bread_crumbs_component = 'Update Users';
4671: $args = {bread_crumbs => $brcrum,
4672: bread_crumbs_component => $bread_crumbs_component};
4673: $r->print(&header(undef,$args));
1.202 raeburn 4674: my $setting = $env{'form.roletype'};
4675: my $choice = $env{'form.bulkaction'};
4676: if ($permission->{'cusr'}) {
1.336 raeburn 4677: &Apache::lonuserutils::update_user_list($r,$context,$setting,$choice,$crstype);
1.221 raeburn 4678: } else {
4679: $r->print(&mt('You are not authorized to make bulk changes to user roles'));
1.223 raeburn 4680: $r->print('<p><a href="/adm/createuser?action=listusers">'.&mt('Display User Lists').'</a>');
1.202 raeburn 4681: }
4682: } else {
1.351 raeburn 4683: push(@{$brcrum},
4684: {href => '/adm/createuser?action=listusers',
4685: text => "List Users",
4686: help => 'Course_View_Class_List'});
4687: $bread_crumbs_component = 'List Users';
4688: $args = {bread_crumbs => $brcrum,
4689: bread_crumbs_component => $bread_crumbs_component};
1.202 raeburn 4690: my ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles);
4691: my $formname = 'studentform';
1.364 raeburn 4692: my $hidecall = "hide_searching();";
1.321 raeburn 4693: if (($context eq 'domain') && (($env{'form.roletype'} eq 'course') ||
4694: ($env{'form.roletype'} eq 'community'))) {
4695: if ($env{'form.roletype'} eq 'course') {
4696: ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles) =
4697: &Apache::lonuserutils::courses_selector($env{'request.role.domain'},
4698: $formname);
4699: } elsif ($env{'form.roletype'} eq 'community') {
4700: $cb_jscript =
4701: &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
4702: my %elements = (
4703: coursepick => 'radio',
4704: coursetotal => 'text',
4705: courselist => 'text',
4706: );
4707: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements);
4708: }
1.364 raeburn 4709: $jscript .= &verify_user_display($context)."\n".
4710: &Apache::loncommon::check_uncheck_jscript();
1.202 raeburn 4711: my $js = &add_script($jscript).$cb_jscript;
4712: my $loadcode =
4713: &Apache::lonuserutils::course_selector_loadcode($formname);
4714: if ($loadcode ne '') {
1.364 raeburn 4715: $args->{add_entries} = {onload => "$loadcode;$hidecall"};
4716: } else {
4717: $args->{add_entries} = {onload => $hidecall};
1.202 raeburn 4718: }
1.351 raeburn 4719: $r->print(&header($js,$args));
1.191 raeburn 4720: } else {
1.364 raeburn 4721: $args->{add_entries} = {onload => $hidecall};
4722: $jscript = &verify_user_display($context).
4723: &Apache::loncommon::check_uncheck_jscript();
4724: $r->print(&header(&add_script($jscript),$args));
1.191 raeburn 4725: }
1.202 raeburn 4726: &Apache::lonuserutils::print_userlist($r,undef,$permission,$context,
1.375 raeburn 4727: $formname,$totcodes,$codetitles,$idlist,$idlist_titles,
4728: $showcredits);
1.191 raeburn 4729: }
1.213 raeburn 4730: } elsif ($env{'form.action'} eq 'drop' && $permission->{'cusr'}) {
1.318 raeburn 4731: my $brtext;
4732: if ($crstype eq 'Community') {
4733: $brtext = 'Drop Members';
4734: } else {
4735: $brtext = 'Drop Students';
4736: }
1.351 raeburn 4737: push(@{$brcrum},
4738: {href => '/adm/createuser?action=drop',
4739: text => $brtext,
4740: help => 'Course_Drop_Student'});
4741: if ($env{'form.state'} eq 'done') {
4742: push(@{$brcrum},
4743: {href=>'/adm/createuser?action=drop',
4744: text=>"Result"});
4745: }
4746: $bread_crumbs_component = $brtext;
4747: $args = {bread_crumbs => $brcrum,
4748: bread_crumbs_component => $bread_crumbs_component};
4749: $r->print(&header(undef,$args));
1.213 raeburn 4750: if (!exists($env{'form.state'})) {
1.318 raeburn 4751: &Apache::lonuserutils::print_drop_menu($r,$context,$permission,$crstype);
1.213 raeburn 4752: } elsif ($env{'form.state'} eq 'done') {
4753: &Apache::lonuserutils::update_user_list($r,$context,undef,
4754: $env{'form.action'});
4755: }
1.202 raeburn 4756: } elsif ($env{'form.action'} eq 'dateselect') {
4757: if ($permission->{'cusr'}) {
1.351 raeburn 4758: $r->print(&header(undef,{'no_nav_bar' => 1}).
1.375 raeburn 4759: &Apache::lonuserutils::date_section_selector($context,$permission,
4760: $crstype,$showcredits));
1.202 raeburn 4761: } else {
1.351 raeburn 4762: $r->print(&header(undef,{'no_nav_bar' => 1}).
4763: '<span class="LC_error">'.&mt('You do not have permission to modify dates or sections for users').'</span>');
1.202 raeburn 4764: }
1.237 raeburn 4765: } elsif ($env{'form.action'} eq 'selfenroll') {
1.351 raeburn 4766: push(@{$brcrum},
4767: {href => '/adm/createuser?action=selfenroll',
4768: text => "Configure Self-enrollment",
4769: help => 'Course_Self_Enrollment'});
1.237 raeburn 4770: if (!exists($env{'form.state'})) {
1.351 raeburn 4771: $args = { bread_crumbs => $brcrum,
4772: bread_crumbs_component => 'Configure Self-enrollment'};
4773: $r->print(&header(undef,$args));
1.241 raeburn 4774: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
1.237 raeburn 4775: &print_selfenroll_menu($r,$context,$permission);
4776: } elsif ($env{'form.state'} eq 'done') {
1.351 raeburn 4777: push (@{$brcrum},
4778: {href=>'/adm/createuser?action=selfenroll',
4779: text=>"Result"});
4780: $args = { bread_crumbs => $brcrum,
4781: bread_crumbs_component => 'Self-enrollment result'};
4782: $r->print(&header(undef,$args));
1.241 raeburn 4783: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
4784: &update_selfenroll_config($r,$context,$permission);
1.237 raeburn 4785: }
1.277 raeburn 4786: } elsif ($env{'form.action'} eq 'selfenrollqueue') {
1.351 raeburn 4787: push(@{$brcrum},
4788: {href => '/adm/createuser?action=selfenrollqueue',
4789: text => 'Enrollment requests',
4790: help => 'Course_Self_Enrollment'});
4791: $bread_crumbs_component = 'Enrollment requests';
4792: if ($env{'form.state'} eq 'done') {
4793: push(@{$brcrum},
4794: {href => '/adm/createuser?action=selfenrollqueue',
4795: text => 'Result',
4796: help => 'Course_Self_Enrollment'});
4797: $bread_crumbs_component = 'Enrollment result';
4798: }
4799: $args = { bread_crumbs => $brcrum,
4800: bread_crumbs_component => $bread_crumbs_component};
4801: $r->print(&header(undef,$args));
1.277 raeburn 4802: my $cid = $env{'request.course.id'};
4803: my $cdom = $env{'course.'.$cid.'.domain'};
4804: my $cnum = $env{'course.'.$cid.'.num'};
1.307 raeburn 4805: my $coursedesc = $env{'course.'.$cid.'.description'};
1.277 raeburn 4806: if (!exists($env{'form.state'})) {
4807: $r->print('<h3>'.&mt('Pending enrollment requests').'</h3>'."\n");
1.307 raeburn 4808: $r->print(&Apache::loncoursequeueadmin::display_queued_requests($context,
4809: $cdom,$cnum));
1.277 raeburn 4810: } elsif ($env{'form.state'} eq 'done') {
4811: $r->print('<h3>'.&mt('Enrollment request processing').'</h3>'."\n");
1.307 raeburn 4812: $r->print(&Apache::loncoursequeueadmin::update_request_queue($context,
4813: $cdom,$cnum,$coursedesc));
1.277 raeburn 4814: }
1.239 raeburn 4815: } elsif ($env{'form.action'} eq 'changelogs') {
1.363 raeburn 4816: my $helpitem;
4817: if ($context eq 'course') {
4818: $helpitem = 'Course_User_Logs';
4819: }
1.351 raeburn 4820: push (@{$brcrum},
4821: {href => '/adm/createuser?action=changelogs',
4822: text => 'User Management Logs',
1.363 raeburn 4823: help => $helpitem});
1.351 raeburn 4824: $bread_crumbs_component = 'User Changes';
4825: $args = { bread_crumbs => $brcrum,
4826: bread_crumbs_component => $bread_crumbs_component};
4827: $r->print(&header(undef,$args));
4828: &print_userchangelogs_display($r,$context,$permission);
1.190 raeburn 4829: } else {
1.351 raeburn 4830: $bread_crumbs_component = 'User Management';
4831: $args = { bread_crumbs => $brcrum,
4832: bread_crumbs_component => $bread_crumbs_component};
4833: $r->print(&header(undef,$args));
1.318 raeburn 4834: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 4835: }
1.351 raeburn 4836: $r->print(&Apache::loncommon::end_page());
1.190 raeburn 4837: return OK;
4838: }
4839:
4840: sub header {
1.351 raeburn 4841: my ($jscript,$args) = @_;
1.190 raeburn 4842: my $start_page;
1.351 raeburn 4843: if (ref($args) eq 'HASH') {
4844: $start_page=&Apache::loncommon::start_page('User Management',$jscript,$args);
1.190 raeburn 4845: } else {
1.351 raeburn 4846: $start_page=&Apache::loncommon::start_page('User Management',$jscript);
1.190 raeburn 4847: }
4848: return $start_page;
4849: }
1.2 www 4850:
1.191 raeburn 4851: sub add_script {
4852: my ($js) = @_;
1.301 bisitz 4853: return '<script type="text/javascript">'."\n"
4854: .'// <![CDATA['."\n"
4855: .$js."\n"
4856: .'// ]]>'."\n"
4857: .'</script>'."\n";
1.191 raeburn 4858: }
4859:
1.202 raeburn 4860: sub verify_user_display {
1.364 raeburn 4861: my ($context) = @_;
1.374 raeburn 4862: my %lt = &Apache::lonlocal::texthash (
4863: course => 'course(s): description, section(s), status',
4864: community => 'community(s): description, section(s), status',
4865: author => 'author',
4866: );
1.364 raeburn 4867: my $photos;
4868: if (($context eq 'course') && $env{'request.course.id'}) {
4869: $photos = $env{'course.'.$env{'request.course.id'}.'.internal.showphoto'};
4870: }
1.202 raeburn 4871: my $output = <<"END";
4872:
1.364 raeburn 4873: function hide_searching() {
4874: if (document.getElementById('searching')) {
4875: document.getElementById('searching').style.display = 'none';
4876: }
4877: return;
4878: }
4879:
1.202 raeburn 4880: function display_update() {
4881: document.studentform.action.value = 'listusers';
4882: document.studentform.phase.value = 'display';
4883: document.studentform.submit();
4884: }
4885:
1.364 raeburn 4886: function updateCols(caller) {
4887: var context = '$context';
4888: var photos = '$photos';
4889: if (caller == 'Status') {
1.374 raeburn 4890: if ((context == 'domain') &&
4891: ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
4892: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community'))) {
1.364 raeburn 4893: document.getElementById('showcolstatus').checked = false;
4894: document.getElementById('showcolstatus').disabled = 'disabled';
4895: document.getElementById('showcolstart').checked = false;
4896: document.getElementById('showcolend').checked = false;
1.374 raeburn 4897: } else {
4898: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
4899: document.getElementById('showcolstatus').checked = true;
4900: document.getElementById('showcolstatus').disabled = '';
4901: document.getElementById('showcolstart').checked = true;
4902: document.getElementById('showcolend').checked = true;
4903: } else {
4904: document.getElementById('showcolstatus').checked = false;
4905: document.getElementById('showcolstatus').disabled = 'disabled';
4906: document.getElementById('showcolstart').checked = false;
4907: document.getElementById('showcolend').checked = false;
4908: }
1.364 raeburn 4909: }
4910: }
4911: if (caller == 'output') {
4912: if (photos == 1) {
4913: if (document.getElementById('showcolphoto')) {
4914: var photoitem = document.getElementById('showcolphoto');
4915: if (document.studentform.output.options[document.studentform.output.selectedIndex].value == 'html') {
4916: photoitem.checked = true;
4917: photoitem.disabled = '';
4918: } else {
4919: photoitem.checked = false;
4920: photoitem.disabled = 'disabled';
4921: }
4922: }
4923: }
4924: }
4925: if (caller == 'showrole') {
1.371 raeburn 4926: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any') ||
4927: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'cr')) {
1.364 raeburn 4928: document.getElementById('showcolrole').checked = true;
4929: document.getElementById('showcolrole').disabled = '';
4930: } else {
4931: document.getElementById('showcolrole').checked = false;
4932: document.getElementById('showcolrole').disabled = 'disabled';
4933: }
1.374 raeburn 4934: if (context == 'domain') {
1.382 raeburn 4935: var quotausageshow = 0;
1.374 raeburn 4936: if ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
4937: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community')) {
4938: document.getElementById('showcolstatus').checked = false;
4939: document.getElementById('showcolstatus').disabled = 'disabled';
4940: document.getElementById('showcolstart').checked = false;
4941: document.getElementById('showcolend').checked = false;
4942: } else {
4943: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
4944: document.getElementById('showcolstatus').checked = true;
4945: document.getElementById('showcolstatus').disabled = '';
4946: document.getElementById('showcolstart').checked = true;
4947: document.getElementById('showcolend').checked = true;
4948: }
4949: }
4950: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'domain') {
4951: document.getElementById('showcolextent').disabled = 'disabled';
4952: document.getElementById('showcolextent').checked = 'false';
4953: document.getElementById('showextent').style.display='none';
4954: document.getElementById('showcoltextextent').innerHTML = '';
1.382 raeburn 4955: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'au') ||
4956: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any')) {
4957: if (document.getElementById('showcolauthorusage')) {
4958: document.getElementById('showcolauthorusage').disabled = '';
4959: }
4960: if (document.getElementById('showcolauthorquota')) {
4961: document.getElementById('showcolauthorquota').disabled = '';
4962: }
4963: quotausageshow = 1;
4964: }
1.374 raeburn 4965: } else {
4966: document.getElementById('showextent').style.display='block';
4967: document.getElementById('showextent').style.textAlign='left';
4968: document.getElementById('showextent').style.textFace='normal';
4969: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'author') {
4970: document.getElementById('showcolextent').disabled = '';
4971: document.getElementById('showcolextent').checked = 'true';
4972: document.getElementById('showcoltextextent').innerHTML="$lt{'author'}";
4973: } else {
4974: document.getElementById('showcolextent').disabled = '';
4975: document.getElementById('showcolextent').checked = 'true';
4976: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community') {
4977: document.getElementById('showcoltextextent').innerHTML="$lt{'community'}";
4978: } else {
4979: document.getElementById('showcoltextextent').innerHTML="$lt{'course'}";
4980: }
4981: }
4982: }
1.382 raeburn 4983: if (quotausageshow == 0) {
4984: if (document.getElementById('showcolauthorusage')) {
4985: document.getElementById('showcolauthorusage').checked = false;
4986: document.getElementById('showcolauthorusage').disabled = 'disabled';
4987: }
4988: if (document.getElementById('showcolauthorquota')) {
4989: document.getElementById('showcolauthorquota').checked = false;
4990: document.getElementById('showcolauthorquota').disabled = 'disabled';
4991: }
4992: }
1.374 raeburn 4993: }
1.364 raeburn 4994: }
4995: return;
4996: }
4997:
1.202 raeburn 4998: END
4999: return $output;
5000:
5001: }
5002:
1.190 raeburn 5003: ###############################################################
5004: ###############################################################
5005: # Menu Phase One
5006: sub print_main_menu {
1.318 raeburn 5007: my ($permission,$context,$crstype) = @_;
5008: my $linkcontext = $context;
5009: my $stuterm = lc(&Apache::lonnet::plaintext('st',$crstype));
5010: if (($context eq 'course') && ($crstype eq 'Community')) {
5011: $linkcontext = lc($crstype);
5012: $stuterm = 'Members';
5013: }
1.208 raeburn 5014: my %links = (
1.298 droeschl 5015: domain => {
5016: upload => 'Upload a File of Users',
5017: singleuser => 'Add/Modify a User',
5018: listusers => 'Manage Users',
5019: },
5020: author => {
5021: upload => 'Upload a File of Co-authors',
5022: singleuser => 'Add/Modify a Co-author',
5023: listusers => 'Manage Co-authors',
5024: },
5025: course => {
5026: upload => 'Upload a File of Course Users',
5027: singleuser => 'Add/Modify a Course User',
1.354 www 5028: listusers => 'List and Modify Multiple Course Users',
1.298 droeschl 5029: },
1.318 raeburn 5030: community => {
5031: upload => 'Upload a File of Community Users',
5032: singleuser => 'Add/Modify a Community User',
1.354 www 5033: listusers => 'List and Modify Multiple Community Users',
1.318 raeburn 5034: },
5035: );
5036: my %linktitles = (
5037: domain => {
5038: singleuser => 'Add a user to the domain, and/or a course or community in the domain.',
5039: listusers => 'Show and manage users in this domain.',
5040: },
5041: author => {
5042: singleuser => 'Add a user with a co- or assistant author role.',
5043: listusers => 'Show and manage co- or assistant authors.',
5044: },
5045: course => {
5046: singleuser => 'Add a user with a certain role to this course.',
5047: listusers => 'Show and manage users in this course.',
5048: },
5049: community => {
5050: singleuser => 'Add a user with a certain role to this community.',
5051: listusers => 'Show and manage users in this community.',
5052: },
1.298 droeschl 5053: );
5054: my @menu = ( {categorytitle => 'Single Users',
5055: items =>
5056: [
5057: {
1.318 raeburn 5058: linktext => $links{$linkcontext}{'singleuser'},
1.298 droeschl 5059: icon => 'edit-redo.png',
5060: #help => 'Course_Change_Privileges',
5061: url => '/adm/createuser?action=singleuser',
5062: permission => $permission->{'cusr'},
1.318 raeburn 5063: linktitle => $linktitles{$linkcontext}{'singleuser'},
1.298 droeschl 5064: },
5065: ]},
5066:
5067: {categorytitle => 'Multiple Users',
5068: items =>
5069: [
5070: {
1.318 raeburn 5071: linktext => $links{$linkcontext}{'upload'},
1.340 wenzelju 5072: icon => 'uplusr.png',
1.298 droeschl 5073: #help => 'Course_Create_Class_List',
5074: url => '/adm/createuser?action=upload',
5075: permission => $permission->{'cusr'},
5076: linktitle => 'Upload a CSV or a text file containing users.',
5077: },
5078: {
1.318 raeburn 5079: linktext => $links{$linkcontext}{'listusers'},
1.340 wenzelju 5080: icon => 'mngcu.png',
1.298 droeschl 5081: #help => 'Course_View_Class_List',
5082: url => '/adm/createuser?action=listusers',
5083: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.318 raeburn 5084: linktitle => $linktitles{$linkcontext}{'listusers'},
1.298 droeschl 5085: },
5086:
5087: ]},
5088:
5089: {categorytitle => 'Administration',
5090: items => [ ]},
5091: );
5092:
1.265 mielkec 5093: if ($context eq 'domain'){
1.298 droeschl 5094:
5095: push(@{ $menu[2]->{items} }, #Category: Administration
5096: {
5097: linktext => 'Custom Roles',
5098: icon => 'emblem-photos.png',
5099: #help => 'Course_Editing_Custom_Roles',
5100: url => '/adm/createuser?action=custom',
5101: permission => $permission->{'custom'},
5102: linktitle => 'Configure a custom role.',
5103: },
1.362 raeburn 5104: {
5105: linktext => 'Authoring Space Requests',
5106: icon => 'selfenrl-queue.png',
5107: #help => 'Domain_Role_Approvals',
5108: url => '/adm/createuser?action=processauthorreq',
5109: permission => $permission->{'cusr'},
5110: linktitle => 'Approve or reject author role requests',
5111: },
1.363 raeburn 5112: {
5113: linktext => 'Change Log',
5114: icon => 'document-properties.png',
5115: #help => 'Course_User_Logs',
5116: url => '/adm/createuser?action=changelogs',
5117: permission => $permission->{'cusr'},
5118: linktitle => 'View change log.',
5119: },
1.298 droeschl 5120: );
5121:
1.265 mielkec 5122: }elsif ($context eq 'course'){
1.298 droeschl 5123: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity();
1.318 raeburn 5124:
5125: my %linktext = (
5126: 'Course' => {
5127: single => 'Add/Modify a Student',
5128: drop => 'Drop Students',
5129: groups => 'Course Groups',
5130: },
5131: 'Community' => {
5132: single => 'Add/Modify a Member',
5133: drop => 'Drop Members',
5134: groups => 'Community Groups',
5135: },
5136: );
5137:
5138: my %linktitle = (
5139: 'Course' => {
5140: single => 'Add a user with the role of student to this course',
5141: drop => 'Remove a student from this course.',
5142: groups => 'Manage course groups',
5143: },
5144: 'Community' => {
5145: single => 'Add a user with the role of member to this community',
5146: drop => 'Remove a member from this community.',
5147: groups => 'Manage community groups',
5148: },
5149: );
5150:
1.298 droeschl 5151: push(@{ $menu[0]->{items} }, #Category: Single Users
5152: {
1.318 raeburn 5153: linktext => $linktext{$crstype}{'single'},
1.298 droeschl 5154: #help => 'Course_Add_Student',
5155: icon => 'list-add.png',
5156: url => '/adm/createuser?action=singlestudent',
5157: permission => $permission->{'cusr'},
1.318 raeburn 5158: linktitle => $linktitle{$crstype}{'single'},
1.298 droeschl 5159: },
5160: );
5161:
5162: push(@{ $menu[1]->{items} }, #Category: Multiple Users
5163: {
1.318 raeburn 5164: linktext => $linktext{$crstype}{'drop'},
1.298 droeschl 5165: icon => 'edit-undo.png',
5166: #help => 'Course_Drop_Student',
5167: url => '/adm/createuser?action=drop',
5168: permission => $permission->{'cusr'},
1.318 raeburn 5169: linktitle => $linktitle{$crstype}{'drop'},
1.298 droeschl 5170: },
5171: );
5172: push(@{ $menu[2]->{items} }, #Category: Administration
5173: {
5174: linktext => 'Custom Roles',
5175: icon => 'emblem-photos.png',
5176: #help => 'Course_Editing_Custom_Roles',
5177: url => '/adm/createuser?action=custom',
5178: permission => $permission->{'custom'},
5179: linktitle => 'Configure a custom role.',
5180: },
5181: {
1.318 raeburn 5182: linktext => $linktext{$crstype}{'groups'},
1.333 wenzelju 5183: icon => 'grps.png',
1.298 droeschl 5184: #help => 'Course_Manage_Group',
5185: url => '/adm/coursegroups?refpage=cusr',
5186: permission => $permission->{'grp_manage'},
1.318 raeburn 5187: linktitle => $linktitle{$crstype}{'groups'},
1.298 droeschl 5188: },
5189: {
1.328 wenzelju 5190: linktext => 'Change Log',
1.298 droeschl 5191: icon => 'document-properties.png',
5192: #help => 'Course_User_Logs',
5193: url => '/adm/createuser?action=changelogs',
5194: permission => $permission->{'cusr'},
5195: linktitle => 'View change log.',
5196: },
5197: );
1.277 raeburn 5198: if ($env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'}) {
1.298 droeschl 5199: push(@{ $menu[2]->{items} },
5200: {
5201: linktext => 'Enrollment Requests',
5202: icon => 'selfenrl-queue.png',
5203: #help => 'Course_Approve_Selfenroll',
5204: url => '/adm/createuser?action=selfenrollqueue',
5205: permission => $permission->{'cusr'},
5206: linktitle =>'Approve or reject enrollment requests.',
5207: },
5208: );
1.277 raeburn 5209: }
1.298 droeschl 5210:
1.265 mielkec 5211: if (!exists($permission->{'cusr_section'})){
1.320 raeburn 5212: if ($crstype ne 'Community') {
5213: push(@{ $menu[2]->{items} },
5214: {
5215: linktext => 'Automated Enrollment',
5216: icon => 'roles.png',
5217: #help => 'Course_Automated_Enrollment',
5218: permission => (&Apache::lonnet::auto_run($cnum,$cdom)
5219: && $permission->{'cusr'}),
5220: url => '/adm/populate',
5221: linktitle => 'Automated enrollment manager.',
5222: }
5223: );
5224: }
5225: push(@{ $menu[2]->{items} },
1.298 droeschl 5226: {
5227: linktext => 'User Self-Enrollment',
1.342 wenzelju 5228: icon => 'self_enroll.png',
1.298 droeschl 5229: #help => 'Course_Self_Enrollment',
5230: url => '/adm/createuser?action=selfenroll',
5231: permission => $permission->{'cusr'},
1.317 bisitz 5232: linktitle => 'Configure user self-enrollment.',
1.298 droeschl 5233: },
5234: );
5235: }
1.363 raeburn 5236: } elsif ($context eq 'author') {
1.370 raeburn 5237: push(@{ $menu[2]->{items} }, #Category: Administration
1.363 raeburn 5238: {
5239: linktext => 'Change Log',
5240: icon => 'document-properties.png',
5241: #help => 'Course_User_Logs',
5242: url => '/adm/createuser?action=changelogs',
5243: permission => $permission->{'cusr'},
5244: linktitle => 'View change log.',
5245: },
1.370 raeburn 5246: );
1.363 raeburn 5247: }
5248: return Apache::lonhtmlcommon::generate_menu(@menu);
1.250 raeburn 5249: # { text => 'View Log-in History',
5250: # help => 'Course_User_Logins',
5251: # action => 'logins',
5252: # permission => $permission->{'cusr'},
5253: # });
1.190 raeburn 5254: }
5255:
1.189 albertel 5256: sub restore_prev_selections {
5257: my %saveable_parameters = ('srchby' => 'scalar',
5258: 'srchin' => 'scalar',
5259: 'srchtype' => 'scalar',
5260: );
5261: &Apache::loncommon::store_settings('user','user_picker',
5262: \%saveable_parameters);
5263: &Apache::loncommon::restore_settings('user','user_picker',
5264: \%saveable_parameters);
5265: }
5266:
1.237 raeburn 5267: sub print_selfenroll_menu {
5268: my ($r,$context,$permission) = @_;
1.322 raeburn 5269: my $crstype = &Apache::loncommon::course_type();
1.237 raeburn 5270: my $formname = 'enrollstudent';
5271: my $nolink = 1;
5272: my ($row,$lt) = &get_selfenroll_titles();
5273: my $groupslist = &Apache::lonuserutils::get_groupslist();
5274: my $setsec_js =
5275: &Apache::lonuserutils::setsections_javascript($formname,$groupslist);
1.249 raeburn 5276: my %alerts = &Apache::lonlocal::texthash(
5277: acto => 'Activation of self-enrollment was selected for the following domain(s)',
5278: butn => 'but no user types have been checked.',
5279: wilf => "Please uncheck 'activate' or check at least one type.",
5280: );
5281: my $selfenroll_js = <<"ENDSCRIPT";
5282: function update_types(caller,num) {
5283: var delidx = getIndexByName('selfenroll_delete');
5284: var actidx = getIndexByName('selfenroll_activate');
5285: if (caller == 'selfenroll_all') {
5286: var selall;
5287: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5288: if (document.$formname.selfenroll_all[i].checked) {
5289: selall = document.$formname.selfenroll_all[i].value;
5290: }
5291: }
5292: if (selall == 1) {
5293: if (delidx != -1) {
5294: if (document.$formname.selfenroll_delete.length) {
5295: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
5296: document.$formname.selfenroll_delete[j].checked = true;
5297: }
5298: } else {
5299: document.$formname.elements[delidx].checked = true;
5300: }
5301: }
5302: if (actidx != -1) {
5303: if (document.$formname.selfenroll_activate.length) {
5304: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5305: document.$formname.selfenroll_activate[j].checked = false;
5306: }
5307: } else {
5308: document.$formname.elements[actidx].checked = false;
5309: }
5310: }
5311: document.$formname.selfenroll_newdom.selectedIndex = 0;
5312: }
5313: }
5314: if (caller == 'selfenroll_activate') {
5315: if (document.$formname.selfenroll_activate.length) {
5316: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5317: if (document.$formname.selfenroll_activate[j].value == num) {
5318: if (document.$formname.selfenroll_activate[j].checked) {
5319: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5320: if (document.$formname.selfenroll_all[i].value == '1') {
5321: document.$formname.selfenroll_all[i].checked = false;
5322: }
5323: if (document.$formname.selfenroll_all[i].value == '0') {
5324: document.$formname.selfenroll_all[i].checked = true;
5325: }
5326: }
5327: }
5328: }
5329: }
5330: } else {
5331: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5332: if (document.$formname.selfenroll_all[i].value == '1') {
5333: document.$formname.selfenroll_all[i].checked = false;
5334: }
5335: if (document.$formname.selfenroll_all[i].value == '0') {
5336: document.$formname.selfenroll_all[i].checked = true;
5337: }
5338: }
5339: }
5340: }
5341: if (caller == 'selfenroll_delete') {
5342: if (document.$formname.selfenroll_delete.length) {
5343: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
5344: if (document.$formname.selfenroll_delete[j].value == num) {
5345: if (document.$formname.selfenroll_delete[j].checked) {
5346: var delindex = getIndexByName('selfenroll_types_'+num);
5347: if (delindex != -1) {
5348: if (document.$formname.elements[delindex].length) {
5349: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
5350: document.$formname.elements[delindex][k].checked = false;
5351: }
5352: } else {
5353: document.$formname.elements[delindex].checked = false;
5354: }
5355: }
5356: }
5357: }
5358: }
5359: } else {
5360: if (document.$formname.selfenroll_delete.checked) {
5361: var delindex = getIndexByName('selfenroll_types_'+num);
5362: if (delindex != -1) {
5363: if (document.$formname.elements[delindex].length) {
5364: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
5365: document.$formname.elements[delindex][k].checked = false;
5366: }
5367: } else {
5368: document.$formname.elements[delindex].checked = false;
5369: }
5370: }
5371: }
5372: }
5373: }
5374: return;
5375: }
5376:
5377: function validate_types(form) {
5378: var needaction = new Array();
5379: var countfail = 0;
5380: var actidx = getIndexByName('selfenroll_activate');
5381: if (actidx != -1) {
5382: if (document.$formname.selfenroll_activate.length) {
5383: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5384: var num = document.$formname.selfenroll_activate[j].value;
5385: if (document.$formname.selfenroll_activate[j].checked) {
5386: countfail = check_types(num,countfail,needaction)
5387: }
5388: }
5389: } else {
5390: if (document.$formname.selfenroll_activate.checked) {
5391: var num = document.enrollstudent.selfenroll_activate.value;
5392: countfail = check_types(num,countfail,needaction)
5393: }
5394: }
5395: }
5396: if (countfail > 0) {
5397: var msg = "$alerts{'acto'}\\n";
5398: var loopend = needaction.length -1;
5399: if (loopend > 0) {
5400: for (var m=0; m<loopend; m++) {
5401: msg += needaction[m]+", ";
5402: }
5403: }
5404: msg += needaction[loopend]+"\\n$alerts{'butn'}\\n$alerts{'wilf'}";
5405: alert(msg);
5406: return;
5407: }
5408: setSections(form);
5409: }
5410:
5411: function check_types(num,countfail,needaction) {
5412: var typeidx = getIndexByName('selfenroll_types_'+num);
5413: var count = 0;
5414: if (typeidx != -1) {
5415: if (document.$formname.elements[typeidx].length) {
5416: for (var k=0; k<document.$formname.elements[typeidx].length; k++) {
5417: if (document.$formname.elements[typeidx][k].checked) {
5418: count ++;
5419: }
5420: }
5421: } else {
5422: if (document.$formname.elements[typeidx].checked) {
5423: count ++;
5424: }
5425: }
5426: if (count == 0) {
5427: var domidx = getIndexByName('selfenroll_dom_'+num);
5428: if (domidx != -1) {
5429: var domname = document.$formname.elements[domidx].value;
5430: needaction[countfail] = domname;
5431: countfail ++;
5432: }
5433: }
5434: }
5435: return countfail;
5436: }
5437:
5438: function getIndexByName(item) {
5439: for (var i=0;i<document.$formname.elements.length;i++) {
5440: if (document.$formname.elements[i].name == item) {
5441: return i;
5442: }
5443: }
5444: return -1;
5445: }
5446: ENDSCRIPT
1.256 raeburn 5447: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
5448: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
5449:
1.237 raeburn 5450: my $output = '<script type="text/javascript">'."\n".
1.301 bisitz 5451: '// <![CDATA['."\n".
1.249 raeburn 5452: $setsec_js."\n".$selfenroll_js."\n".
1.301 bisitz 5453: '// ]]>'."\n".
1.237 raeburn 5454: '</script>'."\n".
1.256 raeburn 5455: '<h3>'.$lt->{'selfenroll'}.'</h3>'."\n";
5456: my ($visible,$cansetvis,$vismsgs,$visactions) = &visible_in_cat($cdom,$cnum);
5457: if (ref($visactions) eq 'HASH') {
5458: if ($visible) {
1.283 bisitz 5459: $output .= '<p class="LC_info">'.$visactions->{'vis'}.'</p>';
1.256 raeburn 5460: } else {
1.283 bisitz 5461: $output .= '<p class="LC_warning">'.$visactions->{'miss'}.'</p>'
5462: .$visactions->{'yous'}.
1.256 raeburn 5463: '<p>'.$visactions->{'gen'}.'<br />'.$visactions->{'coca'};
5464: if (ref($vismsgs) eq 'ARRAY') {
5465: $output .= '<br />'.$visactions->{'make'}.'<ul>';
5466: foreach my $item (@{$vismsgs}) {
5467: $output .= '<li>'.$visactions->{$item}.'</li>';
5468: }
5469: $output .= '</ul>';
5470: }
5471: $output .= '</p>';
5472: }
5473: }
5474: $output .= '<form name="'.$formname.'" method="post" action="/adm/createuser">'."\n".
5475: &Apache::lonhtmlcommon::start_pick_box();
1.237 raeburn 5476: if (ref($row) eq 'ARRAY') {
5477: foreach my $item (@{$row}) {
5478: my $title = $item;
5479: if (ref($lt) eq 'HASH') {
5480: $title = $lt->{$item};
5481: }
1.297 bisitz 5482: $output .= &Apache::lonhtmlcommon::row_title($title);
1.237 raeburn 5483: if ($item eq 'types') {
5484: my $curr_types = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_types'};
1.241 raeburn 5485: my $showdomdesc = 1;
5486: my $includeempty = 1;
5487: my $num = 0;
5488: $output .= &Apache::loncommon::start_data_table().
5489: &Apache::loncommon::start_data_table_row()
5490: .'<td colspan="2"><span class="LC_nobreak"><label>'
5491: .&mt('Any user in any domain:')
5492: .' <input type="radio" name="selfenroll_all" value="1" ';
5493: if ($curr_types eq '*') {
5494: $output .= ' checked="checked" ';
5495: }
1.249 raeburn 5496: $output .= 'onchange="javascript:update_types('.
5497: "'selfenroll_all'".');" />'.&mt('Yes').'</label>'.
5498: ' <input type="radio" name="selfenroll_all" value="0" ';
1.241 raeburn 5499: if ($curr_types ne '*') {
5500: $output .= ' checked="checked" ';
5501: }
1.249 raeburn 5502: $output .= ' onchange="javascript:update_types('.
5503: "'selfenroll_all'".');"/>'.&mt('No').'</label></td>'.
5504: &Apache::loncommon::end_data_table_row().
5505: &Apache::loncommon::end_data_table().
5506: &mt('Or').'<br />'.
5507: &Apache::loncommon::start_data_table();
1.241 raeburn 5508: my %currdoms;
1.249 raeburn 5509: if ($curr_types eq '') {
1.241 raeburn 5510: $output .= &new_selfenroll_dom_row($cdom,'0');
5511: } elsif ($curr_types ne '*') {
5512: my @entries = split(/;/,$curr_types);
5513: if (@entries > 0) {
5514: foreach my $entry (@entries) {
5515: my ($currdom,$typestr) = split(/:/,$entry);
5516: $currdoms{$currdom} = 1;
5517: my $domdesc = &Apache::lonnet::domain($currdom);
1.249 raeburn 5518: my @currinsttypes = split(',',$typestr);
1.241 raeburn 5519: $output .= &Apache::loncommon::start_data_table_row()
5520: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').'<b>'
5521: .' '.$domdesc.' ('.$currdom.')'
5522: .'</b><input type="hidden" name="selfenroll_dom_'.$num
5523: .'" value="'.$currdom.'" /></span><br />'
5524: .'<span class="LC_nobreak"><label><input type="checkbox" '
1.249 raeburn 5525: .'name="selfenroll_delete" value="'.$num.'" onchange="javascript:update_types('."'selfenroll_delete','$num'".');" />'
1.241 raeburn 5526: .&mt('Delete').'</label></span></td>';
1.249 raeburn 5527: $output .= '<td valign="top"> '.&mt('User types:').'<br />'
1.241 raeburn 5528: .&selfenroll_inst_types($num,$currdom,\@currinsttypes).'</td>'
5529: .&Apache::loncommon::end_data_table_row();
5530: $num ++;
5531: }
5532: }
5533: }
1.249 raeburn 5534: my $add_domtitle = &mt('Users in additional domain:');
1.241 raeburn 5535: if ($curr_types eq '*') {
1.249 raeburn 5536: $add_domtitle = &mt('Users in specific domain:');
1.241 raeburn 5537: } elsif ($curr_types eq '') {
1.249 raeburn 5538: $add_domtitle = &mt('Users in other domain:');
1.241 raeburn 5539: }
5540: $output .= &Apache::loncommon::start_data_table_row()
5541: .'<td colspan="2"><span class="LC_nobreak">'.$add_domtitle.'</span><br />'
5542: .&Apache::loncommon::select_dom_form('','selfenroll_newdom',
5543: $includeempty,$showdomdesc)
5544: .'<input type="hidden" name="selfenroll_types_total" value="'.$num.'" />'
5545: .'</td>'.&Apache::loncommon::end_data_table_row()
5546: .&Apache::loncommon::end_data_table();
1.237 raeburn 5547: } elsif ($item eq 'registered') {
5548: my ($regon,$regoff);
5549: if ($env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_registered'}) {
5550: $regon = ' checked="checked" ';
5551: $regoff = ' ';
5552: } else {
5553: $regon = ' ';
5554: $regoff = ' checked="checked" ';
5555: }
5556: $output .= '<label>'.
1.245 raeburn 5557: '<input type="radio" name="selfenroll_registered" value="1"'.$regon.'/>'.
1.244 bisitz 5558: &mt('Yes').'</label> <label>'.
1.245 raeburn 5559: '<input type="radio" name="selfenroll_registered" value="0"'.$regoff.'/>'.
1.244 bisitz 5560: &mt('No').'</label>';
1.237 raeburn 5561: } elsif ($item eq 'enroll_dates') {
5562: my $starttime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_start_date'};
5563: my $endtime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_end_date'};
5564: if ($starttime eq '') {
5565: $starttime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_start_date'};
5566: }
5567: if ($endtime eq '') {
5568: $endtime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_end_date'};
5569: }
5570: my $startform =
5571: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_date',$starttime,
5572: undef,undef,undef,undef,undef,undef,undef,$nolink);
5573: my $endform =
5574: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_date',$endtime,
5575: undef,undef,undef,undef,undef,undef,undef,$nolink);
5576: $output .= &selfenroll_date_forms($startform,$endform);
5577: } elsif ($item eq 'access_dates') {
5578: my $starttime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_start_access'};
5579: my $endtime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_end_access'};
5580: if ($starttime eq '') {
5581: $starttime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_start_date'};
5582: }
5583: if ($endtime eq '') {
5584: $endtime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_end_date'};
5585: }
5586: my $startform =
5587: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_access',$starttime,
5588: undef,undef,undef,undef,undef,undef,undef,$nolink);
5589: my $endform =
5590: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_access',$endtime,
5591: undef,undef,undef,undef,undef,undef,undef,$nolink);
5592: $output .= &selfenroll_date_forms($startform,$endform);
5593: } elsif ($item eq 'section') {
5594: my $currsec = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_section'};
5595: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
5596: my $newsecval;
5597: if ($currsec ne 'none' && $currsec ne '') {
5598: if (!defined($sections_count{$currsec})) {
5599: $newsecval = $currsec;
5600: }
5601: }
5602: my $sections_select =
5603: &Apache::lonuserutils::course_sections(\%sections_count,'st',$currsec);
5604: $output .= '<table class="LC_createuser">'."\n".
5605: '<tr class="LC_section_row">'."\n".
5606: '<td align="center">'.&mt('Existing sections')."\n".
5607: '<br />'.$sections_select.'</td><td align="center">'.
5608: &mt('New section').'<br />'."\n".
5609: '<input type="text" name="newsec" size="15" value="'.$newsecval.'" />'."\n".
5610: '<input type="hidden" name="sections" value="" />'."\n".
5611: '<input type="hidden" name="state" value="done" />'."\n".
5612: '</td></tr></table>'."\n";
1.276 raeburn 5613: } elsif ($item eq 'approval') {
5614: my ($appon,$appoff);
5615: my $cid = $env{'request.course.id'};
5616: my $currnotified = $env{'course.'.$cid.'.internal.selfenroll_notifylist'};
5617: if ($env{'course.'.$cid.'.internal.selfenroll_approval'}) {
5618: $appon = ' checked="checked" ';
5619: $appoff = ' ';
5620: } else {
5621: $appon = ' ';
5622: $appoff = ' checked="checked" ';
5623: }
5624: $output .= '<label>'.
5625: '<input type="radio" name="selfenroll_approval" value="1"'.$appon.'/>'.
5626: &mt('Yes').'</label> <label>'.
5627: '<input type="radio" name="selfenroll_approval" value="0"'.$appoff.'/>'.
5628: &mt('No').'</label>';
5629: my %advhash = &Apache::lonnet::get_course_adv_roles($cid,1);
5630: my (@ccs,%notified);
1.322 raeburn 5631: my $ccrole = 'cc';
5632: if ($crstype eq 'Community') {
5633: $ccrole = 'co';
5634: }
5635: if ($advhash{$ccrole}) {
5636: @ccs = split(/,/,$advhash{$ccrole});
1.276 raeburn 5637: }
5638: if ($currnotified) {
5639: foreach my $current (split(/,/,$currnotified)) {
5640: $notified{$current} = 1;
5641: if (!grep(/^\Q$current\E$/,@ccs)) {
5642: push(@ccs,$current);
5643: }
5644: }
5645: }
5646: if (@ccs) {
1.277 raeburn 5647: $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 5648: &Apache::loncommon::start_data_table_row();
5649: my $count = 0;
5650: my $numcols = 4;
5651: foreach my $cc (sort(@ccs)) {
5652: my $notifyon;
5653: my ($ccuname,$ccudom) = split(/:/,$cc);
5654: if ($notified{$cc}) {
5655: $notifyon = ' checked="checked" ';
5656: }
5657: if ($count && !$count%$numcols) {
5658: $output .= &Apache::loncommon::end_data_table_row().
5659: &Apache::loncommon::start_data_table_row()
5660: }
5661: $output .= '<td><span class="LC_nobreak"><label>'.
5662: '<input type="checkbox" name="selfenroll_notify"'.$notifyon.' value="'.$cc.'" />'.
5663: &Apache::loncommon::plainname($ccuname,$ccudom).
5664: '</label></span></td>';
1.343 raeburn 5665: $count ++;
1.276 raeburn 5666: }
5667: my $rem = $count%$numcols;
5668: if ($rem) {
5669: my $emptycols = $numcols - $rem;
5670: for (my $i=0; $i<$emptycols; $i++) {
5671: $output .= '<td> </td>';
5672: }
5673: }
5674: $output .= &Apache::loncommon::end_data_table_row().
5675: &Apache::loncommon::end_data_table();
5676: }
5677: } elsif ($item eq 'limit') {
5678: my ($crslimit,$selflimit,$nolimit);
5679: my $cid = $env{'request.course.id'};
5680: my $currlim = $env{'course.'.$cid.'.internal.selfenroll_limit'};
5681: my $currcap = $env{'course.'.$cid.'.internal.selfenroll_cap'};
1.343 raeburn 5682: $nolimit = ' checked="checked" ';
1.276 raeburn 5683: if ($currlim eq 'allstudents') {
5684: $crslimit = ' checked="checked" ';
5685: $selflimit = ' ';
5686: $nolimit = ' ';
5687: } elsif ($currlim eq 'selfenrolled') {
5688: $crslimit = ' ';
5689: $selflimit = ' checked="checked" ';
5690: $nolimit = ' ';
5691: } else {
5692: $crslimit = ' ';
5693: $selflimit = ' ';
5694: }
5695: $output .= '<table><tr><td><label>'.
1.278 raeburn 5696: '<input type="radio" name="selfenroll_limit" value="none"'.$nolimit.'/>'.
1.276 raeburn 5697: &mt('No limit').'</label></td><td><label>'.
5698: '<input type="radio" name="selfenroll_limit" value="allstudents"'.$crslimit.'/>'.
5699: &mt('Limit by total students').'</label></td><td><label>'.
5700: '<input type="radio" name="selfenroll_limit" value="selfenrolled"'.$selflimit.'/>'.
5701: &mt('Limit by total self-enrolled students').
5702: '</td></tr><tr>'.
5703: '<td> </td><td colspan="2"><span class="LC_nobreak">'.
5704: (' 'x3).&mt('Maximum number allowed: ').
5705: '<input type="text" name="selfenroll_cap" size = "5" value="'.$currcap.'" /></td></tr></table>';
1.237 raeburn 5706: }
5707: $output .= &Apache::lonhtmlcommon::row_closure(1);
5708: }
5709: }
5710: $output .= &Apache::lonhtmlcommon::end_pick_box().
1.241 raeburn 5711: '<br /><input type="button" name="selfenrollconf" value="'
1.282 schafran 5712: .&mt('Save').'" onclick="validate_types(this.form);" />'
1.241 raeburn 5713: .'<input type="hidden" name="action" value="selfenroll" /></form>';
1.237 raeburn 5714: $r->print($output);
5715: return;
5716: }
5717:
1.256 raeburn 5718: sub visible_in_cat {
5719: my ($cdom,$cnum) = @_;
5720: my %domconf = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
5721: my ($cathash,%settable,@vismsgs,$cansetvis);
5722: my %visactions = &Apache::lonlocal::texthash(
1.316 bisitz 5723: vis => 'Your course/community currently appears in the Course/Community Catalog for this domain.',
1.256 raeburn 5724: 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 5725: miss => 'Your course/community does not currently appear in the Course/Community Catalog for this domain.',
1.256 raeburn 5726: yous => 'You should remedy this if you plan to allow self-enrollment, otherwise students will have difficulty finding your course.',
5727: 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 5728: make => 'Make any changes to self-enrollment settings below, click "Save", then take action to include the course in the Catalog:',
1.256 raeburn 5729: take => 'Take the following action to ensure the course appears in the Catalog:',
5730: dc_unhide => 'Ask a domain coordinator to change the "Exclude from course catalog" setting.',
5731: dc_addinst => 'Ask a domain coordinator to enable display the catalog of "Official courses (with institutional codes)".',
5732: dc_instcode => 'Ask a domain coordinator to assign an institutional code (if this is an official course).',
5733: dc_catalog => 'Ask a domain coordinator to enable or create at least one course category in the domain.',
5734: dc_categories => 'Ask a domain coordinator to create a hierarchy of categories and sub categories for courses in the domain.',
5735: 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',
5736: dc_addcat => 'Ask a domain coordinator to assign a category to the course.',
5737: );
1.347 raeburn 5738: $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>"');
5739: $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>"');
5740: $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 5741: if (ref($domconf{'coursecategories'}) eq 'HASH') {
5742: if ($domconf{'coursecategories'}{'togglecats'} eq 'crs') {
5743: $settable{'togglecats'} = 1;
5744: }
5745: if ($domconf{'coursecategories'}{'categorize'} eq 'crs') {
5746: $settable{'categorize'} = 1;
5747: }
5748: $cathash = $domconf{'coursecategories'}{'cats'};
5749: }
1.260 raeburn 5750: if ($settable{'togglecats'} && $settable{'categorize'}) {
1.256 raeburn 5751: $cansetvis = &mt('You are able to both assign a course category and choose to exclude this course from the catalog.');
5752: } elsif ($settable{'togglecats'}) {
5753: $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 5754: } elsif ($settable{'categorize'}) {
1.256 raeburn 5755: $cansetvis = &mt('You may assign a course category, but only a Domain Coordinator may choose to exclude this course from the catalog.');
5756: } else {
5757: $cansetvis = &mt('Only a Domain Coordinator may assign a course category or choose to exclude this course from the catalog.');
5758: }
5759:
5760: my %currsettings =
5761: &Apache::lonnet::get('environment',['hidefromcat','categories','internal.coursecode'],
5762: $cdom,$cnum);
5763: my $visible = 0;
5764: if ($currsettings{'internal.coursecode'} ne '') {
5765: if (ref($domconf{'coursecategories'}) eq 'HASH') {
5766: $cathash = $domconf{'coursecategories'}{'cats'};
5767: if (ref($cathash) eq 'HASH') {
5768: if ($cathash->{'instcode::0'} eq '') {
5769: push(@vismsgs,'dc_addinst');
5770: } else {
5771: $visible = 1;
5772: }
5773: } else {
5774: $visible = 1;
5775: }
5776: } else {
5777: $visible = 1;
5778: }
5779: } else {
5780: if (ref($cathash) eq 'HASH') {
5781: if ($cathash->{'instcode::0'} ne '') {
5782: push(@vismsgs,'dc_instcode');
5783: }
5784: } else {
5785: push(@vismsgs,'dc_instcode');
5786: }
5787: }
5788: if ($currsettings{'categories'} ne '') {
5789: my $cathash;
5790: if (ref($domconf{'coursecategories'}) eq 'HASH') {
5791: $cathash = $domconf{'coursecategories'}{'cats'};
5792: if (ref($cathash) eq 'HASH') {
5793: if (keys(%{$cathash}) == 0) {
5794: push(@vismsgs,'dc_catalog');
5795: } elsif ((keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} ne '')) {
5796: push(@vismsgs,'dc_categories');
5797: } else {
5798: my @currcategories = split('&',$currsettings{'categories'});
5799: my $matched = 0;
5800: foreach my $cat (@currcategories) {
5801: if ($cathash->{$cat} ne '') {
5802: $visible = 1;
5803: $matched = 1;
5804: last;
5805: }
5806: }
5807: if (!$matched) {
1.260 raeburn 5808: if ($settable{'categorize'}) {
1.256 raeburn 5809: push(@vismsgs,'chgcat');
5810: } else {
5811: push(@vismsgs,'dc_chgcat');
5812: }
5813: }
5814: }
5815: }
5816: }
5817: } else {
5818: if (ref($cathash) eq 'HASH') {
5819: if ((keys(%{$cathash}) > 1) ||
5820: (keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} eq '')) {
1.260 raeburn 5821: if ($settable{'categorize'}) {
1.256 raeburn 5822: push(@vismsgs,'addcat');
5823: } else {
5824: push(@vismsgs,'dc_addcat');
5825: }
5826: }
5827: }
5828: }
5829: if ($currsettings{'hidefromcat'} eq 'yes') {
5830: $visible = 0;
5831: if ($settable{'togglecats'}) {
5832: unshift(@vismsgs,'unhide');
5833: } else {
5834: unshift(@vismsgs,'dc_unhide')
5835: }
5836: }
5837: return ($visible,$cansetvis,\@vismsgs,\%visactions);
5838: }
5839:
1.241 raeburn 5840: sub new_selfenroll_dom_row {
5841: my ($newdom,$num) = @_;
5842: my $domdesc = &Apache::lonnet::domain($newdom);
5843: my $output;
5844: if ($domdesc ne '') {
5845: $output .= &Apache::loncommon::start_data_table_row()
5846: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').' <b>'.$domdesc
5847: .' ('.$newdom.')</b><input type="hidden" name="selfenroll_dom_'.$num
1.249 raeburn 5848: .'" value="'.$newdom.'" /></span><br />'
5849: .'<span class="LC_nobreak"><label><input type="checkbox" '
5850: .'name="selfenroll_activate" value="'.$num.'" '
5851: .'onchange="javascript:update_types('
5852: ."'selfenroll_activate','$num'".');" />'
5853: .&mt('Activate').'</label></span></td>';
1.241 raeburn 5854: my @currinsttypes;
5855: $output .= '<td>'.&mt('User types:').'<br />'
5856: .&selfenroll_inst_types($num,$newdom,\@currinsttypes).'</td>'
5857: .&Apache::loncommon::end_data_table_row();
5858: }
5859: return $output;
5860: }
5861:
5862: sub selfenroll_inst_types {
5863: my ($num,$currdom,$currinsttypes) = @_;
5864: my $output;
5865: my $numinrow = 4;
5866: my $count = 0;
5867: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($currdom);
1.247 raeburn 5868: my $othervalue = 'any';
1.241 raeburn 5869: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
1.251 raeburn 5870: if (keys(%{$usertypes}) > 0) {
1.247 raeburn 5871: $othervalue = 'other';
5872: }
1.241 raeburn 5873: $output .= '<table><tr>';
5874: foreach my $type (@{$types}) {
5875: if (($count > 0) && ($count%$numinrow == 0)) {
5876: $output .= '</tr><tr>';
5877: }
5878: if (defined($usertypes->{$type})) {
1.257 raeburn 5879: my $esc_type = &escape($type);
1.241 raeburn 5880: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.
1.257 raeburn 5881: $esc_type.'" ';
1.241 raeburn 5882: if (ref($currinsttypes) eq 'ARRAY') {
5883: if (@{$currinsttypes} > 0) {
1.249 raeburn 5884: if (grep(/^any$/,@{$currinsttypes})) {
5885: $output .= 'checked="checked"';
1.257 raeburn 5886: } elsif (grep(/^\Q$esc_type\E$/,@{$currinsttypes})) {
1.241 raeburn 5887: $output .= 'checked="checked"';
5888: }
1.249 raeburn 5889: } else {
5890: $output .= 'checked="checked"';
1.241 raeburn 5891: }
5892: }
5893: $output .= ' name="selfenroll_types_'.$num.'" />'.$usertypes->{$type}.'</label></span></td>';
5894: }
5895: $count ++;
5896: }
5897: if (($count > 0) && ($count%$numinrow == 0)) {
5898: $output .= '</tr><tr>';
5899: }
1.249 raeburn 5900: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.$othervalue.'"';
1.241 raeburn 5901: if (ref($currinsttypes) eq 'ARRAY') {
5902: if (@{$currinsttypes} > 0) {
1.249 raeburn 5903: if (grep(/^any$/,@{$currinsttypes})) {
5904: $output .= ' checked="checked"';
5905: } elsif ($othervalue eq 'other') {
5906: if (grep(/^\Q$othervalue\E$/,@{$currinsttypes})) {
5907: $output .= ' checked="checked"';
5908: }
1.241 raeburn 5909: }
1.249 raeburn 5910: } else {
5911: $output .= ' checked="checked"';
1.241 raeburn 5912: }
1.249 raeburn 5913: } else {
5914: $output .= ' checked="checked"';
1.241 raeburn 5915: }
5916: $output .= ' name="selfenroll_types_'.$num.'" />'.$othertitle.'</label></span></td></tr></table>';
5917: }
5918: return $output;
5919: }
5920:
1.237 raeburn 5921: sub selfenroll_date_forms {
5922: my ($startform,$endform) = @_;
5923: my $output .= &Apache::lonhtmlcommon::start_pick_box()."\n".
1.244 bisitz 5924: &Apache::lonhtmlcommon::row_title(&mt('Start date'),
1.237 raeburn 5925: 'LC_oddrow_value')."\n".
5926: $startform."\n".
5927: &Apache::lonhtmlcommon::row_closure(1).
1.244 bisitz 5928: &Apache::lonhtmlcommon::row_title(&mt('End date'),
1.237 raeburn 5929: 'LC_oddrow_value')."\n".
5930: $endform."\n".
5931: &Apache::lonhtmlcommon::row_closure(1).
5932: &Apache::lonhtmlcommon::end_pick_box();
5933: return $output;
5934: }
5935:
1.239 raeburn 5936: sub print_userchangelogs_display {
5937: my ($r,$context,$permission) = @_;
1.363 raeburn 5938: my $formname = 'rolelog';
5939: my ($username,$domain,$crstype,%roleslog);
5940: if ($context eq 'domain') {
5941: $domain = $env{'request.role.domain'};
5942: %roleslog=&Apache::lonnet::dump_dom('nohist_rolelog',$domain);
5943: } else {
5944: if ($context eq 'course') {
5945: $domain = $env{'course.'.$env{'request.course.id'}.'.domain'};
5946: $username = $env{'course.'.$env{'request.course.id'}.'.num'};
5947: $crstype = &Apache::loncommon::course_type();
5948: my %saveable_parameters = ('show' => 'scalar',);
5949: &Apache::loncommon::store_course_settings('roles_log',
5950: \%saveable_parameters);
5951: &Apache::loncommon::restore_course_settings('roles_log',
5952: \%saveable_parameters);
5953: } elsif ($context eq 'author') {
5954: $domain = $env{'user.domain'};
5955: if ($env{'request.role'} =~ m{^au\./\Q$domain\E/$}) {
5956: $username = $env{'user.name'};
5957: } else {
5958: undef($domain);
5959: }
5960: }
5961: if ($domain ne '' && $username ne '') {
5962: %roleslog=&Apache::lonnet::dump('nohist_rolelog',$domain,$username);
5963: }
5964: }
1.239 raeburn 5965: if ((keys(%roleslog))[0]=~/^error\:/) { undef(%roleslog); }
5966:
5967: # set defaults
5968: my $now = time();
5969: my $defstart = $now - (7*24*3600); #7 days ago
5970: my %defaults = (
5971: page => '1',
5972: show => '10',
5973: role => 'any',
5974: chgcontext => 'any',
5975: rolelog_start_date => $defstart,
5976: rolelog_end_date => $now,
5977: );
5978: my $more_records = 0;
5979:
5980: # set current
5981: my %curr;
5982: foreach my $item ('show','page','role','chgcontext') {
5983: $curr{$item} = $env{'form.'.$item};
5984: }
5985: my ($startdate,$enddate) =
5986: &Apache::lonuserutils::get_dates_from_form('rolelog_start_date','rolelog_end_date');
5987: $curr{'rolelog_start_date'} = $startdate;
5988: $curr{'rolelog_end_date'} = $enddate;
5989: foreach my $key (keys(%defaults)) {
5990: if ($curr{$key} eq '') {
5991: $curr{$key} = $defaults{$key};
5992: }
5993: }
1.248 raeburn 5994: my (%whodunit,%changed,$version);
5995: ($version) = ($r->dir_config('lonVersion') =~ /^([\d\.]+)\-/);
1.239 raeburn 5996: my ($minshown,$maxshown);
1.255 raeburn 5997: $minshown = 1;
1.239 raeburn 5998: my $count = 0;
5999: if ($curr{'show'} ne &mt('all')) {
6000: $maxshown = $curr{'page'} * $curr{'show'};
6001: if ($curr{'page'} > 1) {
6002: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
6003: }
6004: }
1.301 bisitz 6005:
1.327 raeburn 6006: # Form Header
6007: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
1.363 raeburn 6008: &role_display_filter($context,$formname,$domain,$username,\%curr,
6009: $version,$crstype));
1.327 raeburn 6010:
6011: # Create navigation
6012: my ($nav_script,$nav_links) = &userlogdisplay_nav($formname,\%curr,$more_records);
6013: my $showntableheader = 0;
6014:
6015: # Table Header
6016: my $tableheader =
6017: &Apache::loncommon::start_data_table_header_row()
6018: .'<th> </th>'
6019: .'<th>'.&mt('When').'</th>'
6020: .'<th>'.&mt('Who made the change').'</th>'
6021: .'<th>'.&mt('Changed User').'</th>'
1.363 raeburn 6022: .'<th>'.&mt('Role').'</th>';
6023:
6024: if ($context eq 'course') {
6025: $tableheader .= '<th>'.&mt('Section').'</th>';
6026: }
6027: $tableheader .=
6028: '<th>'.&mt('Context').'</th>'
1.327 raeburn 6029: .'<th>'.&mt('Start').'</th>'
6030: .'<th>'.&mt('End').'</th>'
6031: .&Apache::loncommon::end_data_table_header_row();
6032:
6033: # Display user change log data
1.239 raeburn 6034: foreach my $id (sort { $roleslog{$b}{'exe_time'}<=>$roleslog{$a}{'exe_time'} } (keys(%roleslog))) {
6035: next if (($roleslog{$id}{'exe_time'} < $curr{'rolelog_start_date'}) ||
6036: ($roleslog{$id}{'exe_time'} > $curr{'rolelog_end_date'}));
6037: if ($curr{'show'} ne &mt('all')) {
6038: if ($count >= $curr{'page'} * $curr{'show'}) {
6039: $more_records = 1;
6040: last;
6041: }
6042: }
6043: if ($curr{'role'} ne 'any') {
6044: next if ($roleslog{$id}{'logentry'}{'role'} ne $curr{'role'});
6045: }
6046: if ($curr{'chgcontext'} ne 'any') {
6047: if ($curr{'chgcontext'} eq 'selfenroll') {
6048: next if (!$roleslog{$id}{'logentry'}{'selfenroll'});
6049: } else {
6050: next if ($roleslog{$id}{'logentry'}{'context'} ne $curr{'chgcontext'});
6051: }
6052: }
6053: $count ++;
6054: next if ($count < $minshown);
1.327 raeburn 6055: unless ($showntableheader) {
6056: $r->print($nav_script
6057: .$nav_links
6058: .&Apache::loncommon::start_data_table()
6059: .$tableheader);
6060: $r->rflush();
6061: $showntableheader = 1;
6062: }
1.239 raeburn 6063: if ($whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} eq '') {
6064: $whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} =
6065: &Apache::loncommon::plainname($roleslog{$id}{'exe_uname'},$roleslog{$id}{'exe_udom'});
6066: }
6067: if ($changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} eq '') {
6068: $changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} =
6069: &Apache::loncommon::plainname($roleslog{$id}{'uname'},$roleslog{$id}{'udom'});
6070: }
6071: my $sec = $roleslog{$id}{'logentry'}{'section'};
6072: if ($sec eq '') {
6073: $sec = &mt('None');
6074: }
6075: my ($rolestart,$roleend);
6076: if ($roleslog{$id}{'delflag'}) {
6077: $rolestart = &mt('deleted');
6078: $roleend = &mt('deleted');
6079: } else {
6080: $rolestart = $roleslog{$id}{'logentry'}{'start'};
6081: $roleend = $roleslog{$id}{'logentry'}{'end'};
6082: if ($rolestart eq '' || $rolestart == 0) {
6083: $rolestart = &mt('No start date');
6084: } else {
6085: $rolestart = &Apache::lonlocal::locallocaltime($rolestart);
6086: }
6087: if ($roleend eq '' || $roleend == 0) {
6088: $roleend = &mt('No end date');
6089: } else {
6090: $roleend = &Apache::lonlocal::locallocaltime($roleend);
6091: }
6092: }
6093: my $chgcontext = $roleslog{$id}{'logentry'}{'context'};
6094: if ($roleslog{$id}{'logentry'}{'selfenroll'}) {
6095: $chgcontext = 'selfenroll';
6096: }
1.363 raeburn 6097: my %lt = &rolechg_contexts($context,$crstype);
1.239 raeburn 6098: if ($chgcontext ne '' && $lt{$chgcontext} ne '') {
6099: $chgcontext = $lt{$chgcontext};
6100: }
1.327 raeburn 6101: $r->print(
1.301 bisitz 6102: &Apache::loncommon::start_data_table_row()
6103: .'<td>'.$count.'</td>'
6104: .'<td>'.&Apache::lonlocal::locallocaltime($roleslog{$id}{'exe_time'}).'</td>'
6105: .'<td>'.$whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}}.'</td>'
6106: .'<td>'.$changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}}.'</td>'
1.363 raeburn 6107: .'<td>'.&Apache::lonnet::plaintext($roleslog{$id}{'logentry'}{'role'},$crstype).'</td>');
6108: if ($context eq 'course') {
6109: $r->print('<td>'.$sec.'</td>');
6110: }
6111: $r->print(
6112: '<td>'.$chgcontext.'</td>'
1.301 bisitz 6113: .'<td>'.$rolestart.'</td>'
6114: .'<td>'.$roleend.'</td>'
1.327 raeburn 6115: .&Apache::loncommon::end_data_table_row()."\n");
1.301 bisitz 6116: }
6117:
1.327 raeburn 6118: if ($showntableheader) { # Table footer, if content displayed above
6119: $r->print(&Apache::loncommon::end_data_table()
6120: .$nav_links);
6121: } else { # No content displayed above
1.301 bisitz 6122: $r->print('<p class="LC_info">'
6123: .&mt('There are no records to display.')
6124: .'</p>'
6125: );
1.239 raeburn 6126: }
1.301 bisitz 6127:
1.327 raeburn 6128: # Form Footer
6129: $r->print(
6130: '<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
6131: .'<input type="hidden" name="action" value="changelogs" />'
6132: .'</form>');
6133: return;
6134: }
1.301 bisitz 6135:
1.327 raeburn 6136: sub userlogdisplay_nav {
6137: my ($formname,$curr,$more_records) = @_;
6138: my ($nav_script,$nav_links);
6139: if (ref($curr) eq 'HASH') {
6140: # Create Navigation:
6141: # Navigation Script
6142: $nav_script = <<"ENDSCRIPT";
1.239 raeburn 6143: <script type="text/javascript">
1.301 bisitz 6144: // <![CDATA[
1.239 raeburn 6145: function chgPage(caller) {
6146: if (caller == 'previous') {
6147: document.$formname.page.value --;
6148: }
6149: if (caller == 'next') {
6150: document.$formname.page.value ++;
6151: }
1.327 raeburn 6152: document.$formname.submit();
1.239 raeburn 6153: return;
6154: }
1.301 bisitz 6155: // ]]>
1.239 raeburn 6156: </script>
6157: ENDSCRIPT
1.327 raeburn 6158: # Navigation Buttons
6159: $nav_links = '<p>';
6160: if (($curr->{'page'} > 1) || ($more_records)) {
6161: if ($curr->{'page'} > 1) {
6162: $nav_links .= '<input type="button"'
6163: .' onclick="javascript:chgPage('."'previous'".');"'
6164: .' value="'.&mt('Previous [_1] changes',$curr->{'show'})
6165: .'" /> ';
6166: }
6167: if ($more_records) {
6168: $nav_links .= '<input type="button"'
6169: .' onclick="javascript:chgPage('."'next'".');"'
6170: .' value="'.&mt('Next [_1] changes',$curr->{'show'})
6171: .'" />';
6172: }
1.301 bisitz 6173: }
1.327 raeburn 6174: $nav_links .= '</p>';
1.301 bisitz 6175: }
1.327 raeburn 6176: return ($nav_script,$nav_links);
1.239 raeburn 6177: }
6178:
6179: sub role_display_filter {
1.363 raeburn 6180: my ($context,$formname,$cdom,$cnum,$curr,$version,$crstype) = @_;
6181: my $lctype;
6182: if ($context eq 'course') {
6183: $lctype = lc($crstype);
6184: }
1.239 raeburn 6185: my $nolink = 1;
6186: my $output = '<table><tr><td valign="top">'.
1.301 bisitz 6187: '<span class="LC_nobreak"><b>'.&mt('Changes/page:').'</b></span><br />'.
1.239 raeburn 6188: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
6189: (&mt('all'),5,10,20,50,100,1000,10000)).
6190: '</td><td> </td>';
6191: my $startform =
6192: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_start_date',
6193: $curr->{'rolelog_start_date'},undef,
6194: undef,undef,undef,undef,undef,undef,$nolink);
6195: my $endform =
6196: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_end_date',
6197: $curr->{'rolelog_end_date'},undef,
6198: undef,undef,undef,undef,undef,undef,$nolink);
1.363 raeburn 6199: my %lt = &rolechg_contexts($context,$crstype);
1.301 bisitz 6200: $output .= '<td valign="top"><b>'.&mt('Window during which changes occurred:').'</b><br />'.
6201: '<table><tr><td>'.&mt('After:').
6202: '</td><td>'.$startform.'</td></tr>'.
6203: '<tr><td>'.&mt('Before:').'</td>'.
6204: '<td>'.$endform.'</td></tr></table>'.
6205: '</td>'.
6206: '<td> </td>'.
1.239 raeburn 6207: '<td valign="top"><b>'.&mt('Role:').'</b><br />'.
6208: '<select name="role"><option value="any"';
6209: if ($curr->{'role'} eq 'any') {
6210: $output .= ' selected="selected"';
6211: }
6212: $output .= '>'.&mt('Any').'</option>'."\n";
1.363 raeburn 6213: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
1.239 raeburn 6214: foreach my $role (@roles) {
6215: my $plrole;
6216: if ($role eq 'cr') {
6217: $plrole = &mt('Custom Role');
6218: } else {
1.318 raeburn 6219: $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.239 raeburn 6220: }
6221: my $selstr = '';
6222: if ($role eq $curr->{'role'}) {
6223: $selstr = ' selected="selected"';
6224: }
6225: $output .= ' <option value="'.$role.'"'.$selstr.'>'.$plrole.'</option>';
6226: }
1.301 bisitz 6227: $output .= '</select></td>'.
6228: '<td> </td>'.
6229: '<td valign="top"><b>'.
1.239 raeburn 6230: &mt('Context:').'</b><br /><select name="chgcontext">';
1.363 raeburn 6231: my @posscontexts;
6232: if ($context eq 'course') {
1.376 raeburn 6233: @posscontexts = ('any','automated','updatenow','createcourse','course','domain','selfenroll','requestcourses');
1.363 raeburn 6234: } elsif ($context eq 'domain') {
6235: @posscontexts = ('any','domain','requestauthor','domconfig','server');
6236: } else {
6237: @posscontexts = ('any','author','domain');
6238: }
6239: foreach my $chgtype (@posscontexts) {
1.239 raeburn 6240: my $selstr = '';
6241: if ($curr->{'chgcontext'} eq $chgtype) {
1.301 bisitz 6242: $selstr = ' selected="selected"';
1.239 raeburn 6243: }
1.363 raeburn 6244: if ($context eq 'course') {
1.376 raeburn 6245: if (($chgtype eq 'automated') || ($chgtype eq 'updatenow')) {
1.363 raeburn 6246: next if (!&Apache::lonnet::auto_run($cnum,$cdom));
6247: }
1.239 raeburn 6248: }
6249: $output .= '<option value="'.$chgtype.'"'.$selstr.'>'.$lt{$chgtype}.'</option>'."\n";
1.248 raeburn 6250: }
1.303 bisitz 6251: $output .= '</select></td>'
6252: .'</tr></table>';
6253:
6254: # Update Display button
6255: $output .= '<p>'
6256: .'<input type="submit" value="'.&mt('Update Display').'" />'
6257: .'</p>';
6258:
6259: # Server version info
1.363 raeburn 6260: my $needsrev = '2.11.0';
6261: if ($context eq 'course') {
6262: $needsrev = '2.7.0';
6263: }
6264:
1.303 bisitz 6265: $output .= '<p class="LC_info">'
6266: .&mt('Only changes made from servers running LON-CAPA [_1] or later are displayed.'
1.363 raeburn 6267: ,$needsrev);
1.248 raeburn 6268: if ($version) {
1.303 bisitz 6269: $output .= ' '.&mt('This LON-CAPA server is version [_1]',$version);
6270: }
6271: $output .= '</p><hr />';
1.239 raeburn 6272: return $output;
6273: }
6274:
6275: sub rolechg_contexts {
1.363 raeburn 6276: my ($context,$crstype) = @_;
6277: my %lt;
6278: if ($context eq 'course') {
6279: %lt = &Apache::lonlocal::texthash (
1.239 raeburn 6280: any => 'Any',
1.376 raeburn 6281: automated => 'Automated Enrollment',
1.239 raeburn 6282: updatenow => 'Roster Update',
6283: createcourse => 'Course Creation',
6284: course => 'User Management in course',
6285: domain => 'User Management in domain',
1.313 raeburn 6286: selfenroll => 'Self-enrolled',
1.318 raeburn 6287: requestcourses => 'Course Request',
1.239 raeburn 6288: );
1.363 raeburn 6289: if ($crstype eq 'Community') {
6290: $lt{'createcourse'} = &mt('Community Creation');
6291: $lt{'course'} = &mt('User Management in community');
6292: $lt{'requestcourses'} = &mt('Community Request');
6293: }
6294: } elsif ($context eq 'domain') {
6295: %lt = &Apache::lonlocal::texthash (
6296: any => 'Any',
6297: domain => 'User Management in domain',
6298: requestauthor => 'Authoring Request',
6299: server => 'Command line script (DC role)',
6300: domconfig => 'Self-enrolled',
6301: );
6302: } else {
6303: %lt = &Apache::lonlocal::texthash (
6304: any => 'Any',
6305: domain => 'User Management in domain',
6306: author => 'User Management by author',
6307: );
6308: }
1.239 raeburn 6309: return %lt;
6310: }
6311:
1.27 matthew 6312: #-------------------------------------------------- functions for &phase_two
1.160 raeburn 6313: sub user_search_result {
1.221 raeburn 6314: my ($context,$srch) = @_;
1.160 raeburn 6315: my %allhomes;
6316: my %inst_matches;
6317: my %srch_results;
1.181 raeburn 6318: my ($response,$currstate,$forcenewuser,$dirsrchres);
1.183 raeburn 6319: $srch->{'srchterm'} =~ s/\s+/ /g;
1.176 raeburn 6320: if ($srch->{'srchby'} !~ /^(uname|lastname|lastfirst)$/) {
1.160 raeburn 6321: $response = &mt('Invalid search.');
6322: }
6323: if ($srch->{'srchin'} !~ /^(crs|dom|alc|instd)$/) {
6324: $response = &mt('Invalid search.');
6325: }
1.177 raeburn 6326: if ($srch->{'srchtype'} !~ /^(exact|contains|begins)$/) {
1.160 raeburn 6327: $response = &mt('Invalid search.');
6328: }
6329: if ($srch->{'srchterm'} eq '') {
6330: $response = &mt('You must enter a search term.');
6331: }
1.183 raeburn 6332: if ($srch->{'srchterm'} =~ /^\s+$/) {
6333: $response = &mt('Your search term must contain more than just spaces.');
6334: }
1.160 raeburn 6335: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'instd')) {
6336: if (($srch->{'srchdomain'} eq '') ||
1.163 albertel 6337: ! (&Apache::lonnet::domain($srch->{'srchdomain'}))) {
1.160 raeburn 6338: $response = &mt('You must specify a valid domain when searching in a domain or institutional directory.')
6339: }
6340: }
6341: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs') ||
6342: ($srch->{'srchin'} eq 'alc')) {
1.176 raeburn 6343: if ($srch->{'srchby'} eq 'uname') {
1.243 raeburn 6344: my $unamecheck = $srch->{'srchterm'};
6345: if ($srch->{'srchtype'} eq 'contains') {
6346: if ($unamecheck !~ /^\w/) {
6347: $unamecheck = 'a'.$unamecheck;
6348: }
6349: }
6350: if ($unamecheck !~ /^$match_username$/) {
1.176 raeburn 6351: $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
6352: }
1.160 raeburn 6353: }
6354: }
1.180 raeburn 6355: if ($response ne '') {
6356: $response = '<span class="LC_warning">'.$response.'</span>';
6357: }
1.160 raeburn 6358: if ($srch->{'srchin'} eq 'instd') {
6359: my $instd_chk = &directorysrch_check($srch);
6360: if ($instd_chk ne 'ok') {
1.180 raeburn 6361: $response = '<span class="LC_warning">'.$instd_chk.'</span>'.
6362: '<br />'.&mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').'<br /><br />';
1.160 raeburn 6363: }
6364: }
6365: if ($response ne '') {
1.180 raeburn 6366: return ($currstate,$response);
1.160 raeburn 6367: }
6368: if ($srch->{'srchby'} eq 'uname') {
6369: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs')) {
6370: if ($env{'form.forcenew'}) {
6371: if ($srch->{'srchdomain'} ne $env{'request.role.domain'}) {
6372: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
6373: if ($uhome eq 'no_host') {
6374: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
1.180 raeburn 6375: my $showdom = &display_domain_info($env{'request.role.domain'});
6376: $response = &mt('New users can only be created in the domain to which your current role belongs - [_1].',$showdom);
1.160 raeburn 6377: } else {
1.179 raeburn 6378: $currstate = 'modify';
1.160 raeburn 6379: }
6380: } else {
1.179 raeburn 6381: $currstate = 'modify';
1.160 raeburn 6382: }
6383: } else {
6384: if ($srch->{'srchin'} eq 'dom') {
1.162 raeburn 6385: if ($srch->{'srchtype'} eq 'exact') {
6386: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
6387: if ($uhome eq 'no_host') {
1.179 raeburn 6388: ($currstate,$response,$forcenewuser) =
1.221 raeburn 6389: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 6390: } else {
1.179 raeburn 6391: $currstate = 'modify';
1.310 raeburn 6392: my $uname = $srch->{'srchterm'};
6393: my $udom = $srch->{'srchdomain'};
6394: $srch_results{$uname.':'.$udom} =
6395: { &Apache::lonnet::get('environment',
6396: ['firstname',
6397: 'lastname',
6398: 'permanentemail'],
6399: $udom,$uname)
6400: };
1.162 raeburn 6401: }
6402: } else {
6403: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 6404: ($currstate,$response,$forcenewuser) =
1.221 raeburn 6405: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 6406: }
6407: } else {
1.167 albertel 6408: my $courseusers = &get_courseusers();
1.162 raeburn 6409: if ($srch->{'srchtype'} eq 'exact') {
1.167 albertel 6410: if (exists($courseusers->{$srch->{'srchterm'}.':'.$srch->{'srchdomain'}})) {
1.179 raeburn 6411: $currstate = 'modify';
1.162 raeburn 6412: } else {
1.179 raeburn 6413: ($currstate,$response,$forcenewuser) =
1.221 raeburn 6414: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 6415: }
1.160 raeburn 6416: } else {
1.167 albertel 6417: foreach my $user (keys(%$courseusers)) {
1.162 raeburn 6418: my ($cuname,$cudomain) = split(/:/,$user);
6419: if ($cudomain eq $srch->{'srchdomain'}) {
1.177 raeburn 6420: my $matched = 0;
6421: if ($srch->{'srchtype'} eq 'begins') {
6422: if ($cuname =~ /^\Q$srch->{'srchterm'}\E/i) {
6423: $matched = 1;
6424: }
6425: } else {
6426: if ($cuname =~ /\Q$srch->{'srchterm'}\E/i) {
6427: $matched = 1;
6428: }
6429: }
6430: if ($matched) {
1.167 albertel 6431: $srch_results{$user} =
6432: {&Apache::lonnet::get('environment',
6433: ['firstname',
6434: 'lastname',
1.194 albertel 6435: 'permanentemail'],
6436: $cudomain,$cuname)};
1.162 raeburn 6437: }
6438: }
6439: }
1.179 raeburn 6440: ($currstate,$response,$forcenewuser) =
1.221 raeburn 6441: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 6442: }
6443: }
6444: }
6445: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 6446: $currstate = 'query';
1.160 raeburn 6447: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 6448: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
6449: if ($dirsrchres eq 'ok') {
6450: ($currstate,$response,$forcenewuser) =
1.221 raeburn 6451: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 6452: } else {
6453: my $showdom = &display_domain_info($srch->{'srchdomain'});
6454: $response = '<span class="LC_warning">'.
6455: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
6456: '</span><br />'.
6457: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
6458: '<br /><br />';
6459: }
1.160 raeburn 6460: }
6461: } else {
6462: if ($srch->{'srchin'} eq 'dom') {
6463: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 6464: ($currstate,$response,$forcenewuser) =
1.221 raeburn 6465: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 6466: } elsif ($srch->{'srchin'} eq 'crs') {
1.167 albertel 6467: my $courseusers = &get_courseusers();
6468: foreach my $user (keys(%$courseusers)) {
1.160 raeburn 6469: my ($uname,$udom) = split(/:/,$user);
6470: my %names = &Apache::loncommon::getnames($uname,$udom);
6471: my %emails = &Apache::loncommon::getemails($uname,$udom);
6472: if ($srch->{'srchby'} eq 'lastname') {
6473: if ((($srch->{'srchtype'} eq 'exact') &&
6474: ($names{'lastname'} eq $srch->{'srchterm'})) ||
1.177 raeburn 6475: (($srch->{'srchtype'} eq 'begins') &&
6476: ($names{'lastname'} =~ /^\Q$srch->{'srchterm'}\E/i)) ||
1.160 raeburn 6477: (($srch->{'srchtype'} eq 'contains') &&
6478: ($names{'lastname'} =~ /\Q$srch->{'srchterm'}\E/i))) {
6479: $srch_results{$user} = {firstname => $names{'firstname'},
6480: lastname => $names{'lastname'},
6481: permanentemail => $emails{'permanentemail'},
6482: };
6483: }
6484: } elsif ($srch->{'srchby'} eq 'lastfirst') {
6485: my ($srchlast,$srchfirst) = split(/,/,$srch->{'srchterm'});
1.177 raeburn 6486: $srchlast =~ s/\s+$//;
6487: $srchfirst =~ s/^\s+//;
1.160 raeburn 6488: if ($srch->{'srchtype'} eq 'exact') {
6489: if (($names{'lastname'} eq $srchlast) &&
6490: ($names{'firstname'} eq $srchfirst)) {
6491: $srch_results{$user} = {firstname => $names{'firstname'},
6492: lastname => $names{'lastname'},
6493: permanentemail => $emails{'permanentemail'},
6494:
6495: };
6496: }
1.177 raeburn 6497: } elsif ($srch->{'srchtype'} eq 'begins') {
6498: if (($names{'lastname'} =~ /^\Q$srchlast\E/i) &&
6499: ($names{'firstname'} =~ /^\Q$srchfirst\E/i)) {
6500: $srch_results{$user} = {firstname => $names{'firstname'},
6501: lastname => $names{'lastname'},
6502: permanentemail => $emails{'permanentemail'},
6503: };
6504: }
6505: } else {
1.160 raeburn 6506: if (($names{'lastname'} =~ /\Q$srchlast\E/i) &&
6507: ($names{'firstname'} =~ /\Q$srchfirst\E/i)) {
6508: $srch_results{$user} = {firstname => $names{'firstname'},
6509: lastname => $names{'lastname'},
6510: permanentemail => $emails{'permanentemail'},
6511: };
6512: }
6513: }
6514: }
6515: }
1.179 raeburn 6516: ($currstate,$response,$forcenewuser) =
1.221 raeburn 6517: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 6518: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 6519: $currstate = 'query';
1.160 raeburn 6520: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 6521: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
6522: if ($dirsrchres eq 'ok') {
6523: ($currstate,$response,$forcenewuser) =
1.221 raeburn 6524: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 6525: } else {
6526: my $showdom = &display_domain_info($srch->{'srchdomain'}); $response = '<span class="LC_warning">'.
6527: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
6528: '</span><br />'.
6529: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
6530: '<br /><br />';
6531: }
1.160 raeburn 6532: }
6533: }
1.179 raeburn 6534: return ($currstate,$response,$forcenewuser,\%srch_results);
1.160 raeburn 6535: }
6536:
6537: sub directorysrch_check {
6538: my ($srch) = @_;
6539: my $can_search = 0;
6540: my $response;
6541: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
6542: ['directorysrch'],$srch->{'srchdomain'});
1.180 raeburn 6543: my $showdom = &display_domain_info($srch->{'srchdomain'});
1.160 raeburn 6544: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
6545: if (!$dom_inst_srch{'directorysrch'}{'available'}) {
1.180 raeburn 6546: return &mt('Institutional directory search is not available in domain: [_1]',$showdom);
1.160 raeburn 6547: }
6548: if ($dom_inst_srch{'directorysrch'}{'localonly'}) {
6549: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
1.180 raeburn 6550: return &mt('Institutional directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
1.160 raeburn 6551: }
6552: my @usertypes = split(/:/,$env{'environment.inststatus'});
6553: if (!@usertypes) {
6554: push(@usertypes,'default');
6555: }
6556: if (ref($dom_inst_srch{'directorysrch'}{'cansearch'}) eq 'ARRAY') {
6557: foreach my $type (@usertypes) {
6558: if (grep(/^\Q$type\E$/,@{$dom_inst_srch{'directorysrch'}{'cansearch'}})) {
6559: $can_search = 1;
6560: last;
6561: }
6562: }
6563: }
6564: if (!$can_search) {
6565: my ($insttypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($srch->{'srchdomain'});
6566: my @longtypes;
6567: foreach my $item (@usertypes) {
1.229 raeburn 6568: if (defined($insttypes->{$item})) {
6569: push (@longtypes,$insttypes->{$item});
6570: } elsif ($item eq 'default') {
6571: push (@longtypes,&mt('other'));
6572: }
1.160 raeburn 6573: }
6574: my $insttype_str = join(', ',@longtypes);
1.180 raeburn 6575: return &mt('Institutional directory search in domain: [_1] is not available to your user type: ',$showdom).$insttype_str;
1.229 raeburn 6576: }
1.160 raeburn 6577: } else {
6578: $can_search = 1;
6579: }
6580: } else {
1.180 raeburn 6581: return &mt('Institutional directory search has not been configured for domain: [_1]',$showdom);
1.160 raeburn 6582: }
6583: my %longtext = &Apache::lonlocal::texthash (
1.167 albertel 6584: uname => 'username',
1.160 raeburn 6585: lastfirst => 'last name, first name',
1.167 albertel 6586: lastname => 'last name',
1.172 raeburn 6587: contains => 'contains',
1.178 raeburn 6588: exact => 'as exact match to',
6589: begins => 'begins with',
1.160 raeburn 6590: );
6591: if ($can_search) {
6592: if (ref($dom_inst_srch{'directorysrch'}{'searchby'}) eq 'ARRAY') {
6593: if (!grep(/^\Q$srch->{'srchby'}\E$/,@{$dom_inst_srch{'directorysrch'}{'searchby'}})) {
1.180 raeburn 6594: return &mt('Institutional directory search in domain: [_1] is not available for searching by "[_2]"',$showdom,$longtext{$srch->{'srchby'}});
1.160 raeburn 6595: }
6596: } else {
1.180 raeburn 6597: return &mt('Institutional directory search in domain: [_1] is not available.', $showdom);
1.160 raeburn 6598: }
6599: }
6600: if ($can_search) {
1.178 raeburn 6601: if (ref($dom_inst_srch{'directorysrch'}{'searchtypes'}) eq 'ARRAY') {
6602: if (grep(/^\Q$srch->{'srchtype'}\E/,@{$dom_inst_srch{'directorysrch'}{'searchtypes'}})) {
6603: return 'ok';
6604: } else {
1.180 raeburn 6605: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 6606: }
6607: } else {
6608: if ((($dom_inst_srch{'directorysrch'}{'searchtypes'} eq 'specify') &&
6609: ($srch->{'srchtype'} eq 'exact' || $srch->{'srchtype'} eq 'contains')) ||
6610: ($dom_inst_srch{'directorysrch'}{'searchtypes'} eq $srch->{'srchtype'})) {
6611: return 'ok';
6612: } else {
1.180 raeburn 6613: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 6614: }
1.160 raeburn 6615: }
6616: }
6617: }
6618:
6619: sub get_courseusers {
6620: my %advhash;
1.167 albertel 6621: my $classlist = &Apache::loncoursedata::get_classlist();
1.160 raeburn 6622: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles();
6623: foreach my $role (sort(keys(%coursepersonnel))) {
6624: foreach my $user (split(/\,/,$coursepersonnel{$role})) {
1.167 albertel 6625: if (!exists($classlist->{$user})) {
6626: $classlist->{$user} = [];
6627: }
1.160 raeburn 6628: }
6629: }
1.167 albertel 6630: return $classlist;
1.160 raeburn 6631: }
6632:
6633: sub build_search_response {
1.221 raeburn 6634: my ($context,$srch,%srch_results) = @_;
1.179 raeburn 6635: my ($currstate,$response,$forcenewuser);
1.160 raeburn 6636: my %names = (
1.330 bisitz 6637: 'uname' => 'username',
6638: 'lastname' => 'last name',
1.160 raeburn 6639: 'lastfirst' => 'last name, first name',
1.330 bisitz 6640: 'crs' => 'this course',
6641: 'dom' => 'LON-CAPA domain',
6642: 'instd' => 'the institutional directory for domain',
1.160 raeburn 6643: );
6644:
6645: my %single = (
1.180 raeburn 6646: begins => 'A match',
1.160 raeburn 6647: contains => 'A match',
1.180 raeburn 6648: exact => 'An exact match',
1.160 raeburn 6649: );
6650: my %nomatch = (
1.180 raeburn 6651: begins => 'No match',
1.160 raeburn 6652: contains => 'No match',
1.180 raeburn 6653: exact => 'No exact match',
1.160 raeburn 6654: );
6655: if (keys(%srch_results) > 1) {
1.179 raeburn 6656: $currstate = 'select';
1.160 raeburn 6657: } else {
6658: if (keys(%srch_results) == 1) {
1.179 raeburn 6659: $currstate = 'modify';
1.180 raeburn 6660: $response = &mt("$single{$srch->{'srchtype'}} was found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}.",$srch->{'srchterm'});
6661: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 6662: $response .= ': '.&display_domain_info($srch->{'srchdomain'});
1.180 raeburn 6663: }
1.330 bisitz 6664: } else { # Search has nothing found. Prepare message to user.
6665: $response = '<span class="LC_warning">';
1.180 raeburn 6666: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 6667: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}: [_2]",
6668: '<b>'.$srch->{'srchterm'}.'</b>',
6669: &display_domain_info($srch->{'srchdomain'}));
6670: } else {
6671: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}.",
6672: '<b>'.$srch->{'srchterm'}.'</b>');
1.180 raeburn 6673: }
6674: $response .= '</span>';
1.330 bisitz 6675:
1.160 raeburn 6676: if ($srch->{'srchin'} ne 'alc') {
6677: $forcenewuser = 1;
6678: my $cansrchinst = 0;
6679: if ($srch->{'srchdomain'}) {
6680: my %domconfig = &Apache::lonnet::get_dom('configuration',['directorysrch'],$srch->{'srchdomain'});
6681: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
6682: if ($domconfig{'directorysrch'}{'available'}) {
6683: $cansrchinst = 1;
6684: }
6685: }
6686: }
1.180 raeburn 6687: if ((($srch->{'srchby'} eq 'lastfirst') ||
6688: ($srch->{'srchby'} eq 'lastname')) &&
6689: ($srch->{'srchin'} eq 'dom')) {
6690: if ($cansrchinst) {
6691: $response .= '<br />'.&mt('You may want to broaden your search to a search of the institutional directory for the domain.');
1.160 raeburn 6692: }
6693: }
1.180 raeburn 6694: if ($srch->{'srchin'} eq 'crs') {
6695: $response .= '<br />'.&mt('You may want to broaden your search to the selected LON-CAPA domain.');
6696: }
6697: }
1.305 raeburn 6698: my $createdom = $env{'request.role.domain'};
6699: if ($context eq 'requestcrs') {
6700: if ($env{'form.coursedom'} ne '') {
6701: $createdom = $env{'form.coursedom'};
6702: }
6703: }
6704: if (!($srch->{'srchby'} eq 'uname' && $srch->{'srchin'} eq 'dom' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchdomain'} eq $createdom)) {
1.221 raeburn 6705: my $cancreate =
1.305 raeburn 6706: &Apache::lonuserutils::can_create_user($createdom,$context);
6707: my $targetdom = '<span class="LC_cusr_emph">'.$createdom.'</span>';
1.221 raeburn 6708: if ($cancreate) {
1.305 raeburn 6709: my $showdom = &display_domain_info($createdom);
1.266 bisitz 6710: $response .= '<br /><br />'
6711: .'<b>'.&mt('To add a new user:').'</b>'
1.305 raeburn 6712: .'<br />';
6713: if ($context eq 'requestcrs') {
6714: $response .= &mt("(You can only define new users in the new course's domain - [_1])",$targetdom);
6715: } else {
6716: $response .= &mt("(You can only create new users in your current role's domain - [_1])",$targetdom);
6717: }
6718: $response .='<ul><li>'
1.266 bisitz 6719: .&mt("Set 'Domain/institution to search' to: [_1]",'<span class="LC_cusr_emph">'.$showdom.'</span>')
6720: .'</li><li>'
6721: .&mt("Set 'Search criteria' to: [_1]username is ..... in selected LON-CAPA domain[_2]",'<span class="LC_cusr_emph">','</span>')
6722: .'</li><li>'
6723: .&mt('Provide the proposed username')
6724: .'</li><li>'
6725: .&mt("Click 'Search'")
6726: .'</li></ul><br />';
1.221 raeburn 6727: } else {
6728: my $helplink = ' href="javascript:helpMenu('."'display'".')"';
1.305 raeburn 6729: $response .= '<br /><br />';
6730: if ($context eq 'requestcrs') {
1.314 raeburn 6731: $response .= &mt("You are not authorized to define new users in the new course's domain - [_1].",$targetdom);
1.305 raeburn 6732: } else {
6733: $response .= &mt("You are not authorized to create new users in your current role's domain - [_1].",$targetdom);
6734: }
6735: $response .= '<br />'
6736: .&mt('Please contact the [_1]helpdesk[_2] if you need to create a new user.'
1.266 bisitz 6737: ,' <a'.$helplink.'>'
6738: ,'</a>')
1.305 raeburn 6739: .'<br /><br />';
1.221 raeburn 6740: }
1.160 raeburn 6741: }
6742: }
6743: }
1.179 raeburn 6744: return ($currstate,$response,$forcenewuser);
1.160 raeburn 6745: }
6746:
1.180 raeburn 6747: sub display_domain_info {
6748: my ($dom) = @_;
6749: my $output = $dom;
6750: if ($dom ne '') {
6751: my $domdesc = &Apache::lonnet::domain($dom,'description');
6752: if ($domdesc ne '') {
6753: $output .= ' <span class="LC_cusr_emph">('.$domdesc.')</span>';
6754: }
6755: }
6756: return $output;
6757: }
6758:
1.160 raeburn 6759: sub crumb_utilities {
6760: my %elements = (
6761: crtuser => {
6762: srchterm => 'text',
1.172 raeburn 6763: srchin => 'selectbox',
1.160 raeburn 6764: srchby => 'selectbox',
6765: srchtype => 'selectbox',
6766: srchdomain => 'selectbox',
6767: },
1.207 raeburn 6768: crtusername => {
6769: srchterm => 'text',
6770: srchdomain => 'selectbox',
6771: },
1.160 raeburn 6772: docustom => {
6773: rolename => 'selectbox',
6774: newrolename => 'textbox',
6775: },
1.179 raeburn 6776: studentform => {
6777: srchterm => 'text',
6778: srchin => 'selectbox',
6779: srchby => 'selectbox',
6780: srchtype => 'selectbox',
6781: srchdomain => 'selectbox',
6782: },
1.160 raeburn 6783: );
6784:
6785: my $jsback .= qq|
6786: function backPage(formname,prevphase,prevstate) {
1.211 raeburn 6787: if (typeof prevphase == 'undefined') {
6788: formname.phase.value = '';
6789: }
6790: else {
6791: formname.phase.value = prevphase;
6792: }
6793: if (typeof prevstate == 'undefined') {
6794: formname.currstate.value = '';
6795: }
6796: else {
6797: formname.currstate.value = prevstate;
6798: }
1.160 raeburn 6799: formname.submit();
6800: }
6801: |;
6802: return ($jsback,\%elements);
6803: }
6804:
1.26 matthew 6805: sub course_level_table {
1.375 raeburn 6806: my ($inccourses,$showcredits,$defaultcredits) = @_;
6807: return unless (ref($inccourses) eq 'HASH');
1.26 matthew 6808: my $table = '';
1.62 www 6809: # Custom Roles?
6810:
1.190 raeburn 6811: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.89 raeburn 6812: my %lt=&Apache::lonlocal::texthash(
6813: 'exs' => "Existing sections",
6814: 'new' => "Define new section",
6815: 'ssd' => "Set Start Date",
6816: 'sed' => "Set End Date",
1.131 raeburn 6817: 'crl' => "Course Level",
1.89 raeburn 6818: 'act' => "Activate",
6819: 'rol' => "Role",
6820: 'ext' => "Extent",
1.113 raeburn 6821: 'grs' => "Section",
1.375 raeburn 6822: 'crd' => "Credits",
1.89 raeburn 6823: 'sta' => "Start",
6824: 'end' => "End"
6825: );
1.62 www 6826:
1.375 raeburn 6827: foreach my $protectedcourse (sort(keys(%{$inccourses}))) {
1.135 raeburn 6828: my $thiscourse=$protectedcourse;
1.26 matthew 6829: $thiscourse=~s:_:/:g;
6830: my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
1.365 raeburn 6831: my $isowner = &Apache::lonuserutils::is_courseowner($protectedcourse,$coursedata{'internal.courseowner'});
1.26 matthew 6832: my $area=$coursedata{'description'};
1.321 raeburn 6833: my $crstype=$coursedata{'type'};
1.135 raeburn 6834: if (!defined($area)) { $area=&mt('Unavailable course').': '.$protectedcourse; }
1.89 raeburn 6835: my ($domain,$cnum)=split(/\//,$thiscourse);
1.115 albertel 6836: my %sections_count;
1.101 albertel 6837: if (defined($env{'request.course.id'})) {
6838: if ($env{'request.course.id'} eq $domain.'_'.$cnum) {
1.115 albertel 6839: %sections_count =
6840: &Apache::loncommon::get_sections($domain,$cnum);
1.92 raeburn 6841: }
6842: }
1.321 raeburn 6843: my @roles = &Apache::lonuserutils::roles_by_context('course','',$crstype);
1.213 raeburn 6844: foreach my $role (@roles) {
1.321 raeburn 6845: my $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.329 raeburn 6846: if ((&Apache::lonnet::allowed('c'.$role,$thiscourse)) ||
6847: ((($role eq 'cc') || ($role eq 'co')) && ($isowner))) {
1.221 raeburn 6848: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 6849: $plrole,\%sections_count,\%lt,
6850: $defaultcredits,$crstype);
1.221 raeburn 6851: } elsif ($env{'request.course.sec'} ne '') {
6852: if (&Apache::lonnet::allowed('c'.$role,$thiscourse.'/'.
6853: $env{'request.course.sec'})) {
6854: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 6855: $plrole,\%sections_count,\%lt,
6856: $defaultcredits,$crstype);
1.26 matthew 6857: }
6858: }
6859: }
1.221 raeburn 6860: if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
1.324 raeburn 6861: foreach my $cust (sort(keys(%customroles))) {
6862: next if ($crstype eq 'Community' && $customroles{$cust} =~ /bre\&S/);
1.221 raeburn 6863: my $role = 'cr_cr_'.$env{'user.domain'}.'_'.$env{'user.name'}.'_'.$cust;
6864: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
6865: $cust,\%sections_count,\%lt);
6866: }
1.62 www 6867: }
1.26 matthew 6868: }
6869: return '' if ($table eq ''); # return nothing if there is nothing
6870: # in the table
1.188 raeburn 6871: my $result;
6872: if (!$env{'request.course.id'}) {
6873: $result = '<h4>'.$lt{'crl'}.'</h4>'."\n";
6874: }
6875: $result .=
1.136 raeburn 6876: &Apache::loncommon::start_data_table().
6877: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 6878: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
6879: '<th>'.$lt{'ext'}.'</th><th>'.$lt{'crd'}.'</th>'."\n".
6880: '<th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th>'."\n".
6881: '<th>'.$lt{'end'}.'</th>'.
1.136 raeburn 6882: &Apache::loncommon::end_data_table_header_row().
6883: $table.
6884: &Apache::loncommon::end_data_table();
1.26 matthew 6885: return $result;
6886: }
1.88 raeburn 6887:
1.221 raeburn 6888: sub course_level_row {
1.375 raeburn 6889: my ($protectedcourse,$role,$area,$domain,$plrole,$sections_count,
6890: $lt,$defaultcredits,$crstype) = @_;
6891: my $creditem;
1.222 raeburn 6892: my $row = &Apache::loncommon::start_data_table_row().
6893: ' <td><input type="checkbox" name="act_'.
6894: $protectedcourse.'_'.$role.'" /></td>'."\n".
6895: ' <td>'.$plrole.'</td>'."\n".
6896: ' <td>'.$area.'<br />Domain: '.$domain.'</td>'."\n";
1.375 raeburn 6897: if (($role eq 'st') && ($crstype eq 'Course')) {
6898: $row .=
6899: '<td><input type="text" name="credits_'.$protectedcourse.'_'.
6900: $role.'" size="3" value="'.$defaultcredits.'" /></td>';
6901: } else {
6902: $row .= '<td> </td>';
6903: }
1.322 raeburn 6904: if (($role eq 'cc') || ($role eq 'co')) {
1.222 raeburn 6905: $row .= '<td> </td>';
1.221 raeburn 6906: } elsif ($env{'request.course.sec'} ne '') {
1.222 raeburn 6907: $row .= ' <td><input type="hidden" value="'.
6908: $env{'request.course.sec'}.'" '.
6909: 'name="sec_'.$protectedcourse.'_'.$role.'" />'.
6910: $env{'request.course.sec'}.'</td>';
1.221 raeburn 6911: } else {
6912: if (ref($sections_count) eq 'HASH') {
6913: my $currsec =
6914: &Apache::lonuserutils::course_sections($sections_count,
6915: $protectedcourse.'_'.$role);
1.222 raeburn 6916: $row .= '<td><table class="LC_createuser">'."\n".
6917: '<tr class="LC_section_row">'."\n".
6918: ' <td valign="top">'.$lt->{'exs'}.'<br />'.
6919: $currsec.'</td>'."\n".
6920: ' <td> </td>'."\n".
6921: ' <td valign="top"> '.$lt->{'new'}.'<br />'.
1.221 raeburn 6922: '<input type="text" name="newsec_'.$protectedcourse.'_'.$role.
6923: '" value="" />'.
6924: '<input type="hidden" '.
6925: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n".
1.222 raeburn 6926: '</tr></table></td>'."\n";
1.221 raeburn 6927: } else {
1.222 raeburn 6928: $row .= '<td><input type="text" size="10" '.
1.375 raeburn 6929: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n";
1.221 raeburn 6930: }
6931: }
1.222 raeburn 6932: $row .= <<ENDTIMEENTRY;
6933: <td><input type="hidden" name="start_$protectedcourse\_$role" value="" />
1.221 raeburn 6934: <a href=
6935: "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 6936: <td><input type="hidden" name="end_$protectedcourse\_$role" value="" />
1.221 raeburn 6937: <a href=
6938: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$role.value,'end_$protectedcourse\_$role','cu.pres','dateset')">$lt->{'sed'}</a></td>
6939: ENDTIMEENTRY
1.222 raeburn 6940: $row .= &Apache::loncommon::end_data_table_row();
6941: return $row;
1.221 raeburn 6942: }
6943:
1.88 raeburn 6944: sub course_level_dc {
1.375 raeburn 6945: my ($dcdom,$showcredits) = @_;
1.190 raeburn 6946: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.213 raeburn 6947: my @roles = &Apache::lonuserutils::roles_by_context('course');
1.88 raeburn 6948: my $hiddenitems = '<input type="hidden" name="dcdomain" value="'.$dcdom.'" />'.
6949: '<input type="hidden" name="origdom" value="'.$dcdom.'" />'.
1.133 raeburn 6950: '<input type="hidden" name="dccourse" value="" />';
1.355 www 6951: my $courseform=&Apache::loncommon::selectcourse_link
1.356 raeburn 6952: ('cu','dccourse','dcdomain','coursedesc',undef,undef,'Select','crstype');
1.375 raeburn 6953: my $credit_elem;
6954: if ($showcredits) {
6955: $credit_elem = 'credits';
6956: }
6957: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,'currsec','cu','role','Course/Community Browser',$credit_elem);
1.88 raeburn 6958: my %lt=&Apache::lonlocal::texthash(
6959: 'rol' => "Role",
1.113 raeburn 6960: 'grs' => "Section",
1.88 raeburn 6961: 'exs' => "Existing sections",
6962: 'new' => "Define new section",
6963: 'sta' => "Start",
6964: 'end' => "End",
6965: 'ssd' => "Set Start Date",
1.355 www 6966: 'sed' => "Set End Date",
1.375 raeburn 6967: 'scc' => "Course/Community",
6968: 'crd' => "Credits",
1.88 raeburn 6969: );
1.323 raeburn 6970: my $header = '<h4>'.&mt('Course/Community Level').'</h4>'.
1.136 raeburn 6971: &Apache::loncommon::start_data_table().
6972: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 6973: '<th>'.$lt{'scc'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
6974: '<th>'.$lt{'grs'}.'</th><th>'.$lt{'crd'}.'</th>'."\n".
6975: '<th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'."\n".
1.136 raeburn 6976: &Apache::loncommon::end_data_table_header_row();
1.143 raeburn 6977: my $otheritems = &Apache::loncommon::start_data_table_row()."\n".
1.356 raeburn 6978: '<td><br /><span class="LC_nobreak"><input type="text" name="coursedesc" value="" onfocus="this.blur();opencrsbrowser('."'cu','dccourse','dcdomain','coursedesc','','','','crstype'".')" />'.
6979: $courseform.(' ' x4).'</span></td>'."\n".
1.323 raeburn 6980: '<td valign><br /><select name="role">'."\n";
1.213 raeburn 6981: foreach my $role (@roles) {
1.135 raeburn 6982: my $plrole=&Apache::lonnet::plaintext($role);
6983: $otheritems .= ' <option value="'.$role.'">'.$plrole;
1.88 raeburn 6984: }
6985: if ( keys %customroles > 0) {
1.135 raeburn 6986: foreach my $cust (sort keys %customroles) {
1.101 albertel 6987: my $custrole='cr_cr_'.$env{'user.domain'}.
1.135 raeburn 6988: '_'.$env{'user.name'}.'_'.$cust;
6989: $otheritems .= ' <option value="'.$custrole.'">'.$cust;
1.88 raeburn 6990: }
6991: }
6992: $otheritems .= '</select></td><td>'.
6993: '<table border="0" cellspacing="0" cellpadding="0">'.
6994: '<tr><td valign="top"><b>'.$lt{'exs'}.'</b><br /><select name="currsec">'.
6995: ' <option value=""><--'.&mt('Pick course first').'</select></td>'.
6996: '<td> </td>'.
6997: '<td valign="top"> <b>'.$lt{'new'}.'</b><br />'.
1.113 raeburn 6998: '<input type="text" name="newsec" value="" />'.
1.237 raeburn 6999: '<input type="hidden" name="section" value="" />'.
1.323 raeburn 7000: '<input type="hidden" name="groups" value="" />'.
7001: '<input type="hidden" name="crstype" value="" /></td>'.
1.375 raeburn 7002: '</tr></table></td>'."\n";
7003: if ($showcredits) {
7004: $otheritems .= '<td><br />'."\n".
7005: '<input type="text" size="3" name="credits" value="" />'."\n";
7006: }
1.88 raeburn 7007: $otheritems .= <<ENDTIMEENTRY;
1.323 raeburn 7008: <td><br /><input type="hidden" name="start" value='' />
1.88 raeburn 7009: <a href=
7010: "javascript:pjump('date_start','Start Date',document.cu.start.value,'start','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.323 raeburn 7011: <td><br /><input type="hidden" name="end" value='' />
1.88 raeburn 7012: <a href=
7013: "javascript:pjump('date_end','End Date',document.cu.end.value,'end','cu.pres','dateset')">$lt{'sed'}</a></td>
7014: ENDTIMEENTRY
1.136 raeburn 7015: $otheritems .= &Apache::loncommon::end_data_table_row().
7016: &Apache::loncommon::end_data_table()."\n";
1.88 raeburn 7017: return $cb_jscript.$header.$hiddenitems.$otheritems;
7018: }
7019:
1.237 raeburn 7020: sub update_selfenroll_config {
1.241 raeburn 7021: my ($r,$context,$permission) = @_;
1.237 raeburn 7022: my ($row,$lt) = &get_selfenroll_titles();
1.241 raeburn 7023: my %curr_groups = &Apache::longroup::coursegroups();
1.237 raeburn 7024: my (%changes,%warning);
7025: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
7026: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.241 raeburn 7027: my $curr_types;
1.237 raeburn 7028: if (ref($row) eq 'ARRAY') {
7029: foreach my $item (@{$row}) {
7030: if ($item eq 'enroll_dates') {
7031: my (%currenrolldate,%newenrolldate);
7032: foreach my $type ('start','end') {
7033: $currenrolldate{$type} = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$type.'_date'};
7034: $newenrolldate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_date');
7035: if ($newenrolldate{$type} ne $currenrolldate{$type}) {
7036: $changes{'internal.selfenroll_'.$type.'_date'} = $newenrolldate{$type};
7037: }
7038: }
7039: } elsif ($item eq 'access_dates') {
7040: my (%currdate,%newdate);
7041: foreach my $type ('start','end') {
7042: $currdate{$type} = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$type.'_access'};
7043: $newdate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_access');
7044: if ($newdate{$type} ne $currdate{$type}) {
7045: $changes{'internal.selfenroll_'.$type.'_access'} = $newdate{$type};
7046: }
7047: }
1.241 raeburn 7048: } elsif ($item eq 'types') {
7049: $curr_types =
7050: $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$item};
7051: if ($env{'form.selfenroll_all'}) {
7052: if ($curr_types ne '*') {
7053: $changes{'internal.selfenroll_types'} = '*';
7054: } else {
7055: next;
7056: }
7057: } else {
1.249 raeburn 7058: my %currdoms;
1.241 raeburn 7059: my @entries = split(/;/,$curr_types);
7060: my @deletedoms = &Apache::loncommon::get_env_multiple('form.selfenroll_delete');
1.249 raeburn 7061: my @activations = &Apache::loncommon::get_env_multiple('form.selfenroll_activate');
1.241 raeburn 7062: my $newnum = 0;
1.249 raeburn 7063: my @latesttypes;
7064: foreach my $num (@activations) {
7065: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$num);
7066: if (@types > 0) {
1.241 raeburn 7067: @types = sort(@types);
7068: my $typestr = join(',',@types);
1.249 raeburn 7069: my $typedom = $env{'form.selfenroll_dom_'.$num};
7070: $latesttypes[$newnum] = $typedom.':'.$typestr;
7071: $currdoms{$typedom} = 1;
1.241 raeburn 7072: $newnum ++;
7073: }
7074: }
1.338 raeburn 7075: for (my $j=0; $j<$env{'form.selfenroll_types_total'}; $j++) {
7076: if ((!grep(/^$j$/,@deletedoms)) && (!grep(/^$j$/,@activations))) {
1.249 raeburn 7077: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$j);
7078: if (@types > 0) {
7079: @types = sort(@types);
7080: my $typestr = join(',',@types);
7081: my $typedom = $env{'form.selfenroll_dom_'.$j};
7082: $latesttypes[$newnum] = $typedom.':'.$typestr;
7083: $currdoms{$typedom} = 1;
7084: $newnum ++;
7085: }
7086: }
7087: }
7088: if ($env{'form.selfenroll_newdom'} ne '') {
7089: my $typedom = $env{'form.selfenroll_newdom'};
7090: if ((!defined($currdoms{$typedom})) &&
7091: (&Apache::lonnet::domain($typedom) ne '')) {
7092: my $typestr;
7093: my ($othertitle,$usertypes,$types) =
7094: &Apache::loncommon::sorted_inst_types($typedom);
7095: my $othervalue = 'any';
7096: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7097: if (@{$types} > 0) {
1.257 raeburn 7098: my @esc_types = map { &escape($_); } @{$types};
1.249 raeburn 7099: $othervalue = 'other';
1.258 raeburn 7100: $typestr = join(',',(@esc_types,$othervalue));
1.249 raeburn 7101: }
7102: $typestr = $othervalue;
7103: } else {
7104: $typestr = $othervalue;
7105: }
7106: $latesttypes[$newnum] = $typedom.':'.$typestr;
7107: $newnum ++ ;
7108: }
7109: }
1.241 raeburn 7110: my $selfenroll_types = join(';',@latesttypes);
7111: if ($selfenroll_types ne $curr_types) {
7112: $changes{'internal.selfenroll_types'} = $selfenroll_types;
7113: }
7114: }
1.276 raeburn 7115: } elsif ($item eq 'limit') {
7116: my $newlimit = $env{'form.selfenroll_limit'};
7117: my $newcap = $env{'form.selfenroll_cap'};
7118: $newcap =~s/\s+//g;
7119: my $currlimit = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_limit'};
7120: $currlimit = 'none' if ($currlimit eq '');
7121: my $currcap = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_cap'};
7122: if ($newlimit ne $currlimit) {
7123: if ($newlimit ne 'none') {
7124: if ($newcap =~ /^\d+$/) {
7125: if ($newcap ne $currcap) {
7126: $changes{'internal.selfenroll_cap'} = $newcap;
7127: }
7128: $changes{'internal.selfenroll_limit'} = $newlimit;
7129: } else {
7130: $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.');
7131: }
7132: } elsif ($currcap ne '') {
7133: $changes{'internal.selfenroll_cap'} = '';
7134: $changes{'internal.selfenroll_limit'} = $newlimit;
7135: }
7136: } elsif ($currlimit ne 'none') {
7137: if ($newcap =~ /^\d+$/) {
7138: if ($newcap ne $currcap) {
7139: $changes{'internal.selfenroll_cap'} = $newcap;
7140: }
7141: } else {
7142: $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.');
7143: }
7144: }
7145: } elsif ($item eq 'approval') {
7146: my (@currnotified,@newnotified);
7147: my $currapproval = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'};
7148: my $currnotifylist = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_notifylist'};
7149: if ($currnotifylist ne '') {
7150: @currnotified = split(/,/,$currnotifylist);
7151: @currnotified = sort(@currnotified);
7152: }
7153: my $newapproval = $env{'form.selfenroll_approval'};
7154: @newnotified = &Apache::loncommon::get_env_multiple('form.selfenroll_notify');
7155: @newnotified = sort(@newnotified);
7156: if ($newapproval ne $currapproval) {
7157: $changes{'internal.selfenroll_approval'} = $newapproval;
7158: if (!$newapproval) {
7159: if ($currnotifylist ne '') {
7160: $changes{'internal.selfenroll_notifylist'} = '';
7161: }
7162: } else {
7163: my @differences =
1.295 raeburn 7164: &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 7165: if (@differences > 0) {
7166: if (@newnotified > 0) {
7167: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
7168: } else {
7169: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
7170: }
7171: }
7172: }
7173: } else {
1.295 raeburn 7174: my @differences = &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 7175: if (@differences > 0) {
7176: if (@newnotified > 0) {
7177: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
7178: } else {
7179: $changes{'internal.selfenroll_notifylist'} = '';
7180: }
7181: }
7182: }
1.237 raeburn 7183: } else {
7184: my $curr_val =
7185: $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$item};
7186: my $newval = $env{'form.selfenroll_'.$item};
7187: if ($item eq 'section') {
7188: $newval = $env{'form.sections'};
1.241 raeburn 7189: if (defined($curr_groups{$newval})) {
1.237 raeburn 7190: $newval = $curr_val;
7191: $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');
7192: } elsif ($newval eq 'all') {
7193: $newval = $curr_val;
1.274 bisitz 7194: $warning{$item} = &mt('Section for self-enrolled users unchanged, as "all" is a reserved section name.');
1.237 raeburn 7195: }
7196: if ($newval eq '') {
7197: $newval = 'none';
7198: }
7199: }
7200: if ($newval ne $curr_val) {
7201: $changes{'internal.selfenroll_'.$item} = $newval;
7202: }
1.241 raeburn 7203: }
1.237 raeburn 7204: }
7205: if (keys(%warning) > 0) {
7206: foreach my $item (@{$row}) {
7207: if (exists($warning{$item})) {
7208: $r->print($warning{$item}.'<br />');
7209: }
7210: }
7211: }
7212: if (keys(%changes) > 0) {
7213: my $putresult = &Apache::lonnet::put('environment',\%changes,$cdom,$cnum);
7214: if ($putresult eq 'ok') {
7215: if ((exists($changes{'internal.selfenroll_types'})) ||
7216: (exists($changes{'internal.selfenroll_start_date'})) ||
7217: (exists($changes{'internal.selfenroll_end_date'}))) {
7218: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',
7219: $cnum,undef,undef,'Course');
7220: my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
7221: if (ref($crsinfo{$env{'request.course.id'}}) eq 'HASH') {
7222: foreach my $item ('selfenroll_types','selfenroll_start_date','selfenroll_end_date') {
7223: if (exists($changes{'internal.'.$item})) {
7224: $crsinfo{$env{'request.course.id'}}{$item} =
7225: $changes{'internal.'.$item};
7226: }
7227: }
7228: my $crsputresult =
7229: &Apache::lonnet::courseidput($cdom,\%crsinfo,
7230: $chome,'notime');
7231: }
7232: }
7233: $r->print(&mt('The following changes were made to self-enrollment settings:').'<ul>');
7234: foreach my $item (@{$row}) {
7235: my $title = $item;
7236: if (ref($lt) eq 'HASH') {
7237: $title = $lt->{$item};
7238: }
7239: if ($item eq 'enroll_dates') {
7240: foreach my $type ('start','end') {
7241: if (exists($changes{'internal.selfenroll_'.$type.'_date'})) {
7242: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_date'});
1.244 bisitz 7243: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 7244: $title,$type,$newdate).'</li>');
7245: }
7246: }
7247: } elsif ($item eq 'access_dates') {
7248: foreach my $type ('start','end') {
7249: if (exists($changes{'internal.selfenroll_'.$type.'_access'})) {
7250: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_access'});
1.244 bisitz 7251: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 7252: $title,$type,$newdate).'</li>');
7253: }
7254: }
1.276 raeburn 7255: } elsif ($item eq 'limit') {
7256: if ((exists($changes{'internal.selfenroll_limit'})) ||
7257: (exists($changes{'internal.selfenroll_cap'}))) {
7258: my ($newval,$newcap);
7259: if ($changes{'internal.selfenroll_cap'} ne '') {
7260: $newcap = $changes{'internal.selfenroll_cap'}
7261: } else {
7262: $newcap = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_cap'};
7263: }
7264: if ($changes{'internal.selfenroll_limit'} eq 'none') {
7265: $newval = &mt('No limit');
7266: } elsif ($changes{'internal.selfenroll_limit'} eq
7267: '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') {
7270: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
7271: } else {
7272: my $currlimit = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_limit'};
7273: if ($currlimit eq 'allstudents') {
7274: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
7275: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
1.308 raeburn 7276: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
1.276 raeburn 7277: }
7278: }
7279: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
7280: }
7281: } elsif ($item eq 'approval') {
7282: if ((exists($changes{'internal.selfenroll_approval'})) ||
7283: (exists($changes{'internal.selfenroll_notifylist'}))) {
7284: my ($newval,$newnotify);
7285: if (exists($changes{'internal.selfenroll_notifylist'})) {
7286: $newnotify = $changes{'internal.selfenroll_notifylist'};
7287: } else {
7288: $newnotify = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_notifylist'};
7289: }
7290: if ($changes{'internal.selfenroll_approval'}) {
7291: $newval = &mt('Yes');
7292: } elsif ($changes{'internal.selfenroll_approval'} eq '0') {
7293: $newval = &mt('No');
7294: } else {
7295: my $currapproval =
7296: $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'};
7297: if ($currapproval) {
7298: $newval = &mt('Yes');
7299: } else {
7300: $newval = &mt('No');
7301: }
7302: }
7303: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval));
7304: if ($newnotify) {
1.277 raeburn 7305: $r->print('<br />'.&mt('The following will be notified when an enrollment request needs approval, or has been approved: [_1].',$newnotify));
1.276 raeburn 7306: } else {
1.277 raeburn 7307: $r->print('<br />'.&mt('No notifications sent when an enrollment request needs approval, or has been approved.'));
1.276 raeburn 7308: }
7309: $r->print('</li>'."\n");
7310: }
1.237 raeburn 7311: } else {
7312: if (exists($changes{'internal.selfenroll_'.$item})) {
1.241 raeburn 7313: my $newval = $changes{'internal.selfenroll_'.$item};
7314: if ($item eq 'types') {
7315: if ($newval eq '') {
7316: $newval = &mt('None');
7317: } elsif ($newval eq '*') {
7318: $newval = &mt('Any user in any domain');
7319: }
1.245 raeburn 7320: } elsif ($item eq 'registered') {
7321: if ($newval eq '1') {
7322: $newval = &mt('Yes');
7323: } elsif ($newval eq '0') {
7324: $newval = &mt('No');
7325: }
1.241 raeburn 7326: }
1.244 bisitz 7327: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
1.237 raeburn 7328: }
7329: }
7330: }
7331: $r->print('</ul>');
7332: my %newenvhash;
7333: foreach my $key (keys(%changes)) {
7334: $newenvhash{'course.'.$env{'request.course.id'}.'.'.$key} = $changes{$key};
7335: }
1.238 raeburn 7336: &Apache::lonnet::appenv(\%newenvhash);
1.237 raeburn 7337: } else {
7338: $r->print(&mt('An error occurred when saving changes to self-enrollment settings in this course.').'<br />'.&mt('The error was: [_1].',$putresult));
7339: }
7340: } else {
1.249 raeburn 7341: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.237 raeburn 7342: }
7343: } else {
1.249 raeburn 7344: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.241 raeburn 7345: }
1.256 raeburn 7346: my ($visible,$cansetvis,$vismsgs,$visactions) = &visible_in_cat($cdom,$cnum);
7347: if (ref($visactions) eq 'HASH') {
7348: if (!$visible) {
1.366 bisitz 7349: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
1.256 raeburn 7350: '<br />');
7351: if (ref($vismsgs) eq 'ARRAY') {
7352: $r->print('<br />'.$visactions->{'take'}.'<ul>');
7353: foreach my $item (@{$vismsgs}) {
7354: $r->print('<li>'.$visactions->{$item}.'</li>');
7355: }
7356: $r->print('</ul>');
7357: }
7358: $r->print($cansetvis);
7359: }
7360: }
1.237 raeburn 7361: return;
7362: }
7363:
7364: sub get_selfenroll_titles {
1.276 raeburn 7365: my @row = ('types','registered','enroll_dates','access_dates','section',
7366: 'approval','limit');
1.237 raeburn 7367: my %lt = &Apache::lonlocal::texthash (
7368: types => 'Users allowed to self-enroll in this course',
1.245 raeburn 7369: registered => 'Restrict self-enrollment to students officially registered for the course',
1.237 raeburn 7370: enroll_dates => 'Dates self-enrollment available',
1.256 raeburn 7371: access_dates => 'Course access dates assigned to self-enrolling users',
7372: section => 'Section assigned to self-enrolling users',
1.276 raeburn 7373: approval => 'Self-enrollment requests need approval?',
7374: limit => 'Enrollment limit',
1.237 raeburn 7375: );
7376: return (\@row,\%lt);
7377: }
7378:
1.27 matthew 7379: #---------------------------------------------- end functions for &phase_two
1.29 matthew 7380:
7381: #--------------------------------- functions for &phase_two and &phase_three
7382:
7383: #--------------------------end of functions for &phase_two and &phase_three
1.372 raeburn 7384:
1.1 www 7385: 1;
7386: __END__
1.2 www 7387:
7388:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>