Annotation of loncom/interface/loncreateuser.pm, revision 1.387
1.20 harris41 1: # The LearningOnline Network with CAPA
1.1 www 2: # Create a user
3: #
1.387 ! bisitz 4: # $Id: loncreateuser.pm,v 1.386 2014/01/15 18:47:56 bisitz 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.386 bisitz 3119: my $linktext = ($crstype eq 'Community' ?
3120: &mt('Enroll Another Member') : &mt('Enroll Another Student'));
3121: $r->print(
3122: &Apache::lonhtmlcommon::actionbox([
3123: '<a href="javascript:backPage(document.userupdate)">'
3124: .($crstype eq 'Community' ?
3125: &mt('Enroll Another Member') : &mt('Enroll Another Student'))
3126: .'</a>']));
1.220 raeburn 3127: } else {
1.375 raeburn 3128: my @rolechanges = &update_roles($r,$context,$showcredits);
1.334 raeburn 3129: if (keys(%namechanged) > 0) {
1.220 raeburn 3130: if ($context eq 'course') {
3131: if (@userroles > 0) {
1.225 raeburn 3132: if ((@rolechanges == 0) ||
3133: (!(grep(/^st$/,@rolechanges)))) {
3134: if (grep(/^st$/,@userroles)) {
3135: my $classlistupdated =
3136: &Apache::lonuserutils::update_classlist($cdom,
1.220 raeburn 3137: $cnum,$env{'form.ccdomain'},
3138: $env{'form.ccuname'},\%userupdate);
1.225 raeburn 3139: }
1.220 raeburn 3140: }
3141: }
3142: }
3143: }
1.226 raeburn 3144: my $userinfo = &Apache::loncommon::plainname($env{'form.ccuname'},
1.233 raeburn 3145: $env{'form.ccdomain'});
3146: if ($env{'form.popup'}) {
3147: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
3148: } else {
1.367 golterma 3149: $r->print('<br />'.&Apache::lonhtmlcommon::actionbox(['<a href="javascript:backPage(document.userupdate,'."'$env{'form.prevphase'}','modify'".')">'
3150: .&mt('Modify this user: [_1]','<span class="LC_cusr_emph">'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.' ('.$userinfo.')</span>').'</a>',
3151: '<a href="javascript:backPage(document.userupdate)">'.&mt('Create/Modify Another User').'</a>']));
1.233 raeburn 3152: }
1.220 raeburn 3153: }
3154: }
3155:
1.334 raeburn 3156: sub display_userinfo {
1.362 raeburn 3157: my ($r,$changed,$order,$canshow,$requestcourses,$usertools,$requestauthor,
3158: $userenv,$changedhash,$namechangedhash,$oldsetting,$oldsettingtext,
1.334 raeburn 3159: $newsetting,$newsettingtext) = @_;
3160: return unless (ref($order) eq 'ARRAY' &&
3161: ref($canshow) eq 'HASH' &&
3162: ref($requestcourses) eq 'ARRAY' &&
1.362 raeburn 3163: ref($requestauthor) eq 'ARRAY' &&
1.334 raeburn 3164: ref($usertools) eq 'ARRAY' &&
3165: ref($userenv) eq 'HASH' &&
3166: ref($changedhash) eq 'HASH' &&
3167: ref($oldsetting) eq 'HASH' &&
3168: ref($oldsettingtext) eq 'HASH' &&
3169: ref($newsetting) eq 'HASH' &&
3170: ref($newsettingtext) eq 'HASH');
3171: my %lt=&Apache::lonlocal::texthash(
1.372 raeburn 3172: 'ui' => 'User Information',
1.334 raeburn 3173: 'uic' => 'User Information Changed',
3174: 'firstname' => 'First Name',
3175: 'middlename' => 'Middle Name',
3176: 'lastname' => 'Last Name',
3177: 'generation' => 'Generation',
3178: 'id' => 'Student/Employee ID',
3179: 'permanentemail' => 'Permanent e-mail address',
1.378 raeburn 3180: 'portfolioquota' => 'Disk space allocated to portfolio files',
1.385 bisitz 3181: 'authorquota' => 'Disk space allocated to Authoring Space',
1.334 raeburn 3182: 'blog' => 'Blog Availability',
1.361 raeburn 3183: 'webdav' => 'WebDAV Availability',
1.334 raeburn 3184: 'aboutme' => 'Personal Information Page Availability',
3185: 'portfolio' => 'Portfolio Availability',
3186: 'official' => 'Can Request Official Courses',
3187: 'unofficial' => 'Can Request Unofficial Courses',
3188: 'community' => 'Can Request Communities',
1.384 raeburn 3189: 'textbook' => 'Can Request Textbook Courses',
1.362 raeburn 3190: 'requestauthor' => 'Can Request Author Role',
1.334 raeburn 3191: 'inststatus' => "Affiliation",
3192: 'prvs' => 'Previous Value:',
3193: 'chto' => 'Changed To:'
3194: );
3195: if ($changed) {
1.372 raeburn 3196: $r->print('<h3>'.$lt{'uic'}.'</h3>'.
1.367 golterma 3197: &Apache::loncommon::start_data_table().
3198: &Apache::loncommon::start_data_table_header_row());
1.334 raeburn 3199: $r->print("<th> </th>\n");
1.367 golterma 3200: $r->print('<th><b>'.$lt{'prvs'}.'</b></th>');
3201: $r->print('<th><span class="LC_nobreak"><b>'.$lt{'chto'}.'</b></span></th>');
3202: $r->print(&Apache::loncommon::end_data_table_header_row());
3203: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
3204:
1.334 raeburn 3205: foreach my $item (@userinfo) {
3206: my $value = $env{'form.c'.$item};
1.367 golterma 3207: #show changes only:
1.383 raeburn 3208: unless ($value eq $userenv->{$item}){
1.367 golterma 3209: $r->print(&Apache::loncommon::start_data_table_row());
3210: $r->print("<td>$lt{$item}</td>\n");
1.383 raeburn 3211: $r->print("<td>".$userenv->{$item}."</td>\n");
1.367 golterma 3212: $r->print("<td>$value </td>\n");
3213: $r->print(&Apache::loncommon::end_data_table_row());
1.334 raeburn 3214: }
3215: }
3216: foreach my $entry (@{$order}) {
1.383 raeburn 3217: if ($canshow->{$entry}) {
3218: if (($entry eq 'requestcourses') || ($entry eq 'reqcrsotherdom') || ($entry eq 'requestauthor')) {
3219: my @items;
3220: if ($entry eq 'requestauthor') {
3221: @items = ($entry);
3222: } else {
3223: @items = @{$requestcourses};
1.384 raeburn 3224: }
1.383 raeburn 3225: foreach my $item (@items) {
3226: if (($newsetting->{$item} ne $oldsetting->{$item}) ||
3227: ($newsettingtext->{$item} ne $oldsettingtext->{$item})) {
3228: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3229: $r->print("<td>$lt{$item}</td>\n");
3230: $r->print("<td>".$oldsetting->{$item});
3231: if ($oldsettingtext->{$item}) {
3232: if ($oldsetting->{$item}) {
3233: $r->print(' -- ');
3234: }
3235: $r->print($oldsettingtext->{$item});
3236: }
3237: $r->print("</td>\n");
3238: $r->print("<td>".$newsetting->{$item});
3239: if ($newsettingtext->{$item}) {
3240: if ($newsetting->{$item}) {
3241: $r->print(' -- ');
3242: }
3243: $r->print($newsettingtext->{$item});
3244: }
3245: $r->print("</td>\n");
3246: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3247: }
3248: }
3249: } elsif ($entry eq 'tools') {
3250: foreach my $item (@{$usertools}) {
1.383 raeburn 3251: if ($newsetting->{$item} ne $oldsetting->{$item}) {
3252: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3253: $r->print("<td>$lt{$item}</td>\n");
3254: $r->print("<td>".$oldsetting->{$item}.' '.$oldsettingtext->{$item}."</td>\n");
3255: $r->print("<td>".$newsetting->{$item}.' '.$newsettingtext->{$item}."</td>\n");
3256: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3257: }
3258: }
1.378 raeburn 3259: } elsif ($entry eq 'quota') {
3260: if ((ref($oldsetting->{$entry}) eq 'HASH') && (ref($oldsettingtext->{$entry}) eq 'HASH') &&
3261: (ref($newsetting->{$entry}) eq 'HASH') && (ref($newsettingtext->{$entry}) eq 'HASH')) {
3262: foreach my $name ('portfolio','author') {
1.383 raeburn 3263: if ($newsetting->{$entry}->{$name} ne $oldsetting->{$entry}->{$name}) {
3264: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3265: $r->print("<td>$lt{$name.$entry}</td>\n");
3266: $r->print("<td>".$oldsettingtext->{$entry}->{$name}."</td>\n");
3267: $r->print("<td>".$newsettingtext->{$entry}->{$name}."</td>\n");
3268: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.378 raeburn 3269: }
3270: }
3271: }
1.334 raeburn 3272: } else {
1.383 raeburn 3273: if ($newsetting->{$entry} ne $oldsetting->{$entry}) {
3274: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3275: $r->print("<td>$lt{$entry}</td>\n");
3276: $r->print("<td>".$oldsetting->{$entry}.' '.$oldsettingtext->{$entry}."</td>\n");
3277: $r->print("<td>".$newsetting->{$entry}.' '.$newsettingtext->{$entry}."</td>\n");
3278: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3279: }
3280: }
3281: }
3282: }
1.367 golterma 3283: $r->print(&Apache::loncommon::end_data_table().'<br />');
1.372 raeburn 3284: } else {
3285: $r->print('<h3>'.$lt{'ui'}.'</h3>'.
3286: '<p>'.&mt('No changes made to user information').'</p>');
1.334 raeburn 3287: }
3288: return;
3289: }
3290:
1.275 raeburn 3291: sub tool_changes {
3292: my ($context,$usertools,$oldaccess,$oldaccesstext,$userenv,$changeHash,
3293: $changed,$newaccess,$newaccesstext) = @_;
3294: if (!((ref($usertools) eq 'ARRAY') && (ref($oldaccess) eq 'HASH') &&
3295: (ref($oldaccesstext) eq 'HASH') && (ref($userenv) eq 'HASH') &&
3296: (ref($changeHash) eq 'HASH') && (ref($changed) eq 'HASH') &&
3297: (ref($newaccess) eq 'HASH') && (ref($newaccesstext) eq 'HASH'))) {
3298: return;
3299: }
1.383 raeburn 3300: my %reqdisplay = &requestchange_display();
1.300 raeburn 3301: if ($context eq 'reqcrsotherdom') {
1.309 raeburn 3302: my @options = ('approval','validate','autolimit');
1.306 raeburn 3303: my $optregex = join('|',@options);
1.300 raeburn 3304: my $cdom = $env{'request.role.domain'};
3305: foreach my $tool (@{$usertools}) {
1.383 raeburn 3306: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
1.314 raeburn 3307: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
1.300 raeburn 3308: $changeHash->{$context.'.'.$tool} = $userenv->{$context.'.'.$tool};
1.383 raeburn 3309: my ($newop,$limit);
1.314 raeburn 3310: if ($env{'form.'.$context.'_'.$tool}) {
3311: $newop = $env{'form.'.$context.'_'.$tool};
3312: if ($newop eq 'autolimit') {
1.383 raeburn 3313: $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
1.314 raeburn 3314: $limit =~ s/\D+//g;
3315: $newop .= '='.$limit;
3316: }
3317: }
1.300 raeburn 3318: if ($userenv->{$context.'.'.$tool} eq '') {
1.314 raeburn 3319: if ($newop) {
3320: $changed->{$tool}=&tool_admin($tool,$cdom.':'.$newop,
1.300 raeburn 3321: $changeHash,$context);
3322: if ($changed->{$tool}) {
1.383 raeburn 3323: if ($newop =~ /^autolimit/) {
3324: if ($limit) {
3325: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3326: } else {
3327: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3328: }
3329: } else {
3330: $newaccesstext->{$tool} = $reqdisplay{$newop};
3331: }
1.300 raeburn 3332: } else {
3333: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3334: }
3335: }
3336: } else {
3337: my @curr = split(',',$userenv->{$context.'.'.$tool});
3338: my @new;
3339: my $changedoms;
1.314 raeburn 3340: foreach my $req (@curr) {
3341: if ($req =~ /^\Q$cdom\E\:($optregex\=?\d*)$/) {
3342: my $oldop = $1;
1.383 raeburn 3343: if ($oldop =~ /^autolimit=(\d*)/) {
3344: my $limit = $1;
3345: if ($limit) {
3346: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3347: } else {
3348: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3349: }
3350: } else {
3351: $oldaccesstext->{$tool} = $reqdisplay{$oldop};
3352: }
1.314 raeburn 3353: if ($oldop ne $newop) {
3354: $changedoms = 1;
3355: foreach my $item (@curr) {
3356: my ($reqdom,$option) = split(':',$item);
3357: unless ($reqdom eq $cdom) {
3358: push(@new,$item);
3359: }
3360: }
3361: if ($newop) {
3362: push(@new,$cdom.':'.$newop);
1.300 raeburn 3363: }
1.314 raeburn 3364: @new = sort(@new);
1.300 raeburn 3365: }
1.314 raeburn 3366: last;
1.300 raeburn 3367: }
1.314 raeburn 3368: }
3369: if ((!$changedoms) && ($newop)) {
1.300 raeburn 3370: $changedoms = 1;
1.306 raeburn 3371: @new = sort(@curr,$cdom.':'.$newop);
1.300 raeburn 3372: }
3373: if ($changedoms) {
1.314 raeburn 3374: my $newdomstr;
1.300 raeburn 3375: if (@new) {
3376: $newdomstr = join(',',@new);
3377: }
3378: $changed->{$tool}=&tool_admin($tool,$newdomstr,$changeHash,
3379: $context);
3380: if ($changed->{$tool}) {
3381: if ($env{'form.'.$context.'_'.$tool}) {
1.306 raeburn 3382: if ($env{'form.'.$context.'_'.$tool} eq 'autolimit') {
1.314 raeburn 3383: my $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
3384: $limit =~ s/\D+//g;
3385: if ($limit) {
1.383 raeburn 3386: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
1.314 raeburn 3387: } else {
1.383 raeburn 3388: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
1.306 raeburn 3389: }
1.314 raeburn 3390: } else {
1.306 raeburn 3391: $newaccesstext->{$tool} = $reqdisplay{$env{'form.'.$context.'_'.$tool}};
3392: }
1.300 raeburn 3393: } else {
1.383 raeburn 3394: $newaccesstext->{$tool} = &mt("availability set to 'off'");
1.300 raeburn 3395: }
3396: }
3397: }
3398: }
3399: }
3400: return;
3401: }
1.275 raeburn 3402: foreach my $tool (@{$usertools}) {
1.383 raeburn 3403: my ($newval,$limit,$envkey);
1.362 raeburn 3404: $envkey = $context.'.'.$tool;
1.306 raeburn 3405: if ($context eq 'requestcourses') {
3406: $newval = $env{'form.crsreq_'.$tool};
3407: if ($newval eq 'autolimit') {
1.383 raeburn 3408: $limit = $env{'form.crsreq_'.$tool.'_limit'};
3409: $limit =~ s/\D+//g;
3410: $newval .= '='.$limit;
1.306 raeburn 3411: }
1.362 raeburn 3412: } elsif ($context eq 'requestauthor') {
3413: $newval = $env{'form.'.$context};
3414: $envkey = $context;
1.314 raeburn 3415: } else {
1.306 raeburn 3416: $newval = $env{'form.'.$context.'_'.$tool};
3417: }
1.362 raeburn 3418: if ($userenv->{$envkey} ne '') {
1.275 raeburn 3419: $oldaccess->{$tool} = &mt('custom');
1.383 raeburn 3420: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3421: if ($userenv->{$envkey} =~ /^autolimit=(\d*)$/) {
3422: my $currlimit = $1;
3423: if ($currlimit eq '') {
3424: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3425: } else {
3426: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$currlimit);
3427: }
3428: } elsif ($userenv->{$envkey}) {
3429: $oldaccesstext->{$tool} = $reqdisplay{$userenv->{$envkey}};
3430: } else {
3431: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
3432: }
1.275 raeburn 3433: } else {
1.383 raeburn 3434: if ($userenv->{$envkey}) {
3435: $oldaccesstext->{$tool} = &mt("availability set to 'on'");
3436: } else {
3437: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
3438: }
1.275 raeburn 3439: }
1.362 raeburn 3440: $changeHash->{$envkey} = $userenv->{$envkey};
1.275 raeburn 3441: if ($env{'form.custom'.$tool} == 1) {
1.362 raeburn 3442: if ($newval ne $userenv->{$envkey}) {
1.306 raeburn 3443: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
3444: $context);
1.275 raeburn 3445: if ($changed->{$tool}) {
3446: $newaccess->{$tool} = &mt('custom');
1.383 raeburn 3447: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3448: if ($newval =~ /^autolimit/) {
3449: if ($limit) {
3450: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3451: } else {
3452: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3453: }
3454: } elsif ($newval) {
3455: $newaccesstext->{$tool} = $reqdisplay{$newval};
3456: } else {
3457: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3458: }
1.275 raeburn 3459: } else {
1.383 raeburn 3460: if ($newval) {
3461: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3462: } else {
3463: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3464: }
1.275 raeburn 3465: }
3466: } else {
3467: $newaccess->{$tool} = $oldaccess->{$tool};
1.383 raeburn 3468: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3469: if ($newval =~ /^autolimit/) {
3470: if ($limit) {
3471: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3472: } else {
3473: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3474: }
3475: } elsif ($newval) {
3476: $newaccesstext->{$tool} = $reqdisplay{$newval};
3477: } else {
3478: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3479: }
1.275 raeburn 3480: } else {
1.383 raeburn 3481: if ($userenv->{$context.'.'.$tool}) {
3482: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3483: } else {
3484: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3485: }
1.275 raeburn 3486: }
3487: }
3488: } else {
3489: $newaccess->{$tool} = $oldaccess->{$tool};
3490: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3491: }
3492: } else {
3493: $changed->{$tool} = &tool_admin($tool,'',$changeHash,$context);
3494: if ($changed->{$tool}) {
3495: $newaccess->{$tool} = &mt('default');
3496: } else {
3497: $newaccess->{$tool} = $oldaccess->{$tool};
1.383 raeburn 3498: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3499: if ($newval =~ /^autolimit/) {
3500: if ($limit) {
3501: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3502: } else {
3503: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3504: }
3505: } elsif ($newval) {
3506: $newaccesstext->{$tool} = $reqdisplay{$newval};
3507: } else {
3508: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3509: }
1.275 raeburn 3510: } else {
1.383 raeburn 3511: if ($userenv->{$context.'.'.$tool}) {
3512: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3513: } else {
3514: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3515: }
1.275 raeburn 3516: }
3517: }
3518: }
3519: } else {
3520: $oldaccess->{$tool} = &mt('default');
3521: if ($env{'form.custom'.$tool} == 1) {
1.306 raeburn 3522: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
3523: $context);
1.275 raeburn 3524: if ($changed->{$tool}) {
3525: $newaccess->{$tool} = &mt('custom');
1.383 raeburn 3526: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3527: if ($newval =~ /^autolimit/) {
3528: if ($limit) {
3529: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3530: } else {
3531: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3532: }
3533: } elsif ($newval) {
3534: $newaccesstext->{$tool} = $reqdisplay{$newval};
3535: } else {
3536: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3537: }
1.275 raeburn 3538: } else {
1.383 raeburn 3539: if ($newval) {
3540: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3541: } else {
3542: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3543: }
1.275 raeburn 3544: }
3545: } else {
3546: $newaccess->{$tool} = $oldaccess->{$tool};
3547: }
3548: } else {
3549: $newaccess->{$tool} = $oldaccess->{$tool};
3550: }
3551: }
3552: }
3553: return;
3554: }
3555:
1.220 raeburn 3556: sub update_roles {
1.375 raeburn 3557: my ($r,$context,$showcredits) = @_;
1.4 www 3558: my $now=time;
1.225 raeburn 3559: my @rolechanges;
1.220 raeburn 3560: my %disallowed;
1.73 sakharuk 3561: $r->print('<h3>'.&mt('Modifying Roles').'</h3>');
1.135 raeburn 3562: foreach my $key (keys (%env)) {
3563: next if (! $env{$key});
1.190 raeburn 3564: next if ($key eq 'form.action');
1.27 matthew 3565: # Revoke roles
1.135 raeburn 3566: if ($key=~/^form\.rev/) {
3567: if ($key=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) {
1.64 www 3568: # Revoke standard role
1.170 albertel 3569: my ($scope,$role) = ($1,$2);
3570: my $result =
3571: &Apache::lonnet::revokerole($env{'form.ccdomain'},
3572: $env{'form.ccuname'},
1.239 raeburn 3573: $scope,$role,'','',$context);
1.367 golterma 3574: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 3575: &mt('Revoking [_1] in [_2]',
3576: &Apache::lonnet::plaintext($role),
1.372 raeburn 3577: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 3578: $result ne "ok").'<br />');
3579: if ($result ne "ok") {
3580: $r->print(&mt('Error: [_1]',$result).'<br />');
3581: }
1.170 albertel 3582: if ($role eq 'st') {
1.202 raeburn 3583: my $result =
1.198 raeburn 3584: &Apache::lonuserutils::classlist_drop($scope,
3585: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 3586: $now);
1.367 golterma 3587: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.53 www 3588: }
1.225 raeburn 3589: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3590: push(@rolechanges,$role);
3591: }
1.196 raeburn 3592: }
1.195 raeburn 3593: if ($key=~m{^form\.rev\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}s) {
1.64 www 3594: # Revoke custom role
1.369 bisitz 3595: my $result = &Apache::lonnet::revokecustomrole(
3596: $env{'form.ccdomain'},$env{'form.ccuname'},$1,$2,$3,$4,'','',$context);
1.367 golterma 3597: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 3598: &mt('Revoking custom role [_1] by [_2] in [_3]',
1.372 raeburn 3599: $4,$3.':'.$2,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 3600: $result ne 'ok').'<br />');
3601: if ($result ne "ok") {
3602: $r->print(&mt('Error: [_1]',$result).'<br />');
3603: }
1.225 raeburn 3604: if (!grep(/^cr$/,@rolechanges)) {
3605: push(@rolechanges,'cr');
3606: }
1.64 www 3607: }
1.135 raeburn 3608: } elsif ($key=~/^form\.del/) {
3609: if ($key=~/^form\.del\:([^\_]+)\_([^\_\.]+)$/) {
1.116 raeburn 3610: # Delete standard role
1.170 albertel 3611: my ($scope,$role) = ($1,$2);
3612: my $result =
3613: &Apache::lonnet::assignrole($env{'form.ccdomain'},
3614: $env{'form.ccuname'},
1.239 raeburn 3615: $scope,$role,$now,0,1,'',
3616: $context);
1.367 golterma 3617: $r->print(&Apache::lonhtmlcommon::confirm_success(
3618: &mt('Deleting [_1] in [_2]',
1.369 bisitz 3619: &Apache::lonnet::plaintext($role),
1.372 raeburn 3620: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 3621: $result ne 'ok').'<br />');
3622: if ($result ne "ok") {
3623: $r->print(&mt('Error: [_1]',$result).'<br />');
3624: }
1.367 golterma 3625:
1.170 albertel 3626: if ($role eq 'st') {
1.202 raeburn 3627: my $result =
1.198 raeburn 3628: &Apache::lonuserutils::classlist_drop($scope,
3629: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 3630: $now);
1.369 bisitz 3631: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.81 albertel 3632: }
1.225 raeburn 3633: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3634: push(@rolechanges,$role);
3635: }
1.116 raeburn 3636: }
1.139 albertel 3637: if ($key=~m{^form\.del\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 3638: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
3639: # Delete custom role
1.369 bisitz 3640: my $result =
3641: &Apache::lonnet::assigncustomrole($env{'form.ccdomain'},
3642: $env{'form.ccuname'},$url,$rdom,$rnam,$rolename,$now,
3643: 0,1,$context);
3644: $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('Deleting custom role [_1] by [_2] in [_3]',
1.372 raeburn 3645: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 3646: $result ne "ok").'<br />');
3647: if ($result ne "ok") {
3648: $r->print(&mt('Error: [_1]',$result).'<br />');
3649: }
1.367 golterma 3650:
1.225 raeburn 3651: if (!grep(/^cr$/,@rolechanges)) {
3652: push(@rolechanges,'cr');
3653: }
1.116 raeburn 3654: }
1.135 raeburn 3655: } elsif ($key=~/^form\.ren/) {
1.101 albertel 3656: my $udom = $env{'form.ccdomain'};
3657: my $uname = $env{'form.ccuname'};
1.116 raeburn 3658: # Re-enable standard role
1.135 raeburn 3659: if ($key=~/^form\.ren\:([^\_]+)\_([^\_\.]+)$/) {
1.89 raeburn 3660: my $url = $1;
3661: my $role = $2;
3662: my $logmsg;
3663: my $output;
3664: if ($role eq 'st') {
1.141 albertel 3665: if ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
1.374 raeburn 3666: my ($cdom,$cnum,$csec) = ($1,$2,$3);
1.375 raeburn 3667: my $credits;
3668: if ($showcredits) {
3669: my $defaultcredits =
3670: &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
3671: $credits = &get_user_credits($defaultcredits,$cdom,$cnum);
3672: }
3673: my $result = &Apache::loncommon::commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$cdom,$cnum,$csec,$context,$credits);
1.220 raeburn 3674: if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course') || ($result eq 'refused')) {
1.223 raeburn 3675: if ($result eq 'refused' && $logmsg) {
3676: $output = $logmsg;
3677: } else {
1.369 bisitz 3678: $output = &mt('Error: [_1]',$result)."\n";
1.223 raeburn 3679: }
1.89 raeburn 3680: } else {
1.372 raeburn 3681: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Assigning [_1] in [_2] starting [_3]',
3682: &Apache::lonnet::plaintext($role),
3683: &Apache::loncommon::show_role_extent($url,$context,'st'),
3684: &Apache::lonlocal::locallocaltime($now))).'<br />'.$logmsg.'<br />';
1.89 raeburn 3685: }
3686: }
3687: } else {
1.101 albertel 3688: my $result=&Apache::lonnet::assignrole($env{'form.ccdomain'},
1.239 raeburn 3689: $env{'form.ccuname'},$url,$role,0,$now,'','',
3690: $context);
1.367 golterma 3691: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Re-enabling [_1] in [_2]',
1.372 raeburn 3692: &Apache::lonnet::plaintext($role),
3693: &Apache::loncommon::show_role_extent($url,$context,$role)),$result ne "ok").'<br />';
1.369 bisitz 3694: if ($result ne "ok") {
3695: $output .= &mt('Error: [_1]',$result).'<br />';
3696: }
3697: }
1.89 raeburn 3698: $r->print($output);
1.225 raeburn 3699: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3700: push(@rolechanges,$role);
3701: }
1.113 raeburn 3702: }
1.116 raeburn 3703: # Re-enable custom role
1.139 albertel 3704: if ($key=~m{^form\.ren\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 3705: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
3706: my $result = &Apache::lonnet::assigncustomrole(
3707: $env{'form.ccdomain'}, $env{'form.ccuname'},
1.240 raeburn 3708: $url,$rdom,$rnam,$rolename,0,$now,undef,$context);
1.369 bisitz 3709: $r->print(&Apache::lonhtmlcommon::confirm_success(
3710: &mt('Re-enabling custom role [_1] by [_2] in [_3]',
1.372 raeburn 3711: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 3712: $result ne "ok").'<br />');
3713: if ($result ne "ok") {
3714: $r->print(&mt('Error: [_1]',$result).'<br />');
3715: }
1.225 raeburn 3716: if (!grep(/^cr$/,@rolechanges)) {
3717: push(@rolechanges,'cr');
3718: }
1.116 raeburn 3719: }
1.135 raeburn 3720: } elsif ($key=~/^form\.act/) {
1.101 albertel 3721: my $udom = $env{'form.ccdomain'};
3722: my $uname = $env{'form.ccuname'};
1.141 albertel 3723: if ($key=~/^form\.act\_($match_domain)\_($match_courseid)\_cr_cr_($match_domain)_($match_username)_([^\_]+)$/) {
1.65 www 3724: # Activate a custom role
1.83 albertel 3725: my ($one,$two,$three,$four,$five)=($1,$2,$3,$4,$5);
3726: my $url='/'.$one.'/'.$two;
3727: my $full=$one.'_'.$two.'_cr_cr_'.$three.'_'.$four.'_'.$five;
1.65 www 3728:
1.101 albertel 3729: my $start = ( $env{'form.start_'.$full} ?
3730: $env{'form.start_'.$full} :
1.88 raeburn 3731: $now );
1.101 albertel 3732: my $end = ( $env{'form.end_'.$full} ?
3733: $env{'form.end_'.$full} :
1.88 raeburn 3734: 0 );
3735:
3736: # split multiple sections
3737: my %sections = ();
1.101 albertel 3738: my $num_sections = &build_roles($env{'form.sec_'.$full},\%sections,$5);
1.88 raeburn 3739: if ($num_sections == 0) {
1.240 raeburn 3740: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end,$context));
1.88 raeburn 3741: } else {
1.114 albertel 3742: my %curr_groups =
1.117 raeburn 3743: &Apache::longroup::coursegroups($one,$two);
1.113 raeburn 3744: foreach my $sec (sort {$a cmp $b} keys %sections) {
3745: if (($sec eq 'none') || ($sec eq 'all') ||
3746: exists($curr_groups{$sec})) {
3747: $disallowed{$sec} = $url;
3748: next;
3749: }
3750: my $securl = $url.'/'.$sec;
1.240 raeburn 3751: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end,$context));
1.88 raeburn 3752: }
3753: }
1.225 raeburn 3754: if (!grep(/^cr$/,@rolechanges)) {
3755: push(@rolechanges,'cr');
3756: }
1.142 raeburn 3757: } elsif ($key=~/^form\.act\_($match_domain)\_($match_name)\_([^\_]+)$/) {
1.27 matthew 3758: # Activate roles for sections with 3 id numbers
3759: # set start, end times, and the url for the class
1.83 albertel 3760: my ($one,$two,$three)=($1,$2,$3);
1.101 albertel 3761: my $start = ( $env{'form.start_'.$one.'_'.$two.'_'.$three} ?
3762: $env{'form.start_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 3763: $now );
1.101 albertel 3764: my $end = ( $env{'form.end_'.$one.'_'.$two.'_'.$three} ?
3765: $env{'form.end_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 3766: 0 );
1.83 albertel 3767: my $url='/'.$one.'/'.$two;
1.88 raeburn 3768: my $type = 'three';
3769: # split multiple sections
3770: my %sections = ();
1.101 albertel 3771: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections,$three);
1.375 raeburn 3772: my $credits;
3773: if ($three eq 'st') {
3774: if ($showcredits) {
3775: my $defaultcredits =
3776: &Apache::lonuserutils::get_defaultcredits($one,$two);
3777: $credits = $env{'form.credits_'.$one.'_'.$two.'_'.$three};
3778: $credits =~ s/[^\d\.]//g;
3779: if ($credits eq $defaultcredits) {
3780: undef($credits);
3781: }
3782: }
3783: }
1.88 raeburn 3784: if ($num_sections == 0) {
1.375 raeburn 3785: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 3786: } else {
1.114 albertel 3787: my %curr_groups =
1.117 raeburn 3788: &Apache::longroup::coursegroups($one,$two);
1.88 raeburn 3789: my $emptysec = 0;
3790: foreach my $sec (sort {$a cmp $b} keys %sections) {
3791: $sec =~ s/\W//g;
1.113 raeburn 3792: if ($sec ne '') {
3793: if (($sec eq 'none') || ($sec eq 'all') ||
3794: exists($curr_groups{$sec})) {
3795: $disallowed{$sec} = $url;
3796: next;
3797: }
1.88 raeburn 3798: my $securl = $url.'/'.$sec;
1.375 raeburn 3799: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec,$context,$credits));
1.88 raeburn 3800: } else {
3801: $emptysec = 1;
3802: }
3803: }
3804: if ($emptysec) {
1.375 raeburn 3805: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 3806: }
1.225 raeburn 3807: }
3808: if (!grep(/^\Q$three\E$/,@rolechanges)) {
3809: push(@rolechanges,$three);
3810: }
1.135 raeburn 3811: } elsif ($key=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
1.27 matthew 3812: # Activate roles for sections with two id numbers
3813: # set start, end times, and the url for the class
1.101 albertel 3814: my $start = ( $env{'form.start_'.$1.'_'.$2} ?
3815: $env{'form.start_'.$1.'_'.$2} :
1.27 matthew 3816: $now );
1.101 albertel 3817: my $end = ( $env{'form.end_'.$1.'_'.$2} ?
3818: $env{'form.end_'.$1.'_'.$2} :
1.27 matthew 3819: 0 );
1.225 raeburn 3820: my $one = $1;
3821: my $two = $2;
3822: my $url='/'.$one.'/';
1.88 raeburn 3823: # split multiple sections
3824: my %sections = ();
1.225 raeburn 3825: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two},\%sections,$two);
1.88 raeburn 3826: if ($num_sections == 0) {
1.240 raeburn 3827: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 3828: } else {
3829: my $emptysec = 0;
3830: foreach my $sec (sort {$a cmp $b} keys %sections) {
3831: if ($sec ne '') {
3832: my $securl = $url.'/'.$sec;
1.240 raeburn 3833: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$two,$start,$end,$one,undef,$sec,$context));
1.88 raeburn 3834: } else {
3835: $emptysec = 1;
3836: }
3837: }
3838: if ($emptysec) {
1.240 raeburn 3839: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 3840: }
3841: }
1.225 raeburn 3842: if (!grep(/^\Q$two\E$/,@rolechanges)) {
3843: push(@rolechanges,$two);
3844: }
1.64 www 3845: } else {
1.190 raeburn 3846: $r->print('<p><span class="LC_error">'.&mt('ERROR').': '.&mt('Unknown command').' <tt>'.$key.'</tt></span></p><br />');
1.64 www 3847: }
1.113 raeburn 3848: foreach my $key (sort(keys(%disallowed))) {
1.274 bisitz 3849: $r->print('<p class="LC_warning">');
1.113 raeburn 3850: if (($key eq 'none') || ($key eq 'all')) {
1.274 bisitz 3851: $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 3852: } else {
1.274 bisitz 3853: $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 3854: }
1.274 bisitz 3855: $r->print('</p><p>'
3856: .&mt('Please [_1]go back[_2] and choose a different section name.'
3857: ,'<a href="javascript:history.go(-1)'
3858: ,'</a>')
3859: .'</p><br />'
3860: );
1.113 raeburn 3861: }
3862: }
1.101 albertel 3863: } # End of foreach (keys(%env))
1.75 www 3864: # Flush the course logs so reverse user roles immediately updated
1.349 raeburn 3865: $r->register_cleanup(\&Apache::lonnet::flushcourselogs);
1.225 raeburn 3866: if (@rolechanges == 0) {
1.372 raeburn 3867: $r->print('<p>'.&mt('No roles to modify').'</p>');
1.193 raeburn 3868: }
1.225 raeburn 3869: return @rolechanges;
1.220 raeburn 3870: }
3871:
1.375 raeburn 3872: sub get_user_credits {
3873: my ($uname,$udom,$defaultcredits,$cdom,$cnum) = @_;
3874: if ($cdom eq '' || $cnum eq '') {
3875: return unless ($env{'request.course.id'});
3876: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
3877: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
3878: }
3879: my $credits;
3880: my %currhash =
3881: &Apache::lonnet::get('classlist',[$uname.':'.$udom],$cdom,$cnum);
3882: if (keys(%currhash) > 0) {
3883: my @items = split(/:/,$currhash{$uname.':'.$udom});
3884: my $crdidx = &Apache::loncoursedata::CL_CREDITS() - 3;
3885: $credits = $items[$crdidx];
3886: $credits =~ s/[^\d\.]//g;
3887: }
3888: if ($credits eq $defaultcredits) {
3889: undef($credits);
3890: }
3891: return $credits;
3892: }
3893:
1.220 raeburn 3894: sub enroll_single_student {
1.375 raeburn 3895: my ($r,$uhome,$amode,$genpwd,$now,$newuser,$context,$crstype,
3896: $showcredits,$defaultcredits) = @_;
1.318 raeburn 3897: $r->print('<h3>');
3898: if ($crstype eq 'Community') {
3899: $r->print(&mt('Enrolling Member'));
3900: } else {
3901: $r->print(&mt('Enrolling Student'));
3902: }
3903: $r->print('</h3>');
1.220 raeburn 3904:
3905: # Remove non alphanumeric values from section
3906: $env{'form.sections'}=~s/\W//g;
3907:
1.375 raeburn 3908: my $credits;
3909: if (($showcredits) && ($env{'form.credits'} ne '')) {
3910: $credits = $env{'form.credits'};
3911: $credits =~ s/[^\d\.]//g;
3912: if ($credits ne '') {
3913: if ($credits eq $defaultcredits) {
3914: undef($credits);
3915: }
3916: }
3917: }
3918:
1.220 raeburn 3919: # Clean out any old student roles the user has in this class.
3920: &Apache::lonuserutils::modifystudent($env{'form.ccdomain'},
3921: $env{'form.ccuname'},$env{'request.course.id'},undef,$uhome);
3922: my ($startdate,$enddate) = &Apache::lonuserutils::get_dates_from_form();
3923: my $enroll_result =
3924: &Apache::lonnet::modify_student_enrollment($env{'form.ccdomain'},
3925: $env{'form.ccuname'},$env{'form.cid'},$env{'form.cfirstname'},
3926: $env{'form.cmiddlename'},$env{'form.clastname'},
3927: $env{'form.generation'},$env{'form.sections'},$enddate,
1.375 raeburn 3928: $startdate,'manual',undef,$env{'request.course.id'},'',$context,
3929: $credits);
1.220 raeburn 3930: if ($enroll_result =~ /^ok/) {
1.381 bisitz 3931: $r->print(&mt('[_1] enrolled','<b>'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.'</b>'));
1.220 raeburn 3932: if ($env{'form.sections'} ne '') {
3933: $r->print(' '.&mt('in section [_1]',$env{'form.sections'}));
3934: }
3935: my ($showstart,$showend);
3936: if ($startdate <= $now) {
3937: $showstart = &mt('Access starts immediately');
3938: } else {
3939: $showstart = &mt('Access starts: ').&Apache::lonlocal::locallocaltime($startdate);
3940: }
3941: if ($enddate == 0) {
3942: $showend = &mt('ends: no ending date');
3943: } else {
3944: $showend = &mt('ends: ').&Apache::lonlocal::locallocaltime($enddate);
3945: }
3946: $r->print('.<br />'.$showstart.'; '.$showend);
3947: if ($startdate <= $now && !$newuser) {
1.386 bisitz 3948: $r->print('<p class="LC_info">');
1.318 raeburn 3949: if ($crstype eq 'Community') {
3950: $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.'));
3951: } else {
3952: $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.'));
3953: }
3954: $r->print('</p>');
1.220 raeburn 3955: }
3956: } else {
3957: $r->print(&mt('unable to enroll').": ".$enroll_result);
3958: }
3959: return;
1.188 raeburn 3960: }
3961:
1.204 raeburn 3962: sub get_defaultquota_text {
3963: my ($settingstatus) = @_;
3964: my $defquotatext;
3965: if ($settingstatus eq '') {
1.383 raeburn 3966: $defquotatext = &mt('default');
1.204 raeburn 3967: } else {
3968: my ($usertypes,$order) =
3969: &Apache::lonnet::retrieve_inst_usertypes($env{'form.ccdomain'});
3970: if ($usertypes->{$settingstatus} eq '') {
1.383 raeburn 3971: $defquotatext = &mt('default');
1.204 raeburn 3972: } else {
1.383 raeburn 3973: $defquotatext = &mt('default for [_1]',$usertypes->{$settingstatus});
1.204 raeburn 3974: }
3975: }
3976: return $defquotatext;
3977: }
3978:
1.188 raeburn 3979: sub update_result_form {
3980: my ($uhome) = @_;
3981: my $outcome =
1.367 golterma 3982: '<form name="userupdate" method="post" action="">'."\n";
1.160 raeburn 3983: foreach my $item ('srchby','srchin','srchtype','srchterm','srchdomain','ccuname','ccdomain') {
1.188 raeburn 3984: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 3985: }
1.207 raeburn 3986: if ($env{'form.origname'} ne '') {
3987: $outcome .= '<input type="hidden" name="origname" value="'.$env{'form.origname'}.'" />'."\n";
3988: }
1.160 raeburn 3989: foreach my $item ('sortby','seluname','seludom') {
3990: if (exists($env{'form.'.$item})) {
1.188 raeburn 3991: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 3992: }
3993: }
1.188 raeburn 3994: if ($uhome eq 'no_host') {
3995: $outcome .= '<input type="hidden" name="forcenewuser" value="1" />'."\n";
3996: }
3997: $outcome .= '<input type="hidden" name="phase" value="" />'."\n".
1.383 raeburn 3998: '<input type="hidden" name="currstate" value="" />'."\n".
3999: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
1.188 raeburn 4000: '</form>';
4001: return $outcome;
1.4 www 4002: }
4003:
1.149 raeburn 4004: sub quota_admin {
1.378 raeburn 4005: my ($setquota,$changeHash,$name) = @_;
1.149 raeburn 4006: my $quotachanged;
4007: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
4008: # Current user has quota modification privileges
1.267 raeburn 4009: if (ref($changeHash) eq 'HASH') {
4010: $quotachanged = 1;
1.378 raeburn 4011: $changeHash->{$name.'quota'} = $setquota;
1.267 raeburn 4012: }
1.149 raeburn 4013: }
4014: return $quotachanged;
4015: }
4016:
1.267 raeburn 4017: sub tool_admin {
1.275 raeburn 4018: my ($tool,$settool,$changeHash,$context) = @_;
4019: my $canchange = 0;
1.279 raeburn 4020: if ($context eq 'requestcourses') {
1.275 raeburn 4021: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
4022: $canchange = 1;
4023: }
1.300 raeburn 4024: } elsif ($context eq 'reqcrsotherdom') {
4025: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
4026: $canchange = 1;
4027: }
1.362 raeburn 4028: } elsif ($context eq 'requestauthor') {
4029: if (&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) {
4030: $canchange = 1;
4031: }
1.275 raeburn 4032: } elsif (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
4033: # Current user has quota modification privileges
4034: $canchange = 1;
4035: }
1.267 raeburn 4036: my $toolchanged;
1.275 raeburn 4037: if ($canchange) {
1.267 raeburn 4038: if (ref($changeHash) eq 'HASH') {
4039: $toolchanged = 1;
1.362 raeburn 4040: if ($tool eq 'requestauthor') {
4041: $changeHash->{$context} = $settool;
4042: } else {
4043: $changeHash->{$context.'.'.$tool} = $settool;
4044: }
1.267 raeburn 4045: }
4046: }
4047: return $toolchanged;
4048: }
4049:
1.88 raeburn 4050: sub build_roles {
1.89 raeburn 4051: my ($sectionstr,$sections,$role) = @_;
1.88 raeburn 4052: my $num_sections = 0;
4053: if ($sectionstr=~ /,/) {
4054: my @secnums = split/,/,$sectionstr;
1.89 raeburn 4055: if ($role eq 'st') {
4056: $secnums[0] =~ s/\W//g;
4057: $$sections{$secnums[0]} = 1;
4058: $num_sections = 1;
4059: } else {
4060: foreach my $sec (@secnums) {
4061: $sec =~ ~s/\W//g;
1.150 banghart 4062: if (!($sec eq "")) {
1.89 raeburn 4063: if (exists($$sections{$sec})) {
4064: $$sections{$sec} ++;
4065: } else {
4066: $$sections{$sec} = 1;
4067: $num_sections ++;
4068: }
1.88 raeburn 4069: }
4070: }
4071: }
4072: } else {
4073: $sectionstr=~s/\W//g;
4074: unless ($sectionstr eq '') {
4075: $$sections{$sectionstr} = 1;
4076: $num_sections ++;
4077: }
4078: }
1.129 albertel 4079:
1.88 raeburn 4080: return $num_sections;
4081: }
4082:
1.58 www 4083: # ========================================================== Custom Role Editor
4084:
4085: sub custom_role_editor {
1.351 raeburn 4086: my ($r,$brcrum) = @_;
1.324 raeburn 4087: my $action = $env{'form.customroleaction'};
4088: my $rolename;
4089: if ($action eq 'new') {
4090: $rolename=$env{'form.newrolename'};
4091: } else {
4092: $rolename=$env{'form.rolename'};
1.59 www 4093: }
4094:
1.324 raeburn 4095: my ($crstype,$context);
4096: if ($env{'request.course.id'}) {
4097: $crstype = &Apache::loncommon::course_type();
4098: $context = 'course';
4099: } else {
4100: $context = 'domain';
4101: $crstype = $env{'form.templatecrstype'};
4102: }
1.351 raeburn 4103:
4104: $rolename=~s/[^A-Za-z0-9]//gs;
4105: if (!$rolename || $env{'form.phase'} eq 'pickrole') {
4106: &print_username_entry_form($r,undef,undef,undef,undef,$crstype,$brcrum);
4107: return;
4108: }
4109:
1.153 banghart 4110: # ------------------------------------------------------- What can be assigned?
4111: my %full=();
4112: my %courselevel=();
4113: my %courselevelcurrent=();
1.61 www 4114: my $syspriv='';
4115: my $dompriv='';
4116: my $coursepriv='';
1.153 banghart 4117: my $body_top;
1.59 www 4118: my ($rdummy,$roledef)=
4119: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
1.60 www 4120: # ------------------------------------------------------- Does this role exist?
1.153 banghart 4121: $body_top .= '<h2>';
1.59 www 4122: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.153 banghart 4123: $body_top .= &mt('Existing Role').' "';
1.61 www 4124: # ------------------------------------------------- Get current role privileges
4125: ($syspriv,$dompriv,$coursepriv)=split(/\_/,$roledef);
1.324 raeburn 4126: if ($crstype eq 'Community') {
4127: $syspriv =~ s/bre\&S//;
4128: }
1.59 www 4129: } else {
1.153 banghart 4130: $body_top .= &mt('New Role').' "';
1.59 www 4131: $roledef='';
4132: }
1.153 banghart 4133: $body_top .= $rolename.'"</h2>';
1.135 raeburn 4134: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
4135: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 4136: if (!$restrict) { $restrict='F'; }
1.60 www 4137: $courselevel{$priv}=$restrict;
1.61 www 4138: if ($coursepriv=~/\:$priv/) {
4139: $courselevelcurrent{$priv}=1;
4140: }
1.60 www 4141: $full{$priv}=1;
4142: }
4143: my %domainlevel=();
1.61 www 4144: my %domainlevelcurrent=();
1.135 raeburn 4145: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
4146: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 4147: if (!$restrict) { $restrict='F'; }
1.60 www 4148: $domainlevel{$priv}=$restrict;
1.61 www 4149: if ($dompriv=~/\:$priv/) {
4150: $domainlevelcurrent{$priv}=1;
4151: }
1.60 www 4152: $full{$priv}=1;
4153: }
1.61 www 4154: my %systemlevel=();
4155: my %systemlevelcurrent=();
1.135 raeburn 4156: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
4157: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 4158: if (!$restrict) { $restrict='F'; }
1.61 www 4159: $systemlevel{$priv}=$restrict;
4160: if ($syspriv=~/\:$priv/) {
4161: $systemlevelcurrent{$priv}=1;
4162: }
4163: $full{$priv}=1;
4164: }
1.160 raeburn 4165: my ($jsback,$elements) = &crumb_utilities();
1.154 banghart 4166: my $button_code = "\n";
1.153 banghart 4167: my $head_script = "\n";
1.301 bisitz 4168: $head_script .= '<script type="text/javascript">'."\n"
4169: .'// <![CDATA['."\n";
1.324 raeburn 4170: my @template_roles = ("in","ta","ep");
4171: if ($context eq 'domain') {
4172: push(@template_roles,"ad");
1.318 raeburn 4173: }
1.324 raeburn 4174: push(@template_roles,"st");
1.318 raeburn 4175: if ($crstype eq 'Community') {
4176: unshift(@template_roles,'co');
4177: } else {
4178: unshift(@template_roles,'cc');
4179: }
1.154 banghart 4180: foreach my $role (@template_roles) {
1.324 raeburn 4181: $head_script .= &make_script_template($role,$crstype);
1.318 raeburn 4182: $button_code .= &make_button_code($role,$crstype).' ';
1.154 banghart 4183: }
1.324 raeburn 4184: my $context_code;
4185: if ($context eq 'domain') {
4186: my $checkedCommunity = '';
4187: my $checkedCourse = ' checked="checked"';
4188: if ($env{'form.templatecrstype'} eq 'Community') {
4189: $checkedCommunity = $checkedCourse;
4190: $checkedCourse = '';
4191: }
4192: $context_code = '<label>'.
4193: '<input type="radio" name="templatecrstype" value="Course"'.$checkedCourse.' onclick="this.form.submit();">'.
4194: &mt('Course').
4195: '</label>'.(' ' x2).
4196: '<label>'.
4197: '<input type="radio" name="templatecrstype" value="Community"'.$checkedCommunity.' onclick="this.form.submit();">'.
4198: &mt('Community').
4199: '</label>'.
4200: '</fieldset>'.
4201: '<input type="hidden" name="customroleaction" value="'.
4202: $action.'" />';
4203: if ($env{'form.customroleaction'} eq 'new') {
4204: $context_code .= '<input type="hidden" name="newrolename" value="'.
4205: $rolename.'" />';
4206: } else {
4207: $context_code .= '<input type="hidden" name="rolename" value="'.
4208: $rolename.'" />';
4209: }
4210: $context_code .= '<input type="hidden" name="action" value="custom" />'.
4211: '<input type="hidden" name="phase" value="selected_custom_edit" />';
4212: }
4213:
1.301 bisitz 4214: $head_script .= "\n".$jsback."\n"
4215: .'// ]]>'."\n"
4216: .'</script>'."\n";
1.351 raeburn 4217: push (@{$brcrum},
4218: {href => "javascript:backPage(document.form1,'pickrole','')",
4219: text => "Pick custom role",
4220: faq => 282,bug=>'Instructor Interface',},
4221: {href => "javascript:backPage(document.form1,'','')",
4222: text => "Edit custom role",
4223: faq => 282,
4224: bug => 'Instructor Interface',
4225: help => 'Course_Editing_Custom_Roles'}
4226: );
4227: my $args = { bread_crumbs => $brcrum,
4228: bread_crumbs_component => 'User Management'};
4229:
4230: $r->print(&Apache::loncommon::start_page('Custom Role Editor',
4231: $head_script,$args).
4232: $body_top);
1.73 sakharuk 4233: my %lt=&Apache::lonlocal::texthash(
4234: 'prv' => "Privilege",
1.131 raeburn 4235: 'crl' => "Course Level",
1.73 sakharuk 4236: 'dml' => "Domain Level",
1.150 banghart 4237: 'ssl' => "System Level");
1.264 bisitz 4238:
1.324 raeburn 4239: $r->print('<div class="LC_left_float">'
1.264 bisitz 4240: .'<form action=""><fieldset>'
4241: .'<legend>'.&mt('Select a Template').'</legend>'
4242: .$button_code
1.324 raeburn 4243: .'</fieldset></form></div>');
4244: if ($context_code) {
4245: $r->print('<div class="LC_left_float">'
4246: .'<form action="/adm/createuser" method="post"><fieldset>'
4247: .'<legend>'.&mt('Context').'</legend>'
4248: .$context_code
4249: .'</form>'
4250: .'</div>'
4251: );
4252: }
4253: $r->print('<br clear="all" />');
1.264 bisitz 4254:
1.61 www 4255: $r->print(<<ENDCCF);
1.380 bisitz 4256: <form name="form1" method="post" action="">
1.61 www 4257: <input type="hidden" name="phase" value="set_custom_roles" />
4258: <input type="hidden" name="rolename" value="$rolename" />
4259: ENDCCF
1.135 raeburn 4260: $r->print(&Apache::loncommon::start_data_table().
4261: &Apache::loncommon::start_data_table_header_row().
4262: '<th>'.$lt{'prv'}.'</th><th>'.$lt{'crl'}.'</th><th>'.$lt{'dml'}.
4263: '</th><th>'.$lt{'ssl'}.'</th>'.
4264: &Apache::loncommon::end_data_table_header_row());
1.324 raeburn 4265: foreach my $priv (sort(keys(%full))) {
1.318 raeburn 4266: my $privtext = &Apache::lonnet::plaintext($priv,$crstype);
1.135 raeburn 4267: $r->print(&Apache::loncommon::start_data_table_row().
4268: '<td>'.$privtext.'</td><td>'.
1.288 bisitz 4269: ($courselevel{$priv}?'<input type="checkbox" name="'.$priv.'_c"'.
4270: ($courselevelcurrent{$priv}?' checked="checked"':'').' />':' ').
1.61 www 4271: '</td><td>'.
1.288 bisitz 4272: ($domainlevel{$priv}?'<input type="checkbox" name="'.$priv.'_d"'.
4273: ($domainlevelcurrent{$priv}?' checked="checked"':'').' />':' ').
1.324 raeburn 4274: '</td><td>');
4275: if ($priv eq 'bre' && $crstype eq 'Community') {
4276: $r->print(' ');
4277: } else {
4278: $r->print($systemlevel{$priv}?'<input type="checkbox" name="'.$priv.'_s"'.
4279: ($systemlevelcurrent{$priv}?' checked="checked"':'').' />':' ');
4280: }
4281: $r->print('</td>'.
4282: &Apache::loncommon::end_data_table_row());
1.60 www 4283: }
1.135 raeburn 4284: $r->print(&Apache::loncommon::end_data_table().
1.190 raeburn 4285: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
1.160 raeburn 4286: '<input type="hidden" name="startrolename" value="'.$env{'form.rolename'}.
1.179 raeburn 4287: '" />'."\n".'<input type="hidden" name="currstate" value="" />'."\n".
1.160 raeburn 4288: '<input type="reset" value="'.&mt("Reset").'" />'."\n".
1.351 raeburn 4289: '<input type="submit" value="'.&mt('Save').'" /></form>');
1.61 www 4290: }
1.153 banghart 4291: # --------------------------------------------------------
4292: sub make_script_template {
1.324 raeburn 4293: my ($role,$crstype) = @_;
1.153 banghart 4294: my %full_c=();
4295: my %full_d=();
4296: my %full_s=();
4297: my $return_script;
4298: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
4299: my ($priv,$restrict)=split(/\&/,$item);
4300: $full_c{$priv}=1;
4301: }
4302: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
4303: my ($priv,$restrict)=split(/\&/,$item);
4304: $full_d{$priv}=1;
4305: }
1.154 banghart 4306: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
1.324 raeburn 4307: next if (($crstype eq 'Community') && ($item eq 'bre&S'));
1.153 banghart 4308: my ($priv,$restrict)=split(/\&/,$item);
4309: $full_s{$priv}=1;
4310: }
4311: $return_script .= 'function set_'.$role.'() {'."\n";
4312: my @temp = split(/:/,$Apache::lonnet::pr{$role.':c'});
4313: my %role_c;
1.155 banghart 4314: foreach my $priv (@temp) {
1.153 banghart 4315: my ($priv_item, $dummy) = split(/\&/,$priv);
4316: $role_c{$priv_item} = 1;
4317: }
1.269 raeburn 4318: my %role_d;
4319: @temp = split(/:/,$Apache::lonnet::pr{$role.':d'});
4320: foreach my $priv(@temp) {
4321: my ($priv_item, $dummy) = split(/\&/,$priv);
4322: $role_d{$priv_item} = 1;
4323: }
4324: my %role_s;
4325: @temp = split(/:/,$Apache::lonnet::pr{$role.':s'});
4326: foreach my $priv(@temp) {
4327: my ($priv_item, $dummy) = split(/\&/,$priv);
4328: $role_s{$priv_item} = 1;
4329: }
1.153 banghart 4330: foreach my $priv_item (keys(%full_c)) {
4331: my ($priv, $dummy) = split(/\&/,$priv_item);
1.269 raeburn 4332: if ((exists($role_c{$priv})) || (exists($role_d{$priv})) ||
4333: (exists($role_s{$priv}))) {
1.153 banghart 4334: $return_script .= "document.form1.$priv"."_c.checked = true;\n";
4335: } else {
4336: $return_script .= "document.form1.$priv"."_c.checked = false;\n";
4337: }
4338: }
1.154 banghart 4339: foreach my $priv_item (keys(%full_d)) {
4340: my ($priv, $dummy) = split(/\&/,$priv_item);
1.269 raeburn 4341: if ((exists($role_d{$priv})) || (exists($role_s{$priv}))) {
1.154 banghart 4342: $return_script .= "document.form1.$priv"."_d.checked = true;\n";
4343: } else {
4344: $return_script .= "document.form1.$priv"."_d.checked = false;\n";
4345: }
4346: }
4347: foreach my $priv_item (keys(%full_s)) {
1.153 banghart 4348: my ($priv, $dummy) = split(/\&/,$priv_item);
1.154 banghart 4349: if (exists($role_s{$priv})) {
4350: $return_script .= "document.form1.$priv"."_s.checked = true;\n";
4351: } else {
4352: $return_script .= "document.form1.$priv"."_s.checked = false;\n";
4353: }
1.153 banghart 4354: }
4355: $return_script .= '}'."\n";
1.154 banghart 4356: return ($return_script);
4357: }
4358: # ----------------------------------------------------------
4359: sub make_button_code {
1.318 raeburn 4360: my ($role,$crstype) = @_;
4361: my $label = &Apache::lonnet::plaintext($role,$crstype);
1.301 bisitz 4362: my $button_code = '<input type="button" onclick="set_'.$role.'()" value="'.$label.'" />';
1.154 banghart 4363: return ($button_code);
1.153 banghart 4364: }
1.61 www 4365: # ---------------------------------------------------------- Call to definerole
4366: sub set_custom_role {
1.351 raeburn 4367: my ($r,$context,$brcrum) = @_;
1.101 albertel 4368: my $rolename=$env{'form.rolename'};
1.63 www 4369: $rolename=~s/[^A-Za-z0-9]//gs;
1.150 banghart 4370: if (!$rolename) {
1.351 raeburn 4371: &custom_role_editor($r,$brcrum);
1.61 www 4372: return;
4373: }
1.160 raeburn 4374: my ($jsback,$elements) = &crumb_utilities();
1.301 bisitz 4375: my $jscript = '<script type="text/javascript">'
4376: .'// <![CDATA['."\n"
4377: .$jsback."\n"
4378: .'// ]]>'."\n"
4379: .'</script>'."\n";
1.352 raeburn 4380: push(@{$brcrum},
4381: {href => "javascript:backPage(document.customresult,'pickrole','')",
4382: text => "Pick custom role",
4383: faq => 282,
4384: bug => 'Instructor Interface',},
4385: {href => "javascript:backPage(document.customresult,'selected_custom_edit','')",
4386: text => "Edit custom role",
4387: faq => 282,
4388: bug => 'Instructor Interface',},
4389: {href => "javascript:backPage(document.customresult,'set_custom_roles','')",
4390: text => "Result",
4391: faq => 282,
4392: bug => 'Instructor Interface',
4393: help => 'Course_Editing_Custom_Roles'},
4394: );
4395: my $args = { bread_crumbs => $brcrum,
1.351 raeburn 4396: bread_crumbs_component => 'User Management'};
4397: $r->print(&Apache::loncommon::start_page('Save Custom Role',$jscript,$args));
1.160 raeburn 4398:
1.61 www 4399: my ($rdummy,$roledef)=
1.110 albertel 4400: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
4401:
1.61 www 4402: # ------------------------------------------------------- Does this role exist?
1.188 raeburn 4403: $r->print('<h3>');
1.61 www 4404: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.73 sakharuk 4405: $r->print(&mt('Existing Role').' "');
1.61 www 4406: } else {
1.73 sakharuk 4407: $r->print(&mt('New Role').' "');
1.61 www 4408: $roledef='';
4409: }
1.188 raeburn 4410: $r->print($rolename.'"</h3>');
1.61 www 4411: # ------------------------------------------------------- What can be assigned?
4412: my $sysrole='';
4413: my $domrole='';
4414: my $courole='';
4415:
1.135 raeburn 4416: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
4417: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 4418: if (!$restrict) { $restrict=''; }
4419: if ($env{'form.'.$priv.'_c'}) {
1.135 raeburn 4420: $courole.=':'.$item;
1.61 www 4421: }
4422: }
4423:
1.135 raeburn 4424: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
4425: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 4426: if (!$restrict) { $restrict=''; }
4427: if ($env{'form.'.$priv.'_d'}) {
1.135 raeburn 4428: $domrole.=':'.$item;
1.61 www 4429: }
4430: }
4431:
1.135 raeburn 4432: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
4433: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 4434: if (!$restrict) { $restrict=''; }
4435: if ($env{'form.'.$priv.'_s'}) {
1.135 raeburn 4436: $sysrole.=':'.$item;
1.61 www 4437: }
4438: }
1.387 ! bisitz 4439: # Assign role; Compile and show result
! 4440: my $errmsg;
! 4441: my $result =
! 4442: &Apache::lonnet::definerole($rolename,$sysrole,$domrole,$courole);
! 4443: if ($result ne 'ok') {
! 4444: $errmsg = ': '.$result;
! 4445: }
! 4446: my $message =
! 4447: &Apache::lonhtmlcommon::confirm_success(
! 4448: &mt('Defining Role').$errmsg, ($result eq 'ok' ? 0 : 1));
1.101 albertel 4449: if ($env{'request.course.id'}) {
4450: my $url='/'.$env{'request.course.id'};
1.63 www 4451: $url=~s/\_/\//g;
1.387 ! bisitz 4452: $result =
! 4453: &Apache::lonnet::assigncustomrole(
! 4454: $env{'user.domain'},$env{'user.name'},
! 4455: $url,
! 4456: $env{'user.domain'},$env{'user.name'},
! 4457: $rolename,undef,undef,undef,$context);
! 4458: if ($result ne 'ok') {
! 4459: $errmsg = ': '.$result;
! 4460: }
! 4461: $message .=
! 4462: '<br />'
! 4463: .&Apache::lonhtmlcommon::confirm_success(
! 4464: &mt('Assigning Role to Self').$errmsg, ($result eq 'ok' ? 0 : 1));
1.63 www 4465: }
1.380 bisitz 4466: $r->print(
1.387 ! bisitz 4467: &Apache::loncommon::confirmwrapper($message)
! 4468: .'<br />'
! 4469: .&Apache::lonhtmlcommon::actionbox([
! 4470: '<a href="javascript:backPage(document.customresult,'."'pickrole'".')">'
! 4471: .&mt('Create or edit another custom role')
! 4472: .'</a>'])
1.380 bisitz 4473: .'<form name="customresult" method="post" action="">'
1.387 ! bisitz 4474: .&Apache::lonhtmlcommon::echo_form_input([])
! 4475: .'</form>'
1.380 bisitz 4476: );
1.58 www 4477: }
4478:
1.2 www 4479: # ================================================================ Main Handler
4480: sub handler {
4481: my $r = shift;
4482: if ($r->header_only) {
1.68 www 4483: &Apache::loncommon::content_type($r,'text/html');
1.2 www 4484: $r->send_http_header;
4485: return OK;
4486: }
1.318 raeburn 4487: my ($context,$crstype);
1.190 raeburn 4488: if ($env{'request.course.id'}) {
4489: $context = 'course';
1.318 raeburn 4490: $crstype = &Apache::loncommon::course_type();
1.190 raeburn 4491: } elsif ($env{'request.role'} =~ /^au\./) {
1.206 raeburn 4492: $context = 'author';
1.190 raeburn 4493: } else {
4494: $context = 'domain';
4495: }
1.375 raeburn 4496:
1.190 raeburn 4497: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.233 raeburn 4498: ['action','state','callingform','roletype','showrole','bulkaction','popup','phase',
4499: 'username','domain','srchterm','srchdomain','srchin','srchby','srchtype']);
1.190 raeburn 4500: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.351 raeburn 4501: my $args;
4502: my $brcrum = [];
4503: my $bread_crumbs_component = 'User Management';
1.202 raeburn 4504: if ($env{'form.action'} ne 'dateselect') {
1.351 raeburn 4505: $brcrum = [{href=>"/adm/createuser",
4506: text=>"User Management",
4507: 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'}
4508: ];
1.202 raeburn 4509: }
1.289 droeschl 4510: #SD Following files not added to help, because the corresponding .tex-files seem to
4511: #be missing: Course_Approve_Selfenroll,Course_User_Logs,
1.209 raeburn 4512: my ($permission,$allowed) =
1.318 raeburn 4513: &Apache::lonuserutils::get_permission($context,$crstype);
1.190 raeburn 4514: if (!$allowed) {
1.358 raeburn 4515: if ($context eq 'course') {
4516: $r->internal_redirect('/adm/viewclasslist');
4517: return OK;
4518: }
1.190 raeburn 4519: $env{'user.error.msg'}=
4520: "/adm/createuser:cst:0:0:Cannot create/modify user data ".
4521: "or view user status.";
4522: return HTTP_NOT_ACCEPTABLE;
4523: }
4524:
4525: &Apache::loncommon::content_type($r,'text/html');
4526: $r->send_http_header;
4527:
1.375 raeburn 4528: my $showcredits;
4529: if ((($context eq 'course') && ($crstype eq 'Course')) ||
4530: ($context eq 'domain')) {
4531: my %domdefaults =
4532: &Apache::lonnet::get_domain_defaults($env{'request.role.domain'});
4533: if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'}) {
4534: $showcredits = 1;
4535: }
4536: }
4537:
1.190 raeburn 4538: # Main switch on form.action and form.state, as appropriate
4539: if (! exists($env{'form.action'})) {
1.351 raeburn 4540: $args = {bread_crumbs => $brcrum,
4541: bread_crumbs_component => $bread_crumbs_component};
4542: $r->print(&header(undef,$args));
1.318 raeburn 4543: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 4544: } elsif ($env{'form.action'} eq 'upload' && $permission->{'cusr'}) {
1.351 raeburn 4545: push(@{$brcrum},
4546: { href => '/adm/createuser?action=upload&state=',
4547: text => 'Upload Users List',
4548: help => 'Course_Create_Class_List',
4549: });
4550: $bread_crumbs_component = 'Upload Users List';
4551: $args = {bread_crumbs => $brcrum,
4552: bread_crumbs_component => $bread_crumbs_component};
4553: $r->print(&header(undef,$args));
1.190 raeburn 4554: $r->print('<form name="studentform" method="post" '.
4555: 'enctype="multipart/form-data" '.
4556: ' action="/adm/createuser">'."\n");
4557: if (! exists($env{'form.state'})) {
4558: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4559: } elsif ($env{'form.state'} eq 'got_file') {
1.375 raeburn 4560: &Apache::lonuserutils::print_upload_manager_form($r,$context,$permission,
4561: $crstype,$showcredits);
1.190 raeburn 4562: } elsif ($env{'form.state'} eq 'enrolling') {
4563: if ($env{'form.datatoken'}) {
1.375 raeburn 4564: &Apache::lonuserutils::upfile_drop_add($r,$context,$permission,
4565: $showcredits);
1.190 raeburn 4566: }
4567: } else {
4568: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4569: }
1.213 raeburn 4570: } elsif ((($env{'form.action'} eq 'singleuser') || ($env{'form.action'}
4571: eq 'singlestudent')) && ($permission->{'cusr'})) {
1.190 raeburn 4572: my $phase = $env{'form.phase'};
4573: my @search = ('srchterm','srchby','srchin','srchtype','srchdomain');
1.192 albertel 4574: &Apache::loncreateuser::restore_prev_selections();
4575: my $srch;
4576: foreach my $item (@search) {
4577: $srch->{$item} = $env{'form.'.$item};
4578: }
1.207 raeburn 4579: if (($phase eq 'get_user_info') || ($phase eq 'userpicked') ||
4580: ($phase eq 'createnewuser')) {
4581: if ($env{'form.phase'} eq 'createnewuser') {
4582: my $response;
4583: if ($env{'form.srchterm'} !~ /^$match_username$/) {
1.366 bisitz 4584: my $response =
4585: '<span class="LC_warning">'
4586: .&mt('You must specify a valid username. Only the following are allowed:'
4587: .' letters numbers - . @')
4588: .'</span>';
1.221 raeburn 4589: $env{'form.phase'} = '';
1.375 raeburn 4590: &print_username_entry_form($r,$context,$response,$srch,undef,
4591: $crstype,$brcrum,$showcredits);
1.207 raeburn 4592: } else {
4593: my $ccuname =&LONCAPA::clean_username($srch->{'srchterm'});
4594: my $ccdomain=&LONCAPA::clean_domain($srch->{'srchdomain'});
4595: &print_user_modification_page($r,$ccuname,$ccdomain,
1.221 raeburn 4596: $srch,$response,$context,
1.375 raeburn 4597: $permission,$crstype,$brcrum,
4598: $showcredits);
1.207 raeburn 4599: }
4600: } elsif ($env{'form.phase'} eq 'get_user_info') {
1.190 raeburn 4601: my ($currstate,$response,$forcenewuser,$results) =
1.221 raeburn 4602: &user_search_result($context,$srch);
1.190 raeburn 4603: if ($env{'form.currstate'} eq 'modify') {
4604: $currstate = $env{'form.currstate'};
4605: }
4606: if ($currstate eq 'select') {
4607: &print_user_selection_page($r,$response,$srch,$results,
1.351 raeburn 4608: \@search,$context,undef,$crstype,
4609: $brcrum);
1.190 raeburn 4610: } elsif ($currstate eq 'modify') {
4611: my ($ccuname,$ccdomain);
4612: if (($srch->{'srchby'} eq 'uname') &&
4613: ($srch->{'srchtype'} eq 'exact')) {
4614: $ccuname = $srch->{'srchterm'};
4615: $ccdomain= $srch->{'srchdomain'};
4616: } else {
4617: my @matchedunames = keys(%{$results});
4618: ($ccuname,$ccdomain) = split(/:/,$matchedunames[0]);
4619: }
4620: $ccuname =&LONCAPA::clean_username($ccuname);
4621: $ccdomain=&LONCAPA::clean_domain($ccdomain);
4622: if ($env{'form.forcenewuser'}) {
4623: $response = '';
4624: }
4625: &print_user_modification_page($r,$ccuname,$ccdomain,
1.221 raeburn 4626: $srch,$response,$context,
1.351 raeburn 4627: $permission,$crstype,$brcrum);
1.190 raeburn 4628: } elsif ($currstate eq 'query') {
1.351 raeburn 4629: &print_user_query_page($r,'createuser',$brcrum);
1.190 raeburn 4630: } else {
1.229 raeburn 4631: $env{'form.phase'} = '';
1.207 raeburn 4632: &print_username_entry_form($r,$context,$response,$srch,
1.351 raeburn 4633: $forcenewuser,$crstype,$brcrum);
1.190 raeburn 4634: }
4635: } elsif ($env{'form.phase'} eq 'userpicked') {
4636: my $ccuname = &LONCAPA::clean_username($env{'form.seluname'});
4637: my $ccdomain = &LONCAPA::clean_domain($env{'form.seludom'});
1.196 raeburn 4638: &print_user_modification_page($r,$ccuname,$ccdomain,$srch,'',
1.351 raeburn 4639: $context,$permission,$crstype,
4640: $brcrum);
1.190 raeburn 4641: }
4642: } elsif ($env{'form.phase'} eq 'update_user_data') {
1.375 raeburn 4643: &update_user_data($r,$context,$crstype,$brcrum,$showcredits);
1.190 raeburn 4644: } else {
1.351 raeburn 4645: &print_username_entry_form($r,$context,undef,$srch,undef,$crstype,
4646: $brcrum);
1.190 raeburn 4647: }
4648: } elsif ($env{'form.action'} eq 'custom' && $permission->{'custom'}) {
4649: if ($env{'form.phase'} eq 'set_custom_roles') {
1.351 raeburn 4650: &set_custom_role($r,$context,$brcrum);
1.190 raeburn 4651: } else {
1.351 raeburn 4652: &custom_role_editor($r,$brcrum);
1.190 raeburn 4653: }
1.362 raeburn 4654: } elsif (($env{'form.action'} eq 'processauthorreq') &&
4655: ($permission->{'cusr'}) &&
4656: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
4657: push(@{$brcrum},
4658: {href => '/adm/createuser?action=processauthorreq',
1.385 bisitz 4659: text => 'Authoring Space requests',
1.362 raeburn 4660: help => 'Domain_Role_Approvals'});
4661: $bread_crumbs_component = 'Authoring requests';
4662: if ($env{'form.state'} eq 'done') {
4663: push(@{$brcrum},
4664: {href => '/adm/createuser?action=authorreqqueue',
4665: text => 'Result',
4666: help => 'Domain_Role_Approvals'});
4667: $bread_crumbs_component = 'Authoring request result';
4668: }
4669: $args = { bread_crumbs => $brcrum,
4670: bread_crumbs_component => $bread_crumbs_component};
4671: $r->print(&header(undef,$args));
4672: if (!exists($env{'form.state'})) {
4673: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestauthor',
4674: $env{'request.role.domain'}));
4675: } elsif ($env{'form.state'} eq 'done') {
4676: $r->print('<h3>'.&mt('Authoring request processing').'</h3>'."\n");
4677: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestauthor',
4678: $env{'request.role.domain'}));
4679: }
1.207 raeburn 4680: } elsif (($env{'form.action'} eq 'listusers') &&
4681: ($permission->{'view'} || $permission->{'cusr'})) {
1.202 raeburn 4682: if ($env{'form.phase'} eq 'bulkchange') {
1.351 raeburn 4683: push(@{$brcrum},
4684: {href => '/adm/createuser?action=listusers',
4685: text => "List Users"},
4686: {href => "/adm/createuser",
4687: text => "Result",
4688: help => 'Course_View_Class_List'});
4689: $bread_crumbs_component = 'Update Users';
4690: $args = {bread_crumbs => $brcrum,
4691: bread_crumbs_component => $bread_crumbs_component};
4692: $r->print(&header(undef,$args));
1.202 raeburn 4693: my $setting = $env{'form.roletype'};
4694: my $choice = $env{'form.bulkaction'};
4695: if ($permission->{'cusr'}) {
1.336 raeburn 4696: &Apache::lonuserutils::update_user_list($r,$context,$setting,$choice,$crstype);
1.221 raeburn 4697: } else {
4698: $r->print(&mt('You are not authorized to make bulk changes to user roles'));
1.223 raeburn 4699: $r->print('<p><a href="/adm/createuser?action=listusers">'.&mt('Display User Lists').'</a>');
1.202 raeburn 4700: }
4701: } else {
1.351 raeburn 4702: push(@{$brcrum},
4703: {href => '/adm/createuser?action=listusers',
4704: text => "List Users",
4705: help => 'Course_View_Class_List'});
4706: $bread_crumbs_component = 'List Users';
4707: $args = {bread_crumbs => $brcrum,
4708: bread_crumbs_component => $bread_crumbs_component};
1.202 raeburn 4709: my ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles);
4710: my $formname = 'studentform';
1.364 raeburn 4711: my $hidecall = "hide_searching();";
1.321 raeburn 4712: if (($context eq 'domain') && (($env{'form.roletype'} eq 'course') ||
4713: ($env{'form.roletype'} eq 'community'))) {
4714: if ($env{'form.roletype'} eq 'course') {
4715: ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles) =
4716: &Apache::lonuserutils::courses_selector($env{'request.role.domain'},
4717: $formname);
4718: } elsif ($env{'form.roletype'} eq 'community') {
4719: $cb_jscript =
4720: &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
4721: my %elements = (
4722: coursepick => 'radio',
4723: coursetotal => 'text',
4724: courselist => 'text',
4725: );
4726: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements);
4727: }
1.364 raeburn 4728: $jscript .= &verify_user_display($context)."\n".
4729: &Apache::loncommon::check_uncheck_jscript();
1.202 raeburn 4730: my $js = &add_script($jscript).$cb_jscript;
4731: my $loadcode =
4732: &Apache::lonuserutils::course_selector_loadcode($formname);
4733: if ($loadcode ne '') {
1.364 raeburn 4734: $args->{add_entries} = {onload => "$loadcode;$hidecall"};
4735: } else {
4736: $args->{add_entries} = {onload => $hidecall};
1.202 raeburn 4737: }
1.351 raeburn 4738: $r->print(&header($js,$args));
1.191 raeburn 4739: } else {
1.364 raeburn 4740: $args->{add_entries} = {onload => $hidecall};
4741: $jscript = &verify_user_display($context).
4742: &Apache::loncommon::check_uncheck_jscript();
4743: $r->print(&header(&add_script($jscript),$args));
1.191 raeburn 4744: }
1.202 raeburn 4745: &Apache::lonuserutils::print_userlist($r,undef,$permission,$context,
1.375 raeburn 4746: $formname,$totcodes,$codetitles,$idlist,$idlist_titles,
4747: $showcredits);
1.191 raeburn 4748: }
1.213 raeburn 4749: } elsif ($env{'form.action'} eq 'drop' && $permission->{'cusr'}) {
1.318 raeburn 4750: my $brtext;
4751: if ($crstype eq 'Community') {
4752: $brtext = 'Drop Members';
4753: } else {
4754: $brtext = 'Drop Students';
4755: }
1.351 raeburn 4756: push(@{$brcrum},
4757: {href => '/adm/createuser?action=drop',
4758: text => $brtext,
4759: help => 'Course_Drop_Student'});
4760: if ($env{'form.state'} eq 'done') {
4761: push(@{$brcrum},
4762: {href=>'/adm/createuser?action=drop',
4763: text=>"Result"});
4764: }
4765: $bread_crumbs_component = $brtext;
4766: $args = {bread_crumbs => $brcrum,
4767: bread_crumbs_component => $bread_crumbs_component};
4768: $r->print(&header(undef,$args));
1.213 raeburn 4769: if (!exists($env{'form.state'})) {
1.318 raeburn 4770: &Apache::lonuserutils::print_drop_menu($r,$context,$permission,$crstype);
1.213 raeburn 4771: } elsif ($env{'form.state'} eq 'done') {
4772: &Apache::lonuserutils::update_user_list($r,$context,undef,
4773: $env{'form.action'});
4774: }
1.202 raeburn 4775: } elsif ($env{'form.action'} eq 'dateselect') {
4776: if ($permission->{'cusr'}) {
1.351 raeburn 4777: $r->print(&header(undef,{'no_nav_bar' => 1}).
1.375 raeburn 4778: &Apache::lonuserutils::date_section_selector($context,$permission,
4779: $crstype,$showcredits));
1.202 raeburn 4780: } else {
1.351 raeburn 4781: $r->print(&header(undef,{'no_nav_bar' => 1}).
4782: '<span class="LC_error">'.&mt('You do not have permission to modify dates or sections for users').'</span>');
1.202 raeburn 4783: }
1.237 raeburn 4784: } elsif ($env{'form.action'} eq 'selfenroll') {
1.351 raeburn 4785: push(@{$brcrum},
4786: {href => '/adm/createuser?action=selfenroll',
4787: text => "Configure Self-enrollment",
4788: help => 'Course_Self_Enrollment'});
1.237 raeburn 4789: if (!exists($env{'form.state'})) {
1.351 raeburn 4790: $args = { bread_crumbs => $brcrum,
4791: bread_crumbs_component => 'Configure Self-enrollment'};
4792: $r->print(&header(undef,$args));
1.241 raeburn 4793: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
1.237 raeburn 4794: &print_selfenroll_menu($r,$context,$permission);
4795: } elsif ($env{'form.state'} eq 'done') {
1.351 raeburn 4796: push (@{$brcrum},
4797: {href=>'/adm/createuser?action=selfenroll',
4798: text=>"Result"});
4799: $args = { bread_crumbs => $brcrum,
4800: bread_crumbs_component => 'Self-enrollment result'};
4801: $r->print(&header(undef,$args));
1.241 raeburn 4802: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
4803: &update_selfenroll_config($r,$context,$permission);
1.237 raeburn 4804: }
1.277 raeburn 4805: } elsif ($env{'form.action'} eq 'selfenrollqueue') {
1.351 raeburn 4806: push(@{$brcrum},
4807: {href => '/adm/createuser?action=selfenrollqueue',
4808: text => 'Enrollment requests',
4809: help => 'Course_Self_Enrollment'});
4810: $bread_crumbs_component = 'Enrollment requests';
4811: if ($env{'form.state'} eq 'done') {
4812: push(@{$brcrum},
4813: {href => '/adm/createuser?action=selfenrollqueue',
4814: text => 'Result',
4815: help => 'Course_Self_Enrollment'});
4816: $bread_crumbs_component = 'Enrollment result';
4817: }
4818: $args = { bread_crumbs => $brcrum,
4819: bread_crumbs_component => $bread_crumbs_component};
4820: $r->print(&header(undef,$args));
1.277 raeburn 4821: my $cid = $env{'request.course.id'};
4822: my $cdom = $env{'course.'.$cid.'.domain'};
4823: my $cnum = $env{'course.'.$cid.'.num'};
1.307 raeburn 4824: my $coursedesc = $env{'course.'.$cid.'.description'};
1.277 raeburn 4825: if (!exists($env{'form.state'})) {
4826: $r->print('<h3>'.&mt('Pending enrollment requests').'</h3>'."\n");
1.307 raeburn 4827: $r->print(&Apache::loncoursequeueadmin::display_queued_requests($context,
4828: $cdom,$cnum));
1.277 raeburn 4829: } elsif ($env{'form.state'} eq 'done') {
4830: $r->print('<h3>'.&mt('Enrollment request processing').'</h3>'."\n");
1.307 raeburn 4831: $r->print(&Apache::loncoursequeueadmin::update_request_queue($context,
4832: $cdom,$cnum,$coursedesc));
1.277 raeburn 4833: }
1.239 raeburn 4834: } elsif ($env{'form.action'} eq 'changelogs') {
1.363 raeburn 4835: my $helpitem;
4836: if ($context eq 'course') {
4837: $helpitem = 'Course_User_Logs';
4838: }
1.351 raeburn 4839: push (@{$brcrum},
4840: {href => '/adm/createuser?action=changelogs',
4841: text => 'User Management Logs',
1.363 raeburn 4842: help => $helpitem});
1.351 raeburn 4843: $bread_crumbs_component = 'User Changes';
4844: $args = { bread_crumbs => $brcrum,
4845: bread_crumbs_component => $bread_crumbs_component};
4846: $r->print(&header(undef,$args));
4847: &print_userchangelogs_display($r,$context,$permission);
1.190 raeburn 4848: } else {
1.351 raeburn 4849: $bread_crumbs_component = 'User Management';
4850: $args = { bread_crumbs => $brcrum,
4851: bread_crumbs_component => $bread_crumbs_component};
4852: $r->print(&header(undef,$args));
1.318 raeburn 4853: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 4854: }
1.351 raeburn 4855: $r->print(&Apache::loncommon::end_page());
1.190 raeburn 4856: return OK;
4857: }
4858:
4859: sub header {
1.351 raeburn 4860: my ($jscript,$args) = @_;
1.190 raeburn 4861: my $start_page;
1.351 raeburn 4862: if (ref($args) eq 'HASH') {
4863: $start_page=&Apache::loncommon::start_page('User Management',$jscript,$args);
1.190 raeburn 4864: } else {
1.351 raeburn 4865: $start_page=&Apache::loncommon::start_page('User Management',$jscript);
1.190 raeburn 4866: }
4867: return $start_page;
4868: }
1.2 www 4869:
1.191 raeburn 4870: sub add_script {
4871: my ($js) = @_;
1.301 bisitz 4872: return '<script type="text/javascript">'."\n"
4873: .'// <![CDATA['."\n"
4874: .$js."\n"
4875: .'// ]]>'."\n"
4876: .'</script>'."\n";
1.191 raeburn 4877: }
4878:
1.202 raeburn 4879: sub verify_user_display {
1.364 raeburn 4880: my ($context) = @_;
1.374 raeburn 4881: my %lt = &Apache::lonlocal::texthash (
4882: course => 'course(s): description, section(s), status',
4883: community => 'community(s): description, section(s), status',
4884: author => 'author',
4885: );
1.364 raeburn 4886: my $photos;
4887: if (($context eq 'course') && $env{'request.course.id'}) {
4888: $photos = $env{'course.'.$env{'request.course.id'}.'.internal.showphoto'};
4889: }
1.202 raeburn 4890: my $output = <<"END";
4891:
1.364 raeburn 4892: function hide_searching() {
4893: if (document.getElementById('searching')) {
4894: document.getElementById('searching').style.display = 'none';
4895: }
4896: return;
4897: }
4898:
1.202 raeburn 4899: function display_update() {
4900: document.studentform.action.value = 'listusers';
4901: document.studentform.phase.value = 'display';
4902: document.studentform.submit();
4903: }
4904:
1.364 raeburn 4905: function updateCols(caller) {
4906: var context = '$context';
4907: var photos = '$photos';
4908: if (caller == 'Status') {
1.374 raeburn 4909: if ((context == 'domain') &&
4910: ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
4911: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community'))) {
1.364 raeburn 4912: document.getElementById('showcolstatus').checked = false;
4913: document.getElementById('showcolstatus').disabled = 'disabled';
4914: document.getElementById('showcolstart').checked = false;
4915: document.getElementById('showcolend').checked = false;
1.374 raeburn 4916: } else {
4917: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
4918: document.getElementById('showcolstatus').checked = true;
4919: document.getElementById('showcolstatus').disabled = '';
4920: document.getElementById('showcolstart').checked = true;
4921: document.getElementById('showcolend').checked = true;
4922: } else {
4923: document.getElementById('showcolstatus').checked = false;
4924: document.getElementById('showcolstatus').disabled = 'disabled';
4925: document.getElementById('showcolstart').checked = false;
4926: document.getElementById('showcolend').checked = false;
4927: }
1.364 raeburn 4928: }
4929: }
4930: if (caller == 'output') {
4931: if (photos == 1) {
4932: if (document.getElementById('showcolphoto')) {
4933: var photoitem = document.getElementById('showcolphoto');
4934: if (document.studentform.output.options[document.studentform.output.selectedIndex].value == 'html') {
4935: photoitem.checked = true;
4936: photoitem.disabled = '';
4937: } else {
4938: photoitem.checked = false;
4939: photoitem.disabled = 'disabled';
4940: }
4941: }
4942: }
4943: }
4944: if (caller == 'showrole') {
1.371 raeburn 4945: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any') ||
4946: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'cr')) {
1.364 raeburn 4947: document.getElementById('showcolrole').checked = true;
4948: document.getElementById('showcolrole').disabled = '';
4949: } else {
4950: document.getElementById('showcolrole').checked = false;
4951: document.getElementById('showcolrole').disabled = 'disabled';
4952: }
1.374 raeburn 4953: if (context == 'domain') {
1.382 raeburn 4954: var quotausageshow = 0;
1.374 raeburn 4955: if ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
4956: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community')) {
4957: document.getElementById('showcolstatus').checked = false;
4958: document.getElementById('showcolstatus').disabled = 'disabled';
4959: document.getElementById('showcolstart').checked = false;
4960: document.getElementById('showcolend').checked = false;
4961: } else {
4962: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
4963: document.getElementById('showcolstatus').checked = true;
4964: document.getElementById('showcolstatus').disabled = '';
4965: document.getElementById('showcolstart').checked = true;
4966: document.getElementById('showcolend').checked = true;
4967: }
4968: }
4969: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'domain') {
4970: document.getElementById('showcolextent').disabled = 'disabled';
4971: document.getElementById('showcolextent').checked = 'false';
4972: document.getElementById('showextent').style.display='none';
4973: document.getElementById('showcoltextextent').innerHTML = '';
1.382 raeburn 4974: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'au') ||
4975: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any')) {
4976: if (document.getElementById('showcolauthorusage')) {
4977: document.getElementById('showcolauthorusage').disabled = '';
4978: }
4979: if (document.getElementById('showcolauthorquota')) {
4980: document.getElementById('showcolauthorquota').disabled = '';
4981: }
4982: quotausageshow = 1;
4983: }
1.374 raeburn 4984: } else {
4985: document.getElementById('showextent').style.display='block';
4986: document.getElementById('showextent').style.textAlign='left';
4987: document.getElementById('showextent').style.textFace='normal';
4988: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'author') {
4989: document.getElementById('showcolextent').disabled = '';
4990: document.getElementById('showcolextent').checked = 'true';
4991: document.getElementById('showcoltextextent').innerHTML="$lt{'author'}";
4992: } else {
4993: document.getElementById('showcolextent').disabled = '';
4994: document.getElementById('showcolextent').checked = 'true';
4995: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community') {
4996: document.getElementById('showcoltextextent').innerHTML="$lt{'community'}";
4997: } else {
4998: document.getElementById('showcoltextextent').innerHTML="$lt{'course'}";
4999: }
5000: }
5001: }
1.382 raeburn 5002: if (quotausageshow == 0) {
5003: if (document.getElementById('showcolauthorusage')) {
5004: document.getElementById('showcolauthorusage').checked = false;
5005: document.getElementById('showcolauthorusage').disabled = 'disabled';
5006: }
5007: if (document.getElementById('showcolauthorquota')) {
5008: document.getElementById('showcolauthorquota').checked = false;
5009: document.getElementById('showcolauthorquota').disabled = 'disabled';
5010: }
5011: }
1.374 raeburn 5012: }
1.364 raeburn 5013: }
5014: return;
5015: }
5016:
1.202 raeburn 5017: END
5018: return $output;
5019:
5020: }
5021:
1.190 raeburn 5022: ###############################################################
5023: ###############################################################
5024: # Menu Phase One
5025: sub print_main_menu {
1.318 raeburn 5026: my ($permission,$context,$crstype) = @_;
5027: my $linkcontext = $context;
5028: my $stuterm = lc(&Apache::lonnet::plaintext('st',$crstype));
5029: if (($context eq 'course') && ($crstype eq 'Community')) {
5030: $linkcontext = lc($crstype);
5031: $stuterm = 'Members';
5032: }
1.208 raeburn 5033: my %links = (
1.298 droeschl 5034: domain => {
5035: upload => 'Upload a File of Users',
5036: singleuser => 'Add/Modify a User',
5037: listusers => 'Manage Users',
5038: },
5039: author => {
5040: upload => 'Upload a File of Co-authors',
5041: singleuser => 'Add/Modify a Co-author',
5042: listusers => 'Manage Co-authors',
5043: },
5044: course => {
5045: upload => 'Upload a File of Course Users',
5046: singleuser => 'Add/Modify a Course User',
1.354 www 5047: listusers => 'List and Modify Multiple Course Users',
1.298 droeschl 5048: },
1.318 raeburn 5049: community => {
5050: upload => 'Upload a File of Community Users',
5051: singleuser => 'Add/Modify a Community User',
1.354 www 5052: listusers => 'List and Modify Multiple Community Users',
1.318 raeburn 5053: },
5054: );
5055: my %linktitles = (
5056: domain => {
5057: singleuser => 'Add a user to the domain, and/or a course or community in the domain.',
5058: listusers => 'Show and manage users in this domain.',
5059: },
5060: author => {
5061: singleuser => 'Add a user with a co- or assistant author role.',
5062: listusers => 'Show and manage co- or assistant authors.',
5063: },
5064: course => {
5065: singleuser => 'Add a user with a certain role to this course.',
5066: listusers => 'Show and manage users in this course.',
5067: },
5068: community => {
5069: singleuser => 'Add a user with a certain role to this community.',
5070: listusers => 'Show and manage users in this community.',
5071: },
1.298 droeschl 5072: );
5073: my @menu = ( {categorytitle => 'Single Users',
5074: items =>
5075: [
5076: {
1.318 raeburn 5077: linktext => $links{$linkcontext}{'singleuser'},
1.298 droeschl 5078: icon => 'edit-redo.png',
5079: #help => 'Course_Change_Privileges',
5080: url => '/adm/createuser?action=singleuser',
5081: permission => $permission->{'cusr'},
1.318 raeburn 5082: linktitle => $linktitles{$linkcontext}{'singleuser'},
1.298 droeschl 5083: },
5084: ]},
5085:
5086: {categorytitle => 'Multiple Users',
5087: items =>
5088: [
5089: {
1.318 raeburn 5090: linktext => $links{$linkcontext}{'upload'},
1.340 wenzelju 5091: icon => 'uplusr.png',
1.298 droeschl 5092: #help => 'Course_Create_Class_List',
5093: url => '/adm/createuser?action=upload',
5094: permission => $permission->{'cusr'},
5095: linktitle => 'Upload a CSV or a text file containing users.',
5096: },
5097: {
1.318 raeburn 5098: linktext => $links{$linkcontext}{'listusers'},
1.340 wenzelju 5099: icon => 'mngcu.png',
1.298 droeschl 5100: #help => 'Course_View_Class_List',
5101: url => '/adm/createuser?action=listusers',
5102: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.318 raeburn 5103: linktitle => $linktitles{$linkcontext}{'listusers'},
1.298 droeschl 5104: },
5105:
5106: ]},
5107:
5108: {categorytitle => 'Administration',
5109: items => [ ]},
5110: );
5111:
1.265 mielkec 5112: if ($context eq 'domain'){
1.298 droeschl 5113:
5114: push(@{ $menu[2]->{items} }, #Category: Administration
5115: {
5116: linktext => 'Custom Roles',
5117: icon => 'emblem-photos.png',
5118: #help => 'Course_Editing_Custom_Roles',
5119: url => '/adm/createuser?action=custom',
5120: permission => $permission->{'custom'},
5121: linktitle => 'Configure a custom role.',
5122: },
1.362 raeburn 5123: {
5124: linktext => 'Authoring Space Requests',
5125: icon => 'selfenrl-queue.png',
5126: #help => 'Domain_Role_Approvals',
5127: url => '/adm/createuser?action=processauthorreq',
5128: permission => $permission->{'cusr'},
5129: linktitle => 'Approve or reject author role requests',
5130: },
1.363 raeburn 5131: {
5132: linktext => 'Change Log',
5133: icon => 'document-properties.png',
5134: #help => 'Course_User_Logs',
5135: url => '/adm/createuser?action=changelogs',
5136: permission => $permission->{'cusr'},
5137: linktitle => 'View change log.',
5138: },
1.298 droeschl 5139: );
5140:
1.265 mielkec 5141: }elsif ($context eq 'course'){
1.298 droeschl 5142: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity();
1.318 raeburn 5143:
5144: my %linktext = (
5145: 'Course' => {
5146: single => 'Add/Modify a Student',
5147: drop => 'Drop Students',
5148: groups => 'Course Groups',
5149: },
5150: 'Community' => {
5151: single => 'Add/Modify a Member',
5152: drop => 'Drop Members',
5153: groups => 'Community Groups',
5154: },
5155: );
5156:
5157: my %linktitle = (
5158: 'Course' => {
5159: single => 'Add a user with the role of student to this course',
5160: drop => 'Remove a student from this course.',
5161: groups => 'Manage course groups',
5162: },
5163: 'Community' => {
5164: single => 'Add a user with the role of member to this community',
5165: drop => 'Remove a member from this community.',
5166: groups => 'Manage community groups',
5167: },
5168: );
5169:
1.298 droeschl 5170: push(@{ $menu[0]->{items} }, #Category: Single Users
5171: {
1.318 raeburn 5172: linktext => $linktext{$crstype}{'single'},
1.298 droeschl 5173: #help => 'Course_Add_Student',
5174: icon => 'list-add.png',
5175: url => '/adm/createuser?action=singlestudent',
5176: permission => $permission->{'cusr'},
1.318 raeburn 5177: linktitle => $linktitle{$crstype}{'single'},
1.298 droeschl 5178: },
5179: );
5180:
5181: push(@{ $menu[1]->{items} }, #Category: Multiple Users
5182: {
1.318 raeburn 5183: linktext => $linktext{$crstype}{'drop'},
1.298 droeschl 5184: icon => 'edit-undo.png',
5185: #help => 'Course_Drop_Student',
5186: url => '/adm/createuser?action=drop',
5187: permission => $permission->{'cusr'},
1.318 raeburn 5188: linktitle => $linktitle{$crstype}{'drop'},
1.298 droeschl 5189: },
5190: );
5191: push(@{ $menu[2]->{items} }, #Category: Administration
5192: {
5193: linktext => 'Custom Roles',
5194: icon => 'emblem-photos.png',
5195: #help => 'Course_Editing_Custom_Roles',
5196: url => '/adm/createuser?action=custom',
5197: permission => $permission->{'custom'},
5198: linktitle => 'Configure a custom role.',
5199: },
5200: {
1.318 raeburn 5201: linktext => $linktext{$crstype}{'groups'},
1.333 wenzelju 5202: icon => 'grps.png',
1.298 droeschl 5203: #help => 'Course_Manage_Group',
5204: url => '/adm/coursegroups?refpage=cusr',
5205: permission => $permission->{'grp_manage'},
1.318 raeburn 5206: linktitle => $linktitle{$crstype}{'groups'},
1.298 droeschl 5207: },
5208: {
1.328 wenzelju 5209: linktext => 'Change Log',
1.298 droeschl 5210: icon => 'document-properties.png',
5211: #help => 'Course_User_Logs',
5212: url => '/adm/createuser?action=changelogs',
5213: permission => $permission->{'cusr'},
5214: linktitle => 'View change log.',
5215: },
5216: );
1.277 raeburn 5217: if ($env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'}) {
1.298 droeschl 5218: push(@{ $menu[2]->{items} },
5219: {
5220: linktext => 'Enrollment Requests',
5221: icon => 'selfenrl-queue.png',
5222: #help => 'Course_Approve_Selfenroll',
5223: url => '/adm/createuser?action=selfenrollqueue',
5224: permission => $permission->{'cusr'},
5225: linktitle =>'Approve or reject enrollment requests.',
5226: },
5227: );
1.277 raeburn 5228: }
1.298 droeschl 5229:
1.265 mielkec 5230: if (!exists($permission->{'cusr_section'})){
1.320 raeburn 5231: if ($crstype ne 'Community') {
5232: push(@{ $menu[2]->{items} },
5233: {
5234: linktext => 'Automated Enrollment',
5235: icon => 'roles.png',
5236: #help => 'Course_Automated_Enrollment',
5237: permission => (&Apache::lonnet::auto_run($cnum,$cdom)
5238: && $permission->{'cusr'}),
5239: url => '/adm/populate',
5240: linktitle => 'Automated enrollment manager.',
5241: }
5242: );
5243: }
5244: push(@{ $menu[2]->{items} },
1.298 droeschl 5245: {
5246: linktext => 'User Self-Enrollment',
1.342 wenzelju 5247: icon => 'self_enroll.png',
1.298 droeschl 5248: #help => 'Course_Self_Enrollment',
5249: url => '/adm/createuser?action=selfenroll',
5250: permission => $permission->{'cusr'},
1.317 bisitz 5251: linktitle => 'Configure user self-enrollment.',
1.298 droeschl 5252: },
5253: );
5254: }
1.363 raeburn 5255: } elsif ($context eq 'author') {
1.370 raeburn 5256: push(@{ $menu[2]->{items} }, #Category: Administration
1.363 raeburn 5257: {
5258: linktext => 'Change Log',
5259: icon => 'document-properties.png',
5260: #help => 'Course_User_Logs',
5261: url => '/adm/createuser?action=changelogs',
5262: permission => $permission->{'cusr'},
5263: linktitle => 'View change log.',
5264: },
1.370 raeburn 5265: );
1.363 raeburn 5266: }
5267: return Apache::lonhtmlcommon::generate_menu(@menu);
1.250 raeburn 5268: # { text => 'View Log-in History',
5269: # help => 'Course_User_Logins',
5270: # action => 'logins',
5271: # permission => $permission->{'cusr'},
5272: # });
1.190 raeburn 5273: }
5274:
1.189 albertel 5275: sub restore_prev_selections {
5276: my %saveable_parameters = ('srchby' => 'scalar',
5277: 'srchin' => 'scalar',
5278: 'srchtype' => 'scalar',
5279: );
5280: &Apache::loncommon::store_settings('user','user_picker',
5281: \%saveable_parameters);
5282: &Apache::loncommon::restore_settings('user','user_picker',
5283: \%saveable_parameters);
5284: }
5285:
1.237 raeburn 5286: sub print_selfenroll_menu {
5287: my ($r,$context,$permission) = @_;
1.322 raeburn 5288: my $crstype = &Apache::loncommon::course_type();
1.237 raeburn 5289: my $formname = 'enrollstudent';
5290: my $nolink = 1;
5291: my ($row,$lt) = &get_selfenroll_titles();
5292: my $groupslist = &Apache::lonuserutils::get_groupslist();
5293: my $setsec_js =
5294: &Apache::lonuserutils::setsections_javascript($formname,$groupslist);
1.249 raeburn 5295: my %alerts = &Apache::lonlocal::texthash(
5296: acto => 'Activation of self-enrollment was selected for the following domain(s)',
5297: butn => 'but no user types have been checked.',
5298: wilf => "Please uncheck 'activate' or check at least one type.",
5299: );
5300: my $selfenroll_js = <<"ENDSCRIPT";
5301: function update_types(caller,num) {
5302: var delidx = getIndexByName('selfenroll_delete');
5303: var actidx = getIndexByName('selfenroll_activate');
5304: if (caller == 'selfenroll_all') {
5305: var selall;
5306: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5307: if (document.$formname.selfenroll_all[i].checked) {
5308: selall = document.$formname.selfenroll_all[i].value;
5309: }
5310: }
5311: if (selall == 1) {
5312: if (delidx != -1) {
5313: if (document.$formname.selfenroll_delete.length) {
5314: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
5315: document.$formname.selfenroll_delete[j].checked = true;
5316: }
5317: } else {
5318: document.$formname.elements[delidx].checked = true;
5319: }
5320: }
5321: if (actidx != -1) {
5322: if (document.$formname.selfenroll_activate.length) {
5323: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5324: document.$formname.selfenroll_activate[j].checked = false;
5325: }
5326: } else {
5327: document.$formname.elements[actidx].checked = false;
5328: }
5329: }
5330: document.$formname.selfenroll_newdom.selectedIndex = 0;
5331: }
5332: }
5333: if (caller == 'selfenroll_activate') {
5334: if (document.$formname.selfenroll_activate.length) {
5335: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5336: if (document.$formname.selfenroll_activate[j].value == num) {
5337: if (document.$formname.selfenroll_activate[j].checked) {
5338: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5339: if (document.$formname.selfenroll_all[i].value == '1') {
5340: document.$formname.selfenroll_all[i].checked = false;
5341: }
5342: if (document.$formname.selfenroll_all[i].value == '0') {
5343: document.$formname.selfenroll_all[i].checked = true;
5344: }
5345: }
5346: }
5347: }
5348: }
5349: } else {
5350: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5351: if (document.$formname.selfenroll_all[i].value == '1') {
5352: document.$formname.selfenroll_all[i].checked = false;
5353: }
5354: if (document.$formname.selfenroll_all[i].value == '0') {
5355: document.$formname.selfenroll_all[i].checked = true;
5356: }
5357: }
5358: }
5359: }
5360: if (caller == 'selfenroll_delete') {
5361: if (document.$formname.selfenroll_delete.length) {
5362: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
5363: if (document.$formname.selfenroll_delete[j].value == num) {
5364: if (document.$formname.selfenroll_delete[j].checked) {
5365: var delindex = getIndexByName('selfenroll_types_'+num);
5366: if (delindex != -1) {
5367: if (document.$formname.elements[delindex].length) {
5368: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
5369: document.$formname.elements[delindex][k].checked = false;
5370: }
5371: } else {
5372: document.$formname.elements[delindex].checked = false;
5373: }
5374: }
5375: }
5376: }
5377: }
5378: } else {
5379: if (document.$formname.selfenroll_delete.checked) {
5380: var delindex = getIndexByName('selfenroll_types_'+num);
5381: if (delindex != -1) {
5382: if (document.$formname.elements[delindex].length) {
5383: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
5384: document.$formname.elements[delindex][k].checked = false;
5385: }
5386: } else {
5387: document.$formname.elements[delindex].checked = false;
5388: }
5389: }
5390: }
5391: }
5392: }
5393: return;
5394: }
5395:
5396: function validate_types(form) {
5397: var needaction = new Array();
5398: var countfail = 0;
5399: var actidx = getIndexByName('selfenroll_activate');
5400: if (actidx != -1) {
5401: if (document.$formname.selfenroll_activate.length) {
5402: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5403: var num = document.$formname.selfenroll_activate[j].value;
5404: if (document.$formname.selfenroll_activate[j].checked) {
5405: countfail = check_types(num,countfail,needaction)
5406: }
5407: }
5408: } else {
5409: if (document.$formname.selfenroll_activate.checked) {
5410: var num = document.enrollstudent.selfenroll_activate.value;
5411: countfail = check_types(num,countfail,needaction)
5412: }
5413: }
5414: }
5415: if (countfail > 0) {
5416: var msg = "$alerts{'acto'}\\n";
5417: var loopend = needaction.length -1;
5418: if (loopend > 0) {
5419: for (var m=0; m<loopend; m++) {
5420: msg += needaction[m]+", ";
5421: }
5422: }
5423: msg += needaction[loopend]+"\\n$alerts{'butn'}\\n$alerts{'wilf'}";
5424: alert(msg);
5425: return;
5426: }
5427: setSections(form);
5428: }
5429:
5430: function check_types(num,countfail,needaction) {
5431: var typeidx = getIndexByName('selfenroll_types_'+num);
5432: var count = 0;
5433: if (typeidx != -1) {
5434: if (document.$formname.elements[typeidx].length) {
5435: for (var k=0; k<document.$formname.elements[typeidx].length; k++) {
5436: if (document.$formname.elements[typeidx][k].checked) {
5437: count ++;
5438: }
5439: }
5440: } else {
5441: if (document.$formname.elements[typeidx].checked) {
5442: count ++;
5443: }
5444: }
5445: if (count == 0) {
5446: var domidx = getIndexByName('selfenroll_dom_'+num);
5447: if (domidx != -1) {
5448: var domname = document.$formname.elements[domidx].value;
5449: needaction[countfail] = domname;
5450: countfail ++;
5451: }
5452: }
5453: }
5454: return countfail;
5455: }
5456:
5457: function getIndexByName(item) {
5458: for (var i=0;i<document.$formname.elements.length;i++) {
5459: if (document.$formname.elements[i].name == item) {
5460: return i;
5461: }
5462: }
5463: return -1;
5464: }
5465: ENDSCRIPT
1.256 raeburn 5466: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
5467: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
5468:
1.237 raeburn 5469: my $output = '<script type="text/javascript">'."\n".
1.301 bisitz 5470: '// <![CDATA['."\n".
1.249 raeburn 5471: $setsec_js."\n".$selfenroll_js."\n".
1.301 bisitz 5472: '// ]]>'."\n".
1.237 raeburn 5473: '</script>'."\n".
1.256 raeburn 5474: '<h3>'.$lt->{'selfenroll'}.'</h3>'."\n";
5475: my ($visible,$cansetvis,$vismsgs,$visactions) = &visible_in_cat($cdom,$cnum);
5476: if (ref($visactions) eq 'HASH') {
5477: if ($visible) {
1.283 bisitz 5478: $output .= '<p class="LC_info">'.$visactions->{'vis'}.'</p>';
1.256 raeburn 5479: } else {
1.283 bisitz 5480: $output .= '<p class="LC_warning">'.$visactions->{'miss'}.'</p>'
5481: .$visactions->{'yous'}.
1.256 raeburn 5482: '<p>'.$visactions->{'gen'}.'<br />'.$visactions->{'coca'};
5483: if (ref($vismsgs) eq 'ARRAY') {
5484: $output .= '<br />'.$visactions->{'make'}.'<ul>';
5485: foreach my $item (@{$vismsgs}) {
5486: $output .= '<li>'.$visactions->{$item}.'</li>';
5487: }
5488: $output .= '</ul>';
5489: }
5490: $output .= '</p>';
5491: }
5492: }
5493: $output .= '<form name="'.$formname.'" method="post" action="/adm/createuser">'."\n".
5494: &Apache::lonhtmlcommon::start_pick_box();
1.237 raeburn 5495: if (ref($row) eq 'ARRAY') {
5496: foreach my $item (@{$row}) {
5497: my $title = $item;
5498: if (ref($lt) eq 'HASH') {
5499: $title = $lt->{$item};
5500: }
1.297 bisitz 5501: $output .= &Apache::lonhtmlcommon::row_title($title);
1.237 raeburn 5502: if ($item eq 'types') {
5503: my $curr_types = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_types'};
1.241 raeburn 5504: my $showdomdesc = 1;
5505: my $includeempty = 1;
5506: my $num = 0;
5507: $output .= &Apache::loncommon::start_data_table().
5508: &Apache::loncommon::start_data_table_row()
5509: .'<td colspan="2"><span class="LC_nobreak"><label>'
5510: .&mt('Any user in any domain:')
5511: .' <input type="radio" name="selfenroll_all" value="1" ';
5512: if ($curr_types eq '*') {
5513: $output .= ' checked="checked" ';
5514: }
1.249 raeburn 5515: $output .= 'onchange="javascript:update_types('.
5516: "'selfenroll_all'".');" />'.&mt('Yes').'</label>'.
5517: ' <input type="radio" name="selfenroll_all" value="0" ';
1.241 raeburn 5518: if ($curr_types ne '*') {
5519: $output .= ' checked="checked" ';
5520: }
1.249 raeburn 5521: $output .= ' onchange="javascript:update_types('.
5522: "'selfenroll_all'".');"/>'.&mt('No').'</label></td>'.
5523: &Apache::loncommon::end_data_table_row().
5524: &Apache::loncommon::end_data_table().
5525: &mt('Or').'<br />'.
5526: &Apache::loncommon::start_data_table();
1.241 raeburn 5527: my %currdoms;
1.249 raeburn 5528: if ($curr_types eq '') {
1.241 raeburn 5529: $output .= &new_selfenroll_dom_row($cdom,'0');
5530: } elsif ($curr_types ne '*') {
5531: my @entries = split(/;/,$curr_types);
5532: if (@entries > 0) {
5533: foreach my $entry (@entries) {
5534: my ($currdom,$typestr) = split(/:/,$entry);
5535: $currdoms{$currdom} = 1;
5536: my $domdesc = &Apache::lonnet::domain($currdom);
1.249 raeburn 5537: my @currinsttypes = split(',',$typestr);
1.241 raeburn 5538: $output .= &Apache::loncommon::start_data_table_row()
5539: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').'<b>'
5540: .' '.$domdesc.' ('.$currdom.')'
5541: .'</b><input type="hidden" name="selfenroll_dom_'.$num
5542: .'" value="'.$currdom.'" /></span><br />'
5543: .'<span class="LC_nobreak"><label><input type="checkbox" '
1.249 raeburn 5544: .'name="selfenroll_delete" value="'.$num.'" onchange="javascript:update_types('."'selfenroll_delete','$num'".');" />'
1.241 raeburn 5545: .&mt('Delete').'</label></span></td>';
1.249 raeburn 5546: $output .= '<td valign="top"> '.&mt('User types:').'<br />'
1.241 raeburn 5547: .&selfenroll_inst_types($num,$currdom,\@currinsttypes).'</td>'
5548: .&Apache::loncommon::end_data_table_row();
5549: $num ++;
5550: }
5551: }
5552: }
1.249 raeburn 5553: my $add_domtitle = &mt('Users in additional domain:');
1.241 raeburn 5554: if ($curr_types eq '*') {
1.249 raeburn 5555: $add_domtitle = &mt('Users in specific domain:');
1.241 raeburn 5556: } elsif ($curr_types eq '') {
1.249 raeburn 5557: $add_domtitle = &mt('Users in other domain:');
1.241 raeburn 5558: }
5559: $output .= &Apache::loncommon::start_data_table_row()
5560: .'<td colspan="2"><span class="LC_nobreak">'.$add_domtitle.'</span><br />'
5561: .&Apache::loncommon::select_dom_form('','selfenroll_newdom',
5562: $includeempty,$showdomdesc)
5563: .'<input type="hidden" name="selfenroll_types_total" value="'.$num.'" />'
5564: .'</td>'.&Apache::loncommon::end_data_table_row()
5565: .&Apache::loncommon::end_data_table();
1.237 raeburn 5566: } elsif ($item eq 'registered') {
5567: my ($regon,$regoff);
5568: if ($env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_registered'}) {
5569: $regon = ' checked="checked" ';
5570: $regoff = ' ';
5571: } else {
5572: $regon = ' ';
5573: $regoff = ' checked="checked" ';
5574: }
5575: $output .= '<label>'.
1.245 raeburn 5576: '<input type="radio" name="selfenroll_registered" value="1"'.$regon.'/>'.
1.244 bisitz 5577: &mt('Yes').'</label> <label>'.
1.245 raeburn 5578: '<input type="radio" name="selfenroll_registered" value="0"'.$regoff.'/>'.
1.244 bisitz 5579: &mt('No').'</label>';
1.237 raeburn 5580: } elsif ($item eq 'enroll_dates') {
5581: my $starttime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_start_date'};
5582: my $endtime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_end_date'};
5583: if ($starttime eq '') {
5584: $starttime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_start_date'};
5585: }
5586: if ($endtime eq '') {
5587: $endtime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_end_date'};
5588: }
5589: my $startform =
5590: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_date',$starttime,
5591: undef,undef,undef,undef,undef,undef,undef,$nolink);
5592: my $endform =
5593: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_date',$endtime,
5594: undef,undef,undef,undef,undef,undef,undef,$nolink);
5595: $output .= &selfenroll_date_forms($startform,$endform);
5596: } elsif ($item eq 'access_dates') {
5597: my $starttime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_start_access'};
5598: my $endtime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_end_access'};
5599: if ($starttime eq '') {
5600: $starttime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_start_date'};
5601: }
5602: if ($endtime eq '') {
5603: $endtime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_end_date'};
5604: }
5605: my $startform =
5606: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_access',$starttime,
5607: undef,undef,undef,undef,undef,undef,undef,$nolink);
5608: my $endform =
5609: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_access',$endtime,
5610: undef,undef,undef,undef,undef,undef,undef,$nolink);
5611: $output .= &selfenroll_date_forms($startform,$endform);
5612: } elsif ($item eq 'section') {
5613: my $currsec = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_section'};
5614: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
5615: my $newsecval;
5616: if ($currsec ne 'none' && $currsec ne '') {
5617: if (!defined($sections_count{$currsec})) {
5618: $newsecval = $currsec;
5619: }
5620: }
5621: my $sections_select =
5622: &Apache::lonuserutils::course_sections(\%sections_count,'st',$currsec);
5623: $output .= '<table class="LC_createuser">'."\n".
5624: '<tr class="LC_section_row">'."\n".
5625: '<td align="center">'.&mt('Existing sections')."\n".
5626: '<br />'.$sections_select.'</td><td align="center">'.
5627: &mt('New section').'<br />'."\n".
5628: '<input type="text" name="newsec" size="15" value="'.$newsecval.'" />'."\n".
5629: '<input type="hidden" name="sections" value="" />'."\n".
5630: '<input type="hidden" name="state" value="done" />'."\n".
5631: '</td></tr></table>'."\n";
1.276 raeburn 5632: } elsif ($item eq 'approval') {
5633: my ($appon,$appoff);
5634: my $cid = $env{'request.course.id'};
5635: my $currnotified = $env{'course.'.$cid.'.internal.selfenroll_notifylist'};
5636: if ($env{'course.'.$cid.'.internal.selfenroll_approval'}) {
5637: $appon = ' checked="checked" ';
5638: $appoff = ' ';
5639: } else {
5640: $appon = ' ';
5641: $appoff = ' checked="checked" ';
5642: }
5643: $output .= '<label>'.
5644: '<input type="radio" name="selfenroll_approval" value="1"'.$appon.'/>'.
5645: &mt('Yes').'</label> <label>'.
5646: '<input type="radio" name="selfenroll_approval" value="0"'.$appoff.'/>'.
5647: &mt('No').'</label>';
5648: my %advhash = &Apache::lonnet::get_course_adv_roles($cid,1);
5649: my (@ccs,%notified);
1.322 raeburn 5650: my $ccrole = 'cc';
5651: if ($crstype eq 'Community') {
5652: $ccrole = 'co';
5653: }
5654: if ($advhash{$ccrole}) {
5655: @ccs = split(/,/,$advhash{$ccrole});
1.276 raeburn 5656: }
5657: if ($currnotified) {
5658: foreach my $current (split(/,/,$currnotified)) {
5659: $notified{$current} = 1;
5660: if (!grep(/^\Q$current\E$/,@ccs)) {
5661: push(@ccs,$current);
5662: }
5663: }
5664: }
5665: if (@ccs) {
1.277 raeburn 5666: $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 5667: &Apache::loncommon::start_data_table_row();
5668: my $count = 0;
5669: my $numcols = 4;
5670: foreach my $cc (sort(@ccs)) {
5671: my $notifyon;
5672: my ($ccuname,$ccudom) = split(/:/,$cc);
5673: if ($notified{$cc}) {
5674: $notifyon = ' checked="checked" ';
5675: }
5676: if ($count && !$count%$numcols) {
5677: $output .= &Apache::loncommon::end_data_table_row().
5678: &Apache::loncommon::start_data_table_row()
5679: }
5680: $output .= '<td><span class="LC_nobreak"><label>'.
5681: '<input type="checkbox" name="selfenroll_notify"'.$notifyon.' value="'.$cc.'" />'.
5682: &Apache::loncommon::plainname($ccuname,$ccudom).
5683: '</label></span></td>';
1.343 raeburn 5684: $count ++;
1.276 raeburn 5685: }
5686: my $rem = $count%$numcols;
5687: if ($rem) {
5688: my $emptycols = $numcols - $rem;
5689: for (my $i=0; $i<$emptycols; $i++) {
5690: $output .= '<td> </td>';
5691: }
5692: }
5693: $output .= &Apache::loncommon::end_data_table_row().
5694: &Apache::loncommon::end_data_table();
5695: }
5696: } elsif ($item eq 'limit') {
5697: my ($crslimit,$selflimit,$nolimit);
5698: my $cid = $env{'request.course.id'};
5699: my $currlim = $env{'course.'.$cid.'.internal.selfenroll_limit'};
5700: my $currcap = $env{'course.'.$cid.'.internal.selfenroll_cap'};
1.343 raeburn 5701: $nolimit = ' checked="checked" ';
1.276 raeburn 5702: if ($currlim eq 'allstudents') {
5703: $crslimit = ' checked="checked" ';
5704: $selflimit = ' ';
5705: $nolimit = ' ';
5706: } elsif ($currlim eq 'selfenrolled') {
5707: $crslimit = ' ';
5708: $selflimit = ' checked="checked" ';
5709: $nolimit = ' ';
5710: } else {
5711: $crslimit = ' ';
5712: $selflimit = ' ';
5713: }
5714: $output .= '<table><tr><td><label>'.
1.278 raeburn 5715: '<input type="radio" name="selfenroll_limit" value="none"'.$nolimit.'/>'.
1.276 raeburn 5716: &mt('No limit').'</label></td><td><label>'.
5717: '<input type="radio" name="selfenroll_limit" value="allstudents"'.$crslimit.'/>'.
5718: &mt('Limit by total students').'</label></td><td><label>'.
5719: '<input type="radio" name="selfenroll_limit" value="selfenrolled"'.$selflimit.'/>'.
5720: &mt('Limit by total self-enrolled students').
5721: '</td></tr><tr>'.
5722: '<td> </td><td colspan="2"><span class="LC_nobreak">'.
5723: (' 'x3).&mt('Maximum number allowed: ').
5724: '<input type="text" name="selfenroll_cap" size = "5" value="'.$currcap.'" /></td></tr></table>';
1.237 raeburn 5725: }
5726: $output .= &Apache::lonhtmlcommon::row_closure(1);
5727: }
5728: }
5729: $output .= &Apache::lonhtmlcommon::end_pick_box().
1.241 raeburn 5730: '<br /><input type="button" name="selfenrollconf" value="'
1.282 schafran 5731: .&mt('Save').'" onclick="validate_types(this.form);" />'
1.241 raeburn 5732: .'<input type="hidden" name="action" value="selfenroll" /></form>';
1.237 raeburn 5733: $r->print($output);
5734: return;
5735: }
5736:
1.256 raeburn 5737: sub visible_in_cat {
5738: my ($cdom,$cnum) = @_;
5739: my %domconf = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
5740: my ($cathash,%settable,@vismsgs,$cansetvis);
5741: my %visactions = &Apache::lonlocal::texthash(
1.316 bisitz 5742: vis => 'Your course/community currently appears in the Course/Community Catalog for this domain.',
1.256 raeburn 5743: 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 5744: miss => 'Your course/community does not currently appear in the Course/Community Catalog for this domain.',
1.256 raeburn 5745: yous => 'You should remedy this if you plan to allow self-enrollment, otherwise students will have difficulty finding your course.',
5746: 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 5747: make => 'Make any changes to self-enrollment settings below, click "Save", then take action to include the course in the Catalog:',
1.256 raeburn 5748: take => 'Take the following action to ensure the course appears in the Catalog:',
5749: dc_unhide => 'Ask a domain coordinator to change the "Exclude from course catalog" setting.',
5750: dc_addinst => 'Ask a domain coordinator to enable display the catalog of "Official courses (with institutional codes)".',
5751: dc_instcode => 'Ask a domain coordinator to assign an institutional code (if this is an official course).',
5752: dc_catalog => 'Ask a domain coordinator to enable or create at least one course category in the domain.',
5753: dc_categories => 'Ask a domain coordinator to create a hierarchy of categories and sub categories for courses in the domain.',
5754: 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',
5755: dc_addcat => 'Ask a domain coordinator to assign a category to the course.',
5756: );
1.347 raeburn 5757: $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>"');
5758: $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>"');
5759: $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 5760: if (ref($domconf{'coursecategories'}) eq 'HASH') {
5761: if ($domconf{'coursecategories'}{'togglecats'} eq 'crs') {
5762: $settable{'togglecats'} = 1;
5763: }
5764: if ($domconf{'coursecategories'}{'categorize'} eq 'crs') {
5765: $settable{'categorize'} = 1;
5766: }
5767: $cathash = $domconf{'coursecategories'}{'cats'};
5768: }
1.260 raeburn 5769: if ($settable{'togglecats'} && $settable{'categorize'}) {
1.256 raeburn 5770: $cansetvis = &mt('You are able to both assign a course category and choose to exclude this course from the catalog.');
5771: } elsif ($settable{'togglecats'}) {
5772: $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 5773: } elsif ($settable{'categorize'}) {
1.256 raeburn 5774: $cansetvis = &mt('You may assign a course category, but only a Domain Coordinator may choose to exclude this course from the catalog.');
5775: } else {
5776: $cansetvis = &mt('Only a Domain Coordinator may assign a course category or choose to exclude this course from the catalog.');
5777: }
5778:
5779: my %currsettings =
5780: &Apache::lonnet::get('environment',['hidefromcat','categories','internal.coursecode'],
5781: $cdom,$cnum);
5782: my $visible = 0;
5783: if ($currsettings{'internal.coursecode'} ne '') {
5784: if (ref($domconf{'coursecategories'}) eq 'HASH') {
5785: $cathash = $domconf{'coursecategories'}{'cats'};
5786: if (ref($cathash) eq 'HASH') {
5787: if ($cathash->{'instcode::0'} eq '') {
5788: push(@vismsgs,'dc_addinst');
5789: } else {
5790: $visible = 1;
5791: }
5792: } else {
5793: $visible = 1;
5794: }
5795: } else {
5796: $visible = 1;
5797: }
5798: } else {
5799: if (ref($cathash) eq 'HASH') {
5800: if ($cathash->{'instcode::0'} ne '') {
5801: push(@vismsgs,'dc_instcode');
5802: }
5803: } else {
5804: push(@vismsgs,'dc_instcode');
5805: }
5806: }
5807: if ($currsettings{'categories'} ne '') {
5808: my $cathash;
5809: if (ref($domconf{'coursecategories'}) eq 'HASH') {
5810: $cathash = $domconf{'coursecategories'}{'cats'};
5811: if (ref($cathash) eq 'HASH') {
5812: if (keys(%{$cathash}) == 0) {
5813: push(@vismsgs,'dc_catalog');
5814: } elsif ((keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} ne '')) {
5815: push(@vismsgs,'dc_categories');
5816: } else {
5817: my @currcategories = split('&',$currsettings{'categories'});
5818: my $matched = 0;
5819: foreach my $cat (@currcategories) {
5820: if ($cathash->{$cat} ne '') {
5821: $visible = 1;
5822: $matched = 1;
5823: last;
5824: }
5825: }
5826: if (!$matched) {
1.260 raeburn 5827: if ($settable{'categorize'}) {
1.256 raeburn 5828: push(@vismsgs,'chgcat');
5829: } else {
5830: push(@vismsgs,'dc_chgcat');
5831: }
5832: }
5833: }
5834: }
5835: }
5836: } else {
5837: if (ref($cathash) eq 'HASH') {
5838: if ((keys(%{$cathash}) > 1) ||
5839: (keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} eq '')) {
1.260 raeburn 5840: if ($settable{'categorize'}) {
1.256 raeburn 5841: push(@vismsgs,'addcat');
5842: } else {
5843: push(@vismsgs,'dc_addcat');
5844: }
5845: }
5846: }
5847: }
5848: if ($currsettings{'hidefromcat'} eq 'yes') {
5849: $visible = 0;
5850: if ($settable{'togglecats'}) {
5851: unshift(@vismsgs,'unhide');
5852: } else {
5853: unshift(@vismsgs,'dc_unhide')
5854: }
5855: }
5856: return ($visible,$cansetvis,\@vismsgs,\%visactions);
5857: }
5858:
1.241 raeburn 5859: sub new_selfenroll_dom_row {
5860: my ($newdom,$num) = @_;
5861: my $domdesc = &Apache::lonnet::domain($newdom);
5862: my $output;
5863: if ($domdesc ne '') {
5864: $output .= &Apache::loncommon::start_data_table_row()
5865: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').' <b>'.$domdesc
5866: .' ('.$newdom.')</b><input type="hidden" name="selfenroll_dom_'.$num
1.249 raeburn 5867: .'" value="'.$newdom.'" /></span><br />'
5868: .'<span class="LC_nobreak"><label><input type="checkbox" '
5869: .'name="selfenroll_activate" value="'.$num.'" '
5870: .'onchange="javascript:update_types('
5871: ."'selfenroll_activate','$num'".');" />'
5872: .&mt('Activate').'</label></span></td>';
1.241 raeburn 5873: my @currinsttypes;
5874: $output .= '<td>'.&mt('User types:').'<br />'
5875: .&selfenroll_inst_types($num,$newdom,\@currinsttypes).'</td>'
5876: .&Apache::loncommon::end_data_table_row();
5877: }
5878: return $output;
5879: }
5880:
5881: sub selfenroll_inst_types {
5882: my ($num,$currdom,$currinsttypes) = @_;
5883: my $output;
5884: my $numinrow = 4;
5885: my $count = 0;
5886: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($currdom);
1.247 raeburn 5887: my $othervalue = 'any';
1.241 raeburn 5888: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
1.251 raeburn 5889: if (keys(%{$usertypes}) > 0) {
1.247 raeburn 5890: $othervalue = 'other';
5891: }
1.241 raeburn 5892: $output .= '<table><tr>';
5893: foreach my $type (@{$types}) {
5894: if (($count > 0) && ($count%$numinrow == 0)) {
5895: $output .= '</tr><tr>';
5896: }
5897: if (defined($usertypes->{$type})) {
1.257 raeburn 5898: my $esc_type = &escape($type);
1.241 raeburn 5899: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.
1.257 raeburn 5900: $esc_type.'" ';
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"';
1.257 raeburn 5905: } elsif (grep(/^\Q$esc_type\E$/,@{$currinsttypes})) {
1.241 raeburn 5906: $output .= 'checked="checked"';
5907: }
1.249 raeburn 5908: } else {
5909: $output .= 'checked="checked"';
1.241 raeburn 5910: }
5911: }
5912: $output .= ' name="selfenroll_types_'.$num.'" />'.$usertypes->{$type}.'</label></span></td>';
5913: }
5914: $count ++;
5915: }
5916: if (($count > 0) && ($count%$numinrow == 0)) {
5917: $output .= '</tr><tr>';
5918: }
1.249 raeburn 5919: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.$othervalue.'"';
1.241 raeburn 5920: if (ref($currinsttypes) eq 'ARRAY') {
5921: if (@{$currinsttypes} > 0) {
1.249 raeburn 5922: if (grep(/^any$/,@{$currinsttypes})) {
5923: $output .= ' checked="checked"';
5924: } elsif ($othervalue eq 'other') {
5925: if (grep(/^\Q$othervalue\E$/,@{$currinsttypes})) {
5926: $output .= ' checked="checked"';
5927: }
1.241 raeburn 5928: }
1.249 raeburn 5929: } else {
5930: $output .= ' checked="checked"';
1.241 raeburn 5931: }
1.249 raeburn 5932: } else {
5933: $output .= ' checked="checked"';
1.241 raeburn 5934: }
5935: $output .= ' name="selfenroll_types_'.$num.'" />'.$othertitle.'</label></span></td></tr></table>';
5936: }
5937: return $output;
5938: }
5939:
1.237 raeburn 5940: sub selfenroll_date_forms {
5941: my ($startform,$endform) = @_;
5942: my $output .= &Apache::lonhtmlcommon::start_pick_box()."\n".
1.244 bisitz 5943: &Apache::lonhtmlcommon::row_title(&mt('Start date'),
1.237 raeburn 5944: 'LC_oddrow_value')."\n".
5945: $startform."\n".
5946: &Apache::lonhtmlcommon::row_closure(1).
1.244 bisitz 5947: &Apache::lonhtmlcommon::row_title(&mt('End date'),
1.237 raeburn 5948: 'LC_oddrow_value')."\n".
5949: $endform."\n".
5950: &Apache::lonhtmlcommon::row_closure(1).
5951: &Apache::lonhtmlcommon::end_pick_box();
5952: return $output;
5953: }
5954:
1.239 raeburn 5955: sub print_userchangelogs_display {
5956: my ($r,$context,$permission) = @_;
1.363 raeburn 5957: my $formname = 'rolelog';
5958: my ($username,$domain,$crstype,%roleslog);
5959: if ($context eq 'domain') {
5960: $domain = $env{'request.role.domain'};
5961: %roleslog=&Apache::lonnet::dump_dom('nohist_rolelog',$domain);
5962: } else {
5963: if ($context eq 'course') {
5964: $domain = $env{'course.'.$env{'request.course.id'}.'.domain'};
5965: $username = $env{'course.'.$env{'request.course.id'}.'.num'};
5966: $crstype = &Apache::loncommon::course_type();
5967: my %saveable_parameters = ('show' => 'scalar',);
5968: &Apache::loncommon::store_course_settings('roles_log',
5969: \%saveable_parameters);
5970: &Apache::loncommon::restore_course_settings('roles_log',
5971: \%saveable_parameters);
5972: } elsif ($context eq 'author') {
5973: $domain = $env{'user.domain'};
5974: if ($env{'request.role'} =~ m{^au\./\Q$domain\E/$}) {
5975: $username = $env{'user.name'};
5976: } else {
5977: undef($domain);
5978: }
5979: }
5980: if ($domain ne '' && $username ne '') {
5981: %roleslog=&Apache::lonnet::dump('nohist_rolelog',$domain,$username);
5982: }
5983: }
1.239 raeburn 5984: if ((keys(%roleslog))[0]=~/^error\:/) { undef(%roleslog); }
5985:
5986: # set defaults
5987: my $now = time();
5988: my $defstart = $now - (7*24*3600); #7 days ago
5989: my %defaults = (
5990: page => '1',
5991: show => '10',
5992: role => 'any',
5993: chgcontext => 'any',
5994: rolelog_start_date => $defstart,
5995: rolelog_end_date => $now,
5996: );
5997: my $more_records = 0;
5998:
5999: # set current
6000: my %curr;
6001: foreach my $item ('show','page','role','chgcontext') {
6002: $curr{$item} = $env{'form.'.$item};
6003: }
6004: my ($startdate,$enddate) =
6005: &Apache::lonuserutils::get_dates_from_form('rolelog_start_date','rolelog_end_date');
6006: $curr{'rolelog_start_date'} = $startdate;
6007: $curr{'rolelog_end_date'} = $enddate;
6008: foreach my $key (keys(%defaults)) {
6009: if ($curr{$key} eq '') {
6010: $curr{$key} = $defaults{$key};
6011: }
6012: }
1.248 raeburn 6013: my (%whodunit,%changed,$version);
6014: ($version) = ($r->dir_config('lonVersion') =~ /^([\d\.]+)\-/);
1.239 raeburn 6015: my ($minshown,$maxshown);
1.255 raeburn 6016: $minshown = 1;
1.239 raeburn 6017: my $count = 0;
6018: if ($curr{'show'} ne &mt('all')) {
6019: $maxshown = $curr{'page'} * $curr{'show'};
6020: if ($curr{'page'} > 1) {
6021: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
6022: }
6023: }
1.301 bisitz 6024:
1.327 raeburn 6025: # Form Header
6026: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
1.363 raeburn 6027: &role_display_filter($context,$formname,$domain,$username,\%curr,
6028: $version,$crstype));
1.327 raeburn 6029:
6030: # Create navigation
6031: my ($nav_script,$nav_links) = &userlogdisplay_nav($formname,\%curr,$more_records);
6032: my $showntableheader = 0;
6033:
6034: # Table Header
6035: my $tableheader =
6036: &Apache::loncommon::start_data_table_header_row()
6037: .'<th> </th>'
6038: .'<th>'.&mt('When').'</th>'
6039: .'<th>'.&mt('Who made the change').'</th>'
6040: .'<th>'.&mt('Changed User').'</th>'
1.363 raeburn 6041: .'<th>'.&mt('Role').'</th>';
6042:
6043: if ($context eq 'course') {
6044: $tableheader .= '<th>'.&mt('Section').'</th>';
6045: }
6046: $tableheader .=
6047: '<th>'.&mt('Context').'</th>'
1.327 raeburn 6048: .'<th>'.&mt('Start').'</th>'
6049: .'<th>'.&mt('End').'</th>'
6050: .&Apache::loncommon::end_data_table_header_row();
6051:
6052: # Display user change log data
1.239 raeburn 6053: foreach my $id (sort { $roleslog{$b}{'exe_time'}<=>$roleslog{$a}{'exe_time'} } (keys(%roleslog))) {
6054: next if (($roleslog{$id}{'exe_time'} < $curr{'rolelog_start_date'}) ||
6055: ($roleslog{$id}{'exe_time'} > $curr{'rolelog_end_date'}));
6056: if ($curr{'show'} ne &mt('all')) {
6057: if ($count >= $curr{'page'} * $curr{'show'}) {
6058: $more_records = 1;
6059: last;
6060: }
6061: }
6062: if ($curr{'role'} ne 'any') {
6063: next if ($roleslog{$id}{'logentry'}{'role'} ne $curr{'role'});
6064: }
6065: if ($curr{'chgcontext'} ne 'any') {
6066: if ($curr{'chgcontext'} eq 'selfenroll') {
6067: next if (!$roleslog{$id}{'logentry'}{'selfenroll'});
6068: } else {
6069: next if ($roleslog{$id}{'logentry'}{'context'} ne $curr{'chgcontext'});
6070: }
6071: }
6072: $count ++;
6073: next if ($count < $minshown);
1.327 raeburn 6074: unless ($showntableheader) {
6075: $r->print($nav_script
6076: .$nav_links
6077: .&Apache::loncommon::start_data_table()
6078: .$tableheader);
6079: $r->rflush();
6080: $showntableheader = 1;
6081: }
1.239 raeburn 6082: if ($whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} eq '') {
6083: $whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} =
6084: &Apache::loncommon::plainname($roleslog{$id}{'exe_uname'},$roleslog{$id}{'exe_udom'});
6085: }
6086: if ($changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} eq '') {
6087: $changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} =
6088: &Apache::loncommon::plainname($roleslog{$id}{'uname'},$roleslog{$id}{'udom'});
6089: }
6090: my $sec = $roleslog{$id}{'logentry'}{'section'};
6091: if ($sec eq '') {
6092: $sec = &mt('None');
6093: }
6094: my ($rolestart,$roleend);
6095: if ($roleslog{$id}{'delflag'}) {
6096: $rolestart = &mt('deleted');
6097: $roleend = &mt('deleted');
6098: } else {
6099: $rolestart = $roleslog{$id}{'logentry'}{'start'};
6100: $roleend = $roleslog{$id}{'logentry'}{'end'};
6101: if ($rolestart eq '' || $rolestart == 0) {
6102: $rolestart = &mt('No start date');
6103: } else {
6104: $rolestart = &Apache::lonlocal::locallocaltime($rolestart);
6105: }
6106: if ($roleend eq '' || $roleend == 0) {
6107: $roleend = &mt('No end date');
6108: } else {
6109: $roleend = &Apache::lonlocal::locallocaltime($roleend);
6110: }
6111: }
6112: my $chgcontext = $roleslog{$id}{'logentry'}{'context'};
6113: if ($roleslog{$id}{'logentry'}{'selfenroll'}) {
6114: $chgcontext = 'selfenroll';
6115: }
1.363 raeburn 6116: my %lt = &rolechg_contexts($context,$crstype);
1.239 raeburn 6117: if ($chgcontext ne '' && $lt{$chgcontext} ne '') {
6118: $chgcontext = $lt{$chgcontext};
6119: }
1.327 raeburn 6120: $r->print(
1.301 bisitz 6121: &Apache::loncommon::start_data_table_row()
6122: .'<td>'.$count.'</td>'
6123: .'<td>'.&Apache::lonlocal::locallocaltime($roleslog{$id}{'exe_time'}).'</td>'
6124: .'<td>'.$whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}}.'</td>'
6125: .'<td>'.$changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}}.'</td>'
1.363 raeburn 6126: .'<td>'.&Apache::lonnet::plaintext($roleslog{$id}{'logentry'}{'role'},$crstype).'</td>');
6127: if ($context eq 'course') {
6128: $r->print('<td>'.$sec.'</td>');
6129: }
6130: $r->print(
6131: '<td>'.$chgcontext.'</td>'
1.301 bisitz 6132: .'<td>'.$rolestart.'</td>'
6133: .'<td>'.$roleend.'</td>'
1.327 raeburn 6134: .&Apache::loncommon::end_data_table_row()."\n");
1.301 bisitz 6135: }
6136:
1.327 raeburn 6137: if ($showntableheader) { # Table footer, if content displayed above
6138: $r->print(&Apache::loncommon::end_data_table()
6139: .$nav_links);
6140: } else { # No content displayed above
1.301 bisitz 6141: $r->print('<p class="LC_info">'
6142: .&mt('There are no records to display.')
6143: .'</p>'
6144: );
1.239 raeburn 6145: }
1.301 bisitz 6146:
1.327 raeburn 6147: # Form Footer
6148: $r->print(
6149: '<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
6150: .'<input type="hidden" name="action" value="changelogs" />'
6151: .'</form>');
6152: return;
6153: }
1.301 bisitz 6154:
1.327 raeburn 6155: sub userlogdisplay_nav {
6156: my ($formname,$curr,$more_records) = @_;
6157: my ($nav_script,$nav_links);
6158: if (ref($curr) eq 'HASH') {
6159: # Create Navigation:
6160: # Navigation Script
6161: $nav_script = <<"ENDSCRIPT";
1.239 raeburn 6162: <script type="text/javascript">
1.301 bisitz 6163: // <![CDATA[
1.239 raeburn 6164: function chgPage(caller) {
6165: if (caller == 'previous') {
6166: document.$formname.page.value --;
6167: }
6168: if (caller == 'next') {
6169: document.$formname.page.value ++;
6170: }
1.327 raeburn 6171: document.$formname.submit();
1.239 raeburn 6172: return;
6173: }
1.301 bisitz 6174: // ]]>
1.239 raeburn 6175: </script>
6176: ENDSCRIPT
1.327 raeburn 6177: # Navigation Buttons
6178: $nav_links = '<p>';
6179: if (($curr->{'page'} > 1) || ($more_records)) {
6180: if ($curr->{'page'} > 1) {
6181: $nav_links .= '<input type="button"'
6182: .' onclick="javascript:chgPage('."'previous'".');"'
6183: .' value="'.&mt('Previous [_1] changes',$curr->{'show'})
6184: .'" /> ';
6185: }
6186: if ($more_records) {
6187: $nav_links .= '<input type="button"'
6188: .' onclick="javascript:chgPage('."'next'".');"'
6189: .' value="'.&mt('Next [_1] changes',$curr->{'show'})
6190: .'" />';
6191: }
1.301 bisitz 6192: }
1.327 raeburn 6193: $nav_links .= '</p>';
1.301 bisitz 6194: }
1.327 raeburn 6195: return ($nav_script,$nav_links);
1.239 raeburn 6196: }
6197:
6198: sub role_display_filter {
1.363 raeburn 6199: my ($context,$formname,$cdom,$cnum,$curr,$version,$crstype) = @_;
6200: my $lctype;
6201: if ($context eq 'course') {
6202: $lctype = lc($crstype);
6203: }
1.239 raeburn 6204: my $nolink = 1;
6205: my $output = '<table><tr><td valign="top">'.
1.301 bisitz 6206: '<span class="LC_nobreak"><b>'.&mt('Changes/page:').'</b></span><br />'.
1.239 raeburn 6207: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
6208: (&mt('all'),5,10,20,50,100,1000,10000)).
6209: '</td><td> </td>';
6210: my $startform =
6211: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_start_date',
6212: $curr->{'rolelog_start_date'},undef,
6213: undef,undef,undef,undef,undef,undef,$nolink);
6214: my $endform =
6215: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_end_date',
6216: $curr->{'rolelog_end_date'},undef,
6217: undef,undef,undef,undef,undef,undef,$nolink);
1.363 raeburn 6218: my %lt = &rolechg_contexts($context,$crstype);
1.301 bisitz 6219: $output .= '<td valign="top"><b>'.&mt('Window during which changes occurred:').'</b><br />'.
6220: '<table><tr><td>'.&mt('After:').
6221: '</td><td>'.$startform.'</td></tr>'.
6222: '<tr><td>'.&mt('Before:').'</td>'.
6223: '<td>'.$endform.'</td></tr></table>'.
6224: '</td>'.
6225: '<td> </td>'.
1.239 raeburn 6226: '<td valign="top"><b>'.&mt('Role:').'</b><br />'.
6227: '<select name="role"><option value="any"';
6228: if ($curr->{'role'} eq 'any') {
6229: $output .= ' selected="selected"';
6230: }
6231: $output .= '>'.&mt('Any').'</option>'."\n";
1.363 raeburn 6232: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
1.239 raeburn 6233: foreach my $role (@roles) {
6234: my $plrole;
6235: if ($role eq 'cr') {
6236: $plrole = &mt('Custom Role');
6237: } else {
1.318 raeburn 6238: $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.239 raeburn 6239: }
6240: my $selstr = '';
6241: if ($role eq $curr->{'role'}) {
6242: $selstr = ' selected="selected"';
6243: }
6244: $output .= ' <option value="'.$role.'"'.$selstr.'>'.$plrole.'</option>';
6245: }
1.301 bisitz 6246: $output .= '</select></td>'.
6247: '<td> </td>'.
6248: '<td valign="top"><b>'.
1.239 raeburn 6249: &mt('Context:').'</b><br /><select name="chgcontext">';
1.363 raeburn 6250: my @posscontexts;
6251: if ($context eq 'course') {
1.376 raeburn 6252: @posscontexts = ('any','automated','updatenow','createcourse','course','domain','selfenroll','requestcourses');
1.363 raeburn 6253: } elsif ($context eq 'domain') {
6254: @posscontexts = ('any','domain','requestauthor','domconfig','server');
6255: } else {
6256: @posscontexts = ('any','author','domain');
6257: }
6258: foreach my $chgtype (@posscontexts) {
1.239 raeburn 6259: my $selstr = '';
6260: if ($curr->{'chgcontext'} eq $chgtype) {
1.301 bisitz 6261: $selstr = ' selected="selected"';
1.239 raeburn 6262: }
1.363 raeburn 6263: if ($context eq 'course') {
1.376 raeburn 6264: if (($chgtype eq 'automated') || ($chgtype eq 'updatenow')) {
1.363 raeburn 6265: next if (!&Apache::lonnet::auto_run($cnum,$cdom));
6266: }
1.239 raeburn 6267: }
6268: $output .= '<option value="'.$chgtype.'"'.$selstr.'>'.$lt{$chgtype}.'</option>'."\n";
1.248 raeburn 6269: }
1.303 bisitz 6270: $output .= '</select></td>'
6271: .'</tr></table>';
6272:
6273: # Update Display button
6274: $output .= '<p>'
6275: .'<input type="submit" value="'.&mt('Update Display').'" />'
6276: .'</p>';
6277:
6278: # Server version info
1.363 raeburn 6279: my $needsrev = '2.11.0';
6280: if ($context eq 'course') {
6281: $needsrev = '2.7.0';
6282: }
6283:
1.303 bisitz 6284: $output .= '<p class="LC_info">'
6285: .&mt('Only changes made from servers running LON-CAPA [_1] or later are displayed.'
1.363 raeburn 6286: ,$needsrev);
1.248 raeburn 6287: if ($version) {
1.303 bisitz 6288: $output .= ' '.&mt('This LON-CAPA server is version [_1]',$version);
6289: }
6290: $output .= '</p><hr />';
1.239 raeburn 6291: return $output;
6292: }
6293:
6294: sub rolechg_contexts {
1.363 raeburn 6295: my ($context,$crstype) = @_;
6296: my %lt;
6297: if ($context eq 'course') {
6298: %lt = &Apache::lonlocal::texthash (
1.239 raeburn 6299: any => 'Any',
1.376 raeburn 6300: automated => 'Automated Enrollment',
1.239 raeburn 6301: updatenow => 'Roster Update',
6302: createcourse => 'Course Creation',
6303: course => 'User Management in course',
6304: domain => 'User Management in domain',
1.313 raeburn 6305: selfenroll => 'Self-enrolled',
1.318 raeburn 6306: requestcourses => 'Course Request',
1.239 raeburn 6307: );
1.363 raeburn 6308: if ($crstype eq 'Community') {
6309: $lt{'createcourse'} = &mt('Community Creation');
6310: $lt{'course'} = &mt('User Management in community');
6311: $lt{'requestcourses'} = &mt('Community Request');
6312: }
6313: } elsif ($context eq 'domain') {
6314: %lt = &Apache::lonlocal::texthash (
6315: any => 'Any',
6316: domain => 'User Management in domain',
6317: requestauthor => 'Authoring Request',
6318: server => 'Command line script (DC role)',
6319: domconfig => 'Self-enrolled',
6320: );
6321: } else {
6322: %lt = &Apache::lonlocal::texthash (
6323: any => 'Any',
6324: domain => 'User Management in domain',
6325: author => 'User Management by author',
6326: );
6327: }
1.239 raeburn 6328: return %lt;
6329: }
6330:
1.27 matthew 6331: #-------------------------------------------------- functions for &phase_two
1.160 raeburn 6332: sub user_search_result {
1.221 raeburn 6333: my ($context,$srch) = @_;
1.160 raeburn 6334: my %allhomes;
6335: my %inst_matches;
6336: my %srch_results;
1.181 raeburn 6337: my ($response,$currstate,$forcenewuser,$dirsrchres);
1.183 raeburn 6338: $srch->{'srchterm'} =~ s/\s+/ /g;
1.176 raeburn 6339: if ($srch->{'srchby'} !~ /^(uname|lastname|lastfirst)$/) {
1.160 raeburn 6340: $response = &mt('Invalid search.');
6341: }
6342: if ($srch->{'srchin'} !~ /^(crs|dom|alc|instd)$/) {
6343: $response = &mt('Invalid search.');
6344: }
1.177 raeburn 6345: if ($srch->{'srchtype'} !~ /^(exact|contains|begins)$/) {
1.160 raeburn 6346: $response = &mt('Invalid search.');
6347: }
6348: if ($srch->{'srchterm'} eq '') {
6349: $response = &mt('You must enter a search term.');
6350: }
1.183 raeburn 6351: if ($srch->{'srchterm'} =~ /^\s+$/) {
6352: $response = &mt('Your search term must contain more than just spaces.');
6353: }
1.160 raeburn 6354: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'instd')) {
6355: if (($srch->{'srchdomain'} eq '') ||
1.163 albertel 6356: ! (&Apache::lonnet::domain($srch->{'srchdomain'}))) {
1.160 raeburn 6357: $response = &mt('You must specify a valid domain when searching in a domain or institutional directory.')
6358: }
6359: }
6360: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs') ||
6361: ($srch->{'srchin'} eq 'alc')) {
1.176 raeburn 6362: if ($srch->{'srchby'} eq 'uname') {
1.243 raeburn 6363: my $unamecheck = $srch->{'srchterm'};
6364: if ($srch->{'srchtype'} eq 'contains') {
6365: if ($unamecheck !~ /^\w/) {
6366: $unamecheck = 'a'.$unamecheck;
6367: }
6368: }
6369: if ($unamecheck !~ /^$match_username$/) {
1.176 raeburn 6370: $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
6371: }
1.160 raeburn 6372: }
6373: }
1.180 raeburn 6374: if ($response ne '') {
6375: $response = '<span class="LC_warning">'.$response.'</span>';
6376: }
1.160 raeburn 6377: if ($srch->{'srchin'} eq 'instd') {
6378: my $instd_chk = &directorysrch_check($srch);
6379: if ($instd_chk ne 'ok') {
1.180 raeburn 6380: $response = '<span class="LC_warning">'.$instd_chk.'</span>'.
6381: '<br />'.&mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').'<br /><br />';
1.160 raeburn 6382: }
6383: }
6384: if ($response ne '') {
1.180 raeburn 6385: return ($currstate,$response);
1.160 raeburn 6386: }
6387: if ($srch->{'srchby'} eq 'uname') {
6388: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs')) {
6389: if ($env{'form.forcenew'}) {
6390: if ($srch->{'srchdomain'} ne $env{'request.role.domain'}) {
6391: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
6392: if ($uhome eq 'no_host') {
6393: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
1.180 raeburn 6394: my $showdom = &display_domain_info($env{'request.role.domain'});
6395: $response = &mt('New users can only be created in the domain to which your current role belongs - [_1].',$showdom);
1.160 raeburn 6396: } else {
1.179 raeburn 6397: $currstate = 'modify';
1.160 raeburn 6398: }
6399: } else {
1.179 raeburn 6400: $currstate = 'modify';
1.160 raeburn 6401: }
6402: } else {
6403: if ($srch->{'srchin'} eq 'dom') {
1.162 raeburn 6404: if ($srch->{'srchtype'} eq 'exact') {
6405: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
6406: if ($uhome eq 'no_host') {
1.179 raeburn 6407: ($currstate,$response,$forcenewuser) =
1.221 raeburn 6408: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 6409: } else {
1.179 raeburn 6410: $currstate = 'modify';
1.310 raeburn 6411: my $uname = $srch->{'srchterm'};
6412: my $udom = $srch->{'srchdomain'};
6413: $srch_results{$uname.':'.$udom} =
6414: { &Apache::lonnet::get('environment',
6415: ['firstname',
6416: 'lastname',
6417: 'permanentemail'],
6418: $udom,$uname)
6419: };
1.162 raeburn 6420: }
6421: } else {
6422: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 6423: ($currstate,$response,$forcenewuser) =
1.221 raeburn 6424: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 6425: }
6426: } else {
1.167 albertel 6427: my $courseusers = &get_courseusers();
1.162 raeburn 6428: if ($srch->{'srchtype'} eq 'exact') {
1.167 albertel 6429: if (exists($courseusers->{$srch->{'srchterm'}.':'.$srch->{'srchdomain'}})) {
1.179 raeburn 6430: $currstate = 'modify';
1.162 raeburn 6431: } else {
1.179 raeburn 6432: ($currstate,$response,$forcenewuser) =
1.221 raeburn 6433: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 6434: }
1.160 raeburn 6435: } else {
1.167 albertel 6436: foreach my $user (keys(%$courseusers)) {
1.162 raeburn 6437: my ($cuname,$cudomain) = split(/:/,$user);
6438: if ($cudomain eq $srch->{'srchdomain'}) {
1.177 raeburn 6439: my $matched = 0;
6440: if ($srch->{'srchtype'} eq 'begins') {
6441: if ($cuname =~ /^\Q$srch->{'srchterm'}\E/i) {
6442: $matched = 1;
6443: }
6444: } else {
6445: if ($cuname =~ /\Q$srch->{'srchterm'}\E/i) {
6446: $matched = 1;
6447: }
6448: }
6449: if ($matched) {
1.167 albertel 6450: $srch_results{$user} =
6451: {&Apache::lonnet::get('environment',
6452: ['firstname',
6453: 'lastname',
1.194 albertel 6454: 'permanentemail'],
6455: $cudomain,$cuname)};
1.162 raeburn 6456: }
6457: }
6458: }
1.179 raeburn 6459: ($currstate,$response,$forcenewuser) =
1.221 raeburn 6460: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 6461: }
6462: }
6463: }
6464: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 6465: $currstate = 'query';
1.160 raeburn 6466: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 6467: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
6468: if ($dirsrchres eq 'ok') {
6469: ($currstate,$response,$forcenewuser) =
1.221 raeburn 6470: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 6471: } else {
6472: my $showdom = &display_domain_info($srch->{'srchdomain'});
6473: $response = '<span class="LC_warning">'.
6474: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
6475: '</span><br />'.
6476: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
6477: '<br /><br />';
6478: }
1.160 raeburn 6479: }
6480: } else {
6481: if ($srch->{'srchin'} eq 'dom') {
6482: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 6483: ($currstate,$response,$forcenewuser) =
1.221 raeburn 6484: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 6485: } elsif ($srch->{'srchin'} eq 'crs') {
1.167 albertel 6486: my $courseusers = &get_courseusers();
6487: foreach my $user (keys(%$courseusers)) {
1.160 raeburn 6488: my ($uname,$udom) = split(/:/,$user);
6489: my %names = &Apache::loncommon::getnames($uname,$udom);
6490: my %emails = &Apache::loncommon::getemails($uname,$udom);
6491: if ($srch->{'srchby'} eq 'lastname') {
6492: if ((($srch->{'srchtype'} eq 'exact') &&
6493: ($names{'lastname'} eq $srch->{'srchterm'})) ||
1.177 raeburn 6494: (($srch->{'srchtype'} eq 'begins') &&
6495: ($names{'lastname'} =~ /^\Q$srch->{'srchterm'}\E/i)) ||
1.160 raeburn 6496: (($srch->{'srchtype'} eq 'contains') &&
6497: ($names{'lastname'} =~ /\Q$srch->{'srchterm'}\E/i))) {
6498: $srch_results{$user} = {firstname => $names{'firstname'},
6499: lastname => $names{'lastname'},
6500: permanentemail => $emails{'permanentemail'},
6501: };
6502: }
6503: } elsif ($srch->{'srchby'} eq 'lastfirst') {
6504: my ($srchlast,$srchfirst) = split(/,/,$srch->{'srchterm'});
1.177 raeburn 6505: $srchlast =~ s/\s+$//;
6506: $srchfirst =~ s/^\s+//;
1.160 raeburn 6507: if ($srch->{'srchtype'} eq 'exact') {
6508: if (($names{'lastname'} eq $srchlast) &&
6509: ($names{'firstname'} eq $srchfirst)) {
6510: $srch_results{$user} = {firstname => $names{'firstname'},
6511: lastname => $names{'lastname'},
6512: permanentemail => $emails{'permanentemail'},
6513:
6514: };
6515: }
1.177 raeburn 6516: } elsif ($srch->{'srchtype'} eq 'begins') {
6517: if (($names{'lastname'} =~ /^\Q$srchlast\E/i) &&
6518: ($names{'firstname'} =~ /^\Q$srchfirst\E/i)) {
6519: $srch_results{$user} = {firstname => $names{'firstname'},
6520: lastname => $names{'lastname'},
6521: permanentemail => $emails{'permanentemail'},
6522: };
6523: }
6524: } else {
1.160 raeburn 6525: if (($names{'lastname'} =~ /\Q$srchlast\E/i) &&
6526: ($names{'firstname'} =~ /\Q$srchfirst\E/i)) {
6527: $srch_results{$user} = {firstname => $names{'firstname'},
6528: lastname => $names{'lastname'},
6529: permanentemail => $emails{'permanentemail'},
6530: };
6531: }
6532: }
6533: }
6534: }
1.179 raeburn 6535: ($currstate,$response,$forcenewuser) =
1.221 raeburn 6536: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 6537: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 6538: $currstate = 'query';
1.160 raeburn 6539: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 6540: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
6541: if ($dirsrchres eq 'ok') {
6542: ($currstate,$response,$forcenewuser) =
1.221 raeburn 6543: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 6544: } else {
6545: my $showdom = &display_domain_info($srch->{'srchdomain'}); $response = '<span class="LC_warning">'.
6546: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
6547: '</span><br />'.
6548: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
6549: '<br /><br />';
6550: }
1.160 raeburn 6551: }
6552: }
1.179 raeburn 6553: return ($currstate,$response,$forcenewuser,\%srch_results);
1.160 raeburn 6554: }
6555:
6556: sub directorysrch_check {
6557: my ($srch) = @_;
6558: my $can_search = 0;
6559: my $response;
6560: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
6561: ['directorysrch'],$srch->{'srchdomain'});
1.180 raeburn 6562: my $showdom = &display_domain_info($srch->{'srchdomain'});
1.160 raeburn 6563: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
6564: if (!$dom_inst_srch{'directorysrch'}{'available'}) {
1.180 raeburn 6565: return &mt('Institutional directory search is not available in domain: [_1]',$showdom);
1.160 raeburn 6566: }
6567: if ($dom_inst_srch{'directorysrch'}{'localonly'}) {
6568: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
1.180 raeburn 6569: return &mt('Institutional directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
1.160 raeburn 6570: }
6571: my @usertypes = split(/:/,$env{'environment.inststatus'});
6572: if (!@usertypes) {
6573: push(@usertypes,'default');
6574: }
6575: if (ref($dom_inst_srch{'directorysrch'}{'cansearch'}) eq 'ARRAY') {
6576: foreach my $type (@usertypes) {
6577: if (grep(/^\Q$type\E$/,@{$dom_inst_srch{'directorysrch'}{'cansearch'}})) {
6578: $can_search = 1;
6579: last;
6580: }
6581: }
6582: }
6583: if (!$can_search) {
6584: my ($insttypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($srch->{'srchdomain'});
6585: my @longtypes;
6586: foreach my $item (@usertypes) {
1.229 raeburn 6587: if (defined($insttypes->{$item})) {
6588: push (@longtypes,$insttypes->{$item});
6589: } elsif ($item eq 'default') {
6590: push (@longtypes,&mt('other'));
6591: }
1.160 raeburn 6592: }
6593: my $insttype_str = join(', ',@longtypes);
1.180 raeburn 6594: return &mt('Institutional directory search in domain: [_1] is not available to your user type: ',$showdom).$insttype_str;
1.229 raeburn 6595: }
1.160 raeburn 6596: } else {
6597: $can_search = 1;
6598: }
6599: } else {
1.180 raeburn 6600: return &mt('Institutional directory search has not been configured for domain: [_1]',$showdom);
1.160 raeburn 6601: }
6602: my %longtext = &Apache::lonlocal::texthash (
1.167 albertel 6603: uname => 'username',
1.160 raeburn 6604: lastfirst => 'last name, first name',
1.167 albertel 6605: lastname => 'last name',
1.172 raeburn 6606: contains => 'contains',
1.178 raeburn 6607: exact => 'as exact match to',
6608: begins => 'begins with',
1.160 raeburn 6609: );
6610: if ($can_search) {
6611: if (ref($dom_inst_srch{'directorysrch'}{'searchby'}) eq 'ARRAY') {
6612: if (!grep(/^\Q$srch->{'srchby'}\E$/,@{$dom_inst_srch{'directorysrch'}{'searchby'}})) {
1.180 raeburn 6613: return &mt('Institutional directory search in domain: [_1] is not available for searching by "[_2]"',$showdom,$longtext{$srch->{'srchby'}});
1.160 raeburn 6614: }
6615: } else {
1.180 raeburn 6616: return &mt('Institutional directory search in domain: [_1] is not available.', $showdom);
1.160 raeburn 6617: }
6618: }
6619: if ($can_search) {
1.178 raeburn 6620: if (ref($dom_inst_srch{'directorysrch'}{'searchtypes'}) eq 'ARRAY') {
6621: if (grep(/^\Q$srch->{'srchtype'}\E/,@{$dom_inst_srch{'directorysrch'}{'searchtypes'}})) {
6622: return 'ok';
6623: } else {
1.180 raeburn 6624: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 6625: }
6626: } else {
6627: if ((($dom_inst_srch{'directorysrch'}{'searchtypes'} eq 'specify') &&
6628: ($srch->{'srchtype'} eq 'exact' || $srch->{'srchtype'} eq 'contains')) ||
6629: ($dom_inst_srch{'directorysrch'}{'searchtypes'} eq $srch->{'srchtype'})) {
6630: return 'ok';
6631: } else {
1.180 raeburn 6632: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 6633: }
1.160 raeburn 6634: }
6635: }
6636: }
6637:
6638: sub get_courseusers {
6639: my %advhash;
1.167 albertel 6640: my $classlist = &Apache::loncoursedata::get_classlist();
1.160 raeburn 6641: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles();
6642: foreach my $role (sort(keys(%coursepersonnel))) {
6643: foreach my $user (split(/\,/,$coursepersonnel{$role})) {
1.167 albertel 6644: if (!exists($classlist->{$user})) {
6645: $classlist->{$user} = [];
6646: }
1.160 raeburn 6647: }
6648: }
1.167 albertel 6649: return $classlist;
1.160 raeburn 6650: }
6651:
6652: sub build_search_response {
1.221 raeburn 6653: my ($context,$srch,%srch_results) = @_;
1.179 raeburn 6654: my ($currstate,$response,$forcenewuser);
1.160 raeburn 6655: my %names = (
1.330 bisitz 6656: 'uname' => 'username',
6657: 'lastname' => 'last name',
1.160 raeburn 6658: 'lastfirst' => 'last name, first name',
1.330 bisitz 6659: 'crs' => 'this course',
6660: 'dom' => 'LON-CAPA domain',
6661: 'instd' => 'the institutional directory for domain',
1.160 raeburn 6662: );
6663:
6664: my %single = (
1.180 raeburn 6665: begins => 'A match',
1.160 raeburn 6666: contains => 'A match',
1.180 raeburn 6667: exact => 'An exact match',
1.160 raeburn 6668: );
6669: my %nomatch = (
1.180 raeburn 6670: begins => 'No match',
1.160 raeburn 6671: contains => 'No match',
1.180 raeburn 6672: exact => 'No exact match',
1.160 raeburn 6673: );
6674: if (keys(%srch_results) > 1) {
1.179 raeburn 6675: $currstate = 'select';
1.160 raeburn 6676: } else {
6677: if (keys(%srch_results) == 1) {
1.179 raeburn 6678: $currstate = 'modify';
1.180 raeburn 6679: $response = &mt("$single{$srch->{'srchtype'}} was found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}.",$srch->{'srchterm'});
6680: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 6681: $response .= ': '.&display_domain_info($srch->{'srchdomain'});
1.180 raeburn 6682: }
1.330 bisitz 6683: } else { # Search has nothing found. Prepare message to user.
6684: $response = '<span class="LC_warning">';
1.180 raeburn 6685: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 6686: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}: [_2]",
6687: '<b>'.$srch->{'srchterm'}.'</b>',
6688: &display_domain_info($srch->{'srchdomain'}));
6689: } else {
6690: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}.",
6691: '<b>'.$srch->{'srchterm'}.'</b>');
1.180 raeburn 6692: }
6693: $response .= '</span>';
1.330 bisitz 6694:
1.160 raeburn 6695: if ($srch->{'srchin'} ne 'alc') {
6696: $forcenewuser = 1;
6697: my $cansrchinst = 0;
6698: if ($srch->{'srchdomain'}) {
6699: my %domconfig = &Apache::lonnet::get_dom('configuration',['directorysrch'],$srch->{'srchdomain'});
6700: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
6701: if ($domconfig{'directorysrch'}{'available'}) {
6702: $cansrchinst = 1;
6703: }
6704: }
6705: }
1.180 raeburn 6706: if ((($srch->{'srchby'} eq 'lastfirst') ||
6707: ($srch->{'srchby'} eq 'lastname')) &&
6708: ($srch->{'srchin'} eq 'dom')) {
6709: if ($cansrchinst) {
6710: $response .= '<br />'.&mt('You may want to broaden your search to a search of the institutional directory for the domain.');
1.160 raeburn 6711: }
6712: }
1.180 raeburn 6713: if ($srch->{'srchin'} eq 'crs') {
6714: $response .= '<br />'.&mt('You may want to broaden your search to the selected LON-CAPA domain.');
6715: }
6716: }
1.305 raeburn 6717: my $createdom = $env{'request.role.domain'};
6718: if ($context eq 'requestcrs') {
6719: if ($env{'form.coursedom'} ne '') {
6720: $createdom = $env{'form.coursedom'};
6721: }
6722: }
6723: if (!($srch->{'srchby'} eq 'uname' && $srch->{'srchin'} eq 'dom' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchdomain'} eq $createdom)) {
1.221 raeburn 6724: my $cancreate =
1.305 raeburn 6725: &Apache::lonuserutils::can_create_user($createdom,$context);
6726: my $targetdom = '<span class="LC_cusr_emph">'.$createdom.'</span>';
1.221 raeburn 6727: if ($cancreate) {
1.305 raeburn 6728: my $showdom = &display_domain_info($createdom);
1.266 bisitz 6729: $response .= '<br /><br />'
6730: .'<b>'.&mt('To add a new user:').'</b>'
1.305 raeburn 6731: .'<br />';
6732: if ($context eq 'requestcrs') {
6733: $response .= &mt("(You can only define new users in the new course's domain - [_1])",$targetdom);
6734: } else {
6735: $response .= &mt("(You can only create new users in your current role's domain - [_1])",$targetdom);
6736: }
6737: $response .='<ul><li>'
1.266 bisitz 6738: .&mt("Set 'Domain/institution to search' to: [_1]",'<span class="LC_cusr_emph">'.$showdom.'</span>')
6739: .'</li><li>'
6740: .&mt("Set 'Search criteria' to: [_1]username is ..... in selected LON-CAPA domain[_2]",'<span class="LC_cusr_emph">','</span>')
6741: .'</li><li>'
6742: .&mt('Provide the proposed username')
6743: .'</li><li>'
6744: .&mt("Click 'Search'")
6745: .'</li></ul><br />';
1.221 raeburn 6746: } else {
6747: my $helplink = ' href="javascript:helpMenu('."'display'".')"';
1.305 raeburn 6748: $response .= '<br /><br />';
6749: if ($context eq 'requestcrs') {
1.314 raeburn 6750: $response .= &mt("You are not authorized to define new users in the new course's domain - [_1].",$targetdom);
1.305 raeburn 6751: } else {
6752: $response .= &mt("You are not authorized to create new users in your current role's domain - [_1].",$targetdom);
6753: }
6754: $response .= '<br />'
6755: .&mt('Please contact the [_1]helpdesk[_2] if you need to create a new user.'
1.266 bisitz 6756: ,' <a'.$helplink.'>'
6757: ,'</a>')
1.305 raeburn 6758: .'<br /><br />';
1.221 raeburn 6759: }
1.160 raeburn 6760: }
6761: }
6762: }
1.179 raeburn 6763: return ($currstate,$response,$forcenewuser);
1.160 raeburn 6764: }
6765:
1.180 raeburn 6766: sub display_domain_info {
6767: my ($dom) = @_;
6768: my $output = $dom;
6769: if ($dom ne '') {
6770: my $domdesc = &Apache::lonnet::domain($dom,'description');
6771: if ($domdesc ne '') {
6772: $output .= ' <span class="LC_cusr_emph">('.$domdesc.')</span>';
6773: }
6774: }
6775: return $output;
6776: }
6777:
1.160 raeburn 6778: sub crumb_utilities {
6779: my %elements = (
6780: crtuser => {
6781: srchterm => 'text',
1.172 raeburn 6782: srchin => 'selectbox',
1.160 raeburn 6783: srchby => 'selectbox',
6784: srchtype => 'selectbox',
6785: srchdomain => 'selectbox',
6786: },
1.207 raeburn 6787: crtusername => {
6788: srchterm => 'text',
6789: srchdomain => 'selectbox',
6790: },
1.160 raeburn 6791: docustom => {
6792: rolename => 'selectbox',
6793: newrolename => 'textbox',
6794: },
1.179 raeburn 6795: studentform => {
6796: srchterm => 'text',
6797: srchin => 'selectbox',
6798: srchby => 'selectbox',
6799: srchtype => 'selectbox',
6800: srchdomain => 'selectbox',
6801: },
1.160 raeburn 6802: );
6803:
6804: my $jsback .= qq|
6805: function backPage(formname,prevphase,prevstate) {
1.211 raeburn 6806: if (typeof prevphase == 'undefined') {
6807: formname.phase.value = '';
6808: }
6809: else {
6810: formname.phase.value = prevphase;
6811: }
6812: if (typeof prevstate == 'undefined') {
6813: formname.currstate.value = '';
6814: }
6815: else {
6816: formname.currstate.value = prevstate;
6817: }
1.160 raeburn 6818: formname.submit();
6819: }
6820: |;
6821: return ($jsback,\%elements);
6822: }
6823:
1.26 matthew 6824: sub course_level_table {
1.375 raeburn 6825: my ($inccourses,$showcredits,$defaultcredits) = @_;
6826: return unless (ref($inccourses) eq 'HASH');
1.26 matthew 6827: my $table = '';
1.62 www 6828: # Custom Roles?
6829:
1.190 raeburn 6830: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.89 raeburn 6831: my %lt=&Apache::lonlocal::texthash(
6832: 'exs' => "Existing sections",
6833: 'new' => "Define new section",
6834: 'ssd' => "Set Start Date",
6835: 'sed' => "Set End Date",
1.131 raeburn 6836: 'crl' => "Course Level",
1.89 raeburn 6837: 'act' => "Activate",
6838: 'rol' => "Role",
6839: 'ext' => "Extent",
1.113 raeburn 6840: 'grs' => "Section",
1.375 raeburn 6841: 'crd' => "Credits",
1.89 raeburn 6842: 'sta' => "Start",
6843: 'end' => "End"
6844: );
1.62 www 6845:
1.375 raeburn 6846: foreach my $protectedcourse (sort(keys(%{$inccourses}))) {
1.135 raeburn 6847: my $thiscourse=$protectedcourse;
1.26 matthew 6848: $thiscourse=~s:_:/:g;
6849: my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
1.365 raeburn 6850: my $isowner = &Apache::lonuserutils::is_courseowner($protectedcourse,$coursedata{'internal.courseowner'});
1.26 matthew 6851: my $area=$coursedata{'description'};
1.321 raeburn 6852: my $crstype=$coursedata{'type'};
1.135 raeburn 6853: if (!defined($area)) { $area=&mt('Unavailable course').': '.$protectedcourse; }
1.89 raeburn 6854: my ($domain,$cnum)=split(/\//,$thiscourse);
1.115 albertel 6855: my %sections_count;
1.101 albertel 6856: if (defined($env{'request.course.id'})) {
6857: if ($env{'request.course.id'} eq $domain.'_'.$cnum) {
1.115 albertel 6858: %sections_count =
6859: &Apache::loncommon::get_sections($domain,$cnum);
1.92 raeburn 6860: }
6861: }
1.321 raeburn 6862: my @roles = &Apache::lonuserutils::roles_by_context('course','',$crstype);
1.213 raeburn 6863: foreach my $role (@roles) {
1.321 raeburn 6864: my $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.329 raeburn 6865: if ((&Apache::lonnet::allowed('c'.$role,$thiscourse)) ||
6866: ((($role eq 'cc') || ($role eq 'co')) && ($isowner))) {
1.221 raeburn 6867: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 6868: $plrole,\%sections_count,\%lt,
6869: $defaultcredits,$crstype);
1.221 raeburn 6870: } elsif ($env{'request.course.sec'} ne '') {
6871: if (&Apache::lonnet::allowed('c'.$role,$thiscourse.'/'.
6872: $env{'request.course.sec'})) {
6873: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 6874: $plrole,\%sections_count,\%lt,
6875: $defaultcredits,$crstype);
1.26 matthew 6876: }
6877: }
6878: }
1.221 raeburn 6879: if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
1.324 raeburn 6880: foreach my $cust (sort(keys(%customroles))) {
6881: next if ($crstype eq 'Community' && $customroles{$cust} =~ /bre\&S/);
1.221 raeburn 6882: my $role = 'cr_cr_'.$env{'user.domain'}.'_'.$env{'user.name'}.'_'.$cust;
6883: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
6884: $cust,\%sections_count,\%lt);
6885: }
1.62 www 6886: }
1.26 matthew 6887: }
6888: return '' if ($table eq ''); # return nothing if there is nothing
6889: # in the table
1.188 raeburn 6890: my $result;
6891: if (!$env{'request.course.id'}) {
6892: $result = '<h4>'.$lt{'crl'}.'</h4>'."\n";
6893: }
6894: $result .=
1.136 raeburn 6895: &Apache::loncommon::start_data_table().
6896: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 6897: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
6898: '<th>'.$lt{'ext'}.'</th><th>'.$lt{'crd'}.'</th>'."\n".
6899: '<th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th>'."\n".
6900: '<th>'.$lt{'end'}.'</th>'.
1.136 raeburn 6901: &Apache::loncommon::end_data_table_header_row().
6902: $table.
6903: &Apache::loncommon::end_data_table();
1.26 matthew 6904: return $result;
6905: }
1.88 raeburn 6906:
1.221 raeburn 6907: sub course_level_row {
1.375 raeburn 6908: my ($protectedcourse,$role,$area,$domain,$plrole,$sections_count,
6909: $lt,$defaultcredits,$crstype) = @_;
6910: my $creditem;
1.222 raeburn 6911: my $row = &Apache::loncommon::start_data_table_row().
6912: ' <td><input type="checkbox" name="act_'.
6913: $protectedcourse.'_'.$role.'" /></td>'."\n".
6914: ' <td>'.$plrole.'</td>'."\n".
6915: ' <td>'.$area.'<br />Domain: '.$domain.'</td>'."\n";
1.375 raeburn 6916: if (($role eq 'st') && ($crstype eq 'Course')) {
6917: $row .=
6918: '<td><input type="text" name="credits_'.$protectedcourse.'_'.
6919: $role.'" size="3" value="'.$defaultcredits.'" /></td>';
6920: } else {
6921: $row .= '<td> </td>';
6922: }
1.322 raeburn 6923: if (($role eq 'cc') || ($role eq 'co')) {
1.222 raeburn 6924: $row .= '<td> </td>';
1.221 raeburn 6925: } elsif ($env{'request.course.sec'} ne '') {
1.222 raeburn 6926: $row .= ' <td><input type="hidden" value="'.
6927: $env{'request.course.sec'}.'" '.
6928: 'name="sec_'.$protectedcourse.'_'.$role.'" />'.
6929: $env{'request.course.sec'}.'</td>';
1.221 raeburn 6930: } else {
6931: if (ref($sections_count) eq 'HASH') {
6932: my $currsec =
6933: &Apache::lonuserutils::course_sections($sections_count,
6934: $protectedcourse.'_'.$role);
1.222 raeburn 6935: $row .= '<td><table class="LC_createuser">'."\n".
6936: '<tr class="LC_section_row">'."\n".
6937: ' <td valign="top">'.$lt->{'exs'}.'<br />'.
6938: $currsec.'</td>'."\n".
6939: ' <td> </td>'."\n".
6940: ' <td valign="top"> '.$lt->{'new'}.'<br />'.
1.221 raeburn 6941: '<input type="text" name="newsec_'.$protectedcourse.'_'.$role.
6942: '" value="" />'.
6943: '<input type="hidden" '.
6944: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n".
1.222 raeburn 6945: '</tr></table></td>'."\n";
1.221 raeburn 6946: } else {
1.222 raeburn 6947: $row .= '<td><input type="text" size="10" '.
1.375 raeburn 6948: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n";
1.221 raeburn 6949: }
6950: }
1.222 raeburn 6951: $row .= <<ENDTIMEENTRY;
6952: <td><input type="hidden" name="start_$protectedcourse\_$role" value="" />
1.221 raeburn 6953: <a href=
6954: "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 6955: <td><input type="hidden" name="end_$protectedcourse\_$role" value="" />
1.221 raeburn 6956: <a href=
6957: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$role.value,'end_$protectedcourse\_$role','cu.pres','dateset')">$lt->{'sed'}</a></td>
6958: ENDTIMEENTRY
1.222 raeburn 6959: $row .= &Apache::loncommon::end_data_table_row();
6960: return $row;
1.221 raeburn 6961: }
6962:
1.88 raeburn 6963: sub course_level_dc {
1.375 raeburn 6964: my ($dcdom,$showcredits) = @_;
1.190 raeburn 6965: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.213 raeburn 6966: my @roles = &Apache::lonuserutils::roles_by_context('course');
1.88 raeburn 6967: my $hiddenitems = '<input type="hidden" name="dcdomain" value="'.$dcdom.'" />'.
6968: '<input type="hidden" name="origdom" value="'.$dcdom.'" />'.
1.133 raeburn 6969: '<input type="hidden" name="dccourse" value="" />';
1.355 www 6970: my $courseform=&Apache::loncommon::selectcourse_link
1.356 raeburn 6971: ('cu','dccourse','dcdomain','coursedesc',undef,undef,'Select','crstype');
1.375 raeburn 6972: my $credit_elem;
6973: if ($showcredits) {
6974: $credit_elem = 'credits';
6975: }
6976: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,'currsec','cu','role','Course/Community Browser',$credit_elem);
1.88 raeburn 6977: my %lt=&Apache::lonlocal::texthash(
6978: 'rol' => "Role",
1.113 raeburn 6979: 'grs' => "Section",
1.88 raeburn 6980: 'exs' => "Existing sections",
6981: 'new' => "Define new section",
6982: 'sta' => "Start",
6983: 'end' => "End",
6984: 'ssd' => "Set Start Date",
1.355 www 6985: 'sed' => "Set End Date",
1.375 raeburn 6986: 'scc' => "Course/Community",
6987: 'crd' => "Credits",
1.88 raeburn 6988: );
1.323 raeburn 6989: my $header = '<h4>'.&mt('Course/Community Level').'</h4>'.
1.136 raeburn 6990: &Apache::loncommon::start_data_table().
6991: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 6992: '<th>'.$lt{'scc'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
6993: '<th>'.$lt{'grs'}.'</th><th>'.$lt{'crd'}.'</th>'."\n".
6994: '<th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'."\n".
1.136 raeburn 6995: &Apache::loncommon::end_data_table_header_row();
1.143 raeburn 6996: my $otheritems = &Apache::loncommon::start_data_table_row()."\n".
1.356 raeburn 6997: '<td><br /><span class="LC_nobreak"><input type="text" name="coursedesc" value="" onfocus="this.blur();opencrsbrowser('."'cu','dccourse','dcdomain','coursedesc','','','','crstype'".')" />'.
6998: $courseform.(' ' x4).'</span></td>'."\n".
1.323 raeburn 6999: '<td valign><br /><select name="role">'."\n";
1.213 raeburn 7000: foreach my $role (@roles) {
1.135 raeburn 7001: my $plrole=&Apache::lonnet::plaintext($role);
7002: $otheritems .= ' <option value="'.$role.'">'.$plrole;
1.88 raeburn 7003: }
7004: if ( keys %customroles > 0) {
1.135 raeburn 7005: foreach my $cust (sort keys %customroles) {
1.101 albertel 7006: my $custrole='cr_cr_'.$env{'user.domain'}.
1.135 raeburn 7007: '_'.$env{'user.name'}.'_'.$cust;
7008: $otheritems .= ' <option value="'.$custrole.'">'.$cust;
1.88 raeburn 7009: }
7010: }
7011: $otheritems .= '</select></td><td>'.
7012: '<table border="0" cellspacing="0" cellpadding="0">'.
7013: '<tr><td valign="top"><b>'.$lt{'exs'}.'</b><br /><select name="currsec">'.
7014: ' <option value=""><--'.&mt('Pick course first').'</select></td>'.
7015: '<td> </td>'.
7016: '<td valign="top"> <b>'.$lt{'new'}.'</b><br />'.
1.113 raeburn 7017: '<input type="text" name="newsec" value="" />'.
1.237 raeburn 7018: '<input type="hidden" name="section" value="" />'.
1.323 raeburn 7019: '<input type="hidden" name="groups" value="" />'.
7020: '<input type="hidden" name="crstype" value="" /></td>'.
1.375 raeburn 7021: '</tr></table></td>'."\n";
7022: if ($showcredits) {
7023: $otheritems .= '<td><br />'."\n".
7024: '<input type="text" size="3" name="credits" value="" />'."\n";
7025: }
1.88 raeburn 7026: $otheritems .= <<ENDTIMEENTRY;
1.323 raeburn 7027: <td><br /><input type="hidden" name="start" value='' />
1.88 raeburn 7028: <a href=
7029: "javascript:pjump('date_start','Start Date',document.cu.start.value,'start','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.323 raeburn 7030: <td><br /><input type="hidden" name="end" value='' />
1.88 raeburn 7031: <a href=
7032: "javascript:pjump('date_end','End Date',document.cu.end.value,'end','cu.pres','dateset')">$lt{'sed'}</a></td>
7033: ENDTIMEENTRY
1.136 raeburn 7034: $otheritems .= &Apache::loncommon::end_data_table_row().
7035: &Apache::loncommon::end_data_table()."\n";
1.88 raeburn 7036: return $cb_jscript.$header.$hiddenitems.$otheritems;
7037: }
7038:
1.237 raeburn 7039: sub update_selfenroll_config {
1.241 raeburn 7040: my ($r,$context,$permission) = @_;
1.237 raeburn 7041: my ($row,$lt) = &get_selfenroll_titles();
1.241 raeburn 7042: my %curr_groups = &Apache::longroup::coursegroups();
1.237 raeburn 7043: my (%changes,%warning);
7044: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
7045: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.241 raeburn 7046: my $curr_types;
1.237 raeburn 7047: if (ref($row) eq 'ARRAY') {
7048: foreach my $item (@{$row}) {
7049: if ($item eq 'enroll_dates') {
7050: my (%currenrolldate,%newenrolldate);
7051: foreach my $type ('start','end') {
7052: $currenrolldate{$type} = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$type.'_date'};
7053: $newenrolldate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_date');
7054: if ($newenrolldate{$type} ne $currenrolldate{$type}) {
7055: $changes{'internal.selfenroll_'.$type.'_date'} = $newenrolldate{$type};
7056: }
7057: }
7058: } elsif ($item eq 'access_dates') {
7059: my (%currdate,%newdate);
7060: foreach my $type ('start','end') {
7061: $currdate{$type} = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$type.'_access'};
7062: $newdate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_access');
7063: if ($newdate{$type} ne $currdate{$type}) {
7064: $changes{'internal.selfenroll_'.$type.'_access'} = $newdate{$type};
7065: }
7066: }
1.241 raeburn 7067: } elsif ($item eq 'types') {
7068: $curr_types =
7069: $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$item};
7070: if ($env{'form.selfenroll_all'}) {
7071: if ($curr_types ne '*') {
7072: $changes{'internal.selfenroll_types'} = '*';
7073: } else {
7074: next;
7075: }
7076: } else {
1.249 raeburn 7077: my %currdoms;
1.241 raeburn 7078: my @entries = split(/;/,$curr_types);
7079: my @deletedoms = &Apache::loncommon::get_env_multiple('form.selfenroll_delete');
1.249 raeburn 7080: my @activations = &Apache::loncommon::get_env_multiple('form.selfenroll_activate');
1.241 raeburn 7081: my $newnum = 0;
1.249 raeburn 7082: my @latesttypes;
7083: foreach my $num (@activations) {
7084: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$num);
7085: if (@types > 0) {
1.241 raeburn 7086: @types = sort(@types);
7087: my $typestr = join(',',@types);
1.249 raeburn 7088: my $typedom = $env{'form.selfenroll_dom_'.$num};
7089: $latesttypes[$newnum] = $typedom.':'.$typestr;
7090: $currdoms{$typedom} = 1;
1.241 raeburn 7091: $newnum ++;
7092: }
7093: }
1.338 raeburn 7094: for (my $j=0; $j<$env{'form.selfenroll_types_total'}; $j++) {
7095: if ((!grep(/^$j$/,@deletedoms)) && (!grep(/^$j$/,@activations))) {
1.249 raeburn 7096: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$j);
7097: if (@types > 0) {
7098: @types = sort(@types);
7099: my $typestr = join(',',@types);
7100: my $typedom = $env{'form.selfenroll_dom_'.$j};
7101: $latesttypes[$newnum] = $typedom.':'.$typestr;
7102: $currdoms{$typedom} = 1;
7103: $newnum ++;
7104: }
7105: }
7106: }
7107: if ($env{'form.selfenroll_newdom'} ne '') {
7108: my $typedom = $env{'form.selfenroll_newdom'};
7109: if ((!defined($currdoms{$typedom})) &&
7110: (&Apache::lonnet::domain($typedom) ne '')) {
7111: my $typestr;
7112: my ($othertitle,$usertypes,$types) =
7113: &Apache::loncommon::sorted_inst_types($typedom);
7114: my $othervalue = 'any';
7115: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7116: if (@{$types} > 0) {
1.257 raeburn 7117: my @esc_types = map { &escape($_); } @{$types};
1.249 raeburn 7118: $othervalue = 'other';
1.258 raeburn 7119: $typestr = join(',',(@esc_types,$othervalue));
1.249 raeburn 7120: }
7121: $typestr = $othervalue;
7122: } else {
7123: $typestr = $othervalue;
7124: }
7125: $latesttypes[$newnum] = $typedom.':'.$typestr;
7126: $newnum ++ ;
7127: }
7128: }
1.241 raeburn 7129: my $selfenroll_types = join(';',@latesttypes);
7130: if ($selfenroll_types ne $curr_types) {
7131: $changes{'internal.selfenroll_types'} = $selfenroll_types;
7132: }
7133: }
1.276 raeburn 7134: } elsif ($item eq 'limit') {
7135: my $newlimit = $env{'form.selfenroll_limit'};
7136: my $newcap = $env{'form.selfenroll_cap'};
7137: $newcap =~s/\s+//g;
7138: my $currlimit = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_limit'};
7139: $currlimit = 'none' if ($currlimit eq '');
7140: my $currcap = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_cap'};
7141: if ($newlimit ne $currlimit) {
7142: if ($newlimit ne 'none') {
7143: if ($newcap =~ /^\d+$/) {
7144: if ($newcap ne $currcap) {
7145: $changes{'internal.selfenroll_cap'} = $newcap;
7146: }
7147: $changes{'internal.selfenroll_limit'} = $newlimit;
7148: } else {
7149: $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.');
7150: }
7151: } elsif ($currcap ne '') {
7152: $changes{'internal.selfenroll_cap'} = '';
7153: $changes{'internal.selfenroll_limit'} = $newlimit;
7154: }
7155: } elsif ($currlimit ne 'none') {
7156: if ($newcap =~ /^\d+$/) {
7157: if ($newcap ne $currcap) {
7158: $changes{'internal.selfenroll_cap'} = $newcap;
7159: }
7160: } else {
7161: $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.');
7162: }
7163: }
7164: } elsif ($item eq 'approval') {
7165: my (@currnotified,@newnotified);
7166: my $currapproval = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'};
7167: my $currnotifylist = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_notifylist'};
7168: if ($currnotifylist ne '') {
7169: @currnotified = split(/,/,$currnotifylist);
7170: @currnotified = sort(@currnotified);
7171: }
7172: my $newapproval = $env{'form.selfenroll_approval'};
7173: @newnotified = &Apache::loncommon::get_env_multiple('form.selfenroll_notify');
7174: @newnotified = sort(@newnotified);
7175: if ($newapproval ne $currapproval) {
7176: $changes{'internal.selfenroll_approval'} = $newapproval;
7177: if (!$newapproval) {
7178: if ($currnotifylist ne '') {
7179: $changes{'internal.selfenroll_notifylist'} = '';
7180: }
7181: } else {
7182: my @differences =
1.295 raeburn 7183: &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 7184: if (@differences > 0) {
7185: if (@newnotified > 0) {
7186: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
7187: } else {
7188: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
7189: }
7190: }
7191: }
7192: } else {
1.295 raeburn 7193: my @differences = &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 7194: if (@differences > 0) {
7195: if (@newnotified > 0) {
7196: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
7197: } else {
7198: $changes{'internal.selfenroll_notifylist'} = '';
7199: }
7200: }
7201: }
1.237 raeburn 7202: } else {
7203: my $curr_val =
7204: $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$item};
7205: my $newval = $env{'form.selfenroll_'.$item};
7206: if ($item eq 'section') {
7207: $newval = $env{'form.sections'};
1.241 raeburn 7208: if (defined($curr_groups{$newval})) {
1.237 raeburn 7209: $newval = $curr_val;
7210: $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');
7211: } elsif ($newval eq 'all') {
7212: $newval = $curr_val;
1.274 bisitz 7213: $warning{$item} = &mt('Section for self-enrolled users unchanged, as "all" is a reserved section name.');
1.237 raeburn 7214: }
7215: if ($newval eq '') {
7216: $newval = 'none';
7217: }
7218: }
7219: if ($newval ne $curr_val) {
7220: $changes{'internal.selfenroll_'.$item} = $newval;
7221: }
1.241 raeburn 7222: }
1.237 raeburn 7223: }
7224: if (keys(%warning) > 0) {
7225: foreach my $item (@{$row}) {
7226: if (exists($warning{$item})) {
7227: $r->print($warning{$item}.'<br />');
7228: }
7229: }
7230: }
7231: if (keys(%changes) > 0) {
7232: my $putresult = &Apache::lonnet::put('environment',\%changes,$cdom,$cnum);
7233: if ($putresult eq 'ok') {
7234: if ((exists($changes{'internal.selfenroll_types'})) ||
7235: (exists($changes{'internal.selfenroll_start_date'})) ||
7236: (exists($changes{'internal.selfenroll_end_date'}))) {
7237: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',
7238: $cnum,undef,undef,'Course');
7239: my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
7240: if (ref($crsinfo{$env{'request.course.id'}}) eq 'HASH') {
7241: foreach my $item ('selfenroll_types','selfenroll_start_date','selfenroll_end_date') {
7242: if (exists($changes{'internal.'.$item})) {
7243: $crsinfo{$env{'request.course.id'}}{$item} =
7244: $changes{'internal.'.$item};
7245: }
7246: }
7247: my $crsputresult =
7248: &Apache::lonnet::courseidput($cdom,\%crsinfo,
7249: $chome,'notime');
7250: }
7251: }
7252: $r->print(&mt('The following changes were made to self-enrollment settings:').'<ul>');
7253: foreach my $item (@{$row}) {
7254: my $title = $item;
7255: if (ref($lt) eq 'HASH') {
7256: $title = $lt->{$item};
7257: }
7258: if ($item eq 'enroll_dates') {
7259: foreach my $type ('start','end') {
7260: if (exists($changes{'internal.selfenroll_'.$type.'_date'})) {
7261: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_date'});
1.244 bisitz 7262: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 7263: $title,$type,$newdate).'</li>');
7264: }
7265: }
7266: } elsif ($item eq 'access_dates') {
7267: foreach my $type ('start','end') {
7268: if (exists($changes{'internal.selfenroll_'.$type.'_access'})) {
7269: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_access'});
1.244 bisitz 7270: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 7271: $title,$type,$newdate).'</li>');
7272: }
7273: }
1.276 raeburn 7274: } elsif ($item eq 'limit') {
7275: if ((exists($changes{'internal.selfenroll_limit'})) ||
7276: (exists($changes{'internal.selfenroll_cap'}))) {
7277: my ($newval,$newcap);
7278: if ($changes{'internal.selfenroll_cap'} ne '') {
7279: $newcap = $changes{'internal.selfenroll_cap'}
7280: } else {
7281: $newcap = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_cap'};
7282: }
7283: if ($changes{'internal.selfenroll_limit'} eq 'none') {
7284: $newval = &mt('No limit');
7285: } elsif ($changes{'internal.selfenroll_limit'} eq
7286: 'allstudents') {
7287: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
7288: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
7289: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
7290: } else {
7291: my $currlimit = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_limit'};
7292: if ($currlimit eq 'allstudents') {
7293: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
7294: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
1.308 raeburn 7295: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
1.276 raeburn 7296: }
7297: }
7298: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
7299: }
7300: } elsif ($item eq 'approval') {
7301: if ((exists($changes{'internal.selfenroll_approval'})) ||
7302: (exists($changes{'internal.selfenroll_notifylist'}))) {
7303: my ($newval,$newnotify);
7304: if (exists($changes{'internal.selfenroll_notifylist'})) {
7305: $newnotify = $changes{'internal.selfenroll_notifylist'};
7306: } else {
7307: $newnotify = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_notifylist'};
7308: }
7309: if ($changes{'internal.selfenroll_approval'}) {
7310: $newval = &mt('Yes');
7311: } elsif ($changes{'internal.selfenroll_approval'} eq '0') {
7312: $newval = &mt('No');
7313: } else {
7314: my $currapproval =
7315: $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'};
7316: if ($currapproval) {
7317: $newval = &mt('Yes');
7318: } else {
7319: $newval = &mt('No');
7320: }
7321: }
7322: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval));
7323: if ($newnotify) {
1.277 raeburn 7324: $r->print('<br />'.&mt('The following will be notified when an enrollment request needs approval, or has been approved: [_1].',$newnotify));
1.276 raeburn 7325: } else {
1.277 raeburn 7326: $r->print('<br />'.&mt('No notifications sent when an enrollment request needs approval, or has been approved.'));
1.276 raeburn 7327: }
7328: $r->print('</li>'."\n");
7329: }
1.237 raeburn 7330: } else {
7331: if (exists($changes{'internal.selfenroll_'.$item})) {
1.241 raeburn 7332: my $newval = $changes{'internal.selfenroll_'.$item};
7333: if ($item eq 'types') {
7334: if ($newval eq '') {
7335: $newval = &mt('None');
7336: } elsif ($newval eq '*') {
7337: $newval = &mt('Any user in any domain');
7338: }
1.245 raeburn 7339: } elsif ($item eq 'registered') {
7340: if ($newval eq '1') {
7341: $newval = &mt('Yes');
7342: } elsif ($newval eq '0') {
7343: $newval = &mt('No');
7344: }
1.241 raeburn 7345: }
1.244 bisitz 7346: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
1.237 raeburn 7347: }
7348: }
7349: }
7350: $r->print('</ul>');
7351: my %newenvhash;
7352: foreach my $key (keys(%changes)) {
7353: $newenvhash{'course.'.$env{'request.course.id'}.'.'.$key} = $changes{$key};
7354: }
1.238 raeburn 7355: &Apache::lonnet::appenv(\%newenvhash);
1.237 raeburn 7356: } else {
7357: $r->print(&mt('An error occurred when saving changes to self-enrollment settings in this course.').'<br />'.&mt('The error was: [_1].',$putresult));
7358: }
7359: } else {
1.249 raeburn 7360: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.237 raeburn 7361: }
7362: } else {
1.249 raeburn 7363: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.241 raeburn 7364: }
1.256 raeburn 7365: my ($visible,$cansetvis,$vismsgs,$visactions) = &visible_in_cat($cdom,$cnum);
7366: if (ref($visactions) eq 'HASH') {
7367: if (!$visible) {
1.366 bisitz 7368: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
1.256 raeburn 7369: '<br />');
7370: if (ref($vismsgs) eq 'ARRAY') {
7371: $r->print('<br />'.$visactions->{'take'}.'<ul>');
7372: foreach my $item (@{$vismsgs}) {
7373: $r->print('<li>'.$visactions->{$item}.'</li>');
7374: }
7375: $r->print('</ul>');
7376: }
7377: $r->print($cansetvis);
7378: }
7379: }
1.237 raeburn 7380: return;
7381: }
7382:
7383: sub get_selfenroll_titles {
1.276 raeburn 7384: my @row = ('types','registered','enroll_dates','access_dates','section',
7385: 'approval','limit');
1.237 raeburn 7386: my %lt = &Apache::lonlocal::texthash (
7387: types => 'Users allowed to self-enroll in this course',
1.245 raeburn 7388: registered => 'Restrict self-enrollment to students officially registered for the course',
1.237 raeburn 7389: enroll_dates => 'Dates self-enrollment available',
1.256 raeburn 7390: access_dates => 'Course access dates assigned to self-enrolling users',
7391: section => 'Section assigned to self-enrolling users',
1.276 raeburn 7392: approval => 'Self-enrollment requests need approval?',
7393: limit => 'Enrollment limit',
1.237 raeburn 7394: );
7395: return (\@row,\%lt);
7396: }
7397:
1.27 matthew 7398: #---------------------------------------------- end functions for &phase_two
1.29 matthew 7399:
7400: #--------------------------------- functions for &phase_two and &phase_three
7401:
7402: #--------------------------end of functions for &phase_two and &phase_three
1.372 raeburn 7403:
1.1 www 7404: 1;
7405: __END__
1.2 www 7406:
7407:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>