Annotation of loncom/interface/loncreateuser.pm, revision 1.389
1.20 harris41 1: # The LearningOnline Network with CAPA
1.1 www 2: # Create a user
3: #
1.389 ! bisitz 4: # $Id: loncreateuser.pm,v 1.388 2014/02/05 18:02:16 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.389 ! bisitz 1233: my $title = '';
1.216 raeburn 1234: if ($newuser) {
1.362 raeburn 1235: my ($portfolioform,$domroleform);
1.267 raeburn 1236: if ((&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) ||
1237: (&Apache::lonnet::allowed('mut',$env{'request.role.domain'}))) {
1238: # Current user has quota or user tools modification privileges
1.378 raeburn 1239: $portfolioform = '<br />'.&user_quotas($ccuname,$ccdomain);
1.134 raeburn 1240: }
1.383 raeburn 1241: if ((&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) &&
1242: ($ccdomain eq $env{'request.role.domain'})) {
1.362 raeburn 1243: $domroleform = '<br />'.&domainrole_req($ccuname,$ccdomain);
1244: }
1.227 raeburn 1245: &initialize_authen_forms($ccdomain,$formname);
1.188 raeburn 1246: my %lt=&Apache::lonlocal::texthash(
1247: 'lg' => 'Login Data',
1.190 raeburn 1248: 'hs' => "Home Server",
1.188 raeburn 1249: );
1.185 raeburn 1250: $r->print(<<ENDTITLE);
1.110 albertel 1251: $start_page
1.160 raeburn 1252: $response
1.25 matthew 1253: $forminfo
1.31 matthew 1254: <script type="text/javascript" language="Javascript">
1.301 bisitz 1255: // <![CDATA[
1.20 harris41 1256: $loginscript
1.301 bisitz 1257: // ]]>
1.31 matthew 1258: </script>
1.20 harris41 1259: <input type='hidden' name='makeuser' value='1' />
1.185 raeburn 1260: ENDTITLE
1.213 raeburn 1261: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1262: if ($crstype eq 'Community') {
1.389 ! bisitz 1263: $title = &mt('Create New User [_1] in domain [_2] as a member',
! 1264: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1265: } else {
1.389 ! bisitz 1266: $title = &mt('Create New User [_1] in domain [_2] as a student',
! 1267: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1268: }
1.389 ! bisitz 1269: } else {
! 1270: $title = &mt('Create New User [_1] in domain [_2]',
! 1271: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.213 raeburn 1272: }
1.389 ! bisitz 1273: $r->print('<h2>'.$title.'</h2>'."\n");
! 1274: $r->print('<div class="LC_left_float">');
1.206 raeburn 1275: my $personal_table =
1.210 raeburn 1276: &personal_data_display($ccuname,$ccdomain,$newuser,$context,
1277: $inst_results{$ccuname.':'.$ccdomain});
1.388 bisitz 1278: # (Do not offer Disable Safeguard here)
1.206 raeburn 1279: $r->print($personal_table);
1.187 raeburn 1280: my ($home_server_pick,$numlib) =
1281: &Apache::loncommon::home_server_form_item($ccdomain,'hserver',
1282: 'default','hide');
1283: if ($numlib > 1) {
1284: $r->print("
1.185 raeburn 1285: <br />
1.187 raeburn 1286: $lt{'hs'}: $home_server_pick
1287: <br />");
1288: } else {
1289: $r->print($home_server_pick);
1290: }
1.304 raeburn 1291: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.362 raeburn 1292: $r->print('<br /><h3>'.
1293: &mt('User Can Request Creation of Courses/Communities in this Domain?').'</h3>'.
1.304 raeburn 1294: &Apache::loncommon::start_data_table().
1295: &build_tools_display($ccuname,$ccdomain,
1296: 'requestcourses').
1297: &Apache::loncommon::end_data_table());
1298: }
1.188 raeburn 1299: $r->print('</div>'."\n".'<div class="LC_left_float"><h3>'.
1300: $lt{'lg'}.'</h3>');
1.185 raeburn 1301: my ($fixedauth,$varauth,$authmsg);
1.193 raeburn 1302: if (ref($rulematch{$ccuname.':'.$ccdomain}) eq 'HASH') {
1303: my $matchedrule = $rulematch{$ccuname.':'.$ccdomain}{'username'};
1304: my ($rules,$ruleorder) =
1305: &Apache::lonnet::inst_userrules($ccdomain,'username');
1.185 raeburn 1306: if (ref($rules) eq 'HASH') {
1.193 raeburn 1307: if (ref($rules->{$matchedrule}) eq 'HASH') {
1308: my $authtype = $rules->{$matchedrule}{'authtype'};
1.185 raeburn 1309: if ($authtype !~ /^(krb4|krb5|int|fsys|loc)$/) {
1.190 raeburn 1310: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.275 raeburn 1311: } else {
1.193 raeburn 1312: my $authparm = $rules->{$matchedrule}{'authparm'};
1.273 raeburn 1313: $authmsg = $rules->{$matchedrule}{'authmsg'};
1.185 raeburn 1314: if ($authtype =~ /^krb(4|5)$/) {
1315: my $ver = $1;
1316: if ($authparm ne '') {
1317: $fixedauth = <<"KERB";
1318: <input type="hidden" name="login" value="krb" />
1319: <input type="hidden" name="krbver" value="$ver" />
1320: <input type="hidden" name="krbarg" value="$authparm" />
1321: KERB
1322: }
1323: } else {
1324: $fixedauth =
1325: '<input type="hidden" name="login" value="'.$authtype.'" />'."\n";
1.193 raeburn 1326: if ($rules->{$matchedrule}{'authparmfixed'}) {
1.185 raeburn 1327: $fixedauth .=
1328: '<input type="hidden" name="'.$authtype.'arg" value="'.$authparm.'" />'."\n";
1329: } else {
1.273 raeburn 1330: if ($authtype eq 'int') {
1331: $varauth = '<br />'.
1.301 bisitz 1332: &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 1333: } elsif ($authtype eq 'loc') {
1334: $varauth = '<br />'.
1335: &mt('[_1] Local Authentication with argument [_2]','','<input type="text" name="'.$authtype.'arg" value="" />')."\n";
1336: } else {
1337: $varauth =
1.185 raeburn 1338: '<input type="text" name="'.$authtype.'arg" value="" />'."\n";
1.273 raeburn 1339: }
1.185 raeburn 1340: }
1341: }
1342: }
1343: } else {
1.190 raeburn 1344: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.185 raeburn 1345: }
1346: }
1347: if ($authmsg) {
1348: $r->print(<<ENDAUTH);
1349: $fixedauth
1350: $authmsg
1351: $varauth
1352: ENDAUTH
1353: }
1354: } else {
1.190 raeburn 1355: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.187 raeburn 1356: }
1.362 raeburn 1357: $r->print($portfolioform.$domroleform);
1.215 raeburn 1358: if ($env{'form.action'} eq 'singlestudent') {
1359: $r->print(&date_sections_select($context,$newuser,$formname,
1.375 raeburn 1360: $permission,$crstype,$ccuname,
1361: $ccdomain,$showcredits));
1.215 raeburn 1362: }
1363: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.216 raeburn 1364: } else { # user already exists
1.389 ! bisitz 1365: $r->print($start_page.$forminfo);
1.213 raeburn 1366: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1367: if ($crstype eq 'Community') {
1.389 ! bisitz 1368: $title = &mt('Enroll one member: [_1] in domain [_2]',
! 1369: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1370: } else {
1.389 ! bisitz 1371: $title = &mt('Enroll one student: [_1] in domain [_2]',
! 1372: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1373: }
1.213 raeburn 1374: } else {
1.389 ! bisitz 1375: $title = &mt('Modify existing user: [_1] in domain [_2]',
! 1376: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.213 raeburn 1377: }
1.389 ! bisitz 1378: $r->print('<h2>'.$title.'</h2>'."\n");
! 1379: $r->print('<div class="LC_left_float">');
1.388 bisitz 1380: my $personal_table =
1.210 raeburn 1381: &personal_data_display($ccuname,$ccdomain,$newuser,$context,
1382: $inst_results{$ccuname.':'.$ccdomain});
1.206 raeburn 1383: $r->print($personal_table);
1.275 raeburn 1384: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.362 raeburn 1385: $r->print('<br /><h3>'.&mt('User Can Request Creation of Courses/Communities in this Domain?').'</h3>'.
1.300 raeburn 1386: &Apache::loncommon::start_data_table());
1.314 raeburn 1387: if ($env{'request.role.domain'} eq $ccdomain) {
1.300 raeburn 1388: $r->print(&build_tools_display($ccuname,$ccdomain,'requestcourses'));
1389: } else {
1390: $r->print(&coursereq_externaluser($ccuname,$ccdomain,
1391: $env{'request.role.domain'}));
1392: }
1393: $r->print(&Apache::loncommon::end_data_table());
1.275 raeburn 1394: }
1.199 raeburn 1395: $r->print('</div>');
1.362 raeburn 1396: my @order = ('auth','quota','tools','requestauthor');
1397: my %user_text;
1398: my ($isadv,$isauthor) =
1399: &Apache::lonnet::is_advanced_user($ccuname,$ccdomain);
1400: if ((!$isauthor) &&
1.383 raeburn 1401: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))
1402: && ($env{'request.role.domain'} eq $ccdomain)) {
1.362 raeburn 1403: $user_text{'requestauthor'} = &domainrole_req($ccuname,$ccdomain);
1404: }
1405: $user_text{'auth'} = &user_authentication($ccuname,$ccdomain,$formname);
1.267 raeburn 1406: if ((&Apache::lonnet::allowed('mpq',$ccdomain)) ||
1407: (&Apache::lonnet::allowed('mut',$ccdomain))) {
1.188 raeburn 1408: # Current user has quota modification privileges
1.378 raeburn 1409: $user_text{'quota'} = &user_quotas($ccuname,$ccdomain);
1.267 raeburn 1410: }
1411: if (!&Apache::lonnet::allowed('mpq',$ccdomain)) {
1412: if (&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) {
1413: my %lt=&Apache::lonlocal::texthash(
1.385 bisitz 1414: 'dska' => "Disk quotas for user's portfolio and Authoring Space",
1415: 'youd' => "You do not have privileges to modify the portfolio and/or Authoring Space quotas for this user.",
1.267 raeburn 1416: 'ichr' => "If a change is required, contact a domain coordinator for the domain",
1417: );
1.362 raeburn 1418: $user_text{'quota'} = <<ENDNOPORTPRIV;
1.188 raeburn 1419: <h3>$lt{'dska'}</h3>
1420: $lt{'youd'} $lt{'ichr'}: $ccdomain
1421: ENDNOPORTPRIV
1.267 raeburn 1422: }
1423: }
1424: if (!&Apache::lonnet::allowed('mut',$ccdomain)) {
1425: if (&Apache::lonnet::allowed('mut',$env{'request.role.domain'})) {
1426: my %lt=&Apache::lonlocal::texthash(
1427: 'utav' => "User Tools Availability",
1.361 raeburn 1428: 'yodo' => "You do not have privileges to modify Portfolio, Blog, WebDAV, or Personal Information Page settings for this user.",
1.267 raeburn 1429: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
1430: );
1.362 raeburn 1431: $user_text{'tools'} = <<ENDNOTOOLSPRIV;
1.267 raeburn 1432: <h3>$lt{'utav'}</h3>
1433: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1434: ENDNOTOOLSPRIV
1435: }
1.188 raeburn 1436: }
1.362 raeburn 1437: my $gotdiv = 0;
1438: foreach my $item (@order) {
1439: if ($user_text{$item} ne '') {
1440: unless ($gotdiv) {
1441: $r->print('<div class="LC_left_float">');
1442: $gotdiv = 1;
1443: }
1444: $r->print('<br />'.$user_text{$item});
1445: }
1446: }
1447: if ($env{'form.action'} eq 'singlestudent') {
1448: unless ($gotdiv) {
1449: $r->print('<div class="LC_left_float">');
1.213 raeburn 1450: }
1.375 raeburn 1451: my $credits;
1452: if ($showcredits) {
1453: $credits = &get_user_credits($ccuname,$ccdomain,$defaultcredits);
1454: if ($credits eq '') {
1455: $credits = $defaultcredits;
1456: }
1457: }
1.374 raeburn 1458: $r->print(&date_sections_select($context,$newuser,$formname,
1.375 raeburn 1459: $permission,$crstype,$ccuname,
1460: $ccdomain,$showcredits));
1.374 raeburn 1461: }
1.362 raeburn 1462: if ($gotdiv) {
1463: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.188 raeburn 1464: }
1.217 raeburn 1465: if ($env{'form.action'} ne 'singlestudent') {
1.329 raeburn 1466: &display_existing_roles($r,$ccuname,$ccdomain,\%inccourses,$context,
1467: $roledom,$crstype);
1.217 raeburn 1468: }
1.25 matthew 1469: } ## End of new user/old user logic
1.218 raeburn 1470: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1471: my $btntxt;
1472: if ($crstype eq 'Community') {
1473: $btntxt = &mt('Enroll Member');
1474: } else {
1475: $btntxt = &mt('Enroll Student');
1476: }
1477: $r->print('<br /><input type="button" value="'.$btntxt.'" onclick="setSections(this.form)" />'."\n");
1.218 raeburn 1478: } else {
1.375 raeburn 1479: $r->print('<fieldset><legend>'.&mt('Add Roles').'</legend>');
1.218 raeburn 1480: my $addrolesdisplay = 0;
1481: if ($context eq 'domain' || $context eq 'author') {
1482: $addrolesdisplay = &new_coauthor_roles($r,$ccuname,$ccdomain);
1483: }
1484: if ($context eq 'domain') {
1.357 raeburn 1485: my $add_domainroles = &new_domain_roles($r,$ccdomain);
1.218 raeburn 1486: if (!$addrolesdisplay) {
1487: $addrolesdisplay = $add_domainroles;
1.2 www 1488: }
1.375 raeburn 1489: $r->print(&course_level_dc($env{'request.role.domain'},$showcredits));
1490: $r->print('</fieldset><br /><input type="button" value="'.&mt('Save').'" onclick="setCourse()" />'."\n");
1.218 raeburn 1491: } elsif ($context eq 'author') {
1492: if ($addrolesdisplay) {
1.375 raeburn 1493: $r->print('</fieldset><br /><input type="button" value="'.&mt('Save').'"');
1.218 raeburn 1494: if ($newuser) {
1.301 bisitz 1495: $r->print(' onclick="auth_check()" \>'."\n");
1.218 raeburn 1496: } else {
1.301 bisitz 1497: $r->print('onclick="this.form.submit()" \>'."\n");
1.218 raeburn 1498: }
1.188 raeburn 1499: } else {
1.375 raeburn 1500: $r->print('</fieldset><br /><a href="javascript:backPage(document.cu)">'.
1.218 raeburn 1501: &mt('Back to previous page').'</a>');
1.188 raeburn 1502: }
1503: } else {
1.375 raeburn 1504: $r->print(&course_level_table(\%inccourses,$showcredits,$defaultcredits));
1505: $r->print('</fieldset><br /><input type="button" value="'.&mt('Save').'" onclick="setSections(this.form)" />'."\n");
1.188 raeburn 1506: }
1.88 raeburn 1507: }
1.188 raeburn 1508: $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','userrole','ccdomain','prevphase','currstate','ccuname','ccdomain']));
1.179 raeburn 1509: $r->print('<input type="hidden" name="currstate" value="" />');
1.352 raeburn 1510: $r->print('<input type="hidden" name="prevphase" value="'.$env{'form.phase'}.'" /></form>');
1.218 raeburn 1511: return;
1.2 www 1512: }
1.1 www 1513:
1.213 raeburn 1514: sub singleuser_breadcrumb {
1.318 raeburn 1515: my ($crstype) = @_;
1.213 raeburn 1516: my %breadcrumb_text;
1517: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1518: if ($crstype eq 'Community') {
1519: $breadcrumb_text{'search'} = 'Enroll a member';
1520: } else {
1521: $breadcrumb_text{'search'} = 'Enroll a student';
1522: }
1.213 raeburn 1523: $breadcrumb_text{'userpicked'} = 'Select a user',
1524: $breadcrumb_text{'modify'} = 'Set section/dates',
1525: } else {
1.229 raeburn 1526: $breadcrumb_text{'search'} = 'Create/modify a user';
1.213 raeburn 1527: $breadcrumb_text{'userpicked'} = 'Select a user',
1528: $breadcrumb_text{'modify'} = 'Set user role',
1529: }
1530: return %breadcrumb_text;
1531: }
1532:
1533: sub date_sections_select {
1.375 raeburn 1534: my ($context,$newuser,$formname,$permission,$crstype,$ccuname,$ccdomain,
1535: $showcredits) = @_;
1536: my $credits;
1537: if ($showcredits) {
1538: my $defaultcredits = &Apache::lonuserutils::get_defaultcredits();
1539: $credits = &get_user_credits($ccuname,$ccdomain,$defaultcredits);
1540: if ($credits eq '') {
1541: $credits = $defaultcredits;
1542: }
1543: }
1.213 raeburn 1544: my $cid = $env{'request.course.id'};
1545: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity($cid);
1546: my $date_table = '<h3>'.&mt('Starting and Ending Dates').'</h3>'."\n".
1547: &Apache::lonuserutils::date_setting_table(undef,undef,$context,
1548: undef,$formname,$permission);
1549: my $rowtitle = 'Section';
1.375 raeburn 1550: my $secbox = '<h3>'.&mt('Section and Credits').'</h3>'."\n".
1.213 raeburn 1551: &Apache::lonuserutils::section_picker($cdom,$cnum,'st',$rowtitle,
1.375 raeburn 1552: $permission,$context,'',$crstype,
1553: $showcredits,$credits);
1.213 raeburn 1554: my $output = $date_table.$secbox;
1555: return $output;
1556: }
1557:
1.216 raeburn 1558: sub validation_javascript {
1.375 raeburn 1559: my ($context,$ccdomain,$pjump_def,$crstype,$groupslist,$newuser,$formname,
1.216 raeburn 1560: $loaditem) = @_;
1561: my $dc_setcourse_code = '';
1562: my $nondc_setsection_code = '';
1563: if ($context eq 'domain') {
1564: my $dcdom = $env{'request.role.domain'};
1565: $loaditem->{'onload'} = "document.cu.coursedesc.value='';";
1.227 raeburn 1566: $dc_setcourse_code =
1567: &Apache::lonuserutils::dc_setcourse_js('cu','singleuser',$context);
1.216 raeburn 1568: } else {
1.227 raeburn 1569: my $checkauth;
1570: if (($newuser) || (&Apache::lonnet::allowed('mau',$ccdomain))) {
1571: $checkauth = 1;
1572: }
1573: if ($context eq 'course') {
1574: $nondc_setsection_code =
1575: &Apache::lonuserutils::setsections_javascript($formname,$groupslist,
1.375 raeburn 1576: undef,$checkauth,
1577: $crstype);
1.227 raeburn 1578: }
1579: if ($checkauth) {
1580: $nondc_setsection_code .=
1581: &Apache::lonuserutils::verify_authen($formname,$context);
1582: }
1.216 raeburn 1583: }
1584: my $js = &user_modification_js($pjump_def,$dc_setcourse_code,
1585: $nondc_setsection_code,$groupslist);
1586: my ($jsback,$elements) = &crumb_utilities();
1587: $js .= "\n".
1.301 bisitz 1588: '<script type="text/javascript">'."\n".
1589: '// <![CDATA['."\n".
1590: $jsback."\n".
1591: '// ]]>'."\n".
1592: '</script>'."\n";
1.216 raeburn 1593: return $js;
1594: }
1595:
1.217 raeburn 1596: sub display_existing_roles {
1.375 raeburn 1597: my ($r,$ccuname,$ccdomain,$inccourses,$context,$roledom,$crstype,
1598: $showcredits) = @_;
1.329 raeburn 1599: my $now=time;
1600: my %lt=&Apache::lonlocal::texthash(
1.217 raeburn 1601: 'rer' => "Existing Roles",
1602: 'rev' => "Revoke",
1603: 'del' => "Delete",
1604: 'ren' => "Re-Enable",
1605: 'rol' => "Role",
1606: 'ext' => "Extent",
1.375 raeburn 1607: 'crd' => "Credits",
1.217 raeburn 1608: 'sta' => "Start",
1609: 'end' => "End",
1610: );
1.329 raeburn 1611: my (%rolesdump,%roletext,%sortrole,%roleclass,%rolepriv);
1612: if ($context eq 'course' || $context eq 'author') {
1613: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
1614: my %roleshash =
1615: &Apache::lonnet::get_my_roles($ccuname,$ccdomain,'userroles',
1616: ['active','previous','future'],\@roles,$roledom,1);
1617: foreach my $key (keys(%roleshash)) {
1618: my ($start,$end) = split(':',$roleshash{$key});
1619: next if ($start eq '-1' || $end eq '-1');
1620: my ($rnum,$rdom,$role,$sec) = split(':',$key);
1621: if ($context eq 'course') {
1622: next unless (($rnum eq $env{'course.'.$env{'request.course.id'}.'.num'})
1623: && ($rdom eq $env{'course.'.$env{'request.course.id'}.'.domain'}));
1624: } elsif ($context eq 'author') {
1625: next unless (($rnum eq $env{'user.name'}) && ($rdom eq $env{'request.role.domain'}));
1626: }
1627: my ($newkey,$newvalue,$newrole);
1628: $newkey = '/'.$rdom.'/'.$rnum;
1629: if ($sec ne '') {
1630: $newkey .= '/'.$sec;
1631: }
1632: $newvalue = $role;
1633: if ($role =~ /^cr/) {
1634: $newrole = 'cr';
1635: } else {
1636: $newrole = $role;
1637: }
1638: $newkey .= '_'.$newrole;
1639: if ($start ne '' && $end ne '') {
1640: $newvalue .= '_'.$end.'_'.$start;
1.335 raeburn 1641: } elsif ($end ne '') {
1642: $newvalue .= '_'.$end;
1.329 raeburn 1643: }
1644: $rolesdump{$newkey} = $newvalue;
1645: }
1646: } else {
1.360 raeburn 1647: %rolesdump=&Apache::lonnet::dump('roles',$ccdomain,$ccuname);
1.329 raeburn 1648: }
1649: # Build up table of user roles to allow revocation and re-enabling of roles.
1650: my ($tmp) = keys(%rolesdump);
1651: return if ($tmp =~ /^(con_lost|error)/i);
1652: foreach my $area (sort { my $a1=join('_',(split('_',$a))[1,0]);
1653: my $b1=join('_',(split('_',$b))[1,0]);
1654: return $a1 cmp $b1;
1655: } keys(%rolesdump)) {
1656: next if ($area =~ /^rolesdef/);
1657: my $envkey=$area;
1658: my $role = $rolesdump{$area};
1659: my $thisrole=$area;
1660: $area =~ s/\_\w\w$//;
1661: my ($role_code,$role_end_time,$role_start_time) =
1662: split(/_/,$role);
1.217 raeburn 1663: # Is this a custom role? Get role owner and title.
1.329 raeburn 1664: my ($croleudom,$croleuname,$croletitle)=
1665: ($role_code=~m{^cr/($match_domain)/($match_username)/(\w+)$});
1666: my $allowed=0;
1667: my $delallowed=0;
1668: my $sortkey=$role_code;
1669: my $class='Unknown';
1.375 raeburn 1670: my $credits='';
1.329 raeburn 1671: if ($area =~ m{^/($match_domain)/($match_courseid)} ) {
1672: $class='Course';
1673: my ($coursedom,$coursedir) = ($1,$2);
1674: my $cid = $1.'_'.$2;
1675: # $1.'_'.$2 is the course id (eg. 103_12345abcef103l3).
1676: my %coursedata=
1677: &Apache::lonnet::coursedescription($cid);
1678: if ($coursedir =~ /^$match_community$/) {
1679: $class='Community';
1680: }
1681: $sortkey.="\0$coursedom";
1682: my $carea;
1683: if (defined($coursedata{'description'})) {
1684: $carea=$coursedata{'description'}.
1685: '<br />'.&mt('Domain').': '.$coursedom.(' 'x8).
1686: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$coursedir,$coursedom);
1687: $sortkey.="\0".$coursedata{'description'};
1688: } else {
1689: if ($class eq 'Community') {
1690: $carea=&mt('Unavailable community').': '.$area;
1691: $sortkey.="\0".&mt('Unavailable community').': '.$area;
1.217 raeburn 1692: } else {
1693: $carea=&mt('Unavailable course').': '.$area;
1694: $sortkey.="\0".&mt('Unavailable course').': '.$area;
1695: }
1.329 raeburn 1696: }
1697: $sortkey.="\0$coursedir";
1698: $inccourses->{$cid}=1;
1.375 raeburn 1699: if (($showcredits) && ($class eq 'Course') && ($role_code eq 'st')) {
1700: my $defaultcredits = $coursedata{'internal.defaultcredits'};
1701: $credits =
1702: &get_user_credits($ccuname,$ccdomain,$defaultcredits,
1703: $coursedom,$coursedir);
1704: if ($credits eq '') {
1705: $credits = $defaultcredits;
1706: }
1707: }
1.329 raeburn 1708: if ((&Apache::lonnet::allowed('c'.$role_code,$coursedom.'/'.$coursedir)) ||
1709: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
1710: $allowed=1;
1711: }
1712: unless ($allowed) {
1.365 raeburn 1713: my $isowner = &Apache::lonuserutils::is_courseowner($cid,$coursedata{'internal.courseowner'});
1.329 raeburn 1714: if ($isowner) {
1715: if (($role_code eq 'co') && ($class eq 'Community')) {
1716: $allowed = 1;
1717: } elsif (($role_code eq 'cc') && ($class eq 'Course')) {
1718: $allowed = 1;
1719: }
1.217 raeburn 1720: }
1.329 raeburn 1721: }
1722: if ((&Apache::lonnet::allowed('dro',$coursedom)) ||
1723: (&Apache::lonnet::allowed('dro',$ccdomain))) {
1724: $delallowed=1;
1725: }
1.217 raeburn 1726: # - custom role. Needs more info, too
1.329 raeburn 1727: if ($croletitle) {
1728: if (&Apache::lonnet::allowed('ccr',$coursedom.'/'.$coursedir)) {
1729: $allowed=1;
1730: $thisrole.='.'.$role_code;
1.217 raeburn 1731: }
1.329 raeburn 1732: }
1733: if ($area=~m{^/($match_domain)/($match_courseid)/(\w+)}) {
1.373 bisitz 1734: $carea.='<br />'.&mt('Section: [_1]',$3);
1.329 raeburn 1735: $sortkey.="\0$3";
1736: if (!$allowed) {
1737: if ($env{'request.course.sec'} eq $3) {
1738: if (&Apache::lonnet::allowed('c'.$role_code,$1.'/'.$2.'/'.$3)) {
1739: $allowed = 1;
1.217 raeburn 1740: }
1741: }
1742: }
1.329 raeburn 1743: }
1744: $area=$carea;
1745: } else {
1746: $sortkey.="\0".$area;
1747: # Determine if current user is able to revoke privileges
1748: if ($area=~m{^/($match_domain)/}) {
1749: if ((&Apache::lonnet::allowed('c'.$role_code,$1)) ||
1750: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
1751: $allowed=1;
1.217 raeburn 1752: }
1.329 raeburn 1753: if (((&Apache::lonnet::allowed('dro',$1)) ||
1754: (&Apache::lonnet::allowed('dro',$ccdomain))) &&
1755: ($role_code ne 'dc')) {
1756: $delallowed=1;
1.217 raeburn 1757: }
1.329 raeburn 1758: } else {
1759: if (&Apache::lonnet::allowed('c'.$role_code,'/')) {
1.217 raeburn 1760: $allowed=1;
1761: }
1762: }
1.363 raeburn 1763: if ($role_code eq 'ca' || $role_code eq 'au' || $role_code eq 'aa') {
1.377 raeburn 1764: $class='Authoring Space';
1.329 raeburn 1765: } elsif ($role_code eq 'su') {
1766: $class='System';
1.217 raeburn 1767: } else {
1.329 raeburn 1768: $class='Domain';
1.217 raeburn 1769: }
1.329 raeburn 1770: }
1771: if (($role_code eq 'ca') || ($role_code eq 'aa')) {
1772: $area=~m{/($match_domain)/($match_username)};
1773: if (&Apache::lonuserutils::authorpriv($2,$1)) {
1774: $allowed=1;
1.217 raeburn 1775: } else {
1.329 raeburn 1776: $allowed=0;
1.217 raeburn 1777: }
1.329 raeburn 1778: }
1779: my $row = '';
1780: $row.= '<td>';
1781: my $active=1;
1782: $active=0 if (($role_end_time) && ($now>$role_end_time));
1783: if (($active) && ($allowed)) {
1784: $row.= '<input type="checkbox" name="rev:'.$thisrole.'" />';
1785: } else {
1786: if ($active) {
1787: $row.=' ';
1.217 raeburn 1788: } else {
1.329 raeburn 1789: $row.=&mt('expired or revoked');
1.217 raeburn 1790: }
1.329 raeburn 1791: }
1792: $row.='</td><td>';
1793: if ($allowed && !$active) {
1794: $row.= '<input type="checkbox" name="ren:'.$thisrole.'" />';
1795: } else {
1796: $row.=' ';
1797: }
1798: $row.='</td><td>';
1799: if ($delallowed) {
1800: $row.= '<input type="checkbox" name="del:'.$thisrole.'" />';
1801: } else {
1802: $row.=' ';
1803: }
1804: my $plaintext='';
1805: if (!$croletitle) {
1.375 raeburn 1806: $plaintext=&Apache::lonnet::plaintext($role_code,$class);
1807: if (($showcredits) && ($credits ne '')) {
1808: $plaintext .= '<br/ ><span class="LC_nobreak">'.
1809: '<span class="LC_fontsize_small">'.
1810: &mt('Credits: [_1]',$credits).
1811: '</span></span>';
1812: }
1.329 raeburn 1813: } else {
1814: $plaintext=
1.346 bisitz 1815: &mt('Customrole [_1][_2]defined by [_3]',
1816: '"'.$croletitle.'"',
1817: '<br />',
1818: $croleuname.':'.$croleudom);
1.329 raeburn 1819: }
1820: $row.= '</td><td>'.$plaintext.
1821: '</td><td>'.$area.
1822: '</td><td>'.($role_start_time?&Apache::lonlocal::locallocaltime($role_start_time)
1823: : ' ' ).
1824: '</td><td>'.($role_end_time ?&Apache::lonlocal::locallocaltime($role_end_time)
1825: : ' ' )
1826: ."</td>";
1827: $sortrole{$sortkey}=$envkey;
1828: $roletext{$envkey}=$row;
1829: $roleclass{$envkey}=$class;
1830: $rolepriv{$envkey}=$allowed;
1831: } # end of foreach (table building loop)
1832:
1833: my $rolesdisplay = 0;
1834: my %output = ();
1.377 raeburn 1835: foreach my $type ('Authoring Space','Course','Community','Domain','System','Unknown') {
1.329 raeburn 1836: $output{$type} = '';
1837: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
1838: if ( ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/ ) && ($rolepriv{$sortrole{$which}}) ) {
1839: $output{$type}.=
1840: &Apache::loncommon::start_data_table_row().
1841: $roletext{$sortrole{$which}}.
1842: &Apache::loncommon::end_data_table_row();
1.217 raeburn 1843: }
1.329 raeburn 1844: }
1845: unless($output{$type} eq '') {
1846: $output{$type} = '<tr class="LC_info_row">'.
1847: "<td align='center' colspan='7'>".&mt($type)."</td></tr>".
1848: $output{$type};
1849: $rolesdisplay = 1;
1850: }
1851: }
1852: if ($rolesdisplay == 1) {
1853: my $contextrole='';
1854: if ($env{'request.course.id'}) {
1855: if (&Apache::loncommon::course_type() eq 'Community') {
1856: $contextrole = &mt('Existing Roles in this Community');
1.290 bisitz 1857: } else {
1.329 raeburn 1858: $contextrole = &mt('Existing Roles in this Course');
1.290 bisitz 1859: }
1.329 raeburn 1860: } elsif ($env{'request.role'} =~ /^au\./) {
1.377 raeburn 1861: $contextrole = &mt('Existing Co-Author Roles in your Authoring Space');
1.329 raeburn 1862: } else {
1863: $contextrole = &mt('Existing Roles in this Domain');
1864: }
1.375 raeburn 1865: $r->print('<div>'.
1866: '<fieldset><legend>'.$contextrole.'</legend>'.
1.217 raeburn 1867: &Apache::loncommon::start_data_table("LC_createuser").
1868: &Apache::loncommon::start_data_table_header_row().
1869: '<th>'.$lt{'rev'}.'</th><th>'.$lt{'ren'}.'</th><th>'.$lt{'del'}.
1870: '</th><th>'.$lt{'rol'}.'</th><th>'.$lt{'ext'}.
1871: '</th><th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
1872: &Apache::loncommon::end_data_table_header_row());
1.377 raeburn 1873: foreach my $type ('Authoring Space','Course','Community','Domain','System','Unknown') {
1.329 raeburn 1874: if ($output{$type}) {
1875: $r->print($output{$type}."\n");
1.217 raeburn 1876: }
1877: }
1.375 raeburn 1878: $r->print(&Apache::loncommon::end_data_table().
1879: '</fieldset></div>');
1.329 raeburn 1880: }
1.217 raeburn 1881: return;
1882: }
1883:
1.218 raeburn 1884: sub new_coauthor_roles {
1885: my ($r,$ccuname,$ccdomain) = @_;
1886: my $addrolesdisplay = 0;
1887: #
1888: # Co-Author
1889: #
1890: if (&Apache::lonuserutils::authorpriv($env{'user.name'},
1891: $env{'request.role.domain'}) &&
1892: ($env{'user.name'} ne $ccuname || $env{'user.domain'} ne $ccdomain)) {
1893: # No sense in assigning co-author role to yourself
1894: $addrolesdisplay = 1;
1895: my $cuname=$env{'user.name'};
1896: my $cudom=$env{'request.role.domain'};
1897: my %lt=&Apache::lonlocal::texthash(
1.377 raeburn 1898: 'cs' => "Authoring Space",
1.218 raeburn 1899: 'act' => "Activate",
1900: 'rol' => "Role",
1901: 'ext' => "Extent",
1902: 'sta' => "Start",
1903: 'end' => "End",
1904: 'cau' => "Co-Author",
1905: 'caa' => "Assistant Co-Author",
1906: 'ssd' => "Set Start Date",
1907: 'sed' => "Set End Date"
1908: );
1909: $r->print('<h4>'.$lt{'cs'}.'</h4>'."\n".
1910: &Apache::loncommon::start_data_table()."\n".
1911: &Apache::loncommon::start_data_table_header_row()."\n".
1912: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'.
1913: '<th>'.$lt{'ext'}.'</th><th>'.$lt{'sta'}.'</th>'.
1914: '<th>'.$lt{'end'}.'</th>'."\n".
1915: &Apache::loncommon::end_data_table_header_row()."\n".
1916: &Apache::loncommon::start_data_table_row().'
1917: <td>
1.291 bisitz 1918: <input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_ca" />
1.218 raeburn 1919: </td>
1920: <td>'.$lt{'cau'}.'</td>
1921: <td>'.$cudom.'_'.$cuname.'</td>
1922: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_ca" value="" />
1923: <a href=
1924: "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>
1925: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_ca" value="" />
1926: <a href=
1927: "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".
1928: &Apache::loncommon::end_data_table_row()."\n".
1929: &Apache::loncommon::start_data_table_row()."\n".
1.291 bisitz 1930: '<td><input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_aa" /></td>
1.218 raeburn 1931: <td>'.$lt{'caa'}.'</td>
1932: <td>'.$cudom.'_'.$cuname.'</td>
1933: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_aa" value="" />
1934: <a href=
1935: "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>
1936: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_aa" value="" />
1937: <a href=
1938: "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".
1939: &Apache::loncommon::end_data_table_row()."\n".
1940: &Apache::loncommon::end_data_table());
1941: } elsif ($env{'request.role'} =~ /^au\./) {
1942: if (!(&Apache::lonuserutils::authorpriv($env{'user.name'},
1943: $env{'request.role.domain'}))) {
1944: $r->print('<span class="LC_error">'.
1945: &mt('You do not have privileges to assign co-author roles.').
1946: '</span>');
1947: } elsif (($env{'user.name'} eq $ccuname) &&
1948: ($env{'user.domain'} eq $ccdomain)) {
1.377 raeburn 1949: $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 1950: }
1951: }
1952: return $addrolesdisplay;;
1953: }
1954:
1955: sub new_domain_roles {
1.357 raeburn 1956: my ($r,$ccdomain) = @_;
1.218 raeburn 1957: my $addrolesdisplay = 0;
1958: #
1959: # Domain level
1960: #
1961: my $num_domain_level = 0;
1962: my $domaintext =
1963: '<h4>'.&mt('Domain Level').'</h4>'.
1964: &Apache::loncommon::start_data_table().
1965: &Apache::loncommon::start_data_table_header_row().
1966: '<th>'.&mt('Activate').'</th><th>'.&mt('Role').'</th><th>'.
1967: &mt('Extent').'</th>'.
1968: '<th>'.&mt('Start').'</th><th>'.&mt('End').'</th>'.
1969: &Apache::loncommon::end_data_table_header_row();
1.312 raeburn 1970: my @allroles = &Apache::lonuserutils::roles_by_context('domain');
1.218 raeburn 1971: foreach my $thisdomain (sort(&Apache::lonnet::all_domains())) {
1.312 raeburn 1972: foreach my $role (@allroles) {
1973: next if ($role eq 'ad');
1.357 raeburn 1974: next if (($role eq 'au') && ($ccdomain ne $thisdomain));
1.218 raeburn 1975: if (&Apache::lonnet::allowed('c'.$role,$thisdomain)) {
1976: my $plrole=&Apache::lonnet::plaintext($role);
1977: my %lt=&Apache::lonlocal::texthash(
1978: 'ssd' => "Set Start Date",
1979: 'sed' => "Set End Date"
1980: );
1981: $num_domain_level ++;
1982: $domaintext .=
1983: &Apache::loncommon::start_data_table_row().
1.291 bisitz 1984: '<td><input type="checkbox" name="act_'.$thisdomain.'_'.$role.'" /></td>
1.218 raeburn 1985: <td>'.$plrole.'</td>
1986: <td>'.$thisdomain.'</td>
1987: <td><input type="hidden" name="start_'.$thisdomain.'_'.$role.'" value="" />
1988: <a href=
1989: "javascript:pjump('."'date_start','Start Date $plrole',document.cu.start_$thisdomain\_$role.value,'start_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'ssd'}.'</a></td>
1990: <td><input type="hidden" name="end_'.$thisdomain.'_'.$role.'" value="" />
1991: <a href=
1992: "javascript:pjump('."'date_end','End Date $plrole',document.cu.end_$thisdomain\_$role.value,'end_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'sed'}.'</a></td>'.
1993: &Apache::loncommon::end_data_table_row();
1994: }
1995: }
1996: }
1997: $domaintext.= &Apache::loncommon::end_data_table();
1998: if ($num_domain_level > 0) {
1999: $r->print($domaintext);
2000: $addrolesdisplay = 1;
2001: }
2002: return $addrolesdisplay;
2003: }
2004:
1.188 raeburn 2005: sub user_authentication {
1.227 raeburn 2006: my ($ccuname,$ccdomain,$formname) = @_;
1.188 raeburn 2007: my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
1.227 raeburn 2008: my $outcome;
1.188 raeburn 2009: # Check for a bad authentication type
2010: if ($currentauth !~ /^(krb4|krb5|unix|internal|localauth):/) {
2011: # bad authentication scheme
2012: my %lt=&Apache::lonlocal::texthash(
2013: 'err' => "ERROR",
2014: 'uuas' => "This user has an unrecognized authentication scheme",
2015: 'adcs' => "Please alert a domain coordinator of this situation",
2016: 'sldb' => "Please specify login data below",
2017: 'ld' => "Login Data"
2018: );
2019: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
1.227 raeburn 2020: &initialize_authen_forms($ccdomain,$formname);
2021:
1.190 raeburn 2022: my $choices = &Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc);
1.188 raeburn 2023: $outcome = <<ENDBADAUTH;
2024: <script type="text/javascript" language="Javascript">
1.301 bisitz 2025: // <![CDATA[
1.188 raeburn 2026: $loginscript
1.301 bisitz 2027: // ]]>
1.188 raeburn 2028: </script>
2029: <span class="LC_error">$lt{'err'}:
2030: $lt{'uuas'} ($currentauth). $lt{'sldb'}.</span>
2031: <h3>$lt{'ld'}</h3>
2032: $choices
2033: ENDBADAUTH
2034: } else {
2035: # This user is not allowed to modify the user's
2036: # authentication scheme, so just notify them of the problem
2037: $outcome = <<ENDBADAUTH;
2038: <span class="LC_error"> $lt{'err'}:
2039: $lt{'uuas'} ($currentauth). $lt{'adcs'}.
2040: </span>
2041: ENDBADAUTH
2042: }
2043: } else { # Authentication type is valid
1.227 raeburn 2044: &initialize_authen_forms($ccdomain,$formname,$currentauth,'modifyuser');
1.205 raeburn 2045: my ($authformcurrent,$can_modify,@authform_others) =
1.188 raeburn 2046: &modify_login_block($ccdomain,$currentauth);
2047: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
2048: # Current user has login modification privileges
2049: my %lt=&Apache::lonlocal::texthash (
2050: 'ld' => "Login Data",
2051: 'ccld' => "Change Current Login Data",
2052: 'enld' => "Enter New Login Data"
2053: );
2054: $outcome =
2055: '<script type="text/javascript" language="Javascript">'."\n".
1.301 bisitz 2056: '// <![CDATA['."\n".
1.188 raeburn 2057: $loginscript."\n".
1.301 bisitz 2058: '// ]]>'."\n".
1.188 raeburn 2059: '</script>'."\n".
2060: '<h3>'.$lt{'ld'}.'</h3>'.
2061: &Apache::loncommon::start_data_table().
1.205 raeburn 2062: &Apache::loncommon::start_data_table_row().
1.188 raeburn 2063: '<td>'.$authformnop;
2064: if ($can_modify) {
2065: $outcome .= '</td>'."\n".
2066: &Apache::loncommon::end_data_table_row().
2067: &Apache::loncommon::start_data_table_row().
2068: '<td>'.$authformcurrent.'</td>'.
2069: &Apache::loncommon::end_data_table_row()."\n";
2070: } else {
1.200 raeburn 2071: $outcome .= ' ('.$authformcurrent.')</td>'.
2072: &Apache::loncommon::end_data_table_row()."\n";
1.188 raeburn 2073: }
1.205 raeburn 2074: foreach my $item (@authform_others) {
2075: $outcome .= &Apache::loncommon::start_data_table_row().
2076: '<td>'.$item.'</td>'.
2077: &Apache::loncommon::end_data_table_row()."\n";
1.188 raeburn 2078: }
1.205 raeburn 2079: $outcome .= &Apache::loncommon::end_data_table();
1.188 raeburn 2080: } else {
2081: if (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
2082: my %lt=&Apache::lonlocal::texthash(
2083: 'ccld' => "Change Current Login Data",
2084: 'yodo' => "You do not have privileges to modify the authentication configuration for this user.",
2085: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
2086: );
2087: $outcome .= <<ENDNOPRIV;
2088: <h3>$lt{'ccld'}</h3>
2089: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1.235 raeburn 2090: <input type="hidden" name="login" value="nochange" />
1.188 raeburn 2091: ENDNOPRIV
2092: }
2093: }
2094: } ## End of "check for bad authentication type" logic
2095: return $outcome;
2096: }
2097:
1.187 raeburn 2098: sub modify_login_block {
2099: my ($dom,$currentauth) = @_;
2100: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2101: my ($authnum,%can_assign) =
2102: &Apache::loncommon::get_assignable_auth($dom);
1.205 raeburn 2103: my ($authformcurrent,@authform_others,$show_override_msg);
1.187 raeburn 2104: if ($currentauth=~/^krb(4|5):/) {
2105: $authformcurrent=$authformkrb;
2106: if ($can_assign{'int'}) {
1.205 raeburn 2107: push(@authform_others,$authformint);
1.187 raeburn 2108: }
2109: if ($can_assign{'loc'}) {
1.205 raeburn 2110: push(@authform_others,$authformloc);
1.187 raeburn 2111: }
2112: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
2113: $show_override_msg = 1;
2114: }
2115: } elsif ($currentauth=~/^internal:/) {
2116: $authformcurrent=$authformint;
2117: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2118: push(@authform_others,$authformkrb);
1.187 raeburn 2119: }
2120: if ($can_assign{'loc'}) {
1.205 raeburn 2121: push(@authform_others,$authformloc);
1.187 raeburn 2122: }
2123: if ($can_assign{'int'}) {
2124: $show_override_msg = 1;
2125: }
2126: } elsif ($currentauth=~/^unix:/) {
2127: $authformcurrent=$authformfsys;
2128: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2129: push(@authform_others,$authformkrb);
1.187 raeburn 2130: }
2131: if ($can_assign{'int'}) {
1.205 raeburn 2132: push(@authform_others,$authformint);
1.187 raeburn 2133: }
2134: if ($can_assign{'loc'}) {
1.205 raeburn 2135: push(@authform_others,$authformloc);
1.187 raeburn 2136: }
2137: if ($can_assign{'fsys'}) {
2138: $show_override_msg = 1;
2139: }
2140: } elsif ($currentauth=~/^localauth:/) {
2141: $authformcurrent=$authformloc;
2142: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2143: push(@authform_others,$authformkrb);
1.187 raeburn 2144: }
2145: if ($can_assign{'int'}) {
1.205 raeburn 2146: push(@authform_others,$authformint);
1.187 raeburn 2147: }
2148: if ($can_assign{'loc'}) {
2149: $show_override_msg = 1;
2150: }
2151: }
2152: if ($show_override_msg) {
1.205 raeburn 2153: $authformcurrent = '<table><tr><td colspan="3">'.$authformcurrent.
2154: '</td></tr>'."\n".
2155: '<tr><td> </td>'.
2156: '<td><b>'.&mt('Currently in use').'</b></td>'.
2157: '<td align="right"><span class="LC_cusr_emph">'.
1.187 raeburn 2158: &mt('will override current values').
1.205 raeburn 2159: '</span></td></tr></table>';
1.187 raeburn 2160: }
1.205 raeburn 2161: return ($authformcurrent,$show_override_msg,@authform_others);
1.187 raeburn 2162: }
2163:
1.188 raeburn 2164: sub personal_data_display {
1.252 raeburn 2165: my ($ccuname,$ccdomain,$newuser,$context,$inst_results,$rolesarray) = @_;
1.388 bisitz 2166: my ($output,%userenv,%canmodify,%canmodify_status);
1.219 raeburn 2167: my @userinfo = ('firstname','middlename','lastname','generation',
2168: 'permanentemail','id');
1.252 raeburn 2169: my $rowcount = 0;
2170: my $editable = 0;
1.286 raeburn 2171: %canmodify_status =
2172: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
2173: ['inststatus'],$rolesarray);
1.253 raeburn 2174: if (!$newuser) {
1.188 raeburn 2175: # Get the users information
2176: %userenv = &Apache::lonnet::get('environment',
2177: ['firstname','middlename','lastname','generation',
1.286 raeburn 2178: 'permanentemail','id','inststatus'],$ccdomain,$ccuname);
1.219 raeburn 2179: %canmodify =
2180: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
1.252 raeburn 2181: \@userinfo,$rolesarray);
1.257 raeburn 2182: } elsif ($context eq 'selfcreate') {
2183: %canmodify = &selfcreate_canmodify($context,$ccdomain,\@userinfo,
2184: $inst_results,$rolesarray);
1.188 raeburn 2185: }
2186: my %lt=&Apache::lonlocal::texthash(
2187: 'pd' => "Personal Data",
2188: 'firstname' => "First Name",
2189: 'middlename' => "Middle Name",
2190: 'lastname' => "Last Name",
2191: 'generation' => "Generation",
2192: 'permanentemail' => "Permanent e-mail address",
1.259 bisitz 2193: 'id' => "Student/Employee ID",
1.286 raeburn 2194: 'lg' => "Login Data",
2195: 'inststatus' => "Affiliation",
1.188 raeburn 2196: );
2197: my %textboxsize = (
2198: firstname => '15',
2199: middlename => '15',
2200: lastname => '15',
2201: generation => '5',
2202: permanentemail => '25',
2203: id => '15',
2204: );
2205: my $genhelp=&Apache::loncommon::help_open_topic('Generation');
2206: $output = '<h3>'.$lt{'pd'}.'</h3>'.
2207: &Apache::lonhtmlcommon::start_pick_box();
2208: foreach my $item (@userinfo) {
2209: my $rowtitle = $lt{$item};
1.252 raeburn 2210: my $hiderow = 0;
1.188 raeburn 2211: if ($item eq 'generation') {
2212: $rowtitle = $genhelp.$rowtitle;
2213: }
1.252 raeburn 2214: my $row = &Apache::lonhtmlcommon::row_title($rowtitle,undef,'LC_oddrow_value')."\n";
1.188 raeburn 2215: if ($newuser) {
1.210 raeburn 2216: if (ref($inst_results) eq 'HASH') {
2217: if ($inst_results->{$item} ne '') {
1.252 raeburn 2218: $row .= '<input type="hidden" name="c'.$item.'" value="'.$inst_results->{$item}.'" />'.$inst_results->{$item};
1.210 raeburn 2219: } else {
1.252 raeburn 2220: if ($context eq 'selfcreate') {
2221: if ($canmodify{$item}) {
2222: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
2223: $editable ++;
2224: } else {
2225: $hiderow = 1;
2226: }
1.253 raeburn 2227: } else {
2228: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1.252 raeburn 2229: }
1.210 raeburn 2230: }
1.188 raeburn 2231: } else {
1.252 raeburn 2232: if ($context eq 'selfcreate') {
1.287 raeburn 2233: if (($item eq 'permanentemail') && ($newuser eq 'email')) {
2234: $row .= $ccuname;
1.252 raeburn 2235: } else {
1.287 raeburn 2236: if ($canmodify{$item}) {
2237: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
2238: $editable ++;
2239: } else {
2240: $hiderow = 1;
2241: }
1.252 raeburn 2242: }
1.253 raeburn 2243: } else {
2244: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1.252 raeburn 2245: }
1.188 raeburn 2246: }
2247: } else {
1.219 raeburn 2248: if ($canmodify{$item}) {
1.252 raeburn 2249: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="'.$userenv{$item}.'" />';
1.188 raeburn 2250: } else {
1.252 raeburn 2251: $row .= $userenv{$item};
1.188 raeburn 2252: }
1.388 bisitz 2253: if (($item eq 'id') && ($canmodify{$item})) {
2254: $row .= '<br />'.&Apache::lonuserutils::forceid_change($context);
1.219 raeburn 2255: }
1.188 raeburn 2256: }
1.252 raeburn 2257: $row .= &Apache::lonhtmlcommon::row_closure(1);
2258: if (!$hiderow) {
2259: $output .= $row;
2260: $rowcount ++;
2261: }
1.188 raeburn 2262: }
1.286 raeburn 2263: if (($canmodify_status{'inststatus'}) || ($context ne 'selfcreate')) {
2264: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($ccdomain);
2265: if (ref($types) eq 'ARRAY') {
2266: if (@{$types} > 0) {
2267: my ($hiderow,$shown);
2268: if ($canmodify_status{'inststatus'}) {
2269: $shown = &pick_inst_statuses($userenv{'inststatus'},$usertypes,$types);
2270: } else {
2271: if ($userenv{'inststatus'} eq '') {
2272: $hiderow = 1;
1.334 raeburn 2273: } else {
2274: my @showitems;
2275: foreach my $item ( map { &unescape($_); } split(':',$userenv{'inststatus'})) {
2276: if (exists($usertypes->{$item})) {
2277: push(@showitems,$usertypes->{$item});
2278: } else {
2279: push(@showitems,$item);
2280: }
2281: }
2282: if (@showitems) {
2283: $shown = join(', ',@showitems);
2284: } else {
2285: $hiderow = 1;
2286: }
1.286 raeburn 2287: }
2288: }
2289: if (!$hiderow) {
1.389 ! bisitz 2290: my $row = &Apache::lonhtmlcommon::row_title(&mt('Affiliations'),undef,'LC_oddrow_value')."\n".
1.286 raeburn 2291: $shown.&Apache::lonhtmlcommon::row_closure(1);
2292: if ($context eq 'selfcreate') {
2293: $rowcount ++;
2294: }
2295: $output .= $row;
2296: }
2297: }
2298: }
2299: }
1.188 raeburn 2300: $output .= &Apache::lonhtmlcommon::end_pick_box();
1.206 raeburn 2301: if (wantarray) {
1.252 raeburn 2302: if ($context eq 'selfcreate') {
2303: return($output,$rowcount,$editable);
2304: } else {
1.388 bisitz 2305: return $output;
1.252 raeburn 2306: }
1.206 raeburn 2307: } else {
2308: return $output;
2309: }
1.188 raeburn 2310: }
2311:
1.286 raeburn 2312: sub pick_inst_statuses {
2313: my ($curr,$usertypes,$types) = @_;
2314: my ($output,$rem,@currtypes);
2315: if ($curr ne '') {
2316: @currtypes = map { &unescape($_); } split(/:/,$curr);
2317: }
2318: my $numinrow = 2;
2319: if (ref($types) eq 'ARRAY') {
2320: $output = '<table>';
2321: my $lastcolspan;
2322: for (my $i=0; $i<@{$types}; $i++) {
2323: if (defined($usertypes->{$types->[$i]})) {
2324: my $rem = $i%($numinrow);
2325: if ($rem == 0) {
2326: if ($i<@{$types}-1) {
2327: if ($i > 0) {
2328: $output .= '</tr>';
2329: }
2330: $output .= '<tr>';
2331: }
2332: } elsif ($i==@{$types}-1) {
2333: my $colsleft = $numinrow - $rem;
2334: if ($colsleft > 1) {
2335: $lastcolspan = ' colspan="'.$colsleft.'"';
2336: }
2337: }
2338: my $check = ' ';
2339: if (grep(/^\Q$types->[$i]\E$/,@currtypes)) {
2340: $check = ' checked="checked" ';
2341: }
2342: $output .= '<td class="LC_left_item"'.$lastcolspan.'>'.
2343: '<span class="LC_nobreak"><label>'.
2344: '<input type="checkbox" name="inststatus" '.
2345: 'value="'.$types->[$i].'"'.$check.'/>'.
2346: $usertypes->{$types->[$i]}.'</label></span></td>';
2347: }
2348: }
2349: $output .= '</tr></table>';
2350: }
2351: return $output;
2352: }
2353:
1.257 raeburn 2354: sub selfcreate_canmodify {
2355: my ($context,$dom,$userinfo,$inst_results,$rolesarray) = @_;
2356: if (ref($inst_results) eq 'HASH') {
2357: my @inststatuses = &get_inststatuses($inst_results);
2358: if (@inststatuses == 0) {
2359: @inststatuses = ('default');
2360: }
2361: $rolesarray = \@inststatuses;
2362: }
2363: my %canmodify =
2364: &Apache::lonuserutils::can_modify_userinfo($context,$dom,$userinfo,
2365: $rolesarray);
2366: return %canmodify;
2367: }
2368:
1.252 raeburn 2369: sub get_inststatuses {
2370: my ($insthashref) = @_;
2371: my @inststatuses = ();
2372: if (ref($insthashref) eq 'HASH') {
2373: if (ref($insthashref->{'inststatus'}) eq 'ARRAY') {
2374: @inststatuses = @{$insthashref->{'inststatus'}};
2375: }
2376: }
2377: return @inststatuses;
2378: }
2379:
1.4 www 2380: # ================================================================= Phase Three
1.42 matthew 2381: sub update_user_data {
1.375 raeburn 2382: my ($r,$context,$crstype,$brcrum,$showcredits) = @_;
1.101 albertel 2383: my $uhome=&Apache::lonnet::homeserver($env{'form.ccuname'},
2384: $env{'form.ccdomain'});
1.27 matthew 2385: # Error messages
1.188 raeburn 2386: my $error = '<span class="LC_error">'.&mt('Error').': ';
1.193 raeburn 2387: my $end = '</span><br /><br />';
2388: my $rtnlink = '<a href="javascript:backPage(document.userupdate,'.
1.188 raeburn 2389: "'$env{'form.prevphase'}','modify')".'" />'.
1.219 raeburn 2390: &mt('Return to previous page').'</a>'.
2391: &Apache::loncommon::end_page();
2392: my $now = time;
1.40 www 2393: my $title;
1.101 albertel 2394: if (exists($env{'form.makeuser'})) {
1.40 www 2395: $title='Set Privileges for New User';
2396: } else {
2397: $title='Modify User Privileges';
2398: }
1.213 raeburn 2399: my $newuser = 0;
1.160 raeburn 2400: my ($jsback,$elements) = &crumb_utilities();
2401: my $jscript = '<script type="text/javascript">'."\n".
1.301 bisitz 2402: '// <![CDATA['."\n".
2403: $jsback."\n".
2404: '// ]]>'."\n".
2405: '</script>'."\n";
1.318 raeburn 2406: my %breadcrumb_text = &singleuser_breadcrumb($crstype);
1.351 raeburn 2407: push (@{$brcrum},
2408: {href => "javascript:backPage(document.userupdate)",
2409: text => $breadcrumb_text{'search'},
2410: faq => 282,
2411: bug => 'Instructor Interface',}
2412: );
2413: if ($env{'form.prevphase'} eq 'userpicked') {
2414: push(@{$brcrum},
2415: {href => "javascript:backPage(document.userupdate,'get_user_info','select')",
2416: text => $breadcrumb_text{'userpicked'},
2417: faq => 282,
2418: bug => 'Instructor Interface',});
1.233 raeburn 2419: }
1.224 raeburn 2420: my $helpitem = 'Course_Change_Privileges';
2421: if ($env{'form.action'} eq 'singlestudent') {
2422: $helpitem = 'Course_Add_Student';
2423: }
1.351 raeburn 2424: push(@{$brcrum},
2425: {href => "javascript:backPage(document.userupdate,'$env{'form.prevphase'}','modify')",
2426: text => $breadcrumb_text{'modify'},
2427: faq => 282,
2428: bug => 'Instructor Interface',},
2429: {href => "/adm/createuser",
2430: text => "Result",
2431: faq => 282,
2432: bug => 'Instructor Interface',
2433: help => $helpitem});
2434: my $args = {bread_crumbs => $brcrum,
2435: bread_crumbs_component => 'User Management'};
2436: if ($env{'form.popup'}) {
2437: $args->{'no_nav_bar'} = 1;
2438: }
2439: $r->print(&Apache::loncommon::start_page($title,$jscript,$args));
1.188 raeburn 2440: $r->print(&update_result_form($uhome));
1.27 matthew 2441: # Check Inputs
1.101 albertel 2442: if (! $env{'form.ccuname'} ) {
1.193 raeburn 2443: $r->print($error.&mt('No login name specified').'.'.$end.$rtnlink);
1.27 matthew 2444: return;
2445: }
1.138 albertel 2446: if ( $env{'form.ccuname'} ne
2447: &LONCAPA::clean_username($env{'form.ccuname'}) ) {
1.281 bisitz 2448: $r->print($error.&mt('Invalid login name.').' '.
2449: &mt('Only letters, numbers, periods, dashes, @, and underscores are valid.').
1.193 raeburn 2450: $end.$rtnlink);
1.27 matthew 2451: return;
2452: }
1.101 albertel 2453: if (! $env{'form.ccdomain'} ) {
1.193 raeburn 2454: $r->print($error.&mt('No domain specified').'.'.$end.$rtnlink);
1.27 matthew 2455: return;
2456: }
1.138 albertel 2457: if ( $env{'form.ccdomain'} ne
2458: &LONCAPA::clean_domain($env{'form.ccdomain'}) ) {
1.281 bisitz 2459: $r->print($error.&mt('Invalid domain name.').' '.
2460: &mt('Only letters, numbers, periods, dashes, and underscores are valid.').
1.193 raeburn 2461: $end.$rtnlink);
1.27 matthew 2462: return;
2463: }
1.219 raeburn 2464: if ($uhome eq 'no_host') {
2465: $newuser = 1;
2466: }
1.101 albertel 2467: if (! exists($env{'form.makeuser'})) {
1.29 matthew 2468: # Modifying an existing user, so check the validity of the name
2469: if ($uhome eq 'no_host') {
1.389 ! bisitz 2470: $r->print(
! 2471: $error
! 2472: .'<p class="LC_error">'
! 2473: .&mt('Unable to determine home server for [_1] in domain [_2].',
! 2474: '"'.$env{'form.ccuname'}.'"','"'.$env{'form.ccdomain'}.'"')
! 2475: .'</p>');
1.29 matthew 2476: return;
2477: }
2478: }
1.27 matthew 2479: # Determine authentication method and password for the user being modified
2480: my $amode='';
2481: my $genpwd='';
1.101 albertel 2482: if ($env{'form.login'} eq 'krb') {
1.41 albertel 2483: $amode='krb';
1.101 albertel 2484: $amode.=$env{'form.krbver'};
2485: $genpwd=$env{'form.krbarg'};
2486: } elsif ($env{'form.login'} eq 'int') {
1.27 matthew 2487: $amode='internal';
1.101 albertel 2488: $genpwd=$env{'form.intarg'};
2489: } elsif ($env{'form.login'} eq 'fsys') {
1.27 matthew 2490: $amode='unix';
1.101 albertel 2491: $genpwd=$env{'form.fsysarg'};
2492: } elsif ($env{'form.login'} eq 'loc') {
1.27 matthew 2493: $amode='localauth';
1.101 albertel 2494: $genpwd=$env{'form.locarg'};
1.27 matthew 2495: $genpwd=" " if (!$genpwd);
1.101 albertel 2496: } elsif (($env{'form.login'} eq 'nochange') ||
2497: ($env{'form.login'} eq '' )) {
1.34 matthew 2498: # There is no need to tell the user we did not change what they
2499: # did not ask us to change.
1.35 matthew 2500: # If they are creating a new user but have not specified login
2501: # information this will be caught below.
1.30 matthew 2502: } else {
1.367 golterma 2503: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
2504: return;
1.27 matthew 2505: }
1.164 albertel 2506:
1.188 raeburn 2507: $r->print('<h3>'.&mt('User [_1] in domain [_2]',
1.367 golterma 2508: $env{'form.ccuname'}.' ('.&Apache::loncommon::plainname($env{'form.ccuname'},
2509: $env{'form.ccdomain'}).')', $env{'form.ccdomain'}).'</h3>');
2510: my %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($r,2);
1.344 bisitz 2511:
1.193 raeburn 2512: my (%alerts,%rulematch,%inst_results,%curr_rules);
1.334 raeburn 2513: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
1.361 raeburn 2514: my @usertools = ('aboutme','blog','webdav','portfolio');
1.384 raeburn 2515: my @requestcourses = ('official','unofficial','community','textbook');
1.362 raeburn 2516: my @requestauthor = ('requestauthor');
1.286 raeburn 2517: my ($othertitle,$usertypes,$types) =
2518: &Apache::loncommon::sorted_inst_types($env{'form.ccdomain'});
1.334 raeburn 2519: my %canmodify_status =
2520: &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},
2521: ['inststatus']);
1.101 albertel 2522: if ($env{'form.makeuser'}) {
1.164 albertel 2523: $r->print('<h3>'.&mt('Creating new account.').'</h3>');
1.27 matthew 2524: # Check for the authentication mode and password
2525: if (! $amode || ! $genpwd) {
1.193 raeburn 2526: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
1.27 matthew 2527: return;
1.18 albertel 2528: }
1.29 matthew 2529: # Determine desired host
1.101 albertel 2530: my $desiredhost = $env{'form.hserver'};
1.29 matthew 2531: if (lc($desiredhost) eq 'default') {
2532: $desiredhost = undef;
2533: } else {
1.147 albertel 2534: my %home_servers =
2535: &Apache::lonnet::get_servers($env{'form.ccdomain'},'library');
1.29 matthew 2536: if (! exists($home_servers{$desiredhost})) {
1.193 raeburn 2537: $r->print($error.&mt('Invalid home server specified').$end.$rtnlink);
2538: return;
2539: }
2540: }
2541: # Check ID format
2542: my %checkhash;
2543: my %checks = ('id' => 1);
2544: %{$checkhash{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}}} = (
1.219 raeburn 2545: 'newuser' => $newuser,
1.196 raeburn 2546: 'id' => $env{'form.cid'},
1.193 raeburn 2547: );
1.196 raeburn 2548: if ($env{'form.cid'} ne '') {
2549: &Apache::loncommon::user_rule_check(\%checkhash,\%checks,\%alerts,
2550: \%rulematch,\%inst_results,\%curr_rules);
2551: if (ref($alerts{'id'}) eq 'HASH') {
2552: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
2553: my $domdesc =
2554: &Apache::lonnet::domain($env{'form.ccdomain'},'description');
2555: if ($alerts{'id'}{$env{'form.ccdomain'}}{$env{'form.cid'}}) {
2556: my $userchkmsg;
2557: if (ref($curr_rules{$env{'form.ccdomain'}}) eq 'HASH') {
2558: $userchkmsg =
2559: &Apache::loncommon::instrule_disallow_msg('id',
2560: $domdesc,1).
2561: &Apache::loncommon::user_rule_formats($env{'form.ccdomain'},
2562: $domdesc,$curr_rules{$env{'form.ccdomain'}}{'id'},'id');
2563: }
2564: $r->print($error.&mt('Invalid ID format').$end.
2565: $userchkmsg.$rtnlink);
2566: return;
2567: }
2568: }
1.29 matthew 2569: }
2570: }
1.367 golterma 2571: &Apache::lonhtmlcommon::Increment_PrgWin($r, \%prog_state);
1.27 matthew 2572: # Call modifyuser
2573: my $result = &Apache::lonnet::modifyuser
1.193 raeburn 2574: ($env{'form.ccdomain'},$env{'form.ccuname'},$env{'form.cid'},
1.188 raeburn 2575: $amode,$genpwd,$env{'form.cfirstname'},
2576: $env{'form.cmiddlename'},$env{'form.clastname'},
2577: $env{'form.cgeneration'},undef,$desiredhost,
2578: $env{'form.cpermanentemail'});
1.77 www 2579: $r->print(&mt('Generating user').': '.$result);
1.219 raeburn 2580: $uhome = &Apache::lonnet::homeserver($env{'form.ccuname'},
1.101 albertel 2581: $env{'form.ccdomain'});
1.334 raeburn 2582: my (%changeHash,%newcustom,%changed,%changedinfo);
1.267 raeburn 2583: if ($uhome ne 'no_host') {
1.334 raeburn 2584: if ($context eq 'domain') {
1.378 raeburn 2585: foreach my $name ('portfolio','author') {
2586: if ($env{'form.custom_'.$name.'quota'} == 1) {
2587: if ($env{'form.'.$name.'quota'} eq '') {
2588: $newcustom{$name.'quota'} = 0;
2589: } else {
2590: $newcustom{$name.'quota'} = $env{'form.'.$name.'quota'};
2591: $newcustom{$name.'quota'} =~ s/[^\d\.]//g;
2592: }
2593: if ("a_admin($newcustom{$name.'quota'},\%changeHash,$name)) {
2594: $changed{$name.'quota'} = 1;
2595: }
1.334 raeburn 2596: }
2597: }
2598: foreach my $item (@usertools) {
2599: if ($env{'form.custom'.$item} == 1) {
2600: $newcustom{$item} = $env{'form.tools_'.$item};
2601: $changed{$item} = &tool_admin($item,$newcustom{$item},
2602: \%changeHash,'tools');
2603: }
1.267 raeburn 2604: }
1.334 raeburn 2605: foreach my $item (@requestcourses) {
1.341 raeburn 2606: if ($env{'form.custom'.$item} == 1) {
2607: $newcustom{$item} = $env{'form.crsreq_'.$item};
2608: if ($env{'form.crsreq_'.$item} eq 'autolimit') {
2609: $newcustom{$item} .= '=';
1.383 raeburn 2610: $env{'form.crsreq_'.$item.'_limit'} =~ s/\D+//g;
2611: if ($env{'form.crsreq_'.$item.'_limit'}) {
1.341 raeburn 2612: $newcustom{$item} .= $env{'form.crsreq_'.$item.'_limit'};
2613: }
1.334 raeburn 2614: }
1.341 raeburn 2615: $changed{$item} = &tool_admin($item,$newcustom{$item},
2616: \%changeHash,'requestcourses');
1.334 raeburn 2617: }
1.275 raeburn 2618: }
1.362 raeburn 2619: if ($env{'form.customrequestauthor'} == 1) {
2620: $newcustom{'requestauthor'} = $env{'form.requestauthor'};
2621: $changed{'requestauthor'} = &tool_admin('requestauthor',
2622: $newcustom{'requestauthor'},
2623: \%changeHash,'requestauthor');
2624: }
1.275 raeburn 2625: }
1.334 raeburn 2626: if ($canmodify_status{'inststatus'}) {
2627: if (exists($env{'form.inststatus'})) {
2628: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
2629: if (@inststatuses > 0) {
2630: $changeHash{'inststatus'} = join(',',@inststatuses);
2631: $changed{'inststatus'} = $changeHash{'inststatus'};
1.306 raeburn 2632: }
2633: }
1.232 raeburn 2634: }
1.334 raeburn 2635: if (keys(%changed)) {
2636: foreach my $item (@userinfo) {
2637: $changeHash{$item} = $env{'form.c'.$item};
1.286 raeburn 2638: }
1.267 raeburn 2639: my $chgresult =
2640: &Apache::lonnet::put('environment',\%changeHash,
2641: $env{'form.ccdomain'},$env{'form.ccuname'});
2642: }
1.232 raeburn 2643: }
1.219 raeburn 2644: $r->print('<br />'.&mt('Home server').': '.$uhome.' '.
2645: &Apache::lonnet::hostname($uhome));
1.101 albertel 2646: } elsif (($env{'form.login'} ne 'nochange') &&
2647: ($env{'form.login'} ne '' )) {
1.27 matthew 2648: # Modify user privileges
2649: if (! $amode || ! $genpwd) {
1.193 raeburn 2650: $r->print($error.'Invalid login mode or password'.$end.$rtnlink);
1.27 matthew 2651: return;
1.20 harris41 2652: }
1.27 matthew 2653: # Only allow authentification modification if the person has authority
1.101 albertel 2654: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.20 harris41 2655: $r->print('Modifying authentication: '.
1.31 matthew 2656: &Apache::lonnet::modifyuserauth(
1.101 albertel 2657: $env{'form.ccdomain'},$env{'form.ccuname'},
1.21 harris41 2658: $amode,$genpwd));
1.102 albertel 2659: $r->print('<br />'.&mt('Home server').': '.&Apache::lonnet::homeserver
1.101 albertel 2660: ($env{'form.ccuname'},$env{'form.ccdomain'}));
1.4 www 2661: } else {
1.27 matthew 2662: # Okay, this is a non-fatal error.
1.193 raeburn 2663: $r->print($error.&mt('You do not have the authority to modify this users authentification information').'.'.$end);
1.27 matthew 2664: }
1.28 matthew 2665: }
1.344 bisitz 2666: $r->rflush(); # Finish display of header before time consuming actions start
1.367 golterma 2667: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state);
1.28 matthew 2668: ##
1.375 raeburn 2669: my (@userroles,%userupdate,$cnum,$cdom,$defaultcredits,%namechanged);
1.213 raeburn 2670: if ($context eq 'course') {
1.375 raeburn 2671: ($cnum,$cdom) =
2672: &Apache::lonuserutils::get_course_identity();
1.318 raeburn 2673: $crstype = &Apache::loncommon::course_type($cdom.'_'.$cnum);
1.375 raeburn 2674: if ($showcredits) {
2675: $defaultcredits = &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
2676: }
1.213 raeburn 2677: }
1.101 albertel 2678: if (! $env{'form.makeuser'} ) {
1.28 matthew 2679: # Check for need to change
2680: my %userenv = &Apache::lonnet::get
1.134 raeburn 2681: ('environment',['firstname','middlename','lastname','generation',
1.378 raeburn 2682: 'id','permanentemail','portfolioquota','authorquota','inststatus',
2683: 'tools.aboutme','tools.blog','tools.webdav','tools.portfolio',
1.361 raeburn 2684: 'requestcourses.official','requestcourses.unofficial',
1.384 raeburn 2685: 'requestcourses.community','requestcourses.textbook',
2686: 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
2687: 'reqcrsotherdom.community','reqcrsotherdom.textbook',
1.362 raeburn 2688: 'requestauthor'],
1.160 raeburn 2689: $env{'form.ccdomain'},$env{'form.ccuname'});
1.28 matthew 2690: my ($tmp) = keys(%userenv);
2691: if ($tmp =~ /^(con_lost|error)/i) {
2692: %userenv = ();
2693: }
1.206 raeburn 2694: my $no_forceid_alert;
2695: # Check to see if user information can be changed
2696: my %domconfig =
2697: &Apache::lonnet::get_dom('configuration',['usermodification'],
2698: $env{'form.ccdomain'});
1.213 raeburn 2699: my @statuses = ('active','future');
2700: my %roles = &Apache::lonnet::get_my_roles($env{'form.ccuname'},$env{'form.ccdomain'},'userroles',\@statuses,undef,$env{'request.role.domain'});
2701: my ($auname,$audom);
1.220 raeburn 2702: if ($context eq 'author') {
1.206 raeburn 2703: $auname = $env{'user.name'};
2704: $audom = $env{'user.domain'};
2705: }
2706: foreach my $item (keys(%roles)) {
1.220 raeburn 2707: my ($rolenum,$roledom,$role) = split(/:/,$item,-1);
1.206 raeburn 2708: if ($context eq 'course') {
2709: if ($cnum ne '' && $cdom ne '') {
2710: if ($rolenum eq $cnum && $roledom eq $cdom) {
2711: if (!grep(/^\Q$role\E$/,@userroles)) {
2712: push(@userroles,$role);
2713: }
2714: }
2715: }
2716: } elsif ($context eq 'author') {
2717: if ($rolenum eq $auname && $roledom eq $audom) {
2718: if (!grep(/^\Q$role\E$/,@userroles)) {
2719: push(@userroles,$role);
2720: }
2721: }
2722: }
2723: }
1.220 raeburn 2724: if ($env{'form.action'} eq 'singlestudent') {
2725: if (!grep(/^st$/,@userroles)) {
2726: push(@userroles,'st');
2727: }
2728: } else {
2729: # Check for course or co-author roles being activated or re-enabled
2730: if ($context eq 'author' || $context eq 'course') {
2731: foreach my $key (keys(%env)) {
2732: if ($context eq 'author') {
2733: if ($key=~/^form\.act_\Q$audom\E_\Q$auname\E_([^_]+)/) {
2734: if (!grep(/^\Q$1\E$/,@userroles)) {
2735: push(@userroles,$1);
2736: }
2737: } elsif ($key =~/^form\.ren\:\Q$audom\E\/\Q$auname\E_([^_]+)/) {
2738: if (!grep(/^\Q$1\E$/,@userroles)) {
2739: push(@userroles,$1);
2740: }
1.206 raeburn 2741: }
1.220 raeburn 2742: } elsif ($context eq 'course') {
2743: if ($key=~/^form\.act_\Q$cdom\E_\Q$cnum\E_([^_]+)/) {
2744: if (!grep(/^\Q$1\E$/,@userroles)) {
2745: push(@userroles,$1);
2746: }
2747: } elsif ($key =~/^form\.ren\:\Q$cdom\E\/\Q$cnum\E(\/?\w*)_([^_]+)/) {
2748: if (!grep(/^\Q$1\E$/,@userroles)) {
2749: push(@userroles,$1);
2750: }
1.206 raeburn 2751: }
2752: }
2753: }
2754: }
2755: }
2756: #Check to see if we can change personal data for the user
2757: my (@mod_disallowed,@longroles);
2758: foreach my $role (@userroles) {
2759: if ($role eq 'cr') {
2760: push(@longroles,'Custom');
2761: } else {
1.318 raeburn 2762: push(@longroles,&Apache::lonnet::plaintext($role,$crstype));
1.206 raeburn 2763: }
2764: }
1.219 raeburn 2765: my %canmodify = &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},\@userinfo,\@userroles);
2766: foreach my $item (@userinfo) {
1.28 matthew 2767: # Strip leading and trailing whitespace
1.203 raeburn 2768: $env{'form.c'.$item} =~ s/(\s+$|^\s+)//g;
1.219 raeburn 2769: if (!$canmodify{$item}) {
1.207 raeburn 2770: if (defined($env{'form.c'.$item})) {
2771: if ($env{'form.c'.$item} ne $userenv{$item}) {
2772: push(@mod_disallowed,$item);
2773: }
1.206 raeburn 2774: }
2775: $env{'form.c'.$item} = $userenv{$item};
2776: }
1.28 matthew 2777: }
1.259 bisitz 2778: # Check to see if we can change the Student/Employee ID
1.196 raeburn 2779: my $forceid = $env{'form.forceid'};
2780: my $recurseid = $env{'form.recurseid'};
2781: my (%alerts,%rulematch,%idinst_results,%curr_rules,%got_rules);
1.203 raeburn 2782: my %uidhash = &Apache::lonnet::idrget($env{'form.ccdomain'},
2783: $env{'form.ccuname'});
2784: if (($uidhash{$env{'form.ccuname'}}) &&
2785: ($uidhash{$env{'form.ccuname'}}!~/error\:/) &&
2786: (!$forceid)) {
2787: if ($env{'form.cid'} ne $uidhash{$env{'form.ccuname'}}) {
2788: $env{'form.cid'} = $userenv{'id'};
1.293 bisitz 2789: $no_forceid_alert = &mt('New student/employee ID does not match existing ID for this user.')
1.259 bisitz 2790: .'<br />'
2791: .&mt("Change is not permitted without checking the 'Force ID change' checkbox on the previous page.")
2792: .'<br />'."\n";
1.203 raeburn 2793: }
2794: }
2795: if ($env{'form.cid'} ne $userenv{'id'}) {
1.196 raeburn 2796: my $checkhash;
2797: my $checks = { 'id' => 1 };
2798: $checkhash->{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}} =
2799: { 'newuser' => $newuser,
2800: 'id' => $env{'form.cid'},
2801: };
2802: &Apache::loncommon::user_rule_check($checkhash,$checks,
2803: \%alerts,\%rulematch,\%idinst_results,\%curr_rules,\%got_rules);
2804: if (ref($alerts{'id'}) eq 'HASH') {
2805: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
1.203 raeburn 2806: $env{'form.cid'} = $userenv{'id'};
1.196 raeburn 2807: }
2808: }
2809: }
1.378 raeburn 2810: my (%quotachanged,%oldquota,%newquota,%olddefquota,%newdefquota,
2811: $oldinststatus,$newinststatus,%oldisdefault,%newisdefault,%oldsettings,
1.339 raeburn 2812: %oldsettingstext,%newsettings,%newsettingstext,@disporder,
1.378 raeburn 2813: %oldsettingstatus,%newsettingstatus);
1.334 raeburn 2814: @disporder = ('inststatus');
2815: if ($env{'request.role.domain'} eq $env{'form.ccdomain'}) {
1.362 raeburn 2816: push(@disporder,'requestcourses','requestauthor');
1.334 raeburn 2817: } else {
2818: push(@disporder,'reqcrsotherdom');
2819: }
2820: push(@disporder,('quota','tools'));
1.338 raeburn 2821: $oldinststatus = $userenv{'inststatus'};
1.378 raeburn 2822: foreach my $name ('portfolio','author') {
2823: ($olddefquota{$name},$oldsettingstatus{$name}) =
2824: &Apache::loncommon::default_quota($env{'form.ccdomain'},$oldinststatus,$name);
2825: ($newdefquota{$name},$newsettingstatus{$name}) = ($olddefquota{$name},$oldsettingstatus{$name});
2826: }
1.334 raeburn 2827: my %canshow;
1.220 raeburn 2828: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
1.334 raeburn 2829: $canshow{'quota'} = 1;
1.220 raeburn 2830: }
1.267 raeburn 2831: if (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
1.334 raeburn 2832: $canshow{'tools'} = 1;
1.267 raeburn 2833: }
1.275 raeburn 2834: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
1.334 raeburn 2835: $canshow{'requestcourses'} = 1;
1.300 raeburn 2836: } elsif (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.334 raeburn 2837: $canshow{'reqcrsotherdom'} = 1;
1.275 raeburn 2838: }
1.286 raeburn 2839: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.334 raeburn 2840: $canshow{'inststatus'} = 1;
1.286 raeburn 2841: }
1.362 raeburn 2842: if (&Apache::lonnet::allowed('cau',$env{'form.ccdomain'})) {
2843: $canshow{'requestauthor'} = 1;
2844: }
1.267 raeburn 2845: my (%changeHash,%changed);
1.286 raeburn 2846: if ($oldinststatus eq '') {
1.334 raeburn 2847: $oldsettings{'inststatus'} = $othertitle;
1.286 raeburn 2848: } else {
2849: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 2850: $oldsettings{'inststatus'} = join(', ',map{ $usertypes->{ &unescape($_) }; } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 2851: } else {
1.334 raeburn 2852: $oldsettings{'inststatus'} = join(', ',map{ &unescape($_); } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 2853: }
2854: }
2855: $changeHash{'inststatus'} = $userenv{'inststatus'};
1.334 raeburn 2856: if ($canmodify_status{'inststatus'}) {
2857: $canshow{'inststatus'} = 1;
1.286 raeburn 2858: if (exists($env{'form.inststatus'})) {
2859: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
2860: if (@inststatuses > 0) {
2861: $newinststatus = join(':',map { &escape($_); } @inststatuses);
2862: $changeHash{'inststatus'} = $newinststatus;
2863: if ($newinststatus ne $oldinststatus) {
2864: $changed{'inststatus'} = $newinststatus;
1.378 raeburn 2865: foreach my $name ('portfolio','author') {
2866: ($newdefquota{$name},$newsettingstatus{$name}) =
2867: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
2868: }
1.286 raeburn 2869: }
2870: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 2871: $newsettings{'inststatus'} = join(', ',map{ $usertypes->{$_}; } (@inststatuses));
1.286 raeburn 2872: } else {
1.337 raeburn 2873: $newsettings{'inststatus'} = join(', ',@inststatuses);
1.286 raeburn 2874: }
1.334 raeburn 2875: }
2876: } else {
2877: $newinststatus = '';
2878: $changeHash{'inststatus'} = $newinststatus;
2879: $newsettings{'inststatus'} = $othertitle;
2880: if ($newinststatus ne $oldinststatus) {
2881: $changed{'inststatus'} = $changeHash{'inststatus'};
1.378 raeburn 2882: foreach my $name ('portfolio','author') {
2883: ($newdefquota{$name},$newsettingstatus{$name}) =
2884: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
2885: }
1.286 raeburn 2886: }
2887: }
1.334 raeburn 2888: } elsif ($context ne 'selfcreate') {
2889: $canshow{'inststatus'} = 1;
1.337 raeburn 2890: $newsettings{'inststatus'} = $oldsettings{'inststatus'};
1.286 raeburn 2891: }
1.378 raeburn 2892: foreach my $name ('portfolio','author') {
2893: $changeHash{$name.'quota'} = $userenv{$name.'quota'};
2894: }
1.334 raeburn 2895: if ($context eq 'domain') {
1.378 raeburn 2896: foreach my $name ('portfolio','author') {
2897: if ($userenv{$name.'quota'} ne '') {
2898: $oldquota{$name} = $userenv{$name.'quota'};
2899: if ($env{'form.custom_'.$name.'quota'} == 1) {
2900: if ($env{'form.'.$name.'quota'} eq '') {
2901: $newquota{$name} = 0;
2902: } else {
2903: $newquota{$name} = $env{'form.'.$name.'quota'};
2904: $newquota{$name} =~ s/[^\d\.]//g;
2905: }
2906: if ($newquota{$name} != $oldquota{$name}) {
2907: if ("a_admin($newquota{$name},\%changeHash,$name)) {
2908: $changed{$name.'quota'} = 1;
2909: }
2910: }
1.334 raeburn 2911: } else {
1.378 raeburn 2912: if ("a_admin('',\%changeHash,$name)) {
2913: $changed{$name.'quota'} = 1;
2914: $newquota{$name} = $newdefquota{$name};
2915: $newisdefault{$name} = 1;
2916: }
1.334 raeburn 2917: }
1.149 raeburn 2918: } else {
1.378 raeburn 2919: $oldisdefault{$name} = 1;
2920: $oldquota{$name} = $olddefquota{$name};
2921: if ($env{'form.custom_'.$name.'quota'} == 1) {
2922: if ($env{'form.'.$name.'quota'} eq '') {
2923: $newquota{$name} = 0;
2924: } else {
2925: $newquota{$name} = $env{'form.'.$name.'quota'};
2926: $newquota{$name} =~ s/[^\d\.]//g;
2927: }
2928: if ("a_admin($newquota{$name},\%changeHash,$name)) {
2929: $changed{$name.'quota'} = 1;
2930: }
1.334 raeburn 2931: } else {
1.378 raeburn 2932: $newquota{$name} = $newdefquota{$name};
2933: $newisdefault{$name} = 1;
1.334 raeburn 2934: }
1.378 raeburn 2935: }
2936: if ($oldisdefault{$name}) {
2937: $oldsettingstext{'quota'}{$name} = &get_defaultquota_text($oldsettingstatus{$name});
1.383 raeburn 2938: } else {
2939: $oldsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$oldquota{$name});
1.378 raeburn 2940: }
2941: if ($newisdefault{$name}) {
2942: $newsettingstext{'quota'}{$name} = &get_defaultquota_text($newsettingstatus{$name});
1.383 raeburn 2943: } else {
2944: $newsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$newquota{$name});
1.134 raeburn 2945: }
2946: }
1.334 raeburn 2947: &tool_changes('tools',\@usertools,\%oldsettings,\%oldsettingstext,\%userenv,
2948: \%changeHash,\%changed,\%newsettings,\%newsettingstext);
2949: if ($env{'form.ccdomain'} eq $env{'request.role.domain'}) {
2950: &tool_changes('requestcourses',\@requestcourses,\%oldsettings,\%oldsettingstext,
2951: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.384 raeburn 2952: &tool_changes('requestauthor',\@requestauthor,\%oldsettings,\%oldsettingstext,
2953: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 2954: } else {
1.334 raeburn 2955: &tool_changes('reqcrsotherdom',\@requestcourses,\%oldsettings,\%oldsettingstext,
2956: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 2957: }
2958: }
1.334 raeburn 2959: foreach my $item (@userinfo) {
2960: if ($env{'form.c'.$item} ne $userenv{$item}) {
2961: $namechanged{$item} = 1;
2962: }
1.204 raeburn 2963: }
1.378 raeburn 2964: foreach my $name ('portfolio','author') {
1.383 raeburn 2965: $oldsettings{'quota'}{$name} = $oldquota{$name}.' MB';
2966: $newsettings{'quota'}{$name} = $newquota{$name}.' MB';
1.378 raeburn 2967: }
1.334 raeburn 2968: if ((keys(%namechanged) > 0) || (keys(%changed) > 0)) {
1.267 raeburn 2969: my ($chgresult,$namechgresult);
2970: if (keys(%changed) > 0) {
2971: $chgresult =
1.204 raeburn 2972: &Apache::lonnet::put('environment',\%changeHash,
2973: $env{'form.ccdomain'},$env{'form.ccuname'});
1.267 raeburn 2974: if ($chgresult eq 'ok') {
2975: if (($env{'user.name'} eq $env{'form.ccuname'}) &&
2976: ($env{'user.domain'} eq $env{'form.ccdomain'})) {
1.270 raeburn 2977: my %newenvhash;
2978: foreach my $key (keys(%changed)) {
1.299 raeburn 2979: if (($key eq 'official') || ($key eq 'unofficial')
2980: || ($key eq 'community')) {
1.279 raeburn 2981: $newenvhash{'environment.requestcourses.'.$key} =
2982: $changeHash{'requestcourses.'.$key};
1.362 raeburn 2983: if ($changeHash{'requestcourses.'.$key}) {
1.332 raeburn 2984: $newenvhash{'environment.canrequest.'.$key} = 1;
1.279 raeburn 2985: } else {
2986: $newenvhash{'environment.canrequest.'.$key} =
2987: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
2988: $key,'reload','requestcourses');
2989: }
1.362 raeburn 2990: } elsif ($key eq 'requestauthor') {
2991: $newenvhash{'environment.'.$key} = $changeHash{$key};
2992: if ($changeHash{$key}) {
2993: $newenvhash{'environment.canrequest.author'} = 1;
2994: } else {
2995: $newenvhash{'environment.canrequest.author'} =
2996: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
2997: $key,'reload','requestauthor');
2998: }
1.275 raeburn 2999: } elsif ($key ne 'quota') {
1.270 raeburn 3000: $newenvhash{'environment.tools.'.$key} =
3001: $changeHash{'tools.'.$key};
1.279 raeburn 3002: if ($changeHash{'tools.'.$key} ne '') {
3003: $newenvhash{'environment.availabletools.'.$key} =
3004: $changeHash{'tools.'.$key};
3005: } else {
3006: $newenvhash{'environment.availabletools.'.$key} =
1.367 golterma 3007: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3008: $key,'reload','tools');
1.279 raeburn 3009: }
1.270 raeburn 3010: }
3011: }
1.271 raeburn 3012: if (keys(%newenvhash)) {
3013: &Apache::lonnet::appenv(\%newenvhash);
3014: }
1.267 raeburn 3015: }
3016: }
1.204 raeburn 3017: }
1.334 raeburn 3018: if (keys(%namechanged) > 0) {
1.337 raeburn 3019: foreach my $field (@userinfo) {
3020: $changeHash{$field} = $env{'form.c'.$field};
3021: }
3022: # Make the change
1.204 raeburn 3023: $namechgresult =
3024: &Apache::lonnet::modifyuser($env{'form.ccdomain'},
3025: $env{'form.ccuname'},$changeHash{'id'},undef,undef,
3026: $changeHash{'firstname'},$changeHash{'middlename'},
3027: $changeHash{'lastname'},$changeHash{'generation'},
1.337 raeburn 3028: $changeHash{'id'},undef,$changeHash{'permanentemail'},undef,\@userinfo);
1.220 raeburn 3029: %userupdate = (
3030: lastname => $env{'form.clastname'},
3031: middlename => $env{'form.cmiddlename'},
3032: firstname => $env{'form.cfirstname'},
3033: generation => $env{'form.cgeneration'},
3034: id => $env{'form.cid'},
3035: );
1.204 raeburn 3036: }
1.334 raeburn 3037: if (((keys(%namechanged) > 0) && $namechgresult eq 'ok') ||
1.267 raeburn 3038: ((keys(%changed) > 0) && $chgresult eq 'ok')) {
1.28 matthew 3039: # Tell the user we changed the name
1.334 raeburn 3040: &display_userinfo($r,1,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 3041: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,
1.334 raeburn 3042: \%oldsettings, \%oldsettingstext,\%newsettings,
3043: \%newsettingstext);
1.203 raeburn 3044: if ($env{'form.cid'} ne $userenv{'id'}) {
3045: &Apache::lonnet::idput($env{'form.ccdomain'},
3046: ($env{'form.ccuname'} => $env{'form.cid'}));
3047: if (($recurseid) &&
3048: (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}))) {
3049: my $idresult =
3050: &Apache::lonuserutils::propagate_id_change(
3051: $env{'form.ccuname'},$env{'form.ccdomain'},
3052: \%userupdate);
3053: $r->print('<br />'.$idresult.'<br />');
3054: }
1.196 raeburn 3055: }
1.149 raeburn 3056: if (($env{'form.ccdomain'} eq $env{'user.domain'}) &&
3057: ($env{'form.ccuname'} eq $env{'user.name'})) {
3058: my %newenvhash;
3059: foreach my $key (keys(%changeHash)) {
3060: $newenvhash{'environment.'.$key} = $changeHash{$key};
3061: }
1.238 raeburn 3062: &Apache::lonnet::appenv(\%newenvhash);
1.149 raeburn 3063: }
1.28 matthew 3064: } else { # error occurred
1.389 ! bisitz 3065: $r->print(
! 3066: '<p class="LC_error">'
! 3067: .&mt('Unable to successfully change environment for [_1] in domain [_2].',
! 3068: '"'.$env{'form.ccuname'}.'"',
! 3069: '"'.$env{'form.ccdomain'}.'"')
! 3070: .'</p>');
1.28 matthew 3071: }
1.334 raeburn 3072: } else { # End of if ($env ... ) logic
1.275 raeburn 3073: # They did not want to change the users name, quota, tool availability,
3074: # or ability to request creation of courses,
1.267 raeburn 3075: # but we can still tell them what the name and quota and availabilities are
1.334 raeburn 3076: &display_userinfo($r,undef,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 3077: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,\%oldsettings,
1.334 raeburn 3078: \%oldsettingstext,\%newsettings,\%newsettingstext);
1.28 matthew 3079: }
1.206 raeburn 3080: if (@mod_disallowed) {
3081: my ($rolestr,$contextname);
3082: if (@longroles > 0) {
3083: $rolestr = join(', ',@longroles);
3084: } else {
3085: $rolestr = &mt('No roles');
3086: }
3087: if ($context eq 'course') {
3088: $contextname = &mt('course');
3089: } elsif ($context eq 'author') {
3090: $contextname = &mt('co-author');
3091: }
3092: $r->print(&mt('The following fields were not updated: ').'<ul>');
3093: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
3094: foreach my $field (@mod_disallowed) {
3095: $r->print('<li>'.$fieldtitles{$field}.'</li>'."\n");
3096: }
1.207 raeburn 3097: $r->print('</ul>');
3098: if (@mod_disallowed == 1) {
3099: $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));
3100: } else {
3101: $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));
3102: }
1.292 bisitz 3103: my $helplink = 'javascript:helpMenu('."'display'".')';
3104: $r->print('<span class="LC_cusr_emph">'.$rolestr.'</span><br />'
3105: .&mt('Please contact your [_1]helpdesk[_2] for more information.'
3106: ,'<a href="'.$helplink.'">','</a>')
3107: .'<br />');
1.206 raeburn 3108: }
1.259 bisitz 3109: $r->print('<span class="LC_warning">'
3110: .$no_forceid_alert
3111: .&Apache::lonuserutils::print_namespacing_alerts($env{'form.ccdomain'},\%alerts,\%curr_rules)
3112: .'</span>');
1.4 www 3113: }
1.367 golterma 3114: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1.220 raeburn 3115: if ($env{'form.action'} eq 'singlestudent') {
1.375 raeburn 3116: &enroll_single_student($r,$uhome,$amode,$genpwd,$now,$newuser,$context,
3117: $crstype,$showcredits,$defaultcredits);
1.386 bisitz 3118: my $linktext = ($crstype eq 'Community' ?
3119: &mt('Enroll Another Member') : &mt('Enroll Another Student'));
3120: $r->print(
3121: &Apache::lonhtmlcommon::actionbox([
3122: '<a href="javascript:backPage(document.userupdate)">'
3123: .($crstype eq 'Community' ?
3124: &mt('Enroll Another Member') : &mt('Enroll Another Student'))
3125: .'</a>']));
1.220 raeburn 3126: } else {
1.375 raeburn 3127: my @rolechanges = &update_roles($r,$context,$showcredits);
1.334 raeburn 3128: if (keys(%namechanged) > 0) {
1.220 raeburn 3129: if ($context eq 'course') {
3130: if (@userroles > 0) {
1.225 raeburn 3131: if ((@rolechanges == 0) ||
3132: (!(grep(/^st$/,@rolechanges)))) {
3133: if (grep(/^st$/,@userroles)) {
3134: my $classlistupdated =
3135: &Apache::lonuserutils::update_classlist($cdom,
1.220 raeburn 3136: $cnum,$env{'form.ccdomain'},
3137: $env{'form.ccuname'},\%userupdate);
1.225 raeburn 3138: }
1.220 raeburn 3139: }
3140: }
3141: }
3142: }
1.226 raeburn 3143: my $userinfo = &Apache::loncommon::plainname($env{'form.ccuname'},
1.233 raeburn 3144: $env{'form.ccdomain'});
3145: if ($env{'form.popup'}) {
3146: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
3147: } else {
1.367 golterma 3148: $r->print('<br />'.&Apache::lonhtmlcommon::actionbox(['<a href="javascript:backPage(document.userupdate,'."'$env{'form.prevphase'}','modify'".')">'
3149: .&mt('Modify this user: [_1]','<span class="LC_cusr_emph">'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.' ('.$userinfo.')</span>').'</a>',
3150: '<a href="javascript:backPage(document.userupdate)">'.&mt('Create/Modify Another User').'</a>']));
1.233 raeburn 3151: }
1.220 raeburn 3152: }
3153: }
3154:
1.334 raeburn 3155: sub display_userinfo {
1.362 raeburn 3156: my ($r,$changed,$order,$canshow,$requestcourses,$usertools,$requestauthor,
3157: $userenv,$changedhash,$namechangedhash,$oldsetting,$oldsettingtext,
1.334 raeburn 3158: $newsetting,$newsettingtext) = @_;
3159: return unless (ref($order) eq 'ARRAY' &&
3160: ref($canshow) eq 'HASH' &&
3161: ref($requestcourses) eq 'ARRAY' &&
1.362 raeburn 3162: ref($requestauthor) eq 'ARRAY' &&
1.334 raeburn 3163: ref($usertools) eq 'ARRAY' &&
3164: ref($userenv) eq 'HASH' &&
3165: ref($changedhash) eq 'HASH' &&
3166: ref($oldsetting) eq 'HASH' &&
3167: ref($oldsettingtext) eq 'HASH' &&
3168: ref($newsetting) eq 'HASH' &&
3169: ref($newsettingtext) eq 'HASH');
3170: my %lt=&Apache::lonlocal::texthash(
1.372 raeburn 3171: 'ui' => 'User Information',
1.334 raeburn 3172: 'uic' => 'User Information Changed',
3173: 'firstname' => 'First Name',
3174: 'middlename' => 'Middle Name',
3175: 'lastname' => 'Last Name',
3176: 'generation' => 'Generation',
3177: 'id' => 'Student/Employee ID',
3178: 'permanentemail' => 'Permanent e-mail address',
1.378 raeburn 3179: 'portfolioquota' => 'Disk space allocated to portfolio files',
1.385 bisitz 3180: 'authorquota' => 'Disk space allocated to Authoring Space',
1.334 raeburn 3181: 'blog' => 'Blog Availability',
1.361 raeburn 3182: 'webdav' => 'WebDAV Availability',
1.334 raeburn 3183: 'aboutme' => 'Personal Information Page Availability',
3184: 'portfolio' => 'Portfolio Availability',
3185: 'official' => 'Can Request Official Courses',
3186: 'unofficial' => 'Can Request Unofficial Courses',
3187: 'community' => 'Can Request Communities',
1.384 raeburn 3188: 'textbook' => 'Can Request Textbook Courses',
1.362 raeburn 3189: 'requestauthor' => 'Can Request Author Role',
1.334 raeburn 3190: 'inststatus' => "Affiliation",
3191: 'prvs' => 'Previous Value:',
3192: 'chto' => 'Changed To:'
3193: );
3194: if ($changed) {
1.372 raeburn 3195: $r->print('<h3>'.$lt{'uic'}.'</h3>'.
1.367 golterma 3196: &Apache::loncommon::start_data_table().
3197: &Apache::loncommon::start_data_table_header_row());
1.334 raeburn 3198: $r->print("<th> </th>\n");
1.367 golterma 3199: $r->print('<th><b>'.$lt{'prvs'}.'</b></th>');
3200: $r->print('<th><span class="LC_nobreak"><b>'.$lt{'chto'}.'</b></span></th>');
3201: $r->print(&Apache::loncommon::end_data_table_header_row());
3202: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
3203:
1.334 raeburn 3204: foreach my $item (@userinfo) {
3205: my $value = $env{'form.c'.$item};
1.367 golterma 3206: #show changes only:
1.383 raeburn 3207: unless ($value eq $userenv->{$item}){
1.367 golterma 3208: $r->print(&Apache::loncommon::start_data_table_row());
3209: $r->print("<td>$lt{$item}</td>\n");
1.383 raeburn 3210: $r->print("<td>".$userenv->{$item}."</td>\n");
1.367 golterma 3211: $r->print("<td>$value </td>\n");
3212: $r->print(&Apache::loncommon::end_data_table_row());
1.334 raeburn 3213: }
3214: }
3215: foreach my $entry (@{$order}) {
1.383 raeburn 3216: if ($canshow->{$entry}) {
3217: if (($entry eq 'requestcourses') || ($entry eq 'reqcrsotherdom') || ($entry eq 'requestauthor')) {
3218: my @items;
3219: if ($entry eq 'requestauthor') {
3220: @items = ($entry);
3221: } else {
3222: @items = @{$requestcourses};
1.384 raeburn 3223: }
1.383 raeburn 3224: foreach my $item (@items) {
3225: if (($newsetting->{$item} ne $oldsetting->{$item}) ||
3226: ($newsettingtext->{$item} ne $oldsettingtext->{$item})) {
3227: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3228: $r->print("<td>$lt{$item}</td>\n");
3229: $r->print("<td>".$oldsetting->{$item});
3230: if ($oldsettingtext->{$item}) {
3231: if ($oldsetting->{$item}) {
3232: $r->print(' -- ');
3233: }
3234: $r->print($oldsettingtext->{$item});
3235: }
3236: $r->print("</td>\n");
3237: $r->print("<td>".$newsetting->{$item});
3238: if ($newsettingtext->{$item}) {
3239: if ($newsetting->{$item}) {
3240: $r->print(' -- ');
3241: }
3242: $r->print($newsettingtext->{$item});
3243: }
3244: $r->print("</td>\n");
3245: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3246: }
3247: }
3248: } elsif ($entry eq 'tools') {
3249: foreach my $item (@{$usertools}) {
1.383 raeburn 3250: if ($newsetting->{$item} ne $oldsetting->{$item}) {
3251: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3252: $r->print("<td>$lt{$item}</td>\n");
3253: $r->print("<td>".$oldsetting->{$item}.' '.$oldsettingtext->{$item}."</td>\n");
3254: $r->print("<td>".$newsetting->{$item}.' '.$newsettingtext->{$item}."</td>\n");
3255: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3256: }
3257: }
1.378 raeburn 3258: } elsif ($entry eq 'quota') {
3259: if ((ref($oldsetting->{$entry}) eq 'HASH') && (ref($oldsettingtext->{$entry}) eq 'HASH') &&
3260: (ref($newsetting->{$entry}) eq 'HASH') && (ref($newsettingtext->{$entry}) eq 'HASH')) {
3261: foreach my $name ('portfolio','author') {
1.383 raeburn 3262: if ($newsetting->{$entry}->{$name} ne $oldsetting->{$entry}->{$name}) {
3263: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3264: $r->print("<td>$lt{$name.$entry}</td>\n");
3265: $r->print("<td>".$oldsettingtext->{$entry}->{$name}."</td>\n");
3266: $r->print("<td>".$newsettingtext->{$entry}->{$name}."</td>\n");
3267: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.378 raeburn 3268: }
3269: }
3270: }
1.334 raeburn 3271: } else {
1.383 raeburn 3272: if ($newsetting->{$entry} ne $oldsetting->{$entry}) {
3273: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3274: $r->print("<td>$lt{$entry}</td>\n");
3275: $r->print("<td>".$oldsetting->{$entry}.' '.$oldsettingtext->{$entry}."</td>\n");
3276: $r->print("<td>".$newsetting->{$entry}.' '.$newsettingtext->{$entry}."</td>\n");
3277: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3278: }
3279: }
3280: }
3281: }
1.367 golterma 3282: $r->print(&Apache::loncommon::end_data_table().'<br />');
1.372 raeburn 3283: } else {
3284: $r->print('<h3>'.$lt{'ui'}.'</h3>'.
3285: '<p>'.&mt('No changes made to user information').'</p>');
1.334 raeburn 3286: }
3287: return;
3288: }
3289:
1.275 raeburn 3290: sub tool_changes {
3291: my ($context,$usertools,$oldaccess,$oldaccesstext,$userenv,$changeHash,
3292: $changed,$newaccess,$newaccesstext) = @_;
3293: if (!((ref($usertools) eq 'ARRAY') && (ref($oldaccess) eq 'HASH') &&
3294: (ref($oldaccesstext) eq 'HASH') && (ref($userenv) eq 'HASH') &&
3295: (ref($changeHash) eq 'HASH') && (ref($changed) eq 'HASH') &&
3296: (ref($newaccess) eq 'HASH') && (ref($newaccesstext) eq 'HASH'))) {
3297: return;
3298: }
1.383 raeburn 3299: my %reqdisplay = &requestchange_display();
1.300 raeburn 3300: if ($context eq 'reqcrsotherdom') {
1.309 raeburn 3301: my @options = ('approval','validate','autolimit');
1.306 raeburn 3302: my $optregex = join('|',@options);
1.300 raeburn 3303: my $cdom = $env{'request.role.domain'};
3304: foreach my $tool (@{$usertools}) {
1.383 raeburn 3305: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
1.314 raeburn 3306: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
1.300 raeburn 3307: $changeHash->{$context.'.'.$tool} = $userenv->{$context.'.'.$tool};
1.383 raeburn 3308: my ($newop,$limit);
1.314 raeburn 3309: if ($env{'form.'.$context.'_'.$tool}) {
3310: $newop = $env{'form.'.$context.'_'.$tool};
3311: if ($newop eq 'autolimit') {
1.383 raeburn 3312: $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
1.314 raeburn 3313: $limit =~ s/\D+//g;
3314: $newop .= '='.$limit;
3315: }
3316: }
1.300 raeburn 3317: if ($userenv->{$context.'.'.$tool} eq '') {
1.314 raeburn 3318: if ($newop) {
3319: $changed->{$tool}=&tool_admin($tool,$cdom.':'.$newop,
1.300 raeburn 3320: $changeHash,$context);
3321: if ($changed->{$tool}) {
1.383 raeburn 3322: if ($newop =~ /^autolimit/) {
3323: if ($limit) {
3324: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3325: } else {
3326: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3327: }
3328: } else {
3329: $newaccesstext->{$tool} = $reqdisplay{$newop};
3330: }
1.300 raeburn 3331: } else {
3332: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3333: }
3334: }
3335: } else {
3336: my @curr = split(',',$userenv->{$context.'.'.$tool});
3337: my @new;
3338: my $changedoms;
1.314 raeburn 3339: foreach my $req (@curr) {
3340: if ($req =~ /^\Q$cdom\E\:($optregex\=?\d*)$/) {
3341: my $oldop = $1;
1.383 raeburn 3342: if ($oldop =~ /^autolimit=(\d*)/) {
3343: my $limit = $1;
3344: if ($limit) {
3345: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3346: } else {
3347: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3348: }
3349: } else {
3350: $oldaccesstext->{$tool} = $reqdisplay{$oldop};
3351: }
1.314 raeburn 3352: if ($oldop ne $newop) {
3353: $changedoms = 1;
3354: foreach my $item (@curr) {
3355: my ($reqdom,$option) = split(':',$item);
3356: unless ($reqdom eq $cdom) {
3357: push(@new,$item);
3358: }
3359: }
3360: if ($newop) {
3361: push(@new,$cdom.':'.$newop);
1.300 raeburn 3362: }
1.314 raeburn 3363: @new = sort(@new);
1.300 raeburn 3364: }
1.314 raeburn 3365: last;
1.300 raeburn 3366: }
1.314 raeburn 3367: }
3368: if ((!$changedoms) && ($newop)) {
1.300 raeburn 3369: $changedoms = 1;
1.306 raeburn 3370: @new = sort(@curr,$cdom.':'.$newop);
1.300 raeburn 3371: }
3372: if ($changedoms) {
1.314 raeburn 3373: my $newdomstr;
1.300 raeburn 3374: if (@new) {
3375: $newdomstr = join(',',@new);
3376: }
3377: $changed->{$tool}=&tool_admin($tool,$newdomstr,$changeHash,
3378: $context);
3379: if ($changed->{$tool}) {
3380: if ($env{'form.'.$context.'_'.$tool}) {
1.306 raeburn 3381: if ($env{'form.'.$context.'_'.$tool} eq 'autolimit') {
1.314 raeburn 3382: my $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
3383: $limit =~ s/\D+//g;
3384: if ($limit) {
1.383 raeburn 3385: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
1.314 raeburn 3386: } else {
1.383 raeburn 3387: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
1.306 raeburn 3388: }
1.314 raeburn 3389: } else {
1.306 raeburn 3390: $newaccesstext->{$tool} = $reqdisplay{$env{'form.'.$context.'_'.$tool}};
3391: }
1.300 raeburn 3392: } else {
1.383 raeburn 3393: $newaccesstext->{$tool} = &mt("availability set to 'off'");
1.300 raeburn 3394: }
3395: }
3396: }
3397: }
3398: }
3399: return;
3400: }
1.275 raeburn 3401: foreach my $tool (@{$usertools}) {
1.383 raeburn 3402: my ($newval,$limit,$envkey);
1.362 raeburn 3403: $envkey = $context.'.'.$tool;
1.306 raeburn 3404: if ($context eq 'requestcourses') {
3405: $newval = $env{'form.crsreq_'.$tool};
3406: if ($newval eq 'autolimit') {
1.383 raeburn 3407: $limit = $env{'form.crsreq_'.$tool.'_limit'};
3408: $limit =~ s/\D+//g;
3409: $newval .= '='.$limit;
1.306 raeburn 3410: }
1.362 raeburn 3411: } elsif ($context eq 'requestauthor') {
3412: $newval = $env{'form.'.$context};
3413: $envkey = $context;
1.314 raeburn 3414: } else {
1.306 raeburn 3415: $newval = $env{'form.'.$context.'_'.$tool};
3416: }
1.362 raeburn 3417: if ($userenv->{$envkey} ne '') {
1.275 raeburn 3418: $oldaccess->{$tool} = &mt('custom');
1.383 raeburn 3419: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3420: if ($userenv->{$envkey} =~ /^autolimit=(\d*)$/) {
3421: my $currlimit = $1;
3422: if ($currlimit eq '') {
3423: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3424: } else {
3425: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$currlimit);
3426: }
3427: } elsif ($userenv->{$envkey}) {
3428: $oldaccesstext->{$tool} = $reqdisplay{$userenv->{$envkey}};
3429: } else {
3430: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
3431: }
1.275 raeburn 3432: } else {
1.383 raeburn 3433: if ($userenv->{$envkey}) {
3434: $oldaccesstext->{$tool} = &mt("availability set to 'on'");
3435: } else {
3436: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
3437: }
1.275 raeburn 3438: }
1.362 raeburn 3439: $changeHash->{$envkey} = $userenv->{$envkey};
1.275 raeburn 3440: if ($env{'form.custom'.$tool} == 1) {
1.362 raeburn 3441: if ($newval ne $userenv->{$envkey}) {
1.306 raeburn 3442: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
3443: $context);
1.275 raeburn 3444: if ($changed->{$tool}) {
3445: $newaccess->{$tool} = &mt('custom');
1.383 raeburn 3446: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3447: if ($newval =~ /^autolimit/) {
3448: if ($limit) {
3449: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3450: } else {
3451: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3452: }
3453: } elsif ($newval) {
3454: $newaccesstext->{$tool} = $reqdisplay{$newval};
3455: } else {
3456: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3457: }
1.275 raeburn 3458: } else {
1.383 raeburn 3459: if ($newval) {
3460: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3461: } else {
3462: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3463: }
1.275 raeburn 3464: }
3465: } else {
3466: $newaccess->{$tool} = $oldaccess->{$tool};
1.383 raeburn 3467: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3468: if ($newval =~ /^autolimit/) {
3469: if ($limit) {
3470: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3471: } else {
3472: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3473: }
3474: } elsif ($newval) {
3475: $newaccesstext->{$tool} = $reqdisplay{$newval};
3476: } else {
3477: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3478: }
1.275 raeburn 3479: } else {
1.383 raeburn 3480: if ($userenv->{$context.'.'.$tool}) {
3481: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3482: } else {
3483: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3484: }
1.275 raeburn 3485: }
3486: }
3487: } else {
3488: $newaccess->{$tool} = $oldaccess->{$tool};
3489: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3490: }
3491: } else {
3492: $changed->{$tool} = &tool_admin($tool,'',$changeHash,$context);
3493: if ($changed->{$tool}) {
3494: $newaccess->{$tool} = &mt('default');
3495: } else {
3496: $newaccess->{$tool} = $oldaccess->{$tool};
1.383 raeburn 3497: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3498: if ($newval =~ /^autolimit/) {
3499: if ($limit) {
3500: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3501: } else {
3502: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3503: }
3504: } elsif ($newval) {
3505: $newaccesstext->{$tool} = $reqdisplay{$newval};
3506: } else {
3507: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3508: }
1.275 raeburn 3509: } else {
1.383 raeburn 3510: if ($userenv->{$context.'.'.$tool}) {
3511: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3512: } else {
3513: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3514: }
1.275 raeburn 3515: }
3516: }
3517: }
3518: } else {
3519: $oldaccess->{$tool} = &mt('default');
3520: if ($env{'form.custom'.$tool} == 1) {
1.306 raeburn 3521: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
3522: $context);
1.275 raeburn 3523: if ($changed->{$tool}) {
3524: $newaccess->{$tool} = &mt('custom');
1.383 raeburn 3525: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3526: if ($newval =~ /^autolimit/) {
3527: if ($limit) {
3528: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3529: } else {
3530: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3531: }
3532: } elsif ($newval) {
3533: $newaccesstext->{$tool} = $reqdisplay{$newval};
3534: } else {
3535: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3536: }
1.275 raeburn 3537: } else {
1.383 raeburn 3538: if ($newval) {
3539: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3540: } else {
3541: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3542: }
1.275 raeburn 3543: }
3544: } else {
3545: $newaccess->{$tool} = $oldaccess->{$tool};
3546: }
3547: } else {
3548: $newaccess->{$tool} = $oldaccess->{$tool};
3549: }
3550: }
3551: }
3552: return;
3553: }
3554:
1.220 raeburn 3555: sub update_roles {
1.375 raeburn 3556: my ($r,$context,$showcredits) = @_;
1.4 www 3557: my $now=time;
1.225 raeburn 3558: my @rolechanges;
1.220 raeburn 3559: my %disallowed;
1.73 sakharuk 3560: $r->print('<h3>'.&mt('Modifying Roles').'</h3>');
1.135 raeburn 3561: foreach my $key (keys (%env)) {
3562: next if (! $env{$key});
1.190 raeburn 3563: next if ($key eq 'form.action');
1.27 matthew 3564: # Revoke roles
1.135 raeburn 3565: if ($key=~/^form\.rev/) {
3566: if ($key=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) {
1.64 www 3567: # Revoke standard role
1.170 albertel 3568: my ($scope,$role) = ($1,$2);
3569: my $result =
3570: &Apache::lonnet::revokerole($env{'form.ccdomain'},
3571: $env{'form.ccuname'},
1.239 raeburn 3572: $scope,$role,'','',$context);
1.367 golterma 3573: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 3574: &mt('Revoking [_1] in [_2]',
3575: &Apache::lonnet::plaintext($role),
1.372 raeburn 3576: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 3577: $result ne "ok").'<br />');
3578: if ($result ne "ok") {
3579: $r->print(&mt('Error: [_1]',$result).'<br />');
3580: }
1.170 albertel 3581: if ($role eq 'st') {
1.202 raeburn 3582: my $result =
1.198 raeburn 3583: &Apache::lonuserutils::classlist_drop($scope,
3584: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 3585: $now);
1.367 golterma 3586: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.53 www 3587: }
1.225 raeburn 3588: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3589: push(@rolechanges,$role);
3590: }
1.196 raeburn 3591: }
1.195 raeburn 3592: if ($key=~m{^form\.rev\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}s) {
1.64 www 3593: # Revoke custom role
1.369 bisitz 3594: my $result = &Apache::lonnet::revokecustomrole(
3595: $env{'form.ccdomain'},$env{'form.ccuname'},$1,$2,$3,$4,'','',$context);
1.367 golterma 3596: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 3597: &mt('Revoking custom role [_1] by [_2] in [_3]',
1.372 raeburn 3598: $4,$3.':'.$2,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 3599: $result ne 'ok').'<br />');
3600: if ($result ne "ok") {
3601: $r->print(&mt('Error: [_1]',$result).'<br />');
3602: }
1.225 raeburn 3603: if (!grep(/^cr$/,@rolechanges)) {
3604: push(@rolechanges,'cr');
3605: }
1.64 www 3606: }
1.135 raeburn 3607: } elsif ($key=~/^form\.del/) {
3608: if ($key=~/^form\.del\:([^\_]+)\_([^\_\.]+)$/) {
1.116 raeburn 3609: # Delete standard role
1.170 albertel 3610: my ($scope,$role) = ($1,$2);
3611: my $result =
3612: &Apache::lonnet::assignrole($env{'form.ccdomain'},
3613: $env{'form.ccuname'},
1.239 raeburn 3614: $scope,$role,$now,0,1,'',
3615: $context);
1.367 golterma 3616: $r->print(&Apache::lonhtmlcommon::confirm_success(
3617: &mt('Deleting [_1] in [_2]',
1.369 bisitz 3618: &Apache::lonnet::plaintext($role),
1.372 raeburn 3619: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 3620: $result ne 'ok').'<br />');
3621: if ($result ne "ok") {
3622: $r->print(&mt('Error: [_1]',$result).'<br />');
3623: }
1.367 golterma 3624:
1.170 albertel 3625: if ($role eq 'st') {
1.202 raeburn 3626: my $result =
1.198 raeburn 3627: &Apache::lonuserutils::classlist_drop($scope,
3628: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 3629: $now);
1.369 bisitz 3630: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.81 albertel 3631: }
1.225 raeburn 3632: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3633: push(@rolechanges,$role);
3634: }
1.116 raeburn 3635: }
1.139 albertel 3636: if ($key=~m{^form\.del\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 3637: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
3638: # Delete custom role
1.369 bisitz 3639: my $result =
3640: &Apache::lonnet::assigncustomrole($env{'form.ccdomain'},
3641: $env{'form.ccuname'},$url,$rdom,$rnam,$rolename,$now,
3642: 0,1,$context);
3643: $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('Deleting custom role [_1] by [_2] in [_3]',
1.372 raeburn 3644: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 3645: $result ne "ok").'<br />');
3646: if ($result ne "ok") {
3647: $r->print(&mt('Error: [_1]',$result).'<br />');
3648: }
1.367 golterma 3649:
1.225 raeburn 3650: if (!grep(/^cr$/,@rolechanges)) {
3651: push(@rolechanges,'cr');
3652: }
1.116 raeburn 3653: }
1.135 raeburn 3654: } elsif ($key=~/^form\.ren/) {
1.101 albertel 3655: my $udom = $env{'form.ccdomain'};
3656: my $uname = $env{'form.ccuname'};
1.116 raeburn 3657: # Re-enable standard role
1.135 raeburn 3658: if ($key=~/^form\.ren\:([^\_]+)\_([^\_\.]+)$/) {
1.89 raeburn 3659: my $url = $1;
3660: my $role = $2;
3661: my $logmsg;
3662: my $output;
3663: if ($role eq 'st') {
1.141 albertel 3664: if ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
1.374 raeburn 3665: my ($cdom,$cnum,$csec) = ($1,$2,$3);
1.375 raeburn 3666: my $credits;
3667: if ($showcredits) {
3668: my $defaultcredits =
3669: &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
3670: $credits = &get_user_credits($defaultcredits,$cdom,$cnum);
3671: }
3672: my $result = &Apache::loncommon::commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$cdom,$cnum,$csec,$context,$credits);
1.220 raeburn 3673: if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course') || ($result eq 'refused')) {
1.223 raeburn 3674: if ($result eq 'refused' && $logmsg) {
3675: $output = $logmsg;
3676: } else {
1.369 bisitz 3677: $output = &mt('Error: [_1]',$result)."\n";
1.223 raeburn 3678: }
1.89 raeburn 3679: } else {
1.372 raeburn 3680: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Assigning [_1] in [_2] starting [_3]',
3681: &Apache::lonnet::plaintext($role),
3682: &Apache::loncommon::show_role_extent($url,$context,'st'),
3683: &Apache::lonlocal::locallocaltime($now))).'<br />'.$logmsg.'<br />';
1.89 raeburn 3684: }
3685: }
3686: } else {
1.101 albertel 3687: my $result=&Apache::lonnet::assignrole($env{'form.ccdomain'},
1.239 raeburn 3688: $env{'form.ccuname'},$url,$role,0,$now,'','',
3689: $context);
1.367 golterma 3690: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Re-enabling [_1] in [_2]',
1.372 raeburn 3691: &Apache::lonnet::plaintext($role),
3692: &Apache::loncommon::show_role_extent($url,$context,$role)),$result ne "ok").'<br />';
1.369 bisitz 3693: if ($result ne "ok") {
3694: $output .= &mt('Error: [_1]',$result).'<br />';
3695: }
3696: }
1.89 raeburn 3697: $r->print($output);
1.225 raeburn 3698: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3699: push(@rolechanges,$role);
3700: }
1.113 raeburn 3701: }
1.116 raeburn 3702: # Re-enable custom role
1.139 albertel 3703: if ($key=~m{^form\.ren\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 3704: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
3705: my $result = &Apache::lonnet::assigncustomrole(
3706: $env{'form.ccdomain'}, $env{'form.ccuname'},
1.240 raeburn 3707: $url,$rdom,$rnam,$rolename,0,$now,undef,$context);
1.369 bisitz 3708: $r->print(&Apache::lonhtmlcommon::confirm_success(
3709: &mt('Re-enabling custom role [_1] by [_2] in [_3]',
1.372 raeburn 3710: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 3711: $result ne "ok").'<br />');
3712: if ($result ne "ok") {
3713: $r->print(&mt('Error: [_1]',$result).'<br />');
3714: }
1.225 raeburn 3715: if (!grep(/^cr$/,@rolechanges)) {
3716: push(@rolechanges,'cr');
3717: }
1.116 raeburn 3718: }
1.135 raeburn 3719: } elsif ($key=~/^form\.act/) {
1.101 albertel 3720: my $udom = $env{'form.ccdomain'};
3721: my $uname = $env{'form.ccuname'};
1.141 albertel 3722: if ($key=~/^form\.act\_($match_domain)\_($match_courseid)\_cr_cr_($match_domain)_($match_username)_([^\_]+)$/) {
1.65 www 3723: # Activate a custom role
1.83 albertel 3724: my ($one,$two,$three,$four,$five)=($1,$2,$3,$4,$5);
3725: my $url='/'.$one.'/'.$two;
3726: my $full=$one.'_'.$two.'_cr_cr_'.$three.'_'.$four.'_'.$five;
1.65 www 3727:
1.101 albertel 3728: my $start = ( $env{'form.start_'.$full} ?
3729: $env{'form.start_'.$full} :
1.88 raeburn 3730: $now );
1.101 albertel 3731: my $end = ( $env{'form.end_'.$full} ?
3732: $env{'form.end_'.$full} :
1.88 raeburn 3733: 0 );
3734:
3735: # split multiple sections
3736: my %sections = ();
1.101 albertel 3737: my $num_sections = &build_roles($env{'form.sec_'.$full},\%sections,$5);
1.88 raeburn 3738: if ($num_sections == 0) {
1.240 raeburn 3739: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end,$context));
1.88 raeburn 3740: } else {
1.114 albertel 3741: my %curr_groups =
1.117 raeburn 3742: &Apache::longroup::coursegroups($one,$two);
1.113 raeburn 3743: foreach my $sec (sort {$a cmp $b} keys %sections) {
3744: if (($sec eq 'none') || ($sec eq 'all') ||
3745: exists($curr_groups{$sec})) {
3746: $disallowed{$sec} = $url;
3747: next;
3748: }
3749: my $securl = $url.'/'.$sec;
1.240 raeburn 3750: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end,$context));
1.88 raeburn 3751: }
3752: }
1.225 raeburn 3753: if (!grep(/^cr$/,@rolechanges)) {
3754: push(@rolechanges,'cr');
3755: }
1.142 raeburn 3756: } elsif ($key=~/^form\.act\_($match_domain)\_($match_name)\_([^\_]+)$/) {
1.27 matthew 3757: # Activate roles for sections with 3 id numbers
3758: # set start, end times, and the url for the class
1.83 albertel 3759: my ($one,$two,$three)=($1,$2,$3);
1.101 albertel 3760: my $start = ( $env{'form.start_'.$one.'_'.$two.'_'.$three} ?
3761: $env{'form.start_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 3762: $now );
1.101 albertel 3763: my $end = ( $env{'form.end_'.$one.'_'.$two.'_'.$three} ?
3764: $env{'form.end_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 3765: 0 );
1.83 albertel 3766: my $url='/'.$one.'/'.$two;
1.88 raeburn 3767: my $type = 'three';
3768: # split multiple sections
3769: my %sections = ();
1.101 albertel 3770: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections,$three);
1.375 raeburn 3771: my $credits;
3772: if ($three eq 'st') {
3773: if ($showcredits) {
3774: my $defaultcredits =
3775: &Apache::lonuserutils::get_defaultcredits($one,$two);
3776: $credits = $env{'form.credits_'.$one.'_'.$two.'_'.$three};
3777: $credits =~ s/[^\d\.]//g;
3778: if ($credits eq $defaultcredits) {
3779: undef($credits);
3780: }
3781: }
3782: }
1.88 raeburn 3783: if ($num_sections == 0) {
1.375 raeburn 3784: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 3785: } else {
1.114 albertel 3786: my %curr_groups =
1.117 raeburn 3787: &Apache::longroup::coursegroups($one,$two);
1.88 raeburn 3788: my $emptysec = 0;
3789: foreach my $sec (sort {$a cmp $b} keys %sections) {
3790: $sec =~ s/\W//g;
1.113 raeburn 3791: if ($sec ne '') {
3792: if (($sec eq 'none') || ($sec eq 'all') ||
3793: exists($curr_groups{$sec})) {
3794: $disallowed{$sec} = $url;
3795: next;
3796: }
1.88 raeburn 3797: my $securl = $url.'/'.$sec;
1.375 raeburn 3798: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec,$context,$credits));
1.88 raeburn 3799: } else {
3800: $emptysec = 1;
3801: }
3802: }
3803: if ($emptysec) {
1.375 raeburn 3804: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 3805: }
1.225 raeburn 3806: }
3807: if (!grep(/^\Q$three\E$/,@rolechanges)) {
3808: push(@rolechanges,$three);
3809: }
1.135 raeburn 3810: } elsif ($key=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
1.27 matthew 3811: # Activate roles for sections with two id numbers
3812: # set start, end times, and the url for the class
1.101 albertel 3813: my $start = ( $env{'form.start_'.$1.'_'.$2} ?
3814: $env{'form.start_'.$1.'_'.$2} :
1.27 matthew 3815: $now );
1.101 albertel 3816: my $end = ( $env{'form.end_'.$1.'_'.$2} ?
3817: $env{'form.end_'.$1.'_'.$2} :
1.27 matthew 3818: 0 );
1.225 raeburn 3819: my $one = $1;
3820: my $two = $2;
3821: my $url='/'.$one.'/';
1.88 raeburn 3822: # split multiple sections
3823: my %sections = ();
1.225 raeburn 3824: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two},\%sections,$two);
1.88 raeburn 3825: if ($num_sections == 0) {
1.240 raeburn 3826: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 3827: } else {
3828: my $emptysec = 0;
3829: foreach my $sec (sort {$a cmp $b} keys %sections) {
3830: if ($sec ne '') {
3831: my $securl = $url.'/'.$sec;
1.240 raeburn 3832: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$two,$start,$end,$one,undef,$sec,$context));
1.88 raeburn 3833: } else {
3834: $emptysec = 1;
3835: }
3836: }
3837: if ($emptysec) {
1.240 raeburn 3838: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 3839: }
3840: }
1.225 raeburn 3841: if (!grep(/^\Q$two\E$/,@rolechanges)) {
3842: push(@rolechanges,$two);
3843: }
1.64 www 3844: } else {
1.190 raeburn 3845: $r->print('<p><span class="LC_error">'.&mt('ERROR').': '.&mt('Unknown command').' <tt>'.$key.'</tt></span></p><br />');
1.64 www 3846: }
1.113 raeburn 3847: foreach my $key (sort(keys(%disallowed))) {
1.274 bisitz 3848: $r->print('<p class="LC_warning">');
1.113 raeburn 3849: if (($key eq 'none') || ($key eq 'all')) {
1.274 bisitz 3850: $r->print(&mt('[_1] may not be used as the name for a section, as it is a reserved word.','<tt>'.$key.'</tt>'));
1.113 raeburn 3851: } else {
1.274 bisitz 3852: $r->print(&mt('[_1] may not be used as the name for a section, as it is the name of a course group.','<tt>'.$key.'</tt>'));
1.113 raeburn 3853: }
1.274 bisitz 3854: $r->print('</p><p>'
3855: .&mt('Please [_1]go back[_2] and choose a different section name.'
3856: ,'<a href="javascript:history.go(-1)'
3857: ,'</a>')
3858: .'</p><br />'
3859: );
1.113 raeburn 3860: }
3861: }
1.101 albertel 3862: } # End of foreach (keys(%env))
1.75 www 3863: # Flush the course logs so reverse user roles immediately updated
1.349 raeburn 3864: $r->register_cleanup(\&Apache::lonnet::flushcourselogs);
1.225 raeburn 3865: if (@rolechanges == 0) {
1.372 raeburn 3866: $r->print('<p>'.&mt('No roles to modify').'</p>');
1.193 raeburn 3867: }
1.225 raeburn 3868: return @rolechanges;
1.220 raeburn 3869: }
3870:
1.375 raeburn 3871: sub get_user_credits {
3872: my ($uname,$udom,$defaultcredits,$cdom,$cnum) = @_;
3873: if ($cdom eq '' || $cnum eq '') {
3874: return unless ($env{'request.course.id'});
3875: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
3876: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
3877: }
3878: my $credits;
3879: my %currhash =
3880: &Apache::lonnet::get('classlist',[$uname.':'.$udom],$cdom,$cnum);
3881: if (keys(%currhash) > 0) {
3882: my @items = split(/:/,$currhash{$uname.':'.$udom});
3883: my $crdidx = &Apache::loncoursedata::CL_CREDITS() - 3;
3884: $credits = $items[$crdidx];
3885: $credits =~ s/[^\d\.]//g;
3886: }
3887: if ($credits eq $defaultcredits) {
3888: undef($credits);
3889: }
3890: return $credits;
3891: }
3892:
1.220 raeburn 3893: sub enroll_single_student {
1.375 raeburn 3894: my ($r,$uhome,$amode,$genpwd,$now,$newuser,$context,$crstype,
3895: $showcredits,$defaultcredits) = @_;
1.318 raeburn 3896: $r->print('<h3>');
3897: if ($crstype eq 'Community') {
3898: $r->print(&mt('Enrolling Member'));
3899: } else {
3900: $r->print(&mt('Enrolling Student'));
3901: }
3902: $r->print('</h3>');
1.220 raeburn 3903:
3904: # Remove non alphanumeric values from section
3905: $env{'form.sections'}=~s/\W//g;
3906:
1.375 raeburn 3907: my $credits;
3908: if (($showcredits) && ($env{'form.credits'} ne '')) {
3909: $credits = $env{'form.credits'};
3910: $credits =~ s/[^\d\.]//g;
3911: if ($credits ne '') {
3912: if ($credits eq $defaultcredits) {
3913: undef($credits);
3914: }
3915: }
3916: }
3917:
1.220 raeburn 3918: # Clean out any old student roles the user has in this class.
3919: &Apache::lonuserutils::modifystudent($env{'form.ccdomain'},
3920: $env{'form.ccuname'},$env{'request.course.id'},undef,$uhome);
3921: my ($startdate,$enddate) = &Apache::lonuserutils::get_dates_from_form();
3922: my $enroll_result =
3923: &Apache::lonnet::modify_student_enrollment($env{'form.ccdomain'},
3924: $env{'form.ccuname'},$env{'form.cid'},$env{'form.cfirstname'},
3925: $env{'form.cmiddlename'},$env{'form.clastname'},
3926: $env{'form.generation'},$env{'form.sections'},$enddate,
1.375 raeburn 3927: $startdate,'manual',undef,$env{'request.course.id'},'',$context,
3928: $credits);
1.220 raeburn 3929: if ($enroll_result =~ /^ok/) {
1.381 bisitz 3930: $r->print(&mt('[_1] enrolled','<b>'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.'</b>'));
1.220 raeburn 3931: if ($env{'form.sections'} ne '') {
3932: $r->print(' '.&mt('in section [_1]',$env{'form.sections'}));
3933: }
3934: my ($showstart,$showend);
3935: if ($startdate <= $now) {
3936: $showstart = &mt('Access starts immediately');
3937: } else {
3938: $showstart = &mt('Access starts: ').&Apache::lonlocal::locallocaltime($startdate);
3939: }
3940: if ($enddate == 0) {
3941: $showend = &mt('ends: no ending date');
3942: } else {
3943: $showend = &mt('ends: ').&Apache::lonlocal::locallocaltime($enddate);
3944: }
3945: $r->print('.<br />'.$showstart.'; '.$showend);
3946: if ($startdate <= $now && !$newuser) {
1.386 bisitz 3947: $r->print('<p class="LC_info">');
1.318 raeburn 3948: if ($crstype eq 'Community') {
3949: $r->print(&mt('If the member is currently logged-in to LON-CAPA, the new role will be available when the member next logs in.'));
3950: } else {
3951: $r->print(&mt('If the student is currently logged-in to LON-CAPA, the new role will be available when the student next logs in.'));
3952: }
3953: $r->print('</p>');
1.220 raeburn 3954: }
3955: } else {
3956: $r->print(&mt('unable to enroll').": ".$enroll_result);
3957: }
3958: return;
1.188 raeburn 3959: }
3960:
1.204 raeburn 3961: sub get_defaultquota_text {
3962: my ($settingstatus) = @_;
3963: my $defquotatext;
3964: if ($settingstatus eq '') {
1.383 raeburn 3965: $defquotatext = &mt('default');
1.204 raeburn 3966: } else {
3967: my ($usertypes,$order) =
3968: &Apache::lonnet::retrieve_inst_usertypes($env{'form.ccdomain'});
3969: if ($usertypes->{$settingstatus} eq '') {
1.383 raeburn 3970: $defquotatext = &mt('default');
1.204 raeburn 3971: } else {
1.383 raeburn 3972: $defquotatext = &mt('default for [_1]',$usertypes->{$settingstatus});
1.204 raeburn 3973: }
3974: }
3975: return $defquotatext;
3976: }
3977:
1.188 raeburn 3978: sub update_result_form {
3979: my ($uhome) = @_;
3980: my $outcome =
1.367 golterma 3981: '<form name="userupdate" method="post" action="">'."\n";
1.160 raeburn 3982: foreach my $item ('srchby','srchin','srchtype','srchterm','srchdomain','ccuname','ccdomain') {
1.188 raeburn 3983: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 3984: }
1.207 raeburn 3985: if ($env{'form.origname'} ne '') {
3986: $outcome .= '<input type="hidden" name="origname" value="'.$env{'form.origname'}.'" />'."\n";
3987: }
1.160 raeburn 3988: foreach my $item ('sortby','seluname','seludom') {
3989: if (exists($env{'form.'.$item})) {
1.188 raeburn 3990: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 3991: }
3992: }
1.188 raeburn 3993: if ($uhome eq 'no_host') {
3994: $outcome .= '<input type="hidden" name="forcenewuser" value="1" />'."\n";
3995: }
3996: $outcome .= '<input type="hidden" name="phase" value="" />'."\n".
1.383 raeburn 3997: '<input type="hidden" name="currstate" value="" />'."\n".
3998: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
1.188 raeburn 3999: '</form>';
4000: return $outcome;
1.4 www 4001: }
4002:
1.149 raeburn 4003: sub quota_admin {
1.378 raeburn 4004: my ($setquota,$changeHash,$name) = @_;
1.149 raeburn 4005: my $quotachanged;
4006: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
4007: # Current user has quota modification privileges
1.267 raeburn 4008: if (ref($changeHash) eq 'HASH') {
4009: $quotachanged = 1;
1.378 raeburn 4010: $changeHash->{$name.'quota'} = $setquota;
1.267 raeburn 4011: }
1.149 raeburn 4012: }
4013: return $quotachanged;
4014: }
4015:
1.267 raeburn 4016: sub tool_admin {
1.275 raeburn 4017: my ($tool,$settool,$changeHash,$context) = @_;
4018: my $canchange = 0;
1.279 raeburn 4019: if ($context eq 'requestcourses') {
1.275 raeburn 4020: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
4021: $canchange = 1;
4022: }
1.300 raeburn 4023: } elsif ($context eq 'reqcrsotherdom') {
4024: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
4025: $canchange = 1;
4026: }
1.362 raeburn 4027: } elsif ($context eq 'requestauthor') {
4028: if (&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) {
4029: $canchange = 1;
4030: }
1.275 raeburn 4031: } elsif (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
4032: # Current user has quota modification privileges
4033: $canchange = 1;
4034: }
1.267 raeburn 4035: my $toolchanged;
1.275 raeburn 4036: if ($canchange) {
1.267 raeburn 4037: if (ref($changeHash) eq 'HASH') {
4038: $toolchanged = 1;
1.362 raeburn 4039: if ($tool eq 'requestauthor') {
4040: $changeHash->{$context} = $settool;
4041: } else {
4042: $changeHash->{$context.'.'.$tool} = $settool;
4043: }
1.267 raeburn 4044: }
4045: }
4046: return $toolchanged;
4047: }
4048:
1.88 raeburn 4049: sub build_roles {
1.89 raeburn 4050: my ($sectionstr,$sections,$role) = @_;
1.88 raeburn 4051: my $num_sections = 0;
4052: if ($sectionstr=~ /,/) {
4053: my @secnums = split/,/,$sectionstr;
1.89 raeburn 4054: if ($role eq 'st') {
4055: $secnums[0] =~ s/\W//g;
4056: $$sections{$secnums[0]} = 1;
4057: $num_sections = 1;
4058: } else {
4059: foreach my $sec (@secnums) {
4060: $sec =~ ~s/\W//g;
1.150 banghart 4061: if (!($sec eq "")) {
1.89 raeburn 4062: if (exists($$sections{$sec})) {
4063: $$sections{$sec} ++;
4064: } else {
4065: $$sections{$sec} = 1;
4066: $num_sections ++;
4067: }
1.88 raeburn 4068: }
4069: }
4070: }
4071: } else {
4072: $sectionstr=~s/\W//g;
4073: unless ($sectionstr eq '') {
4074: $$sections{$sectionstr} = 1;
4075: $num_sections ++;
4076: }
4077: }
1.129 albertel 4078:
1.88 raeburn 4079: return $num_sections;
4080: }
4081:
1.58 www 4082: # ========================================================== Custom Role Editor
4083:
4084: sub custom_role_editor {
1.351 raeburn 4085: my ($r,$brcrum) = @_;
1.324 raeburn 4086: my $action = $env{'form.customroleaction'};
4087: my $rolename;
4088: if ($action eq 'new') {
4089: $rolename=$env{'form.newrolename'};
4090: } else {
4091: $rolename=$env{'form.rolename'};
1.59 www 4092: }
4093:
1.324 raeburn 4094: my ($crstype,$context);
4095: if ($env{'request.course.id'}) {
4096: $crstype = &Apache::loncommon::course_type();
4097: $context = 'course';
4098: } else {
4099: $context = 'domain';
4100: $crstype = $env{'form.templatecrstype'};
4101: }
1.351 raeburn 4102:
4103: $rolename=~s/[^A-Za-z0-9]//gs;
4104: if (!$rolename || $env{'form.phase'} eq 'pickrole') {
4105: &print_username_entry_form($r,undef,undef,undef,undef,$crstype,$brcrum);
4106: return;
4107: }
4108:
1.153 banghart 4109: # ------------------------------------------------------- What can be assigned?
4110: my %full=();
4111: my %courselevel=();
4112: my %courselevelcurrent=();
1.61 www 4113: my $syspriv='';
4114: my $dompriv='';
4115: my $coursepriv='';
1.153 banghart 4116: my $body_top;
1.59 www 4117: my ($rdummy,$roledef)=
4118: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
1.60 www 4119: # ------------------------------------------------------- Does this role exist?
1.153 banghart 4120: $body_top .= '<h2>';
1.59 www 4121: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.153 banghart 4122: $body_top .= &mt('Existing Role').' "';
1.61 www 4123: # ------------------------------------------------- Get current role privileges
4124: ($syspriv,$dompriv,$coursepriv)=split(/\_/,$roledef);
1.324 raeburn 4125: if ($crstype eq 'Community') {
4126: $syspriv =~ s/bre\&S//;
4127: }
1.59 www 4128: } else {
1.153 banghart 4129: $body_top .= &mt('New Role').' "';
1.59 www 4130: $roledef='';
4131: }
1.153 banghart 4132: $body_top .= $rolename.'"</h2>';
1.135 raeburn 4133: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
4134: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 4135: if (!$restrict) { $restrict='F'; }
1.60 www 4136: $courselevel{$priv}=$restrict;
1.61 www 4137: if ($coursepriv=~/\:$priv/) {
4138: $courselevelcurrent{$priv}=1;
4139: }
1.60 www 4140: $full{$priv}=1;
4141: }
4142: my %domainlevel=();
1.61 www 4143: my %domainlevelcurrent=();
1.135 raeburn 4144: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
4145: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 4146: if (!$restrict) { $restrict='F'; }
1.60 www 4147: $domainlevel{$priv}=$restrict;
1.61 www 4148: if ($dompriv=~/\:$priv/) {
4149: $domainlevelcurrent{$priv}=1;
4150: }
1.60 www 4151: $full{$priv}=1;
4152: }
1.61 www 4153: my %systemlevel=();
4154: my %systemlevelcurrent=();
1.135 raeburn 4155: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
4156: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 4157: if (!$restrict) { $restrict='F'; }
1.61 www 4158: $systemlevel{$priv}=$restrict;
4159: if ($syspriv=~/\:$priv/) {
4160: $systemlevelcurrent{$priv}=1;
4161: }
4162: $full{$priv}=1;
4163: }
1.160 raeburn 4164: my ($jsback,$elements) = &crumb_utilities();
1.154 banghart 4165: my $button_code = "\n";
1.153 banghart 4166: my $head_script = "\n";
1.301 bisitz 4167: $head_script .= '<script type="text/javascript">'."\n"
4168: .'// <![CDATA['."\n";
1.324 raeburn 4169: my @template_roles = ("in","ta","ep");
4170: if ($context eq 'domain') {
4171: push(@template_roles,"ad");
1.318 raeburn 4172: }
1.324 raeburn 4173: push(@template_roles,"st");
1.318 raeburn 4174: if ($crstype eq 'Community') {
4175: unshift(@template_roles,'co');
4176: } else {
4177: unshift(@template_roles,'cc');
4178: }
1.154 banghart 4179: foreach my $role (@template_roles) {
1.324 raeburn 4180: $head_script .= &make_script_template($role,$crstype);
1.318 raeburn 4181: $button_code .= &make_button_code($role,$crstype).' ';
1.154 banghart 4182: }
1.324 raeburn 4183: my $context_code;
4184: if ($context eq 'domain') {
4185: my $checkedCommunity = '';
4186: my $checkedCourse = ' checked="checked"';
4187: if ($env{'form.templatecrstype'} eq 'Community') {
4188: $checkedCommunity = $checkedCourse;
4189: $checkedCourse = '';
4190: }
4191: $context_code = '<label>'.
4192: '<input type="radio" name="templatecrstype" value="Course"'.$checkedCourse.' onclick="this.form.submit();">'.
4193: &mt('Course').
4194: '</label>'.(' ' x2).
4195: '<label>'.
4196: '<input type="radio" name="templatecrstype" value="Community"'.$checkedCommunity.' onclick="this.form.submit();">'.
4197: &mt('Community').
4198: '</label>'.
4199: '</fieldset>'.
4200: '<input type="hidden" name="customroleaction" value="'.
4201: $action.'" />';
4202: if ($env{'form.customroleaction'} eq 'new') {
4203: $context_code .= '<input type="hidden" name="newrolename" value="'.
4204: $rolename.'" />';
4205: } else {
4206: $context_code .= '<input type="hidden" name="rolename" value="'.
4207: $rolename.'" />';
4208: }
4209: $context_code .= '<input type="hidden" name="action" value="custom" />'.
4210: '<input type="hidden" name="phase" value="selected_custom_edit" />';
4211: }
4212:
1.301 bisitz 4213: $head_script .= "\n".$jsback."\n"
4214: .'// ]]>'."\n"
4215: .'</script>'."\n";
1.351 raeburn 4216: push (@{$brcrum},
4217: {href => "javascript:backPage(document.form1,'pickrole','')",
4218: text => "Pick custom role",
4219: faq => 282,bug=>'Instructor Interface',},
4220: {href => "javascript:backPage(document.form1,'','')",
4221: text => "Edit custom role",
4222: faq => 282,
4223: bug => 'Instructor Interface',
4224: help => 'Course_Editing_Custom_Roles'}
4225: );
4226: my $args = { bread_crumbs => $brcrum,
4227: bread_crumbs_component => 'User Management'};
4228:
4229: $r->print(&Apache::loncommon::start_page('Custom Role Editor',
4230: $head_script,$args).
4231: $body_top);
1.73 sakharuk 4232: my %lt=&Apache::lonlocal::texthash(
4233: 'prv' => "Privilege",
1.131 raeburn 4234: 'crl' => "Course Level",
1.73 sakharuk 4235: 'dml' => "Domain Level",
1.150 banghart 4236: 'ssl' => "System Level");
1.264 bisitz 4237:
1.324 raeburn 4238: $r->print('<div class="LC_left_float">'
1.264 bisitz 4239: .'<form action=""><fieldset>'
4240: .'<legend>'.&mt('Select a Template').'</legend>'
4241: .$button_code
1.324 raeburn 4242: .'</fieldset></form></div>');
4243: if ($context_code) {
4244: $r->print('<div class="LC_left_float">'
4245: .'<form action="/adm/createuser" method="post"><fieldset>'
4246: .'<legend>'.&mt('Context').'</legend>'
4247: .$context_code
4248: .'</form>'
4249: .'</div>'
4250: );
4251: }
4252: $r->print('<br clear="all" />');
1.264 bisitz 4253:
1.61 www 4254: $r->print(<<ENDCCF);
1.380 bisitz 4255: <form name="form1" method="post" action="">
1.61 www 4256: <input type="hidden" name="phase" value="set_custom_roles" />
4257: <input type="hidden" name="rolename" value="$rolename" />
4258: ENDCCF
1.135 raeburn 4259: $r->print(&Apache::loncommon::start_data_table().
4260: &Apache::loncommon::start_data_table_header_row().
4261: '<th>'.$lt{'prv'}.'</th><th>'.$lt{'crl'}.'</th><th>'.$lt{'dml'}.
4262: '</th><th>'.$lt{'ssl'}.'</th>'.
4263: &Apache::loncommon::end_data_table_header_row());
1.324 raeburn 4264: foreach my $priv (sort(keys(%full))) {
1.318 raeburn 4265: my $privtext = &Apache::lonnet::plaintext($priv,$crstype);
1.135 raeburn 4266: $r->print(&Apache::loncommon::start_data_table_row().
4267: '<td>'.$privtext.'</td><td>'.
1.288 bisitz 4268: ($courselevel{$priv}?'<input type="checkbox" name="'.$priv.'_c"'.
4269: ($courselevelcurrent{$priv}?' checked="checked"':'').' />':' ').
1.61 www 4270: '</td><td>'.
1.288 bisitz 4271: ($domainlevel{$priv}?'<input type="checkbox" name="'.$priv.'_d"'.
4272: ($domainlevelcurrent{$priv}?' checked="checked"':'').' />':' ').
1.324 raeburn 4273: '</td><td>');
4274: if ($priv eq 'bre' && $crstype eq 'Community') {
4275: $r->print(' ');
4276: } else {
4277: $r->print($systemlevel{$priv}?'<input type="checkbox" name="'.$priv.'_s"'.
4278: ($systemlevelcurrent{$priv}?' checked="checked"':'').' />':' ');
4279: }
4280: $r->print('</td>'.
4281: &Apache::loncommon::end_data_table_row());
1.60 www 4282: }
1.135 raeburn 4283: $r->print(&Apache::loncommon::end_data_table().
1.190 raeburn 4284: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
1.160 raeburn 4285: '<input type="hidden" name="startrolename" value="'.$env{'form.rolename'}.
1.179 raeburn 4286: '" />'."\n".'<input type="hidden" name="currstate" value="" />'."\n".
1.160 raeburn 4287: '<input type="reset" value="'.&mt("Reset").'" />'."\n".
1.351 raeburn 4288: '<input type="submit" value="'.&mt('Save').'" /></form>');
1.61 www 4289: }
1.153 banghart 4290: # --------------------------------------------------------
4291: sub make_script_template {
1.324 raeburn 4292: my ($role,$crstype) = @_;
1.153 banghart 4293: my %full_c=();
4294: my %full_d=();
4295: my %full_s=();
4296: my $return_script;
4297: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
4298: my ($priv,$restrict)=split(/\&/,$item);
4299: $full_c{$priv}=1;
4300: }
4301: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
4302: my ($priv,$restrict)=split(/\&/,$item);
4303: $full_d{$priv}=1;
4304: }
1.154 banghart 4305: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
1.324 raeburn 4306: next if (($crstype eq 'Community') && ($item eq 'bre&S'));
1.153 banghart 4307: my ($priv,$restrict)=split(/\&/,$item);
4308: $full_s{$priv}=1;
4309: }
4310: $return_script .= 'function set_'.$role.'() {'."\n";
4311: my @temp = split(/:/,$Apache::lonnet::pr{$role.':c'});
4312: my %role_c;
1.155 banghart 4313: foreach my $priv (@temp) {
1.153 banghart 4314: my ($priv_item, $dummy) = split(/\&/,$priv);
4315: $role_c{$priv_item} = 1;
4316: }
1.269 raeburn 4317: my %role_d;
4318: @temp = split(/:/,$Apache::lonnet::pr{$role.':d'});
4319: foreach my $priv(@temp) {
4320: my ($priv_item, $dummy) = split(/\&/,$priv);
4321: $role_d{$priv_item} = 1;
4322: }
4323: my %role_s;
4324: @temp = split(/:/,$Apache::lonnet::pr{$role.':s'});
4325: foreach my $priv(@temp) {
4326: my ($priv_item, $dummy) = split(/\&/,$priv);
4327: $role_s{$priv_item} = 1;
4328: }
1.153 banghart 4329: foreach my $priv_item (keys(%full_c)) {
4330: my ($priv, $dummy) = split(/\&/,$priv_item);
1.269 raeburn 4331: if ((exists($role_c{$priv})) || (exists($role_d{$priv})) ||
4332: (exists($role_s{$priv}))) {
1.153 banghart 4333: $return_script .= "document.form1.$priv"."_c.checked = true;\n";
4334: } else {
4335: $return_script .= "document.form1.$priv"."_c.checked = false;\n";
4336: }
4337: }
1.154 banghart 4338: foreach my $priv_item (keys(%full_d)) {
4339: my ($priv, $dummy) = split(/\&/,$priv_item);
1.269 raeburn 4340: if ((exists($role_d{$priv})) || (exists($role_s{$priv}))) {
1.154 banghart 4341: $return_script .= "document.form1.$priv"."_d.checked = true;\n";
4342: } else {
4343: $return_script .= "document.form1.$priv"."_d.checked = false;\n";
4344: }
4345: }
4346: foreach my $priv_item (keys(%full_s)) {
1.153 banghart 4347: my ($priv, $dummy) = split(/\&/,$priv_item);
1.154 banghart 4348: if (exists($role_s{$priv})) {
4349: $return_script .= "document.form1.$priv"."_s.checked = true;\n";
4350: } else {
4351: $return_script .= "document.form1.$priv"."_s.checked = false;\n";
4352: }
1.153 banghart 4353: }
4354: $return_script .= '}'."\n";
1.154 banghart 4355: return ($return_script);
4356: }
4357: # ----------------------------------------------------------
4358: sub make_button_code {
1.318 raeburn 4359: my ($role,$crstype) = @_;
4360: my $label = &Apache::lonnet::plaintext($role,$crstype);
1.301 bisitz 4361: my $button_code = '<input type="button" onclick="set_'.$role.'()" value="'.$label.'" />';
1.154 banghart 4362: return ($button_code);
1.153 banghart 4363: }
1.61 www 4364: # ---------------------------------------------------------- Call to definerole
4365: sub set_custom_role {
1.351 raeburn 4366: my ($r,$context,$brcrum) = @_;
1.101 albertel 4367: my $rolename=$env{'form.rolename'};
1.63 www 4368: $rolename=~s/[^A-Za-z0-9]//gs;
1.150 banghart 4369: if (!$rolename) {
1.351 raeburn 4370: &custom_role_editor($r,$brcrum);
1.61 www 4371: return;
4372: }
1.160 raeburn 4373: my ($jsback,$elements) = &crumb_utilities();
1.301 bisitz 4374: my $jscript = '<script type="text/javascript">'
4375: .'// <![CDATA['."\n"
4376: .$jsback."\n"
4377: .'// ]]>'."\n"
4378: .'</script>'."\n";
1.352 raeburn 4379: push(@{$brcrum},
4380: {href => "javascript:backPage(document.customresult,'pickrole','')",
4381: text => "Pick custom role",
4382: faq => 282,
4383: bug => 'Instructor Interface',},
4384: {href => "javascript:backPage(document.customresult,'selected_custom_edit','')",
4385: text => "Edit custom role",
4386: faq => 282,
4387: bug => 'Instructor Interface',},
4388: {href => "javascript:backPage(document.customresult,'set_custom_roles','')",
4389: text => "Result",
4390: faq => 282,
4391: bug => 'Instructor Interface',
4392: help => 'Course_Editing_Custom_Roles'},
4393: );
4394: my $args = { bread_crumbs => $brcrum,
1.351 raeburn 4395: bread_crumbs_component => 'User Management'};
4396: $r->print(&Apache::loncommon::start_page('Save Custom Role',$jscript,$args));
1.160 raeburn 4397:
1.61 www 4398: my ($rdummy,$roledef)=
1.110 albertel 4399: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
4400:
1.61 www 4401: # ------------------------------------------------------- Does this role exist?
1.188 raeburn 4402: $r->print('<h3>');
1.61 www 4403: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.73 sakharuk 4404: $r->print(&mt('Existing Role').' "');
1.61 www 4405: } else {
1.73 sakharuk 4406: $r->print(&mt('New Role').' "');
1.61 www 4407: $roledef='';
4408: }
1.188 raeburn 4409: $r->print($rolename.'"</h3>');
1.61 www 4410: # ------------------------------------------------------- What can be assigned?
4411: my $sysrole='';
4412: my $domrole='';
4413: my $courole='';
4414:
1.135 raeburn 4415: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
4416: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 4417: if (!$restrict) { $restrict=''; }
4418: if ($env{'form.'.$priv.'_c'}) {
1.135 raeburn 4419: $courole.=':'.$item;
1.61 www 4420: }
4421: }
4422:
1.135 raeburn 4423: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
4424: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 4425: if (!$restrict) { $restrict=''; }
4426: if ($env{'form.'.$priv.'_d'}) {
1.135 raeburn 4427: $domrole.=':'.$item;
1.61 www 4428: }
4429: }
4430:
1.135 raeburn 4431: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
4432: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 4433: if (!$restrict) { $restrict=''; }
4434: if ($env{'form.'.$priv.'_s'}) {
1.135 raeburn 4435: $sysrole.=':'.$item;
1.61 www 4436: }
4437: }
1.387 bisitz 4438: # Assign role; Compile and show result
4439: my $errmsg;
4440: my $result =
4441: &Apache::lonnet::definerole($rolename,$sysrole,$domrole,$courole);
4442: if ($result ne 'ok') {
4443: $errmsg = ': '.$result;
4444: }
4445: my $message =
4446: &Apache::lonhtmlcommon::confirm_success(
4447: &mt('Defining Role').$errmsg, ($result eq 'ok' ? 0 : 1));
1.101 albertel 4448: if ($env{'request.course.id'}) {
4449: my $url='/'.$env{'request.course.id'};
1.63 www 4450: $url=~s/\_/\//g;
1.387 bisitz 4451: $result =
4452: &Apache::lonnet::assigncustomrole(
4453: $env{'user.domain'},$env{'user.name'},
4454: $url,
4455: $env{'user.domain'},$env{'user.name'},
4456: $rolename,undef,undef,undef,$context);
4457: if ($result ne 'ok') {
4458: $errmsg = ': '.$result;
4459: }
4460: $message .=
4461: '<br />'
4462: .&Apache::lonhtmlcommon::confirm_success(
4463: &mt('Assigning Role to Self').$errmsg, ($result eq 'ok' ? 0 : 1));
1.63 www 4464: }
1.380 bisitz 4465: $r->print(
1.387 bisitz 4466: &Apache::loncommon::confirmwrapper($message)
4467: .'<br />'
4468: .&Apache::lonhtmlcommon::actionbox([
4469: '<a href="javascript:backPage(document.customresult,'."'pickrole'".')">'
4470: .&mt('Create or edit another custom role')
4471: .'</a>'])
1.380 bisitz 4472: .'<form name="customresult" method="post" action="">'
1.387 bisitz 4473: .&Apache::lonhtmlcommon::echo_form_input([])
4474: .'</form>'
1.380 bisitz 4475: );
1.58 www 4476: }
4477:
1.2 www 4478: # ================================================================ Main Handler
4479: sub handler {
4480: my $r = shift;
4481: if ($r->header_only) {
1.68 www 4482: &Apache::loncommon::content_type($r,'text/html');
1.2 www 4483: $r->send_http_header;
4484: return OK;
4485: }
1.318 raeburn 4486: my ($context,$crstype);
1.190 raeburn 4487: if ($env{'request.course.id'}) {
4488: $context = 'course';
1.318 raeburn 4489: $crstype = &Apache::loncommon::course_type();
1.190 raeburn 4490: } elsif ($env{'request.role'} =~ /^au\./) {
1.206 raeburn 4491: $context = 'author';
1.190 raeburn 4492: } else {
4493: $context = 'domain';
4494: }
1.375 raeburn 4495:
1.190 raeburn 4496: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.233 raeburn 4497: ['action','state','callingform','roletype','showrole','bulkaction','popup','phase',
4498: 'username','domain','srchterm','srchdomain','srchin','srchby','srchtype']);
1.190 raeburn 4499: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.351 raeburn 4500: my $args;
4501: my $brcrum = [];
4502: my $bread_crumbs_component = 'User Management';
1.202 raeburn 4503: if ($env{'form.action'} ne 'dateselect') {
1.351 raeburn 4504: $brcrum = [{href=>"/adm/createuser",
4505: text=>"User Management",
4506: 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'}
4507: ];
1.202 raeburn 4508: }
1.289 droeschl 4509: #SD Following files not added to help, because the corresponding .tex-files seem to
4510: #be missing: Course_Approve_Selfenroll,Course_User_Logs,
1.209 raeburn 4511: my ($permission,$allowed) =
1.318 raeburn 4512: &Apache::lonuserutils::get_permission($context,$crstype);
1.190 raeburn 4513: if (!$allowed) {
1.358 raeburn 4514: if ($context eq 'course') {
4515: $r->internal_redirect('/adm/viewclasslist');
4516: return OK;
4517: }
1.190 raeburn 4518: $env{'user.error.msg'}=
4519: "/adm/createuser:cst:0:0:Cannot create/modify user data ".
4520: "or view user status.";
4521: return HTTP_NOT_ACCEPTABLE;
4522: }
4523:
4524: &Apache::loncommon::content_type($r,'text/html');
4525: $r->send_http_header;
4526:
1.375 raeburn 4527: my $showcredits;
4528: if ((($context eq 'course') && ($crstype eq 'Course')) ||
4529: ($context eq 'domain')) {
4530: my %domdefaults =
4531: &Apache::lonnet::get_domain_defaults($env{'request.role.domain'});
4532: if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'}) {
4533: $showcredits = 1;
4534: }
4535: }
4536:
1.190 raeburn 4537: # Main switch on form.action and form.state, as appropriate
4538: if (! exists($env{'form.action'})) {
1.351 raeburn 4539: $args = {bread_crumbs => $brcrum,
4540: bread_crumbs_component => $bread_crumbs_component};
4541: $r->print(&header(undef,$args));
1.318 raeburn 4542: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 4543: } elsif ($env{'form.action'} eq 'upload' && $permission->{'cusr'}) {
1.351 raeburn 4544: push(@{$brcrum},
4545: { href => '/adm/createuser?action=upload&state=',
4546: text => 'Upload Users List',
4547: help => 'Course_Create_Class_List',
4548: });
4549: $bread_crumbs_component = 'Upload Users List';
4550: $args = {bread_crumbs => $brcrum,
4551: bread_crumbs_component => $bread_crumbs_component};
4552: $r->print(&header(undef,$args));
1.190 raeburn 4553: $r->print('<form name="studentform" method="post" '.
4554: 'enctype="multipart/form-data" '.
4555: ' action="/adm/createuser">'."\n");
4556: if (! exists($env{'form.state'})) {
4557: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4558: } elsif ($env{'form.state'} eq 'got_file') {
1.375 raeburn 4559: &Apache::lonuserutils::print_upload_manager_form($r,$context,$permission,
4560: $crstype,$showcredits);
1.190 raeburn 4561: } elsif ($env{'form.state'} eq 'enrolling') {
4562: if ($env{'form.datatoken'}) {
1.375 raeburn 4563: &Apache::lonuserutils::upfile_drop_add($r,$context,$permission,
4564: $showcredits);
1.190 raeburn 4565: }
4566: } else {
4567: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4568: }
1.213 raeburn 4569: } elsif ((($env{'form.action'} eq 'singleuser') || ($env{'form.action'}
4570: eq 'singlestudent')) && ($permission->{'cusr'})) {
1.190 raeburn 4571: my $phase = $env{'form.phase'};
4572: my @search = ('srchterm','srchby','srchin','srchtype','srchdomain');
1.192 albertel 4573: &Apache::loncreateuser::restore_prev_selections();
4574: my $srch;
4575: foreach my $item (@search) {
4576: $srch->{$item} = $env{'form.'.$item};
4577: }
1.207 raeburn 4578: if (($phase eq 'get_user_info') || ($phase eq 'userpicked') ||
4579: ($phase eq 'createnewuser')) {
4580: if ($env{'form.phase'} eq 'createnewuser') {
4581: my $response;
4582: if ($env{'form.srchterm'} !~ /^$match_username$/) {
1.366 bisitz 4583: my $response =
4584: '<span class="LC_warning">'
4585: .&mt('You must specify a valid username. Only the following are allowed:'
4586: .' letters numbers - . @')
4587: .'</span>';
1.221 raeburn 4588: $env{'form.phase'} = '';
1.375 raeburn 4589: &print_username_entry_form($r,$context,$response,$srch,undef,
4590: $crstype,$brcrum,$showcredits);
1.207 raeburn 4591: } else {
4592: my $ccuname =&LONCAPA::clean_username($srch->{'srchterm'});
4593: my $ccdomain=&LONCAPA::clean_domain($srch->{'srchdomain'});
4594: &print_user_modification_page($r,$ccuname,$ccdomain,
1.221 raeburn 4595: $srch,$response,$context,
1.375 raeburn 4596: $permission,$crstype,$brcrum,
4597: $showcredits);
1.207 raeburn 4598: }
4599: } elsif ($env{'form.phase'} eq 'get_user_info') {
1.190 raeburn 4600: my ($currstate,$response,$forcenewuser,$results) =
1.221 raeburn 4601: &user_search_result($context,$srch);
1.190 raeburn 4602: if ($env{'form.currstate'} eq 'modify') {
4603: $currstate = $env{'form.currstate'};
4604: }
4605: if ($currstate eq 'select') {
4606: &print_user_selection_page($r,$response,$srch,$results,
1.351 raeburn 4607: \@search,$context,undef,$crstype,
4608: $brcrum);
1.190 raeburn 4609: } elsif ($currstate eq 'modify') {
4610: my ($ccuname,$ccdomain);
4611: if (($srch->{'srchby'} eq 'uname') &&
4612: ($srch->{'srchtype'} eq 'exact')) {
4613: $ccuname = $srch->{'srchterm'};
4614: $ccdomain= $srch->{'srchdomain'};
4615: } else {
4616: my @matchedunames = keys(%{$results});
4617: ($ccuname,$ccdomain) = split(/:/,$matchedunames[0]);
4618: }
4619: $ccuname =&LONCAPA::clean_username($ccuname);
4620: $ccdomain=&LONCAPA::clean_domain($ccdomain);
4621: if ($env{'form.forcenewuser'}) {
4622: $response = '';
4623: }
4624: &print_user_modification_page($r,$ccuname,$ccdomain,
1.221 raeburn 4625: $srch,$response,$context,
1.351 raeburn 4626: $permission,$crstype,$brcrum);
1.190 raeburn 4627: } elsif ($currstate eq 'query') {
1.351 raeburn 4628: &print_user_query_page($r,'createuser',$brcrum);
1.190 raeburn 4629: } else {
1.229 raeburn 4630: $env{'form.phase'} = '';
1.207 raeburn 4631: &print_username_entry_form($r,$context,$response,$srch,
1.351 raeburn 4632: $forcenewuser,$crstype,$brcrum);
1.190 raeburn 4633: }
4634: } elsif ($env{'form.phase'} eq 'userpicked') {
4635: my $ccuname = &LONCAPA::clean_username($env{'form.seluname'});
4636: my $ccdomain = &LONCAPA::clean_domain($env{'form.seludom'});
1.196 raeburn 4637: &print_user_modification_page($r,$ccuname,$ccdomain,$srch,'',
1.351 raeburn 4638: $context,$permission,$crstype,
4639: $brcrum);
1.190 raeburn 4640: }
4641: } elsif ($env{'form.phase'} eq 'update_user_data') {
1.375 raeburn 4642: &update_user_data($r,$context,$crstype,$brcrum,$showcredits);
1.190 raeburn 4643: } else {
1.351 raeburn 4644: &print_username_entry_form($r,$context,undef,$srch,undef,$crstype,
4645: $brcrum);
1.190 raeburn 4646: }
4647: } elsif ($env{'form.action'} eq 'custom' && $permission->{'custom'}) {
4648: if ($env{'form.phase'} eq 'set_custom_roles') {
1.351 raeburn 4649: &set_custom_role($r,$context,$brcrum);
1.190 raeburn 4650: } else {
1.351 raeburn 4651: &custom_role_editor($r,$brcrum);
1.190 raeburn 4652: }
1.362 raeburn 4653: } elsif (($env{'form.action'} eq 'processauthorreq') &&
4654: ($permission->{'cusr'}) &&
4655: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
4656: push(@{$brcrum},
4657: {href => '/adm/createuser?action=processauthorreq',
1.385 bisitz 4658: text => 'Authoring Space requests',
1.362 raeburn 4659: help => 'Domain_Role_Approvals'});
4660: $bread_crumbs_component = 'Authoring requests';
4661: if ($env{'form.state'} eq 'done') {
4662: push(@{$brcrum},
4663: {href => '/adm/createuser?action=authorreqqueue',
4664: text => 'Result',
4665: help => 'Domain_Role_Approvals'});
4666: $bread_crumbs_component = 'Authoring request result';
4667: }
4668: $args = { bread_crumbs => $brcrum,
4669: bread_crumbs_component => $bread_crumbs_component};
4670: $r->print(&header(undef,$args));
4671: if (!exists($env{'form.state'})) {
4672: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestauthor',
4673: $env{'request.role.domain'}));
4674: } elsif ($env{'form.state'} eq 'done') {
4675: $r->print('<h3>'.&mt('Authoring request processing').'</h3>'."\n");
4676: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestauthor',
4677: $env{'request.role.domain'}));
4678: }
1.207 raeburn 4679: } elsif (($env{'form.action'} eq 'listusers') &&
4680: ($permission->{'view'} || $permission->{'cusr'})) {
1.202 raeburn 4681: if ($env{'form.phase'} eq 'bulkchange') {
1.351 raeburn 4682: push(@{$brcrum},
4683: {href => '/adm/createuser?action=listusers',
4684: text => "List Users"},
4685: {href => "/adm/createuser",
4686: text => "Result",
4687: help => 'Course_View_Class_List'});
4688: $bread_crumbs_component = 'Update Users';
4689: $args = {bread_crumbs => $brcrum,
4690: bread_crumbs_component => $bread_crumbs_component};
4691: $r->print(&header(undef,$args));
1.202 raeburn 4692: my $setting = $env{'form.roletype'};
4693: my $choice = $env{'form.bulkaction'};
4694: if ($permission->{'cusr'}) {
1.336 raeburn 4695: &Apache::lonuserutils::update_user_list($r,$context,$setting,$choice,$crstype);
1.221 raeburn 4696: } else {
4697: $r->print(&mt('You are not authorized to make bulk changes to user roles'));
1.223 raeburn 4698: $r->print('<p><a href="/adm/createuser?action=listusers">'.&mt('Display User Lists').'</a>');
1.202 raeburn 4699: }
4700: } else {
1.351 raeburn 4701: push(@{$brcrum},
4702: {href => '/adm/createuser?action=listusers',
4703: text => "List Users",
4704: help => 'Course_View_Class_List'});
4705: $bread_crumbs_component = 'List Users';
4706: $args = {bread_crumbs => $brcrum,
4707: bread_crumbs_component => $bread_crumbs_component};
1.202 raeburn 4708: my ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles);
4709: my $formname = 'studentform';
1.364 raeburn 4710: my $hidecall = "hide_searching();";
1.321 raeburn 4711: if (($context eq 'domain') && (($env{'form.roletype'} eq 'course') ||
4712: ($env{'form.roletype'} eq 'community'))) {
4713: if ($env{'form.roletype'} eq 'course') {
4714: ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles) =
4715: &Apache::lonuserutils::courses_selector($env{'request.role.domain'},
4716: $formname);
4717: } elsif ($env{'form.roletype'} eq 'community') {
4718: $cb_jscript =
4719: &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
4720: my %elements = (
4721: coursepick => 'radio',
4722: coursetotal => 'text',
4723: courselist => 'text',
4724: );
4725: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements);
4726: }
1.364 raeburn 4727: $jscript .= &verify_user_display($context)."\n".
4728: &Apache::loncommon::check_uncheck_jscript();
1.202 raeburn 4729: my $js = &add_script($jscript).$cb_jscript;
4730: my $loadcode =
4731: &Apache::lonuserutils::course_selector_loadcode($formname);
4732: if ($loadcode ne '') {
1.364 raeburn 4733: $args->{add_entries} = {onload => "$loadcode;$hidecall"};
4734: } else {
4735: $args->{add_entries} = {onload => $hidecall};
1.202 raeburn 4736: }
1.351 raeburn 4737: $r->print(&header($js,$args));
1.191 raeburn 4738: } else {
1.364 raeburn 4739: $args->{add_entries} = {onload => $hidecall};
4740: $jscript = &verify_user_display($context).
4741: &Apache::loncommon::check_uncheck_jscript();
4742: $r->print(&header(&add_script($jscript),$args));
1.191 raeburn 4743: }
1.202 raeburn 4744: &Apache::lonuserutils::print_userlist($r,undef,$permission,$context,
1.375 raeburn 4745: $formname,$totcodes,$codetitles,$idlist,$idlist_titles,
4746: $showcredits);
1.191 raeburn 4747: }
1.213 raeburn 4748: } elsif ($env{'form.action'} eq 'drop' && $permission->{'cusr'}) {
1.318 raeburn 4749: my $brtext;
4750: if ($crstype eq 'Community') {
4751: $brtext = 'Drop Members';
4752: } else {
4753: $brtext = 'Drop Students';
4754: }
1.351 raeburn 4755: push(@{$brcrum},
4756: {href => '/adm/createuser?action=drop',
4757: text => $brtext,
4758: help => 'Course_Drop_Student'});
4759: if ($env{'form.state'} eq 'done') {
4760: push(@{$brcrum},
4761: {href=>'/adm/createuser?action=drop',
4762: text=>"Result"});
4763: }
4764: $bread_crumbs_component = $brtext;
4765: $args = {bread_crumbs => $brcrum,
4766: bread_crumbs_component => $bread_crumbs_component};
4767: $r->print(&header(undef,$args));
1.213 raeburn 4768: if (!exists($env{'form.state'})) {
1.318 raeburn 4769: &Apache::lonuserutils::print_drop_menu($r,$context,$permission,$crstype);
1.213 raeburn 4770: } elsif ($env{'form.state'} eq 'done') {
4771: &Apache::lonuserutils::update_user_list($r,$context,undef,
4772: $env{'form.action'});
4773: }
1.202 raeburn 4774: } elsif ($env{'form.action'} eq 'dateselect') {
4775: if ($permission->{'cusr'}) {
1.351 raeburn 4776: $r->print(&header(undef,{'no_nav_bar' => 1}).
1.375 raeburn 4777: &Apache::lonuserutils::date_section_selector($context,$permission,
4778: $crstype,$showcredits));
1.202 raeburn 4779: } else {
1.351 raeburn 4780: $r->print(&header(undef,{'no_nav_bar' => 1}).
4781: '<span class="LC_error">'.&mt('You do not have permission to modify dates or sections for users').'</span>');
1.202 raeburn 4782: }
1.237 raeburn 4783: } elsif ($env{'form.action'} eq 'selfenroll') {
1.351 raeburn 4784: push(@{$brcrum},
4785: {href => '/adm/createuser?action=selfenroll',
4786: text => "Configure Self-enrollment",
4787: help => 'Course_Self_Enrollment'});
1.237 raeburn 4788: if (!exists($env{'form.state'})) {
1.351 raeburn 4789: $args = { bread_crumbs => $brcrum,
4790: bread_crumbs_component => 'Configure Self-enrollment'};
4791: $r->print(&header(undef,$args));
1.241 raeburn 4792: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
1.237 raeburn 4793: &print_selfenroll_menu($r,$context,$permission);
4794: } elsif ($env{'form.state'} eq 'done') {
1.351 raeburn 4795: push (@{$brcrum},
4796: {href=>'/adm/createuser?action=selfenroll',
4797: text=>"Result"});
4798: $args = { bread_crumbs => $brcrum,
4799: bread_crumbs_component => 'Self-enrollment result'};
4800: $r->print(&header(undef,$args));
1.241 raeburn 4801: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
4802: &update_selfenroll_config($r,$context,$permission);
1.237 raeburn 4803: }
1.277 raeburn 4804: } elsif ($env{'form.action'} eq 'selfenrollqueue') {
1.351 raeburn 4805: push(@{$brcrum},
4806: {href => '/adm/createuser?action=selfenrollqueue',
4807: text => 'Enrollment requests',
4808: help => 'Course_Self_Enrollment'});
4809: $bread_crumbs_component = 'Enrollment requests';
4810: if ($env{'form.state'} eq 'done') {
4811: push(@{$brcrum},
4812: {href => '/adm/createuser?action=selfenrollqueue',
4813: text => 'Result',
4814: help => 'Course_Self_Enrollment'});
4815: $bread_crumbs_component = 'Enrollment result';
4816: }
4817: $args = { bread_crumbs => $brcrum,
4818: bread_crumbs_component => $bread_crumbs_component};
4819: $r->print(&header(undef,$args));
1.277 raeburn 4820: my $cid = $env{'request.course.id'};
4821: my $cdom = $env{'course.'.$cid.'.domain'};
4822: my $cnum = $env{'course.'.$cid.'.num'};
1.307 raeburn 4823: my $coursedesc = $env{'course.'.$cid.'.description'};
1.277 raeburn 4824: if (!exists($env{'form.state'})) {
4825: $r->print('<h3>'.&mt('Pending enrollment requests').'</h3>'."\n");
1.307 raeburn 4826: $r->print(&Apache::loncoursequeueadmin::display_queued_requests($context,
4827: $cdom,$cnum));
1.277 raeburn 4828: } elsif ($env{'form.state'} eq 'done') {
4829: $r->print('<h3>'.&mt('Enrollment request processing').'</h3>'."\n");
1.307 raeburn 4830: $r->print(&Apache::loncoursequeueadmin::update_request_queue($context,
4831: $cdom,$cnum,$coursedesc));
1.277 raeburn 4832: }
1.239 raeburn 4833: } elsif ($env{'form.action'} eq 'changelogs') {
1.363 raeburn 4834: my $helpitem;
4835: if ($context eq 'course') {
4836: $helpitem = 'Course_User_Logs';
4837: }
1.351 raeburn 4838: push (@{$brcrum},
4839: {href => '/adm/createuser?action=changelogs',
4840: text => 'User Management Logs',
1.363 raeburn 4841: help => $helpitem});
1.351 raeburn 4842: $bread_crumbs_component = 'User Changes';
4843: $args = { bread_crumbs => $brcrum,
4844: bread_crumbs_component => $bread_crumbs_component};
4845: $r->print(&header(undef,$args));
4846: &print_userchangelogs_display($r,$context,$permission);
1.190 raeburn 4847: } else {
1.351 raeburn 4848: $bread_crumbs_component = 'User Management';
4849: $args = { bread_crumbs => $brcrum,
4850: bread_crumbs_component => $bread_crumbs_component};
4851: $r->print(&header(undef,$args));
1.318 raeburn 4852: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 4853: }
1.351 raeburn 4854: $r->print(&Apache::loncommon::end_page());
1.190 raeburn 4855: return OK;
4856: }
4857:
4858: sub header {
1.351 raeburn 4859: my ($jscript,$args) = @_;
1.190 raeburn 4860: my $start_page;
1.351 raeburn 4861: if (ref($args) eq 'HASH') {
4862: $start_page=&Apache::loncommon::start_page('User Management',$jscript,$args);
1.190 raeburn 4863: } else {
1.351 raeburn 4864: $start_page=&Apache::loncommon::start_page('User Management',$jscript);
1.190 raeburn 4865: }
4866: return $start_page;
4867: }
1.2 www 4868:
1.191 raeburn 4869: sub add_script {
4870: my ($js) = @_;
1.301 bisitz 4871: return '<script type="text/javascript">'."\n"
4872: .'// <![CDATA['."\n"
4873: .$js."\n"
4874: .'// ]]>'."\n"
4875: .'</script>'."\n";
1.191 raeburn 4876: }
4877:
1.202 raeburn 4878: sub verify_user_display {
1.364 raeburn 4879: my ($context) = @_;
1.374 raeburn 4880: my %lt = &Apache::lonlocal::texthash (
4881: course => 'course(s): description, section(s), status',
4882: community => 'community(s): description, section(s), status',
4883: author => 'author',
4884: );
1.364 raeburn 4885: my $photos;
4886: if (($context eq 'course') && $env{'request.course.id'}) {
4887: $photos = $env{'course.'.$env{'request.course.id'}.'.internal.showphoto'};
4888: }
1.202 raeburn 4889: my $output = <<"END";
4890:
1.364 raeburn 4891: function hide_searching() {
4892: if (document.getElementById('searching')) {
4893: document.getElementById('searching').style.display = 'none';
4894: }
4895: return;
4896: }
4897:
1.202 raeburn 4898: function display_update() {
4899: document.studentform.action.value = 'listusers';
4900: document.studentform.phase.value = 'display';
4901: document.studentform.submit();
4902: }
4903:
1.364 raeburn 4904: function updateCols(caller) {
4905: var context = '$context';
4906: var photos = '$photos';
4907: if (caller == 'Status') {
1.374 raeburn 4908: if ((context == 'domain') &&
4909: ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
4910: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community'))) {
1.364 raeburn 4911: document.getElementById('showcolstatus').checked = false;
4912: document.getElementById('showcolstatus').disabled = 'disabled';
4913: document.getElementById('showcolstart').checked = false;
4914: document.getElementById('showcolend').checked = false;
1.374 raeburn 4915: } else {
4916: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
4917: document.getElementById('showcolstatus').checked = true;
4918: document.getElementById('showcolstatus').disabled = '';
4919: document.getElementById('showcolstart').checked = true;
4920: document.getElementById('showcolend').checked = true;
4921: } else {
4922: document.getElementById('showcolstatus').checked = false;
4923: document.getElementById('showcolstatus').disabled = 'disabled';
4924: document.getElementById('showcolstart').checked = false;
4925: document.getElementById('showcolend').checked = false;
4926: }
1.364 raeburn 4927: }
4928: }
4929: if (caller == 'output') {
4930: if (photos == 1) {
4931: if (document.getElementById('showcolphoto')) {
4932: var photoitem = document.getElementById('showcolphoto');
4933: if (document.studentform.output.options[document.studentform.output.selectedIndex].value == 'html') {
4934: photoitem.checked = true;
4935: photoitem.disabled = '';
4936: } else {
4937: photoitem.checked = false;
4938: photoitem.disabled = 'disabled';
4939: }
4940: }
4941: }
4942: }
4943: if (caller == 'showrole') {
1.371 raeburn 4944: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any') ||
4945: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'cr')) {
1.364 raeburn 4946: document.getElementById('showcolrole').checked = true;
4947: document.getElementById('showcolrole').disabled = '';
4948: } else {
4949: document.getElementById('showcolrole').checked = false;
4950: document.getElementById('showcolrole').disabled = 'disabled';
4951: }
1.374 raeburn 4952: if (context == 'domain') {
1.382 raeburn 4953: var quotausageshow = 0;
1.374 raeburn 4954: if ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
4955: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community')) {
4956: document.getElementById('showcolstatus').checked = false;
4957: document.getElementById('showcolstatus').disabled = 'disabled';
4958: document.getElementById('showcolstart').checked = false;
4959: document.getElementById('showcolend').checked = false;
4960: } else {
4961: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
4962: document.getElementById('showcolstatus').checked = true;
4963: document.getElementById('showcolstatus').disabled = '';
4964: document.getElementById('showcolstart').checked = true;
4965: document.getElementById('showcolend').checked = true;
4966: }
4967: }
4968: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'domain') {
4969: document.getElementById('showcolextent').disabled = 'disabled';
4970: document.getElementById('showcolextent').checked = 'false';
4971: document.getElementById('showextent').style.display='none';
4972: document.getElementById('showcoltextextent').innerHTML = '';
1.382 raeburn 4973: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'au') ||
4974: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any')) {
4975: if (document.getElementById('showcolauthorusage')) {
4976: document.getElementById('showcolauthorusage').disabled = '';
4977: }
4978: if (document.getElementById('showcolauthorquota')) {
4979: document.getElementById('showcolauthorquota').disabled = '';
4980: }
4981: quotausageshow = 1;
4982: }
1.374 raeburn 4983: } else {
4984: document.getElementById('showextent').style.display='block';
4985: document.getElementById('showextent').style.textAlign='left';
4986: document.getElementById('showextent').style.textFace='normal';
4987: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'author') {
4988: document.getElementById('showcolextent').disabled = '';
4989: document.getElementById('showcolextent').checked = 'true';
4990: document.getElementById('showcoltextextent').innerHTML="$lt{'author'}";
4991: } else {
4992: document.getElementById('showcolextent').disabled = '';
4993: document.getElementById('showcolextent').checked = 'true';
4994: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community') {
4995: document.getElementById('showcoltextextent').innerHTML="$lt{'community'}";
4996: } else {
4997: document.getElementById('showcoltextextent').innerHTML="$lt{'course'}";
4998: }
4999: }
5000: }
1.382 raeburn 5001: if (quotausageshow == 0) {
5002: if (document.getElementById('showcolauthorusage')) {
5003: document.getElementById('showcolauthorusage').checked = false;
5004: document.getElementById('showcolauthorusage').disabled = 'disabled';
5005: }
5006: if (document.getElementById('showcolauthorquota')) {
5007: document.getElementById('showcolauthorquota').checked = false;
5008: document.getElementById('showcolauthorquota').disabled = 'disabled';
5009: }
5010: }
1.374 raeburn 5011: }
1.364 raeburn 5012: }
5013: return;
5014: }
5015:
1.202 raeburn 5016: END
5017: return $output;
5018:
5019: }
5020:
1.190 raeburn 5021: ###############################################################
5022: ###############################################################
5023: # Menu Phase One
5024: sub print_main_menu {
1.318 raeburn 5025: my ($permission,$context,$crstype) = @_;
5026: my $linkcontext = $context;
5027: my $stuterm = lc(&Apache::lonnet::plaintext('st',$crstype));
5028: if (($context eq 'course') && ($crstype eq 'Community')) {
5029: $linkcontext = lc($crstype);
5030: $stuterm = 'Members';
5031: }
1.208 raeburn 5032: my %links = (
1.298 droeschl 5033: domain => {
5034: upload => 'Upload a File of Users',
5035: singleuser => 'Add/Modify a User',
5036: listusers => 'Manage Users',
5037: },
5038: author => {
5039: upload => 'Upload a File of Co-authors',
5040: singleuser => 'Add/Modify a Co-author',
5041: listusers => 'Manage Co-authors',
5042: },
5043: course => {
5044: upload => 'Upload a File of Course Users',
5045: singleuser => 'Add/Modify a Course User',
1.354 www 5046: listusers => 'List and Modify Multiple Course Users',
1.298 droeschl 5047: },
1.318 raeburn 5048: community => {
5049: upload => 'Upload a File of Community Users',
5050: singleuser => 'Add/Modify a Community User',
1.354 www 5051: listusers => 'List and Modify Multiple Community Users',
1.318 raeburn 5052: },
5053: );
5054: my %linktitles = (
5055: domain => {
5056: singleuser => 'Add a user to the domain, and/or a course or community in the domain.',
5057: listusers => 'Show and manage users in this domain.',
5058: },
5059: author => {
5060: singleuser => 'Add a user with a co- or assistant author role.',
5061: listusers => 'Show and manage co- or assistant authors.',
5062: },
5063: course => {
5064: singleuser => 'Add a user with a certain role to this course.',
5065: listusers => 'Show and manage users in this course.',
5066: },
5067: community => {
5068: singleuser => 'Add a user with a certain role to this community.',
5069: listusers => 'Show and manage users in this community.',
5070: },
1.298 droeschl 5071: );
5072: my @menu = ( {categorytitle => 'Single Users',
5073: items =>
5074: [
5075: {
1.318 raeburn 5076: linktext => $links{$linkcontext}{'singleuser'},
1.298 droeschl 5077: icon => 'edit-redo.png',
5078: #help => 'Course_Change_Privileges',
5079: url => '/adm/createuser?action=singleuser',
5080: permission => $permission->{'cusr'},
1.318 raeburn 5081: linktitle => $linktitles{$linkcontext}{'singleuser'},
1.298 droeschl 5082: },
5083: ]},
5084:
5085: {categorytitle => 'Multiple Users',
5086: items =>
5087: [
5088: {
1.318 raeburn 5089: linktext => $links{$linkcontext}{'upload'},
1.340 wenzelju 5090: icon => 'uplusr.png',
1.298 droeschl 5091: #help => 'Course_Create_Class_List',
5092: url => '/adm/createuser?action=upload',
5093: permission => $permission->{'cusr'},
5094: linktitle => 'Upload a CSV or a text file containing users.',
5095: },
5096: {
1.318 raeburn 5097: linktext => $links{$linkcontext}{'listusers'},
1.340 wenzelju 5098: icon => 'mngcu.png',
1.298 droeschl 5099: #help => 'Course_View_Class_List',
5100: url => '/adm/createuser?action=listusers',
5101: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.318 raeburn 5102: linktitle => $linktitles{$linkcontext}{'listusers'},
1.298 droeschl 5103: },
5104:
5105: ]},
5106:
5107: {categorytitle => 'Administration',
5108: items => [ ]},
5109: );
5110:
1.265 mielkec 5111: if ($context eq 'domain'){
1.298 droeschl 5112:
5113: push(@{ $menu[2]->{items} }, #Category: Administration
5114: {
5115: linktext => 'Custom Roles',
5116: icon => 'emblem-photos.png',
5117: #help => 'Course_Editing_Custom_Roles',
5118: url => '/adm/createuser?action=custom',
5119: permission => $permission->{'custom'},
5120: linktitle => 'Configure a custom role.',
5121: },
1.362 raeburn 5122: {
5123: linktext => 'Authoring Space Requests',
5124: icon => 'selfenrl-queue.png',
5125: #help => 'Domain_Role_Approvals',
5126: url => '/adm/createuser?action=processauthorreq',
5127: permission => $permission->{'cusr'},
5128: linktitle => 'Approve or reject author role requests',
5129: },
1.363 raeburn 5130: {
5131: linktext => 'Change Log',
5132: icon => 'document-properties.png',
5133: #help => 'Course_User_Logs',
5134: url => '/adm/createuser?action=changelogs',
5135: permission => $permission->{'cusr'},
5136: linktitle => 'View change log.',
5137: },
1.298 droeschl 5138: );
5139:
1.265 mielkec 5140: }elsif ($context eq 'course'){
1.298 droeschl 5141: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity();
1.318 raeburn 5142:
5143: my %linktext = (
5144: 'Course' => {
5145: single => 'Add/Modify a Student',
5146: drop => 'Drop Students',
5147: groups => 'Course Groups',
5148: },
5149: 'Community' => {
5150: single => 'Add/Modify a Member',
5151: drop => 'Drop Members',
5152: groups => 'Community Groups',
5153: },
5154: );
5155:
5156: my %linktitle = (
5157: 'Course' => {
5158: single => 'Add a user with the role of student to this course',
5159: drop => 'Remove a student from this course.',
5160: groups => 'Manage course groups',
5161: },
5162: 'Community' => {
5163: single => 'Add a user with the role of member to this community',
5164: drop => 'Remove a member from this community.',
5165: groups => 'Manage community groups',
5166: },
5167: );
5168:
1.298 droeschl 5169: push(@{ $menu[0]->{items} }, #Category: Single Users
5170: {
1.318 raeburn 5171: linktext => $linktext{$crstype}{'single'},
1.298 droeschl 5172: #help => 'Course_Add_Student',
5173: icon => 'list-add.png',
5174: url => '/adm/createuser?action=singlestudent',
5175: permission => $permission->{'cusr'},
1.318 raeburn 5176: linktitle => $linktitle{$crstype}{'single'},
1.298 droeschl 5177: },
5178: );
5179:
5180: push(@{ $menu[1]->{items} }, #Category: Multiple Users
5181: {
1.318 raeburn 5182: linktext => $linktext{$crstype}{'drop'},
1.298 droeschl 5183: icon => 'edit-undo.png',
5184: #help => 'Course_Drop_Student',
5185: url => '/adm/createuser?action=drop',
5186: permission => $permission->{'cusr'},
1.318 raeburn 5187: linktitle => $linktitle{$crstype}{'drop'},
1.298 droeschl 5188: },
5189: );
5190: push(@{ $menu[2]->{items} }, #Category: Administration
5191: {
5192: linktext => 'Custom Roles',
5193: icon => 'emblem-photos.png',
5194: #help => 'Course_Editing_Custom_Roles',
5195: url => '/adm/createuser?action=custom',
5196: permission => $permission->{'custom'},
5197: linktitle => 'Configure a custom role.',
5198: },
5199: {
1.318 raeburn 5200: linktext => $linktext{$crstype}{'groups'},
1.333 wenzelju 5201: icon => 'grps.png',
1.298 droeschl 5202: #help => 'Course_Manage_Group',
5203: url => '/adm/coursegroups?refpage=cusr',
5204: permission => $permission->{'grp_manage'},
1.318 raeburn 5205: linktitle => $linktitle{$crstype}{'groups'},
1.298 droeschl 5206: },
5207: {
1.328 wenzelju 5208: linktext => 'Change Log',
1.298 droeschl 5209: icon => 'document-properties.png',
5210: #help => 'Course_User_Logs',
5211: url => '/adm/createuser?action=changelogs',
5212: permission => $permission->{'cusr'},
5213: linktitle => 'View change log.',
5214: },
5215: );
1.277 raeburn 5216: if ($env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'}) {
1.298 droeschl 5217: push(@{ $menu[2]->{items} },
5218: {
5219: linktext => 'Enrollment Requests',
5220: icon => 'selfenrl-queue.png',
5221: #help => 'Course_Approve_Selfenroll',
5222: url => '/adm/createuser?action=selfenrollqueue',
5223: permission => $permission->{'cusr'},
5224: linktitle =>'Approve or reject enrollment requests.',
5225: },
5226: );
1.277 raeburn 5227: }
1.298 droeschl 5228:
1.265 mielkec 5229: if (!exists($permission->{'cusr_section'})){
1.320 raeburn 5230: if ($crstype ne 'Community') {
5231: push(@{ $menu[2]->{items} },
5232: {
5233: linktext => 'Automated Enrollment',
5234: icon => 'roles.png',
5235: #help => 'Course_Automated_Enrollment',
5236: permission => (&Apache::lonnet::auto_run($cnum,$cdom)
5237: && $permission->{'cusr'}),
5238: url => '/adm/populate',
5239: linktitle => 'Automated enrollment manager.',
5240: }
5241: );
5242: }
5243: push(@{ $menu[2]->{items} },
1.298 droeschl 5244: {
5245: linktext => 'User Self-Enrollment',
1.342 wenzelju 5246: icon => 'self_enroll.png',
1.298 droeschl 5247: #help => 'Course_Self_Enrollment',
5248: url => '/adm/createuser?action=selfenroll',
5249: permission => $permission->{'cusr'},
1.317 bisitz 5250: linktitle => 'Configure user self-enrollment.',
1.298 droeschl 5251: },
5252: );
5253: }
1.363 raeburn 5254: } elsif ($context eq 'author') {
1.370 raeburn 5255: push(@{ $menu[2]->{items} }, #Category: Administration
1.363 raeburn 5256: {
5257: linktext => 'Change Log',
5258: icon => 'document-properties.png',
5259: #help => 'Course_User_Logs',
5260: url => '/adm/createuser?action=changelogs',
5261: permission => $permission->{'cusr'},
5262: linktitle => 'View change log.',
5263: },
1.370 raeburn 5264: );
1.363 raeburn 5265: }
5266: return Apache::lonhtmlcommon::generate_menu(@menu);
1.250 raeburn 5267: # { text => 'View Log-in History',
5268: # help => 'Course_User_Logins',
5269: # action => 'logins',
5270: # permission => $permission->{'cusr'},
5271: # });
1.190 raeburn 5272: }
5273:
1.189 albertel 5274: sub restore_prev_selections {
5275: my %saveable_parameters = ('srchby' => 'scalar',
5276: 'srchin' => 'scalar',
5277: 'srchtype' => 'scalar',
5278: );
5279: &Apache::loncommon::store_settings('user','user_picker',
5280: \%saveable_parameters);
5281: &Apache::loncommon::restore_settings('user','user_picker',
5282: \%saveable_parameters);
5283: }
5284:
1.237 raeburn 5285: sub print_selfenroll_menu {
5286: my ($r,$context,$permission) = @_;
1.322 raeburn 5287: my $crstype = &Apache::loncommon::course_type();
1.237 raeburn 5288: my $formname = 'enrollstudent';
5289: my $nolink = 1;
5290: my ($row,$lt) = &get_selfenroll_titles();
5291: my $groupslist = &Apache::lonuserutils::get_groupslist();
5292: my $setsec_js =
5293: &Apache::lonuserutils::setsections_javascript($formname,$groupslist);
1.249 raeburn 5294: my %alerts = &Apache::lonlocal::texthash(
5295: acto => 'Activation of self-enrollment was selected for the following domain(s)',
5296: butn => 'but no user types have been checked.',
5297: wilf => "Please uncheck 'activate' or check at least one type.",
5298: );
5299: my $selfenroll_js = <<"ENDSCRIPT";
5300: function update_types(caller,num) {
5301: var delidx = getIndexByName('selfenroll_delete');
5302: var actidx = getIndexByName('selfenroll_activate');
5303: if (caller == 'selfenroll_all') {
5304: var selall;
5305: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5306: if (document.$formname.selfenroll_all[i].checked) {
5307: selall = document.$formname.selfenroll_all[i].value;
5308: }
5309: }
5310: if (selall == 1) {
5311: if (delidx != -1) {
5312: if (document.$formname.selfenroll_delete.length) {
5313: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
5314: document.$formname.selfenroll_delete[j].checked = true;
5315: }
5316: } else {
5317: document.$formname.elements[delidx].checked = true;
5318: }
5319: }
5320: if (actidx != -1) {
5321: if (document.$formname.selfenroll_activate.length) {
5322: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5323: document.$formname.selfenroll_activate[j].checked = false;
5324: }
5325: } else {
5326: document.$formname.elements[actidx].checked = false;
5327: }
5328: }
5329: document.$formname.selfenroll_newdom.selectedIndex = 0;
5330: }
5331: }
5332: if (caller == 'selfenroll_activate') {
5333: if (document.$formname.selfenroll_activate.length) {
5334: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5335: if (document.$formname.selfenroll_activate[j].value == num) {
5336: if (document.$formname.selfenroll_activate[j].checked) {
5337: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5338: if (document.$formname.selfenroll_all[i].value == '1') {
5339: document.$formname.selfenroll_all[i].checked = false;
5340: }
5341: if (document.$formname.selfenroll_all[i].value == '0') {
5342: document.$formname.selfenroll_all[i].checked = true;
5343: }
5344: }
5345: }
5346: }
5347: }
5348: } else {
5349: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5350: if (document.$formname.selfenroll_all[i].value == '1') {
5351: document.$formname.selfenroll_all[i].checked = false;
5352: }
5353: if (document.$formname.selfenroll_all[i].value == '0') {
5354: document.$formname.selfenroll_all[i].checked = true;
5355: }
5356: }
5357: }
5358: }
5359: if (caller == 'selfenroll_delete') {
5360: if (document.$formname.selfenroll_delete.length) {
5361: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
5362: if (document.$formname.selfenroll_delete[j].value == num) {
5363: if (document.$formname.selfenroll_delete[j].checked) {
5364: var delindex = getIndexByName('selfenroll_types_'+num);
5365: if (delindex != -1) {
5366: if (document.$formname.elements[delindex].length) {
5367: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
5368: document.$formname.elements[delindex][k].checked = false;
5369: }
5370: } else {
5371: document.$formname.elements[delindex].checked = false;
5372: }
5373: }
5374: }
5375: }
5376: }
5377: } else {
5378: if (document.$formname.selfenroll_delete.checked) {
5379: var delindex = getIndexByName('selfenroll_types_'+num);
5380: if (delindex != -1) {
5381: if (document.$formname.elements[delindex].length) {
5382: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
5383: document.$formname.elements[delindex][k].checked = false;
5384: }
5385: } else {
5386: document.$formname.elements[delindex].checked = false;
5387: }
5388: }
5389: }
5390: }
5391: }
5392: return;
5393: }
5394:
5395: function validate_types(form) {
5396: var needaction = new Array();
5397: var countfail = 0;
5398: var actidx = getIndexByName('selfenroll_activate');
5399: if (actidx != -1) {
5400: if (document.$formname.selfenroll_activate.length) {
5401: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5402: var num = document.$formname.selfenroll_activate[j].value;
5403: if (document.$formname.selfenroll_activate[j].checked) {
5404: countfail = check_types(num,countfail,needaction)
5405: }
5406: }
5407: } else {
5408: if (document.$formname.selfenroll_activate.checked) {
5409: var num = document.enrollstudent.selfenroll_activate.value;
5410: countfail = check_types(num,countfail,needaction)
5411: }
5412: }
5413: }
5414: if (countfail > 0) {
5415: var msg = "$alerts{'acto'}\\n";
5416: var loopend = needaction.length -1;
5417: if (loopend > 0) {
5418: for (var m=0; m<loopend; m++) {
5419: msg += needaction[m]+", ";
5420: }
5421: }
5422: msg += needaction[loopend]+"\\n$alerts{'butn'}\\n$alerts{'wilf'}";
5423: alert(msg);
5424: return;
5425: }
5426: setSections(form);
5427: }
5428:
5429: function check_types(num,countfail,needaction) {
5430: var typeidx = getIndexByName('selfenroll_types_'+num);
5431: var count = 0;
5432: if (typeidx != -1) {
5433: if (document.$formname.elements[typeidx].length) {
5434: for (var k=0; k<document.$formname.elements[typeidx].length; k++) {
5435: if (document.$formname.elements[typeidx][k].checked) {
5436: count ++;
5437: }
5438: }
5439: } else {
5440: if (document.$formname.elements[typeidx].checked) {
5441: count ++;
5442: }
5443: }
5444: if (count == 0) {
5445: var domidx = getIndexByName('selfenroll_dom_'+num);
5446: if (domidx != -1) {
5447: var domname = document.$formname.elements[domidx].value;
5448: needaction[countfail] = domname;
5449: countfail ++;
5450: }
5451: }
5452: }
5453: return countfail;
5454: }
5455:
5456: function getIndexByName(item) {
5457: for (var i=0;i<document.$formname.elements.length;i++) {
5458: if (document.$formname.elements[i].name == item) {
5459: return i;
5460: }
5461: }
5462: return -1;
5463: }
5464: ENDSCRIPT
1.256 raeburn 5465: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
5466: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
5467:
1.237 raeburn 5468: my $output = '<script type="text/javascript">'."\n".
1.301 bisitz 5469: '// <![CDATA['."\n".
1.249 raeburn 5470: $setsec_js."\n".$selfenroll_js."\n".
1.301 bisitz 5471: '// ]]>'."\n".
1.237 raeburn 5472: '</script>'."\n".
1.256 raeburn 5473: '<h3>'.$lt->{'selfenroll'}.'</h3>'."\n";
5474: my ($visible,$cansetvis,$vismsgs,$visactions) = &visible_in_cat($cdom,$cnum);
5475: if (ref($visactions) eq 'HASH') {
5476: if ($visible) {
1.283 bisitz 5477: $output .= '<p class="LC_info">'.$visactions->{'vis'}.'</p>';
1.256 raeburn 5478: } else {
1.283 bisitz 5479: $output .= '<p class="LC_warning">'.$visactions->{'miss'}.'</p>'
5480: .$visactions->{'yous'}.
1.256 raeburn 5481: '<p>'.$visactions->{'gen'}.'<br />'.$visactions->{'coca'};
5482: if (ref($vismsgs) eq 'ARRAY') {
5483: $output .= '<br />'.$visactions->{'make'}.'<ul>';
5484: foreach my $item (@{$vismsgs}) {
5485: $output .= '<li>'.$visactions->{$item}.'</li>';
5486: }
5487: $output .= '</ul>';
5488: }
5489: $output .= '</p>';
5490: }
5491: }
5492: $output .= '<form name="'.$formname.'" method="post" action="/adm/createuser">'."\n".
5493: &Apache::lonhtmlcommon::start_pick_box();
1.237 raeburn 5494: if (ref($row) eq 'ARRAY') {
5495: foreach my $item (@{$row}) {
5496: my $title = $item;
5497: if (ref($lt) eq 'HASH') {
5498: $title = $lt->{$item};
5499: }
1.297 bisitz 5500: $output .= &Apache::lonhtmlcommon::row_title($title);
1.237 raeburn 5501: if ($item eq 'types') {
5502: my $curr_types = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_types'};
1.241 raeburn 5503: my $showdomdesc = 1;
5504: my $includeempty = 1;
5505: my $num = 0;
5506: $output .= &Apache::loncommon::start_data_table().
5507: &Apache::loncommon::start_data_table_row()
5508: .'<td colspan="2"><span class="LC_nobreak"><label>'
5509: .&mt('Any user in any domain:')
5510: .' <input type="radio" name="selfenroll_all" value="1" ';
5511: if ($curr_types eq '*') {
5512: $output .= ' checked="checked" ';
5513: }
1.249 raeburn 5514: $output .= 'onchange="javascript:update_types('.
5515: "'selfenroll_all'".');" />'.&mt('Yes').'</label>'.
5516: ' <input type="radio" name="selfenroll_all" value="0" ';
1.241 raeburn 5517: if ($curr_types ne '*') {
5518: $output .= ' checked="checked" ';
5519: }
1.249 raeburn 5520: $output .= ' onchange="javascript:update_types('.
5521: "'selfenroll_all'".');"/>'.&mt('No').'</label></td>'.
5522: &Apache::loncommon::end_data_table_row().
5523: &Apache::loncommon::end_data_table().
5524: &mt('Or').'<br />'.
5525: &Apache::loncommon::start_data_table();
1.241 raeburn 5526: my %currdoms;
1.249 raeburn 5527: if ($curr_types eq '') {
1.241 raeburn 5528: $output .= &new_selfenroll_dom_row($cdom,'0');
5529: } elsif ($curr_types ne '*') {
5530: my @entries = split(/;/,$curr_types);
5531: if (@entries > 0) {
5532: foreach my $entry (@entries) {
5533: my ($currdom,$typestr) = split(/:/,$entry);
5534: $currdoms{$currdom} = 1;
5535: my $domdesc = &Apache::lonnet::domain($currdom);
1.249 raeburn 5536: my @currinsttypes = split(',',$typestr);
1.241 raeburn 5537: $output .= &Apache::loncommon::start_data_table_row()
5538: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').'<b>'
5539: .' '.$domdesc.' ('.$currdom.')'
5540: .'</b><input type="hidden" name="selfenroll_dom_'.$num
5541: .'" value="'.$currdom.'" /></span><br />'
5542: .'<span class="LC_nobreak"><label><input type="checkbox" '
1.249 raeburn 5543: .'name="selfenroll_delete" value="'.$num.'" onchange="javascript:update_types('."'selfenroll_delete','$num'".');" />'
1.241 raeburn 5544: .&mt('Delete').'</label></span></td>';
1.249 raeburn 5545: $output .= '<td valign="top"> '.&mt('User types:').'<br />'
1.241 raeburn 5546: .&selfenroll_inst_types($num,$currdom,\@currinsttypes).'</td>'
5547: .&Apache::loncommon::end_data_table_row();
5548: $num ++;
5549: }
5550: }
5551: }
1.249 raeburn 5552: my $add_domtitle = &mt('Users in additional domain:');
1.241 raeburn 5553: if ($curr_types eq '*') {
1.249 raeburn 5554: $add_domtitle = &mt('Users in specific domain:');
1.241 raeburn 5555: } elsif ($curr_types eq '') {
1.249 raeburn 5556: $add_domtitle = &mt('Users in other domain:');
1.241 raeburn 5557: }
5558: $output .= &Apache::loncommon::start_data_table_row()
5559: .'<td colspan="2"><span class="LC_nobreak">'.$add_domtitle.'</span><br />'
5560: .&Apache::loncommon::select_dom_form('','selfenroll_newdom',
5561: $includeempty,$showdomdesc)
5562: .'<input type="hidden" name="selfenroll_types_total" value="'.$num.'" />'
5563: .'</td>'.&Apache::loncommon::end_data_table_row()
5564: .&Apache::loncommon::end_data_table();
1.237 raeburn 5565: } elsif ($item eq 'registered') {
5566: my ($regon,$regoff);
5567: if ($env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_registered'}) {
5568: $regon = ' checked="checked" ';
5569: $regoff = ' ';
5570: } else {
5571: $regon = ' ';
5572: $regoff = ' checked="checked" ';
5573: }
5574: $output .= '<label>'.
1.245 raeburn 5575: '<input type="radio" name="selfenroll_registered" value="1"'.$regon.'/>'.
1.244 bisitz 5576: &mt('Yes').'</label> <label>'.
1.245 raeburn 5577: '<input type="radio" name="selfenroll_registered" value="0"'.$regoff.'/>'.
1.244 bisitz 5578: &mt('No').'</label>';
1.237 raeburn 5579: } elsif ($item eq 'enroll_dates') {
5580: my $starttime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_start_date'};
5581: my $endtime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_end_date'};
5582: if ($starttime eq '') {
5583: $starttime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_start_date'};
5584: }
5585: if ($endtime eq '') {
5586: $endtime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_end_date'};
5587: }
5588: my $startform =
5589: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_date',$starttime,
5590: undef,undef,undef,undef,undef,undef,undef,$nolink);
5591: my $endform =
5592: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_date',$endtime,
5593: undef,undef,undef,undef,undef,undef,undef,$nolink);
5594: $output .= &selfenroll_date_forms($startform,$endform);
5595: } elsif ($item eq 'access_dates') {
5596: my $starttime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_start_access'};
5597: my $endtime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_end_access'};
5598: if ($starttime eq '') {
5599: $starttime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_start_date'};
5600: }
5601: if ($endtime eq '') {
5602: $endtime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_end_date'};
5603: }
5604: my $startform =
5605: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_access',$starttime,
5606: undef,undef,undef,undef,undef,undef,undef,$nolink);
5607: my $endform =
5608: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_access',$endtime,
5609: undef,undef,undef,undef,undef,undef,undef,$nolink);
5610: $output .= &selfenroll_date_forms($startform,$endform);
5611: } elsif ($item eq 'section') {
5612: my $currsec = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_section'};
5613: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
5614: my $newsecval;
5615: if ($currsec ne 'none' && $currsec ne '') {
5616: if (!defined($sections_count{$currsec})) {
5617: $newsecval = $currsec;
5618: }
5619: }
5620: my $sections_select =
5621: &Apache::lonuserutils::course_sections(\%sections_count,'st',$currsec);
5622: $output .= '<table class="LC_createuser">'."\n".
5623: '<tr class="LC_section_row">'."\n".
5624: '<td align="center">'.&mt('Existing sections')."\n".
5625: '<br />'.$sections_select.'</td><td align="center">'.
5626: &mt('New section').'<br />'."\n".
5627: '<input type="text" name="newsec" size="15" value="'.$newsecval.'" />'."\n".
5628: '<input type="hidden" name="sections" value="" />'."\n".
5629: '<input type="hidden" name="state" value="done" />'."\n".
5630: '</td></tr></table>'."\n";
1.276 raeburn 5631: } elsif ($item eq 'approval') {
5632: my ($appon,$appoff);
5633: my $cid = $env{'request.course.id'};
5634: my $currnotified = $env{'course.'.$cid.'.internal.selfenroll_notifylist'};
5635: if ($env{'course.'.$cid.'.internal.selfenroll_approval'}) {
5636: $appon = ' checked="checked" ';
5637: $appoff = ' ';
5638: } else {
5639: $appon = ' ';
5640: $appoff = ' checked="checked" ';
5641: }
5642: $output .= '<label>'.
5643: '<input type="radio" name="selfenroll_approval" value="1"'.$appon.'/>'.
5644: &mt('Yes').'</label> <label>'.
5645: '<input type="radio" name="selfenroll_approval" value="0"'.$appoff.'/>'.
5646: &mt('No').'</label>';
5647: my %advhash = &Apache::lonnet::get_course_adv_roles($cid,1);
5648: my (@ccs,%notified);
1.322 raeburn 5649: my $ccrole = 'cc';
5650: if ($crstype eq 'Community') {
5651: $ccrole = 'co';
5652: }
5653: if ($advhash{$ccrole}) {
5654: @ccs = split(/,/,$advhash{$ccrole});
1.276 raeburn 5655: }
5656: if ($currnotified) {
5657: foreach my $current (split(/,/,$currnotified)) {
5658: $notified{$current} = 1;
5659: if (!grep(/^\Q$current\E$/,@ccs)) {
5660: push(@ccs,$current);
5661: }
5662: }
5663: }
5664: if (@ccs) {
1.277 raeburn 5665: $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 5666: &Apache::loncommon::start_data_table_row();
5667: my $count = 0;
5668: my $numcols = 4;
5669: foreach my $cc (sort(@ccs)) {
5670: my $notifyon;
5671: my ($ccuname,$ccudom) = split(/:/,$cc);
5672: if ($notified{$cc}) {
5673: $notifyon = ' checked="checked" ';
5674: }
5675: if ($count && !$count%$numcols) {
5676: $output .= &Apache::loncommon::end_data_table_row().
5677: &Apache::loncommon::start_data_table_row()
5678: }
5679: $output .= '<td><span class="LC_nobreak"><label>'.
5680: '<input type="checkbox" name="selfenroll_notify"'.$notifyon.' value="'.$cc.'" />'.
5681: &Apache::loncommon::plainname($ccuname,$ccudom).
5682: '</label></span></td>';
1.343 raeburn 5683: $count ++;
1.276 raeburn 5684: }
5685: my $rem = $count%$numcols;
5686: if ($rem) {
5687: my $emptycols = $numcols - $rem;
5688: for (my $i=0; $i<$emptycols; $i++) {
5689: $output .= '<td> </td>';
5690: }
5691: }
5692: $output .= &Apache::loncommon::end_data_table_row().
5693: &Apache::loncommon::end_data_table();
5694: }
5695: } elsif ($item eq 'limit') {
5696: my ($crslimit,$selflimit,$nolimit);
5697: my $cid = $env{'request.course.id'};
5698: my $currlim = $env{'course.'.$cid.'.internal.selfenroll_limit'};
5699: my $currcap = $env{'course.'.$cid.'.internal.selfenroll_cap'};
1.343 raeburn 5700: $nolimit = ' checked="checked" ';
1.276 raeburn 5701: if ($currlim eq 'allstudents') {
5702: $crslimit = ' checked="checked" ';
5703: $selflimit = ' ';
5704: $nolimit = ' ';
5705: } elsif ($currlim eq 'selfenrolled') {
5706: $crslimit = ' ';
5707: $selflimit = ' checked="checked" ';
5708: $nolimit = ' ';
5709: } else {
5710: $crslimit = ' ';
5711: $selflimit = ' ';
5712: }
5713: $output .= '<table><tr><td><label>'.
1.278 raeburn 5714: '<input type="radio" name="selfenroll_limit" value="none"'.$nolimit.'/>'.
1.276 raeburn 5715: &mt('No limit').'</label></td><td><label>'.
5716: '<input type="radio" name="selfenroll_limit" value="allstudents"'.$crslimit.'/>'.
5717: &mt('Limit by total students').'</label></td><td><label>'.
5718: '<input type="radio" name="selfenroll_limit" value="selfenrolled"'.$selflimit.'/>'.
5719: &mt('Limit by total self-enrolled students').
5720: '</td></tr><tr>'.
5721: '<td> </td><td colspan="2"><span class="LC_nobreak">'.
5722: (' 'x3).&mt('Maximum number allowed: ').
5723: '<input type="text" name="selfenroll_cap" size = "5" value="'.$currcap.'" /></td></tr></table>';
1.237 raeburn 5724: }
5725: $output .= &Apache::lonhtmlcommon::row_closure(1);
5726: }
5727: }
5728: $output .= &Apache::lonhtmlcommon::end_pick_box().
1.241 raeburn 5729: '<br /><input type="button" name="selfenrollconf" value="'
1.282 schafran 5730: .&mt('Save').'" onclick="validate_types(this.form);" />'
1.241 raeburn 5731: .'<input type="hidden" name="action" value="selfenroll" /></form>';
1.237 raeburn 5732: $r->print($output);
5733: return;
5734: }
5735:
1.256 raeburn 5736: sub visible_in_cat {
5737: my ($cdom,$cnum) = @_;
5738: my %domconf = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
5739: my ($cathash,%settable,@vismsgs,$cansetvis);
5740: my %visactions = &Apache::lonlocal::texthash(
1.316 bisitz 5741: vis => 'Your course/community currently appears in the Course/Community Catalog for this domain.',
1.256 raeburn 5742: 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 5743: miss => 'Your course/community does not currently appear in the Course/Community Catalog for this domain.',
1.256 raeburn 5744: yous => 'You should remedy this if you plan to allow self-enrollment, otherwise students will have difficulty finding your course.',
5745: 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 5746: make => 'Make any changes to self-enrollment settings below, click "Save", then take action to include the course in the Catalog:',
1.256 raeburn 5747: take => 'Take the following action to ensure the course appears in the Catalog:',
5748: dc_unhide => 'Ask a domain coordinator to change the "Exclude from course catalog" setting.',
5749: dc_addinst => 'Ask a domain coordinator to enable display the catalog of "Official courses (with institutional codes)".',
5750: dc_instcode => 'Ask a domain coordinator to assign an institutional code (if this is an official course).',
5751: dc_catalog => 'Ask a domain coordinator to enable or create at least one course category in the domain.',
5752: dc_categories => 'Ask a domain coordinator to create a hierarchy of categories and sub categories for courses in the domain.',
5753: 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',
5754: dc_addcat => 'Ask a domain coordinator to assign a category to the course.',
5755: );
1.347 raeburn 5756: $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>"');
5757: $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>"');
5758: $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 5759: if (ref($domconf{'coursecategories'}) eq 'HASH') {
5760: if ($domconf{'coursecategories'}{'togglecats'} eq 'crs') {
5761: $settable{'togglecats'} = 1;
5762: }
5763: if ($domconf{'coursecategories'}{'categorize'} eq 'crs') {
5764: $settable{'categorize'} = 1;
5765: }
5766: $cathash = $domconf{'coursecategories'}{'cats'};
5767: }
1.260 raeburn 5768: if ($settable{'togglecats'} && $settable{'categorize'}) {
1.256 raeburn 5769: $cansetvis = &mt('You are able to both assign a course category and choose to exclude this course from the catalog.');
5770: } elsif ($settable{'togglecats'}) {
5771: $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 5772: } elsif ($settable{'categorize'}) {
1.256 raeburn 5773: $cansetvis = &mt('You may assign a course category, but only a Domain Coordinator may choose to exclude this course from the catalog.');
5774: } else {
5775: $cansetvis = &mt('Only a Domain Coordinator may assign a course category or choose to exclude this course from the catalog.');
5776: }
5777:
5778: my %currsettings =
5779: &Apache::lonnet::get('environment',['hidefromcat','categories','internal.coursecode'],
5780: $cdom,$cnum);
5781: my $visible = 0;
5782: if ($currsettings{'internal.coursecode'} ne '') {
5783: if (ref($domconf{'coursecategories'}) eq 'HASH') {
5784: $cathash = $domconf{'coursecategories'}{'cats'};
5785: if (ref($cathash) eq 'HASH') {
5786: if ($cathash->{'instcode::0'} eq '') {
5787: push(@vismsgs,'dc_addinst');
5788: } else {
5789: $visible = 1;
5790: }
5791: } else {
5792: $visible = 1;
5793: }
5794: } else {
5795: $visible = 1;
5796: }
5797: } else {
5798: if (ref($cathash) eq 'HASH') {
5799: if ($cathash->{'instcode::0'} ne '') {
5800: push(@vismsgs,'dc_instcode');
5801: }
5802: } else {
5803: push(@vismsgs,'dc_instcode');
5804: }
5805: }
5806: if ($currsettings{'categories'} ne '') {
5807: my $cathash;
5808: if (ref($domconf{'coursecategories'}) eq 'HASH') {
5809: $cathash = $domconf{'coursecategories'}{'cats'};
5810: if (ref($cathash) eq 'HASH') {
5811: if (keys(%{$cathash}) == 0) {
5812: push(@vismsgs,'dc_catalog');
5813: } elsif ((keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} ne '')) {
5814: push(@vismsgs,'dc_categories');
5815: } else {
5816: my @currcategories = split('&',$currsettings{'categories'});
5817: my $matched = 0;
5818: foreach my $cat (@currcategories) {
5819: if ($cathash->{$cat} ne '') {
5820: $visible = 1;
5821: $matched = 1;
5822: last;
5823: }
5824: }
5825: if (!$matched) {
1.260 raeburn 5826: if ($settable{'categorize'}) {
1.256 raeburn 5827: push(@vismsgs,'chgcat');
5828: } else {
5829: push(@vismsgs,'dc_chgcat');
5830: }
5831: }
5832: }
5833: }
5834: }
5835: } else {
5836: if (ref($cathash) eq 'HASH') {
5837: if ((keys(%{$cathash}) > 1) ||
5838: (keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} eq '')) {
1.260 raeburn 5839: if ($settable{'categorize'}) {
1.256 raeburn 5840: push(@vismsgs,'addcat');
5841: } else {
5842: push(@vismsgs,'dc_addcat');
5843: }
5844: }
5845: }
5846: }
5847: if ($currsettings{'hidefromcat'} eq 'yes') {
5848: $visible = 0;
5849: if ($settable{'togglecats'}) {
5850: unshift(@vismsgs,'unhide');
5851: } else {
5852: unshift(@vismsgs,'dc_unhide')
5853: }
5854: }
5855: return ($visible,$cansetvis,\@vismsgs,\%visactions);
5856: }
5857:
1.241 raeburn 5858: sub new_selfenroll_dom_row {
5859: my ($newdom,$num) = @_;
5860: my $domdesc = &Apache::lonnet::domain($newdom);
5861: my $output;
5862: if ($domdesc ne '') {
5863: $output .= &Apache::loncommon::start_data_table_row()
5864: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').' <b>'.$domdesc
5865: .' ('.$newdom.')</b><input type="hidden" name="selfenroll_dom_'.$num
1.249 raeburn 5866: .'" value="'.$newdom.'" /></span><br />'
5867: .'<span class="LC_nobreak"><label><input type="checkbox" '
5868: .'name="selfenroll_activate" value="'.$num.'" '
5869: .'onchange="javascript:update_types('
5870: ."'selfenroll_activate','$num'".');" />'
5871: .&mt('Activate').'</label></span></td>';
1.241 raeburn 5872: my @currinsttypes;
5873: $output .= '<td>'.&mt('User types:').'<br />'
5874: .&selfenroll_inst_types($num,$newdom,\@currinsttypes).'</td>'
5875: .&Apache::loncommon::end_data_table_row();
5876: }
5877: return $output;
5878: }
5879:
5880: sub selfenroll_inst_types {
5881: my ($num,$currdom,$currinsttypes) = @_;
5882: my $output;
5883: my $numinrow = 4;
5884: my $count = 0;
5885: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($currdom);
1.247 raeburn 5886: my $othervalue = 'any';
1.241 raeburn 5887: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
1.251 raeburn 5888: if (keys(%{$usertypes}) > 0) {
1.247 raeburn 5889: $othervalue = 'other';
5890: }
1.241 raeburn 5891: $output .= '<table><tr>';
5892: foreach my $type (@{$types}) {
5893: if (($count > 0) && ($count%$numinrow == 0)) {
5894: $output .= '</tr><tr>';
5895: }
5896: if (defined($usertypes->{$type})) {
1.257 raeburn 5897: my $esc_type = &escape($type);
1.241 raeburn 5898: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.
1.257 raeburn 5899: $esc_type.'" ';
1.241 raeburn 5900: if (ref($currinsttypes) eq 'ARRAY') {
5901: if (@{$currinsttypes} > 0) {
1.249 raeburn 5902: if (grep(/^any$/,@{$currinsttypes})) {
5903: $output .= 'checked="checked"';
1.257 raeburn 5904: } elsif (grep(/^\Q$esc_type\E$/,@{$currinsttypes})) {
1.241 raeburn 5905: $output .= 'checked="checked"';
5906: }
1.249 raeburn 5907: } else {
5908: $output .= 'checked="checked"';
1.241 raeburn 5909: }
5910: }
5911: $output .= ' name="selfenroll_types_'.$num.'" />'.$usertypes->{$type}.'</label></span></td>';
5912: }
5913: $count ++;
5914: }
5915: if (($count > 0) && ($count%$numinrow == 0)) {
5916: $output .= '</tr><tr>';
5917: }
1.249 raeburn 5918: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.$othervalue.'"';
1.241 raeburn 5919: if (ref($currinsttypes) eq 'ARRAY') {
5920: if (@{$currinsttypes} > 0) {
1.249 raeburn 5921: if (grep(/^any$/,@{$currinsttypes})) {
5922: $output .= ' checked="checked"';
5923: } elsif ($othervalue eq 'other') {
5924: if (grep(/^\Q$othervalue\E$/,@{$currinsttypes})) {
5925: $output .= ' checked="checked"';
5926: }
1.241 raeburn 5927: }
1.249 raeburn 5928: } else {
5929: $output .= ' checked="checked"';
1.241 raeburn 5930: }
1.249 raeburn 5931: } else {
5932: $output .= ' checked="checked"';
1.241 raeburn 5933: }
5934: $output .= ' name="selfenroll_types_'.$num.'" />'.$othertitle.'</label></span></td></tr></table>';
5935: }
5936: return $output;
5937: }
5938:
1.237 raeburn 5939: sub selfenroll_date_forms {
5940: my ($startform,$endform) = @_;
5941: my $output .= &Apache::lonhtmlcommon::start_pick_box()."\n".
1.244 bisitz 5942: &Apache::lonhtmlcommon::row_title(&mt('Start date'),
1.237 raeburn 5943: 'LC_oddrow_value')."\n".
5944: $startform."\n".
5945: &Apache::lonhtmlcommon::row_closure(1).
1.244 bisitz 5946: &Apache::lonhtmlcommon::row_title(&mt('End date'),
1.237 raeburn 5947: 'LC_oddrow_value')."\n".
5948: $endform."\n".
5949: &Apache::lonhtmlcommon::row_closure(1).
5950: &Apache::lonhtmlcommon::end_pick_box();
5951: return $output;
5952: }
5953:
1.239 raeburn 5954: sub print_userchangelogs_display {
5955: my ($r,$context,$permission) = @_;
1.363 raeburn 5956: my $formname = 'rolelog';
5957: my ($username,$domain,$crstype,%roleslog);
5958: if ($context eq 'domain') {
5959: $domain = $env{'request.role.domain'};
5960: %roleslog=&Apache::lonnet::dump_dom('nohist_rolelog',$domain);
5961: } else {
5962: if ($context eq 'course') {
5963: $domain = $env{'course.'.$env{'request.course.id'}.'.domain'};
5964: $username = $env{'course.'.$env{'request.course.id'}.'.num'};
5965: $crstype = &Apache::loncommon::course_type();
5966: my %saveable_parameters = ('show' => 'scalar',);
5967: &Apache::loncommon::store_course_settings('roles_log',
5968: \%saveable_parameters);
5969: &Apache::loncommon::restore_course_settings('roles_log',
5970: \%saveable_parameters);
5971: } elsif ($context eq 'author') {
5972: $domain = $env{'user.domain'};
5973: if ($env{'request.role'} =~ m{^au\./\Q$domain\E/$}) {
5974: $username = $env{'user.name'};
5975: } else {
5976: undef($domain);
5977: }
5978: }
5979: if ($domain ne '' && $username ne '') {
5980: %roleslog=&Apache::lonnet::dump('nohist_rolelog',$domain,$username);
5981: }
5982: }
1.239 raeburn 5983: if ((keys(%roleslog))[0]=~/^error\:/) { undef(%roleslog); }
5984:
5985: # set defaults
5986: my $now = time();
5987: my $defstart = $now - (7*24*3600); #7 days ago
5988: my %defaults = (
5989: page => '1',
5990: show => '10',
5991: role => 'any',
5992: chgcontext => 'any',
5993: rolelog_start_date => $defstart,
5994: rolelog_end_date => $now,
5995: );
5996: my $more_records = 0;
5997:
5998: # set current
5999: my %curr;
6000: foreach my $item ('show','page','role','chgcontext') {
6001: $curr{$item} = $env{'form.'.$item};
6002: }
6003: my ($startdate,$enddate) =
6004: &Apache::lonuserutils::get_dates_from_form('rolelog_start_date','rolelog_end_date');
6005: $curr{'rolelog_start_date'} = $startdate;
6006: $curr{'rolelog_end_date'} = $enddate;
6007: foreach my $key (keys(%defaults)) {
6008: if ($curr{$key} eq '') {
6009: $curr{$key} = $defaults{$key};
6010: }
6011: }
1.248 raeburn 6012: my (%whodunit,%changed,$version);
6013: ($version) = ($r->dir_config('lonVersion') =~ /^([\d\.]+)\-/);
1.239 raeburn 6014: my ($minshown,$maxshown);
1.255 raeburn 6015: $minshown = 1;
1.239 raeburn 6016: my $count = 0;
6017: if ($curr{'show'} ne &mt('all')) {
6018: $maxshown = $curr{'page'} * $curr{'show'};
6019: if ($curr{'page'} > 1) {
6020: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
6021: }
6022: }
1.301 bisitz 6023:
1.327 raeburn 6024: # Form Header
6025: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
1.363 raeburn 6026: &role_display_filter($context,$formname,$domain,$username,\%curr,
6027: $version,$crstype));
1.327 raeburn 6028:
6029: # Create navigation
6030: my ($nav_script,$nav_links) = &userlogdisplay_nav($formname,\%curr,$more_records);
6031: my $showntableheader = 0;
6032:
6033: # Table Header
6034: my $tableheader =
6035: &Apache::loncommon::start_data_table_header_row()
6036: .'<th> </th>'
6037: .'<th>'.&mt('When').'</th>'
6038: .'<th>'.&mt('Who made the change').'</th>'
6039: .'<th>'.&mt('Changed User').'</th>'
1.363 raeburn 6040: .'<th>'.&mt('Role').'</th>';
6041:
6042: if ($context eq 'course') {
6043: $tableheader .= '<th>'.&mt('Section').'</th>';
6044: }
6045: $tableheader .=
6046: '<th>'.&mt('Context').'</th>'
1.327 raeburn 6047: .'<th>'.&mt('Start').'</th>'
6048: .'<th>'.&mt('End').'</th>'
6049: .&Apache::loncommon::end_data_table_header_row();
6050:
6051: # Display user change log data
1.239 raeburn 6052: foreach my $id (sort { $roleslog{$b}{'exe_time'}<=>$roleslog{$a}{'exe_time'} } (keys(%roleslog))) {
6053: next if (($roleslog{$id}{'exe_time'} < $curr{'rolelog_start_date'}) ||
6054: ($roleslog{$id}{'exe_time'} > $curr{'rolelog_end_date'}));
6055: if ($curr{'show'} ne &mt('all')) {
6056: if ($count >= $curr{'page'} * $curr{'show'}) {
6057: $more_records = 1;
6058: last;
6059: }
6060: }
6061: if ($curr{'role'} ne 'any') {
6062: next if ($roleslog{$id}{'logentry'}{'role'} ne $curr{'role'});
6063: }
6064: if ($curr{'chgcontext'} ne 'any') {
6065: if ($curr{'chgcontext'} eq 'selfenroll') {
6066: next if (!$roleslog{$id}{'logentry'}{'selfenroll'});
6067: } else {
6068: next if ($roleslog{$id}{'logentry'}{'context'} ne $curr{'chgcontext'});
6069: }
6070: }
6071: $count ++;
6072: next if ($count < $minshown);
1.327 raeburn 6073: unless ($showntableheader) {
6074: $r->print($nav_script
6075: .$nav_links
6076: .&Apache::loncommon::start_data_table()
6077: .$tableheader);
6078: $r->rflush();
6079: $showntableheader = 1;
6080: }
1.239 raeburn 6081: if ($whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} eq '') {
6082: $whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} =
6083: &Apache::loncommon::plainname($roleslog{$id}{'exe_uname'},$roleslog{$id}{'exe_udom'});
6084: }
6085: if ($changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} eq '') {
6086: $changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} =
6087: &Apache::loncommon::plainname($roleslog{$id}{'uname'},$roleslog{$id}{'udom'});
6088: }
6089: my $sec = $roleslog{$id}{'logentry'}{'section'};
6090: if ($sec eq '') {
6091: $sec = &mt('None');
6092: }
6093: my ($rolestart,$roleend);
6094: if ($roleslog{$id}{'delflag'}) {
6095: $rolestart = &mt('deleted');
6096: $roleend = &mt('deleted');
6097: } else {
6098: $rolestart = $roleslog{$id}{'logentry'}{'start'};
6099: $roleend = $roleslog{$id}{'logentry'}{'end'};
6100: if ($rolestart eq '' || $rolestart == 0) {
6101: $rolestart = &mt('No start date');
6102: } else {
6103: $rolestart = &Apache::lonlocal::locallocaltime($rolestart);
6104: }
6105: if ($roleend eq '' || $roleend == 0) {
6106: $roleend = &mt('No end date');
6107: } else {
6108: $roleend = &Apache::lonlocal::locallocaltime($roleend);
6109: }
6110: }
6111: my $chgcontext = $roleslog{$id}{'logentry'}{'context'};
6112: if ($roleslog{$id}{'logentry'}{'selfenroll'}) {
6113: $chgcontext = 'selfenroll';
6114: }
1.363 raeburn 6115: my %lt = &rolechg_contexts($context,$crstype);
1.239 raeburn 6116: if ($chgcontext ne '' && $lt{$chgcontext} ne '') {
6117: $chgcontext = $lt{$chgcontext};
6118: }
1.327 raeburn 6119: $r->print(
1.301 bisitz 6120: &Apache::loncommon::start_data_table_row()
6121: .'<td>'.$count.'</td>'
6122: .'<td>'.&Apache::lonlocal::locallocaltime($roleslog{$id}{'exe_time'}).'</td>'
6123: .'<td>'.$whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}}.'</td>'
6124: .'<td>'.$changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}}.'</td>'
1.363 raeburn 6125: .'<td>'.&Apache::lonnet::plaintext($roleslog{$id}{'logentry'}{'role'},$crstype).'</td>');
6126: if ($context eq 'course') {
6127: $r->print('<td>'.$sec.'</td>');
6128: }
6129: $r->print(
6130: '<td>'.$chgcontext.'</td>'
1.301 bisitz 6131: .'<td>'.$rolestart.'</td>'
6132: .'<td>'.$roleend.'</td>'
1.327 raeburn 6133: .&Apache::loncommon::end_data_table_row()."\n");
1.301 bisitz 6134: }
6135:
1.327 raeburn 6136: if ($showntableheader) { # Table footer, if content displayed above
6137: $r->print(&Apache::loncommon::end_data_table()
6138: .$nav_links);
6139: } else { # No content displayed above
1.301 bisitz 6140: $r->print('<p class="LC_info">'
6141: .&mt('There are no records to display.')
6142: .'</p>'
6143: );
1.239 raeburn 6144: }
1.301 bisitz 6145:
1.327 raeburn 6146: # Form Footer
6147: $r->print(
6148: '<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
6149: .'<input type="hidden" name="action" value="changelogs" />'
6150: .'</form>');
6151: return;
6152: }
1.301 bisitz 6153:
1.327 raeburn 6154: sub userlogdisplay_nav {
6155: my ($formname,$curr,$more_records) = @_;
6156: my ($nav_script,$nav_links);
6157: if (ref($curr) eq 'HASH') {
6158: # Create Navigation:
6159: # Navigation Script
6160: $nav_script = <<"ENDSCRIPT";
1.239 raeburn 6161: <script type="text/javascript">
1.301 bisitz 6162: // <![CDATA[
1.239 raeburn 6163: function chgPage(caller) {
6164: if (caller == 'previous') {
6165: document.$formname.page.value --;
6166: }
6167: if (caller == 'next') {
6168: document.$formname.page.value ++;
6169: }
1.327 raeburn 6170: document.$formname.submit();
1.239 raeburn 6171: return;
6172: }
1.301 bisitz 6173: // ]]>
1.239 raeburn 6174: </script>
6175: ENDSCRIPT
1.327 raeburn 6176: # Navigation Buttons
6177: $nav_links = '<p>';
6178: if (($curr->{'page'} > 1) || ($more_records)) {
6179: if ($curr->{'page'} > 1) {
6180: $nav_links .= '<input type="button"'
6181: .' onclick="javascript:chgPage('."'previous'".');"'
6182: .' value="'.&mt('Previous [_1] changes',$curr->{'show'})
6183: .'" /> ';
6184: }
6185: if ($more_records) {
6186: $nav_links .= '<input type="button"'
6187: .' onclick="javascript:chgPage('."'next'".');"'
6188: .' value="'.&mt('Next [_1] changes',$curr->{'show'})
6189: .'" />';
6190: }
1.301 bisitz 6191: }
1.327 raeburn 6192: $nav_links .= '</p>';
1.301 bisitz 6193: }
1.327 raeburn 6194: return ($nav_script,$nav_links);
1.239 raeburn 6195: }
6196:
6197: sub role_display_filter {
1.363 raeburn 6198: my ($context,$formname,$cdom,$cnum,$curr,$version,$crstype) = @_;
6199: my $lctype;
6200: if ($context eq 'course') {
6201: $lctype = lc($crstype);
6202: }
1.239 raeburn 6203: my $nolink = 1;
6204: my $output = '<table><tr><td valign="top">'.
1.301 bisitz 6205: '<span class="LC_nobreak"><b>'.&mt('Changes/page:').'</b></span><br />'.
1.239 raeburn 6206: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
6207: (&mt('all'),5,10,20,50,100,1000,10000)).
6208: '</td><td> </td>';
6209: my $startform =
6210: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_start_date',
6211: $curr->{'rolelog_start_date'},undef,
6212: undef,undef,undef,undef,undef,undef,$nolink);
6213: my $endform =
6214: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_end_date',
6215: $curr->{'rolelog_end_date'},undef,
6216: undef,undef,undef,undef,undef,undef,$nolink);
1.363 raeburn 6217: my %lt = &rolechg_contexts($context,$crstype);
1.301 bisitz 6218: $output .= '<td valign="top"><b>'.&mt('Window during which changes occurred:').'</b><br />'.
6219: '<table><tr><td>'.&mt('After:').
6220: '</td><td>'.$startform.'</td></tr>'.
6221: '<tr><td>'.&mt('Before:').'</td>'.
6222: '<td>'.$endform.'</td></tr></table>'.
6223: '</td>'.
6224: '<td> </td>'.
1.239 raeburn 6225: '<td valign="top"><b>'.&mt('Role:').'</b><br />'.
6226: '<select name="role"><option value="any"';
6227: if ($curr->{'role'} eq 'any') {
6228: $output .= ' selected="selected"';
6229: }
6230: $output .= '>'.&mt('Any').'</option>'."\n";
1.363 raeburn 6231: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
1.239 raeburn 6232: foreach my $role (@roles) {
6233: my $plrole;
6234: if ($role eq 'cr') {
6235: $plrole = &mt('Custom Role');
6236: } else {
1.318 raeburn 6237: $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.239 raeburn 6238: }
6239: my $selstr = '';
6240: if ($role eq $curr->{'role'}) {
6241: $selstr = ' selected="selected"';
6242: }
6243: $output .= ' <option value="'.$role.'"'.$selstr.'>'.$plrole.'</option>';
6244: }
1.301 bisitz 6245: $output .= '</select></td>'.
6246: '<td> </td>'.
6247: '<td valign="top"><b>'.
1.239 raeburn 6248: &mt('Context:').'</b><br /><select name="chgcontext">';
1.363 raeburn 6249: my @posscontexts;
6250: if ($context eq 'course') {
1.376 raeburn 6251: @posscontexts = ('any','automated','updatenow','createcourse','course','domain','selfenroll','requestcourses');
1.363 raeburn 6252: } elsif ($context eq 'domain') {
6253: @posscontexts = ('any','domain','requestauthor','domconfig','server');
6254: } else {
6255: @posscontexts = ('any','author','domain');
6256: }
6257: foreach my $chgtype (@posscontexts) {
1.239 raeburn 6258: my $selstr = '';
6259: if ($curr->{'chgcontext'} eq $chgtype) {
1.301 bisitz 6260: $selstr = ' selected="selected"';
1.239 raeburn 6261: }
1.363 raeburn 6262: if ($context eq 'course') {
1.376 raeburn 6263: if (($chgtype eq 'automated') || ($chgtype eq 'updatenow')) {
1.363 raeburn 6264: next if (!&Apache::lonnet::auto_run($cnum,$cdom));
6265: }
1.239 raeburn 6266: }
6267: $output .= '<option value="'.$chgtype.'"'.$selstr.'>'.$lt{$chgtype}.'</option>'."\n";
1.248 raeburn 6268: }
1.303 bisitz 6269: $output .= '</select></td>'
6270: .'</tr></table>';
6271:
6272: # Update Display button
6273: $output .= '<p>'
6274: .'<input type="submit" value="'.&mt('Update Display').'" />'
6275: .'</p>';
6276:
6277: # Server version info
1.363 raeburn 6278: my $needsrev = '2.11.0';
6279: if ($context eq 'course') {
6280: $needsrev = '2.7.0';
6281: }
6282:
1.303 bisitz 6283: $output .= '<p class="LC_info">'
6284: .&mt('Only changes made from servers running LON-CAPA [_1] or later are displayed.'
1.363 raeburn 6285: ,$needsrev);
1.248 raeburn 6286: if ($version) {
1.303 bisitz 6287: $output .= ' '.&mt('This LON-CAPA server is version [_1]',$version);
6288: }
6289: $output .= '</p><hr />';
1.239 raeburn 6290: return $output;
6291: }
6292:
6293: sub rolechg_contexts {
1.363 raeburn 6294: my ($context,$crstype) = @_;
6295: my %lt;
6296: if ($context eq 'course') {
6297: %lt = &Apache::lonlocal::texthash (
1.239 raeburn 6298: any => 'Any',
1.376 raeburn 6299: automated => 'Automated Enrollment',
1.239 raeburn 6300: updatenow => 'Roster Update',
6301: createcourse => 'Course Creation',
6302: course => 'User Management in course',
6303: domain => 'User Management in domain',
1.313 raeburn 6304: selfenroll => 'Self-enrolled',
1.318 raeburn 6305: requestcourses => 'Course Request',
1.239 raeburn 6306: );
1.363 raeburn 6307: if ($crstype eq 'Community') {
6308: $lt{'createcourse'} = &mt('Community Creation');
6309: $lt{'course'} = &mt('User Management in community');
6310: $lt{'requestcourses'} = &mt('Community Request');
6311: }
6312: } elsif ($context eq 'domain') {
6313: %lt = &Apache::lonlocal::texthash (
6314: any => 'Any',
6315: domain => 'User Management in domain',
6316: requestauthor => 'Authoring Request',
6317: server => 'Command line script (DC role)',
6318: domconfig => 'Self-enrolled',
6319: );
6320: } else {
6321: %lt = &Apache::lonlocal::texthash (
6322: any => 'Any',
6323: domain => 'User Management in domain',
6324: author => 'User Management by author',
6325: );
6326: }
1.239 raeburn 6327: return %lt;
6328: }
6329:
1.27 matthew 6330: #-------------------------------------------------- functions for &phase_two
1.160 raeburn 6331: sub user_search_result {
1.221 raeburn 6332: my ($context,$srch) = @_;
1.160 raeburn 6333: my %allhomes;
6334: my %inst_matches;
6335: my %srch_results;
1.181 raeburn 6336: my ($response,$currstate,$forcenewuser,$dirsrchres);
1.183 raeburn 6337: $srch->{'srchterm'} =~ s/\s+/ /g;
1.176 raeburn 6338: if ($srch->{'srchby'} !~ /^(uname|lastname|lastfirst)$/) {
1.160 raeburn 6339: $response = &mt('Invalid search.');
6340: }
6341: if ($srch->{'srchin'} !~ /^(crs|dom|alc|instd)$/) {
6342: $response = &mt('Invalid search.');
6343: }
1.177 raeburn 6344: if ($srch->{'srchtype'} !~ /^(exact|contains|begins)$/) {
1.160 raeburn 6345: $response = &mt('Invalid search.');
6346: }
6347: if ($srch->{'srchterm'} eq '') {
6348: $response = &mt('You must enter a search term.');
6349: }
1.183 raeburn 6350: if ($srch->{'srchterm'} =~ /^\s+$/) {
6351: $response = &mt('Your search term must contain more than just spaces.');
6352: }
1.160 raeburn 6353: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'instd')) {
6354: if (($srch->{'srchdomain'} eq '') ||
1.163 albertel 6355: ! (&Apache::lonnet::domain($srch->{'srchdomain'}))) {
1.160 raeburn 6356: $response = &mt('You must specify a valid domain when searching in a domain or institutional directory.')
6357: }
6358: }
6359: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs') ||
6360: ($srch->{'srchin'} eq 'alc')) {
1.176 raeburn 6361: if ($srch->{'srchby'} eq 'uname') {
1.243 raeburn 6362: my $unamecheck = $srch->{'srchterm'};
6363: if ($srch->{'srchtype'} eq 'contains') {
6364: if ($unamecheck !~ /^\w/) {
6365: $unamecheck = 'a'.$unamecheck;
6366: }
6367: }
6368: if ($unamecheck !~ /^$match_username$/) {
1.176 raeburn 6369: $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
6370: }
1.160 raeburn 6371: }
6372: }
1.180 raeburn 6373: if ($response ne '') {
6374: $response = '<span class="LC_warning">'.$response.'</span>';
6375: }
1.160 raeburn 6376: if ($srch->{'srchin'} eq 'instd') {
6377: my $instd_chk = &directorysrch_check($srch);
6378: if ($instd_chk ne 'ok') {
1.180 raeburn 6379: $response = '<span class="LC_warning">'.$instd_chk.'</span>'.
6380: '<br />'.&mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').'<br /><br />';
1.160 raeburn 6381: }
6382: }
6383: if ($response ne '') {
1.180 raeburn 6384: return ($currstate,$response);
1.160 raeburn 6385: }
6386: if ($srch->{'srchby'} eq 'uname') {
6387: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs')) {
6388: if ($env{'form.forcenew'}) {
6389: if ($srch->{'srchdomain'} ne $env{'request.role.domain'}) {
6390: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
6391: if ($uhome eq 'no_host') {
6392: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
1.180 raeburn 6393: my $showdom = &display_domain_info($env{'request.role.domain'});
6394: $response = &mt('New users can only be created in the domain to which your current role belongs - [_1].',$showdom);
1.160 raeburn 6395: } else {
1.179 raeburn 6396: $currstate = 'modify';
1.160 raeburn 6397: }
6398: } else {
1.179 raeburn 6399: $currstate = 'modify';
1.160 raeburn 6400: }
6401: } else {
6402: if ($srch->{'srchin'} eq 'dom') {
1.162 raeburn 6403: if ($srch->{'srchtype'} eq 'exact') {
6404: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
6405: if ($uhome eq 'no_host') {
1.179 raeburn 6406: ($currstate,$response,$forcenewuser) =
1.221 raeburn 6407: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 6408: } else {
1.179 raeburn 6409: $currstate = 'modify';
1.310 raeburn 6410: my $uname = $srch->{'srchterm'};
6411: my $udom = $srch->{'srchdomain'};
6412: $srch_results{$uname.':'.$udom} =
6413: { &Apache::lonnet::get('environment',
6414: ['firstname',
6415: 'lastname',
6416: 'permanentemail'],
6417: $udom,$uname)
6418: };
1.162 raeburn 6419: }
6420: } else {
6421: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 6422: ($currstate,$response,$forcenewuser) =
1.221 raeburn 6423: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 6424: }
6425: } else {
1.167 albertel 6426: my $courseusers = &get_courseusers();
1.162 raeburn 6427: if ($srch->{'srchtype'} eq 'exact') {
1.167 albertel 6428: if (exists($courseusers->{$srch->{'srchterm'}.':'.$srch->{'srchdomain'}})) {
1.179 raeburn 6429: $currstate = 'modify';
1.162 raeburn 6430: } else {
1.179 raeburn 6431: ($currstate,$response,$forcenewuser) =
1.221 raeburn 6432: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 6433: }
1.160 raeburn 6434: } else {
1.167 albertel 6435: foreach my $user (keys(%$courseusers)) {
1.162 raeburn 6436: my ($cuname,$cudomain) = split(/:/,$user);
6437: if ($cudomain eq $srch->{'srchdomain'}) {
1.177 raeburn 6438: my $matched = 0;
6439: if ($srch->{'srchtype'} eq 'begins') {
6440: if ($cuname =~ /^\Q$srch->{'srchterm'}\E/i) {
6441: $matched = 1;
6442: }
6443: } else {
6444: if ($cuname =~ /\Q$srch->{'srchterm'}\E/i) {
6445: $matched = 1;
6446: }
6447: }
6448: if ($matched) {
1.167 albertel 6449: $srch_results{$user} =
6450: {&Apache::lonnet::get('environment',
6451: ['firstname',
6452: 'lastname',
1.194 albertel 6453: 'permanentemail'],
6454: $cudomain,$cuname)};
1.162 raeburn 6455: }
6456: }
6457: }
1.179 raeburn 6458: ($currstate,$response,$forcenewuser) =
1.221 raeburn 6459: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 6460: }
6461: }
6462: }
6463: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 6464: $currstate = 'query';
1.160 raeburn 6465: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 6466: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
6467: if ($dirsrchres eq 'ok') {
6468: ($currstate,$response,$forcenewuser) =
1.221 raeburn 6469: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 6470: } else {
6471: my $showdom = &display_domain_info($srch->{'srchdomain'});
6472: $response = '<span class="LC_warning">'.
6473: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
6474: '</span><br />'.
6475: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
6476: '<br /><br />';
6477: }
1.160 raeburn 6478: }
6479: } else {
6480: if ($srch->{'srchin'} eq 'dom') {
6481: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 6482: ($currstate,$response,$forcenewuser) =
1.221 raeburn 6483: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 6484: } elsif ($srch->{'srchin'} eq 'crs') {
1.167 albertel 6485: my $courseusers = &get_courseusers();
6486: foreach my $user (keys(%$courseusers)) {
1.160 raeburn 6487: my ($uname,$udom) = split(/:/,$user);
6488: my %names = &Apache::loncommon::getnames($uname,$udom);
6489: my %emails = &Apache::loncommon::getemails($uname,$udom);
6490: if ($srch->{'srchby'} eq 'lastname') {
6491: if ((($srch->{'srchtype'} eq 'exact') &&
6492: ($names{'lastname'} eq $srch->{'srchterm'})) ||
1.177 raeburn 6493: (($srch->{'srchtype'} eq 'begins') &&
6494: ($names{'lastname'} =~ /^\Q$srch->{'srchterm'}\E/i)) ||
1.160 raeburn 6495: (($srch->{'srchtype'} eq 'contains') &&
6496: ($names{'lastname'} =~ /\Q$srch->{'srchterm'}\E/i))) {
6497: $srch_results{$user} = {firstname => $names{'firstname'},
6498: lastname => $names{'lastname'},
6499: permanentemail => $emails{'permanentemail'},
6500: };
6501: }
6502: } elsif ($srch->{'srchby'} eq 'lastfirst') {
6503: my ($srchlast,$srchfirst) = split(/,/,$srch->{'srchterm'});
1.177 raeburn 6504: $srchlast =~ s/\s+$//;
6505: $srchfirst =~ s/^\s+//;
1.160 raeburn 6506: if ($srch->{'srchtype'} eq 'exact') {
6507: if (($names{'lastname'} eq $srchlast) &&
6508: ($names{'firstname'} eq $srchfirst)) {
6509: $srch_results{$user} = {firstname => $names{'firstname'},
6510: lastname => $names{'lastname'},
6511: permanentemail => $emails{'permanentemail'},
6512:
6513: };
6514: }
1.177 raeburn 6515: } elsif ($srch->{'srchtype'} eq 'begins') {
6516: if (($names{'lastname'} =~ /^\Q$srchlast\E/i) &&
6517: ($names{'firstname'} =~ /^\Q$srchfirst\E/i)) {
6518: $srch_results{$user} = {firstname => $names{'firstname'},
6519: lastname => $names{'lastname'},
6520: permanentemail => $emails{'permanentemail'},
6521: };
6522: }
6523: } else {
1.160 raeburn 6524: if (($names{'lastname'} =~ /\Q$srchlast\E/i) &&
6525: ($names{'firstname'} =~ /\Q$srchfirst\E/i)) {
6526: $srch_results{$user} = {firstname => $names{'firstname'},
6527: lastname => $names{'lastname'},
6528: permanentemail => $emails{'permanentemail'},
6529: };
6530: }
6531: }
6532: }
6533: }
1.179 raeburn 6534: ($currstate,$response,$forcenewuser) =
1.221 raeburn 6535: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 6536: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 6537: $currstate = 'query';
1.160 raeburn 6538: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 6539: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
6540: if ($dirsrchres eq 'ok') {
6541: ($currstate,$response,$forcenewuser) =
1.221 raeburn 6542: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 6543: } else {
6544: my $showdom = &display_domain_info($srch->{'srchdomain'}); $response = '<span class="LC_warning">'.
6545: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
6546: '</span><br />'.
6547: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
6548: '<br /><br />';
6549: }
1.160 raeburn 6550: }
6551: }
1.179 raeburn 6552: return ($currstate,$response,$forcenewuser,\%srch_results);
1.160 raeburn 6553: }
6554:
6555: sub directorysrch_check {
6556: my ($srch) = @_;
6557: my $can_search = 0;
6558: my $response;
6559: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
6560: ['directorysrch'],$srch->{'srchdomain'});
1.180 raeburn 6561: my $showdom = &display_domain_info($srch->{'srchdomain'});
1.160 raeburn 6562: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
6563: if (!$dom_inst_srch{'directorysrch'}{'available'}) {
1.180 raeburn 6564: return &mt('Institutional directory search is not available in domain: [_1]',$showdom);
1.160 raeburn 6565: }
6566: if ($dom_inst_srch{'directorysrch'}{'localonly'}) {
6567: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
1.180 raeburn 6568: return &mt('Institutional directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
1.160 raeburn 6569: }
6570: my @usertypes = split(/:/,$env{'environment.inststatus'});
6571: if (!@usertypes) {
6572: push(@usertypes,'default');
6573: }
6574: if (ref($dom_inst_srch{'directorysrch'}{'cansearch'}) eq 'ARRAY') {
6575: foreach my $type (@usertypes) {
6576: if (grep(/^\Q$type\E$/,@{$dom_inst_srch{'directorysrch'}{'cansearch'}})) {
6577: $can_search = 1;
6578: last;
6579: }
6580: }
6581: }
6582: if (!$can_search) {
6583: my ($insttypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($srch->{'srchdomain'});
6584: my @longtypes;
6585: foreach my $item (@usertypes) {
1.229 raeburn 6586: if (defined($insttypes->{$item})) {
6587: push (@longtypes,$insttypes->{$item});
6588: } elsif ($item eq 'default') {
6589: push (@longtypes,&mt('other'));
6590: }
1.160 raeburn 6591: }
6592: my $insttype_str = join(', ',@longtypes);
1.180 raeburn 6593: return &mt('Institutional directory search in domain: [_1] is not available to your user type: ',$showdom).$insttype_str;
1.229 raeburn 6594: }
1.160 raeburn 6595: } else {
6596: $can_search = 1;
6597: }
6598: } else {
1.180 raeburn 6599: return &mt('Institutional directory search has not been configured for domain: [_1]',$showdom);
1.160 raeburn 6600: }
6601: my %longtext = &Apache::lonlocal::texthash (
1.167 albertel 6602: uname => 'username',
1.160 raeburn 6603: lastfirst => 'last name, first name',
1.167 albertel 6604: lastname => 'last name',
1.172 raeburn 6605: contains => 'contains',
1.178 raeburn 6606: exact => 'as exact match to',
6607: begins => 'begins with',
1.160 raeburn 6608: );
6609: if ($can_search) {
6610: if (ref($dom_inst_srch{'directorysrch'}{'searchby'}) eq 'ARRAY') {
6611: if (!grep(/^\Q$srch->{'srchby'}\E$/,@{$dom_inst_srch{'directorysrch'}{'searchby'}})) {
1.180 raeburn 6612: return &mt('Institutional directory search in domain: [_1] is not available for searching by "[_2]"',$showdom,$longtext{$srch->{'srchby'}});
1.160 raeburn 6613: }
6614: } else {
1.180 raeburn 6615: return &mt('Institutional directory search in domain: [_1] is not available.', $showdom);
1.160 raeburn 6616: }
6617: }
6618: if ($can_search) {
1.178 raeburn 6619: if (ref($dom_inst_srch{'directorysrch'}{'searchtypes'}) eq 'ARRAY') {
6620: if (grep(/^\Q$srch->{'srchtype'}\E/,@{$dom_inst_srch{'directorysrch'}{'searchtypes'}})) {
6621: return 'ok';
6622: } else {
1.180 raeburn 6623: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 6624: }
6625: } else {
6626: if ((($dom_inst_srch{'directorysrch'}{'searchtypes'} eq 'specify') &&
6627: ($srch->{'srchtype'} eq 'exact' || $srch->{'srchtype'} eq 'contains')) ||
6628: ($dom_inst_srch{'directorysrch'}{'searchtypes'} eq $srch->{'srchtype'})) {
6629: return 'ok';
6630: } else {
1.180 raeburn 6631: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 6632: }
1.160 raeburn 6633: }
6634: }
6635: }
6636:
6637: sub get_courseusers {
6638: my %advhash;
1.167 albertel 6639: my $classlist = &Apache::loncoursedata::get_classlist();
1.160 raeburn 6640: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles();
6641: foreach my $role (sort(keys(%coursepersonnel))) {
6642: foreach my $user (split(/\,/,$coursepersonnel{$role})) {
1.167 albertel 6643: if (!exists($classlist->{$user})) {
6644: $classlist->{$user} = [];
6645: }
1.160 raeburn 6646: }
6647: }
1.167 albertel 6648: return $classlist;
1.160 raeburn 6649: }
6650:
6651: sub build_search_response {
1.221 raeburn 6652: my ($context,$srch,%srch_results) = @_;
1.179 raeburn 6653: my ($currstate,$response,$forcenewuser);
1.160 raeburn 6654: my %names = (
1.330 bisitz 6655: 'uname' => 'username',
6656: 'lastname' => 'last name',
1.160 raeburn 6657: 'lastfirst' => 'last name, first name',
1.330 bisitz 6658: 'crs' => 'this course',
6659: 'dom' => 'LON-CAPA domain',
6660: 'instd' => 'the institutional directory for domain',
1.160 raeburn 6661: );
6662:
6663: my %single = (
1.180 raeburn 6664: begins => 'A match',
1.160 raeburn 6665: contains => 'A match',
1.180 raeburn 6666: exact => 'An exact match',
1.160 raeburn 6667: );
6668: my %nomatch = (
1.180 raeburn 6669: begins => 'No match',
1.160 raeburn 6670: contains => 'No match',
1.180 raeburn 6671: exact => 'No exact match',
1.160 raeburn 6672: );
6673: if (keys(%srch_results) > 1) {
1.179 raeburn 6674: $currstate = 'select';
1.160 raeburn 6675: } else {
6676: if (keys(%srch_results) == 1) {
1.179 raeburn 6677: $currstate = 'modify';
1.180 raeburn 6678: $response = &mt("$single{$srch->{'srchtype'}} was found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}.",$srch->{'srchterm'});
6679: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 6680: $response .= ': '.&display_domain_info($srch->{'srchdomain'});
1.180 raeburn 6681: }
1.330 bisitz 6682: } else { # Search has nothing found. Prepare message to user.
6683: $response = '<span class="LC_warning">';
1.180 raeburn 6684: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 6685: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}: [_2]",
6686: '<b>'.$srch->{'srchterm'}.'</b>',
6687: &display_domain_info($srch->{'srchdomain'}));
6688: } else {
6689: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}.",
6690: '<b>'.$srch->{'srchterm'}.'</b>');
1.180 raeburn 6691: }
6692: $response .= '</span>';
1.330 bisitz 6693:
1.160 raeburn 6694: if ($srch->{'srchin'} ne 'alc') {
6695: $forcenewuser = 1;
6696: my $cansrchinst = 0;
6697: if ($srch->{'srchdomain'}) {
6698: my %domconfig = &Apache::lonnet::get_dom('configuration',['directorysrch'],$srch->{'srchdomain'});
6699: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
6700: if ($domconfig{'directorysrch'}{'available'}) {
6701: $cansrchinst = 1;
6702: }
6703: }
6704: }
1.180 raeburn 6705: if ((($srch->{'srchby'} eq 'lastfirst') ||
6706: ($srch->{'srchby'} eq 'lastname')) &&
6707: ($srch->{'srchin'} eq 'dom')) {
6708: if ($cansrchinst) {
6709: $response .= '<br />'.&mt('You may want to broaden your search to a search of the institutional directory for the domain.');
1.160 raeburn 6710: }
6711: }
1.180 raeburn 6712: if ($srch->{'srchin'} eq 'crs') {
6713: $response .= '<br />'.&mt('You may want to broaden your search to the selected LON-CAPA domain.');
6714: }
6715: }
1.305 raeburn 6716: my $createdom = $env{'request.role.domain'};
6717: if ($context eq 'requestcrs') {
6718: if ($env{'form.coursedom'} ne '') {
6719: $createdom = $env{'form.coursedom'};
6720: }
6721: }
6722: if (!($srch->{'srchby'} eq 'uname' && $srch->{'srchin'} eq 'dom' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchdomain'} eq $createdom)) {
1.221 raeburn 6723: my $cancreate =
1.305 raeburn 6724: &Apache::lonuserutils::can_create_user($createdom,$context);
6725: my $targetdom = '<span class="LC_cusr_emph">'.$createdom.'</span>';
1.221 raeburn 6726: if ($cancreate) {
1.305 raeburn 6727: my $showdom = &display_domain_info($createdom);
1.266 bisitz 6728: $response .= '<br /><br />'
6729: .'<b>'.&mt('To add a new user:').'</b>'
1.305 raeburn 6730: .'<br />';
6731: if ($context eq 'requestcrs') {
6732: $response .= &mt("(You can only define new users in the new course's domain - [_1])",$targetdom);
6733: } else {
6734: $response .= &mt("(You can only create new users in your current role's domain - [_1])",$targetdom);
6735: }
6736: $response .='<ul><li>'
1.266 bisitz 6737: .&mt("Set 'Domain/institution to search' to: [_1]",'<span class="LC_cusr_emph">'.$showdom.'</span>')
6738: .'</li><li>'
6739: .&mt("Set 'Search criteria' to: [_1]username is ..... in selected LON-CAPA domain[_2]",'<span class="LC_cusr_emph">','</span>')
6740: .'</li><li>'
6741: .&mt('Provide the proposed username')
6742: .'</li><li>'
6743: .&mt("Click 'Search'")
6744: .'</li></ul><br />';
1.221 raeburn 6745: } else {
6746: my $helplink = ' href="javascript:helpMenu('."'display'".')"';
1.305 raeburn 6747: $response .= '<br /><br />';
6748: if ($context eq 'requestcrs') {
1.314 raeburn 6749: $response .= &mt("You are not authorized to define new users in the new course's domain - [_1].",$targetdom);
1.305 raeburn 6750: } else {
6751: $response .= &mt("You are not authorized to create new users in your current role's domain - [_1].",$targetdom);
6752: }
6753: $response .= '<br />'
6754: .&mt('Please contact the [_1]helpdesk[_2] if you need to create a new user.'
1.266 bisitz 6755: ,' <a'.$helplink.'>'
6756: ,'</a>')
1.305 raeburn 6757: .'<br /><br />';
1.221 raeburn 6758: }
1.160 raeburn 6759: }
6760: }
6761: }
1.179 raeburn 6762: return ($currstate,$response,$forcenewuser);
1.160 raeburn 6763: }
6764:
1.180 raeburn 6765: sub display_domain_info {
6766: my ($dom) = @_;
6767: my $output = $dom;
6768: if ($dom ne '') {
6769: my $domdesc = &Apache::lonnet::domain($dom,'description');
6770: if ($domdesc ne '') {
6771: $output .= ' <span class="LC_cusr_emph">('.$domdesc.')</span>';
6772: }
6773: }
6774: return $output;
6775: }
6776:
1.160 raeburn 6777: sub crumb_utilities {
6778: my %elements = (
6779: crtuser => {
6780: srchterm => 'text',
1.172 raeburn 6781: srchin => 'selectbox',
1.160 raeburn 6782: srchby => 'selectbox',
6783: srchtype => 'selectbox',
6784: srchdomain => 'selectbox',
6785: },
1.207 raeburn 6786: crtusername => {
6787: srchterm => 'text',
6788: srchdomain => 'selectbox',
6789: },
1.160 raeburn 6790: docustom => {
6791: rolename => 'selectbox',
6792: newrolename => 'textbox',
6793: },
1.179 raeburn 6794: studentform => {
6795: srchterm => 'text',
6796: srchin => 'selectbox',
6797: srchby => 'selectbox',
6798: srchtype => 'selectbox',
6799: srchdomain => 'selectbox',
6800: },
1.160 raeburn 6801: );
6802:
6803: my $jsback .= qq|
6804: function backPage(formname,prevphase,prevstate) {
1.211 raeburn 6805: if (typeof prevphase == 'undefined') {
6806: formname.phase.value = '';
6807: }
6808: else {
6809: formname.phase.value = prevphase;
6810: }
6811: if (typeof prevstate == 'undefined') {
6812: formname.currstate.value = '';
6813: }
6814: else {
6815: formname.currstate.value = prevstate;
6816: }
1.160 raeburn 6817: formname.submit();
6818: }
6819: |;
6820: return ($jsback,\%elements);
6821: }
6822:
1.26 matthew 6823: sub course_level_table {
1.375 raeburn 6824: my ($inccourses,$showcredits,$defaultcredits) = @_;
6825: return unless (ref($inccourses) eq 'HASH');
1.26 matthew 6826: my $table = '';
1.62 www 6827: # Custom Roles?
6828:
1.190 raeburn 6829: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.89 raeburn 6830: my %lt=&Apache::lonlocal::texthash(
6831: 'exs' => "Existing sections",
6832: 'new' => "Define new section",
6833: 'ssd' => "Set Start Date",
6834: 'sed' => "Set End Date",
1.131 raeburn 6835: 'crl' => "Course Level",
1.89 raeburn 6836: 'act' => "Activate",
6837: 'rol' => "Role",
6838: 'ext' => "Extent",
1.113 raeburn 6839: 'grs' => "Section",
1.375 raeburn 6840: 'crd' => "Credits",
1.89 raeburn 6841: 'sta' => "Start",
6842: 'end' => "End"
6843: );
1.62 www 6844:
1.375 raeburn 6845: foreach my $protectedcourse (sort(keys(%{$inccourses}))) {
1.135 raeburn 6846: my $thiscourse=$protectedcourse;
1.26 matthew 6847: $thiscourse=~s:_:/:g;
6848: my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
1.365 raeburn 6849: my $isowner = &Apache::lonuserutils::is_courseowner($protectedcourse,$coursedata{'internal.courseowner'});
1.26 matthew 6850: my $area=$coursedata{'description'};
1.321 raeburn 6851: my $crstype=$coursedata{'type'};
1.135 raeburn 6852: if (!defined($area)) { $area=&mt('Unavailable course').': '.$protectedcourse; }
1.89 raeburn 6853: my ($domain,$cnum)=split(/\//,$thiscourse);
1.115 albertel 6854: my %sections_count;
1.101 albertel 6855: if (defined($env{'request.course.id'})) {
6856: if ($env{'request.course.id'} eq $domain.'_'.$cnum) {
1.115 albertel 6857: %sections_count =
6858: &Apache::loncommon::get_sections($domain,$cnum);
1.92 raeburn 6859: }
6860: }
1.321 raeburn 6861: my @roles = &Apache::lonuserutils::roles_by_context('course','',$crstype);
1.213 raeburn 6862: foreach my $role (@roles) {
1.321 raeburn 6863: my $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.329 raeburn 6864: if ((&Apache::lonnet::allowed('c'.$role,$thiscourse)) ||
6865: ((($role eq 'cc') || ($role eq 'co')) && ($isowner))) {
1.221 raeburn 6866: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 6867: $plrole,\%sections_count,\%lt,
6868: $defaultcredits,$crstype);
1.221 raeburn 6869: } elsif ($env{'request.course.sec'} ne '') {
6870: if (&Apache::lonnet::allowed('c'.$role,$thiscourse.'/'.
6871: $env{'request.course.sec'})) {
6872: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 6873: $plrole,\%sections_count,\%lt,
6874: $defaultcredits,$crstype);
1.26 matthew 6875: }
6876: }
6877: }
1.221 raeburn 6878: if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
1.324 raeburn 6879: foreach my $cust (sort(keys(%customroles))) {
6880: next if ($crstype eq 'Community' && $customroles{$cust} =~ /bre\&S/);
1.221 raeburn 6881: my $role = 'cr_cr_'.$env{'user.domain'}.'_'.$env{'user.name'}.'_'.$cust;
6882: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
6883: $cust,\%sections_count,\%lt);
6884: }
1.62 www 6885: }
1.26 matthew 6886: }
6887: return '' if ($table eq ''); # return nothing if there is nothing
6888: # in the table
1.188 raeburn 6889: my $result;
6890: if (!$env{'request.course.id'}) {
6891: $result = '<h4>'.$lt{'crl'}.'</h4>'."\n";
6892: }
6893: $result .=
1.136 raeburn 6894: &Apache::loncommon::start_data_table().
6895: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 6896: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
6897: '<th>'.$lt{'ext'}.'</th><th>'.$lt{'crd'}.'</th>'."\n".
6898: '<th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th>'."\n".
6899: '<th>'.$lt{'end'}.'</th>'.
1.136 raeburn 6900: &Apache::loncommon::end_data_table_header_row().
6901: $table.
6902: &Apache::loncommon::end_data_table();
1.26 matthew 6903: return $result;
6904: }
1.88 raeburn 6905:
1.221 raeburn 6906: sub course_level_row {
1.375 raeburn 6907: my ($protectedcourse,$role,$area,$domain,$plrole,$sections_count,
6908: $lt,$defaultcredits,$crstype) = @_;
6909: my $creditem;
1.222 raeburn 6910: my $row = &Apache::loncommon::start_data_table_row().
6911: ' <td><input type="checkbox" name="act_'.
6912: $protectedcourse.'_'.$role.'" /></td>'."\n".
6913: ' <td>'.$plrole.'</td>'."\n".
6914: ' <td>'.$area.'<br />Domain: '.$domain.'</td>'."\n";
1.375 raeburn 6915: if (($role eq 'st') && ($crstype eq 'Course')) {
6916: $row .=
6917: '<td><input type="text" name="credits_'.$protectedcourse.'_'.
6918: $role.'" size="3" value="'.$defaultcredits.'" /></td>';
6919: } else {
6920: $row .= '<td> </td>';
6921: }
1.322 raeburn 6922: if (($role eq 'cc') || ($role eq 'co')) {
1.222 raeburn 6923: $row .= '<td> </td>';
1.221 raeburn 6924: } elsif ($env{'request.course.sec'} ne '') {
1.222 raeburn 6925: $row .= ' <td><input type="hidden" value="'.
6926: $env{'request.course.sec'}.'" '.
6927: 'name="sec_'.$protectedcourse.'_'.$role.'" />'.
6928: $env{'request.course.sec'}.'</td>';
1.221 raeburn 6929: } else {
6930: if (ref($sections_count) eq 'HASH') {
6931: my $currsec =
6932: &Apache::lonuserutils::course_sections($sections_count,
6933: $protectedcourse.'_'.$role);
1.222 raeburn 6934: $row .= '<td><table class="LC_createuser">'."\n".
6935: '<tr class="LC_section_row">'."\n".
6936: ' <td valign="top">'.$lt->{'exs'}.'<br />'.
6937: $currsec.'</td>'."\n".
6938: ' <td> </td>'."\n".
6939: ' <td valign="top"> '.$lt->{'new'}.'<br />'.
1.221 raeburn 6940: '<input type="text" name="newsec_'.$protectedcourse.'_'.$role.
6941: '" value="" />'.
6942: '<input type="hidden" '.
6943: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n".
1.222 raeburn 6944: '</tr></table></td>'."\n";
1.221 raeburn 6945: } else {
1.222 raeburn 6946: $row .= '<td><input type="text" size="10" '.
1.375 raeburn 6947: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n";
1.221 raeburn 6948: }
6949: }
1.222 raeburn 6950: $row .= <<ENDTIMEENTRY;
6951: <td><input type="hidden" name="start_$protectedcourse\_$role" value="" />
1.221 raeburn 6952: <a href=
6953: "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 6954: <td><input type="hidden" name="end_$protectedcourse\_$role" value="" />
1.221 raeburn 6955: <a href=
6956: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$role.value,'end_$protectedcourse\_$role','cu.pres','dateset')">$lt->{'sed'}</a></td>
6957: ENDTIMEENTRY
1.222 raeburn 6958: $row .= &Apache::loncommon::end_data_table_row();
6959: return $row;
1.221 raeburn 6960: }
6961:
1.88 raeburn 6962: sub course_level_dc {
1.375 raeburn 6963: my ($dcdom,$showcredits) = @_;
1.190 raeburn 6964: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.213 raeburn 6965: my @roles = &Apache::lonuserutils::roles_by_context('course');
1.88 raeburn 6966: my $hiddenitems = '<input type="hidden" name="dcdomain" value="'.$dcdom.'" />'.
6967: '<input type="hidden" name="origdom" value="'.$dcdom.'" />'.
1.133 raeburn 6968: '<input type="hidden" name="dccourse" value="" />';
1.355 www 6969: my $courseform=&Apache::loncommon::selectcourse_link
1.356 raeburn 6970: ('cu','dccourse','dcdomain','coursedesc',undef,undef,'Select','crstype');
1.375 raeburn 6971: my $credit_elem;
6972: if ($showcredits) {
6973: $credit_elem = 'credits';
6974: }
6975: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,'currsec','cu','role','Course/Community Browser',$credit_elem);
1.88 raeburn 6976: my %lt=&Apache::lonlocal::texthash(
6977: 'rol' => "Role",
1.113 raeburn 6978: 'grs' => "Section",
1.88 raeburn 6979: 'exs' => "Existing sections",
6980: 'new' => "Define new section",
6981: 'sta' => "Start",
6982: 'end' => "End",
6983: 'ssd' => "Set Start Date",
1.355 www 6984: 'sed' => "Set End Date",
1.375 raeburn 6985: 'scc' => "Course/Community",
6986: 'crd' => "Credits",
1.88 raeburn 6987: );
1.323 raeburn 6988: my $header = '<h4>'.&mt('Course/Community Level').'</h4>'.
1.136 raeburn 6989: &Apache::loncommon::start_data_table().
6990: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 6991: '<th>'.$lt{'scc'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
6992: '<th>'.$lt{'grs'}.'</th><th>'.$lt{'crd'}.'</th>'."\n".
6993: '<th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'."\n".
1.136 raeburn 6994: &Apache::loncommon::end_data_table_header_row();
1.143 raeburn 6995: my $otheritems = &Apache::loncommon::start_data_table_row()."\n".
1.356 raeburn 6996: '<td><br /><span class="LC_nobreak"><input type="text" name="coursedesc" value="" onfocus="this.blur();opencrsbrowser('."'cu','dccourse','dcdomain','coursedesc','','','','crstype'".')" />'.
6997: $courseform.(' ' x4).'</span></td>'."\n".
1.389 ! bisitz 6998: '<td valign="top"><br /><select name="role">'."\n";
1.213 raeburn 6999: foreach my $role (@roles) {
1.135 raeburn 7000: my $plrole=&Apache::lonnet::plaintext($role);
1.389 ! bisitz 7001: $otheritems .= ' <option value="'.$role.'">'.$plrole.'</option>';
1.88 raeburn 7002: }
7003: if ( keys %customroles > 0) {
1.135 raeburn 7004: foreach my $cust (sort keys %customroles) {
1.101 albertel 7005: my $custrole='cr_cr_'.$env{'user.domain'}.
1.135 raeburn 7006: '_'.$env{'user.name'}.'_'.$cust;
1.389 ! bisitz 7007: $otheritems .= ' <option value="'.$custrole.'">'.$cust.'</option>';
1.88 raeburn 7008: }
7009: }
7010: $otheritems .= '</select></td><td>'.
7011: '<table border="0" cellspacing="0" cellpadding="0">'.
7012: '<tr><td valign="top"><b>'.$lt{'exs'}.'</b><br /><select name="currsec">'.
1.389 ! bisitz 7013: ' <option value=""><--'.&mt('Pick course first').'</option></select></td>'.
1.88 raeburn 7014: '<td> </td>'.
7015: '<td valign="top"> <b>'.$lt{'new'}.'</b><br />'.
1.113 raeburn 7016: '<input type="text" name="newsec" value="" />'.
1.237 raeburn 7017: '<input type="hidden" name="section" value="" />'.
1.323 raeburn 7018: '<input type="hidden" name="groups" value="" />'.
7019: '<input type="hidden" name="crstype" value="" /></td>'.
1.375 raeburn 7020: '</tr></table></td>'."\n";
7021: if ($showcredits) {
7022: $otheritems .= '<td><br />'."\n".
7023: '<input type="text" size="3" name="credits" value="" />'."\n";
7024: }
1.88 raeburn 7025: $otheritems .= <<ENDTIMEENTRY;
1.323 raeburn 7026: <td><br /><input type="hidden" name="start" value='' />
1.88 raeburn 7027: <a href=
7028: "javascript:pjump('date_start','Start Date',document.cu.start.value,'start','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.323 raeburn 7029: <td><br /><input type="hidden" name="end" value='' />
1.88 raeburn 7030: <a href=
7031: "javascript:pjump('date_end','End Date',document.cu.end.value,'end','cu.pres','dateset')">$lt{'sed'}</a></td>
7032: ENDTIMEENTRY
1.136 raeburn 7033: $otheritems .= &Apache::loncommon::end_data_table_row().
7034: &Apache::loncommon::end_data_table()."\n";
1.88 raeburn 7035: return $cb_jscript.$header.$hiddenitems.$otheritems;
7036: }
7037:
1.237 raeburn 7038: sub update_selfenroll_config {
1.241 raeburn 7039: my ($r,$context,$permission) = @_;
1.237 raeburn 7040: my ($row,$lt) = &get_selfenroll_titles();
1.241 raeburn 7041: my %curr_groups = &Apache::longroup::coursegroups();
1.237 raeburn 7042: my (%changes,%warning);
7043: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
7044: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.241 raeburn 7045: my $curr_types;
1.237 raeburn 7046: if (ref($row) eq 'ARRAY') {
7047: foreach my $item (@{$row}) {
7048: if ($item eq 'enroll_dates') {
7049: my (%currenrolldate,%newenrolldate);
7050: foreach my $type ('start','end') {
7051: $currenrolldate{$type} = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$type.'_date'};
7052: $newenrolldate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_date');
7053: if ($newenrolldate{$type} ne $currenrolldate{$type}) {
7054: $changes{'internal.selfenroll_'.$type.'_date'} = $newenrolldate{$type};
7055: }
7056: }
7057: } elsif ($item eq 'access_dates') {
7058: my (%currdate,%newdate);
7059: foreach my $type ('start','end') {
7060: $currdate{$type} = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$type.'_access'};
7061: $newdate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_access');
7062: if ($newdate{$type} ne $currdate{$type}) {
7063: $changes{'internal.selfenroll_'.$type.'_access'} = $newdate{$type};
7064: }
7065: }
1.241 raeburn 7066: } elsif ($item eq 'types') {
7067: $curr_types =
7068: $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$item};
7069: if ($env{'form.selfenroll_all'}) {
7070: if ($curr_types ne '*') {
7071: $changes{'internal.selfenroll_types'} = '*';
7072: } else {
7073: next;
7074: }
7075: } else {
1.249 raeburn 7076: my %currdoms;
1.241 raeburn 7077: my @entries = split(/;/,$curr_types);
7078: my @deletedoms = &Apache::loncommon::get_env_multiple('form.selfenroll_delete');
1.249 raeburn 7079: my @activations = &Apache::loncommon::get_env_multiple('form.selfenroll_activate');
1.241 raeburn 7080: my $newnum = 0;
1.249 raeburn 7081: my @latesttypes;
7082: foreach my $num (@activations) {
7083: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$num);
7084: if (@types > 0) {
1.241 raeburn 7085: @types = sort(@types);
7086: my $typestr = join(',',@types);
1.249 raeburn 7087: my $typedom = $env{'form.selfenroll_dom_'.$num};
7088: $latesttypes[$newnum] = $typedom.':'.$typestr;
7089: $currdoms{$typedom} = 1;
1.241 raeburn 7090: $newnum ++;
7091: }
7092: }
1.338 raeburn 7093: for (my $j=0; $j<$env{'form.selfenroll_types_total'}; $j++) {
7094: if ((!grep(/^$j$/,@deletedoms)) && (!grep(/^$j$/,@activations))) {
1.249 raeburn 7095: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$j);
7096: if (@types > 0) {
7097: @types = sort(@types);
7098: my $typestr = join(',',@types);
7099: my $typedom = $env{'form.selfenroll_dom_'.$j};
7100: $latesttypes[$newnum] = $typedom.':'.$typestr;
7101: $currdoms{$typedom} = 1;
7102: $newnum ++;
7103: }
7104: }
7105: }
7106: if ($env{'form.selfenroll_newdom'} ne '') {
7107: my $typedom = $env{'form.selfenroll_newdom'};
7108: if ((!defined($currdoms{$typedom})) &&
7109: (&Apache::lonnet::domain($typedom) ne '')) {
7110: my $typestr;
7111: my ($othertitle,$usertypes,$types) =
7112: &Apache::loncommon::sorted_inst_types($typedom);
7113: my $othervalue = 'any';
7114: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7115: if (@{$types} > 0) {
1.257 raeburn 7116: my @esc_types = map { &escape($_); } @{$types};
1.249 raeburn 7117: $othervalue = 'other';
1.258 raeburn 7118: $typestr = join(',',(@esc_types,$othervalue));
1.249 raeburn 7119: }
7120: $typestr = $othervalue;
7121: } else {
7122: $typestr = $othervalue;
7123: }
7124: $latesttypes[$newnum] = $typedom.':'.$typestr;
7125: $newnum ++ ;
7126: }
7127: }
1.241 raeburn 7128: my $selfenroll_types = join(';',@latesttypes);
7129: if ($selfenroll_types ne $curr_types) {
7130: $changes{'internal.selfenroll_types'} = $selfenroll_types;
7131: }
7132: }
1.276 raeburn 7133: } elsif ($item eq 'limit') {
7134: my $newlimit = $env{'form.selfenroll_limit'};
7135: my $newcap = $env{'form.selfenroll_cap'};
7136: $newcap =~s/\s+//g;
7137: my $currlimit = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_limit'};
7138: $currlimit = 'none' if ($currlimit eq '');
7139: my $currcap = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_cap'};
7140: if ($newlimit ne $currlimit) {
7141: if ($newlimit ne 'none') {
7142: if ($newcap =~ /^\d+$/) {
7143: if ($newcap ne $currcap) {
7144: $changes{'internal.selfenroll_cap'} = $newcap;
7145: }
7146: $changes{'internal.selfenroll_limit'} = $newlimit;
7147: } else {
7148: $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.');
7149: }
7150: } elsif ($currcap ne '') {
7151: $changes{'internal.selfenroll_cap'} = '';
7152: $changes{'internal.selfenroll_limit'} = $newlimit;
7153: }
7154: } elsif ($currlimit ne 'none') {
7155: if ($newcap =~ /^\d+$/) {
7156: if ($newcap ne $currcap) {
7157: $changes{'internal.selfenroll_cap'} = $newcap;
7158: }
7159: } else {
7160: $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.');
7161: }
7162: }
7163: } elsif ($item eq 'approval') {
7164: my (@currnotified,@newnotified);
7165: my $currapproval = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'};
7166: my $currnotifylist = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_notifylist'};
7167: if ($currnotifylist ne '') {
7168: @currnotified = split(/,/,$currnotifylist);
7169: @currnotified = sort(@currnotified);
7170: }
7171: my $newapproval = $env{'form.selfenroll_approval'};
7172: @newnotified = &Apache::loncommon::get_env_multiple('form.selfenroll_notify');
7173: @newnotified = sort(@newnotified);
7174: if ($newapproval ne $currapproval) {
7175: $changes{'internal.selfenroll_approval'} = $newapproval;
7176: if (!$newapproval) {
7177: if ($currnotifylist ne '') {
7178: $changes{'internal.selfenroll_notifylist'} = '';
7179: }
7180: } else {
7181: my @differences =
1.295 raeburn 7182: &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 7183: if (@differences > 0) {
7184: if (@newnotified > 0) {
7185: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
7186: } else {
7187: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
7188: }
7189: }
7190: }
7191: } else {
1.295 raeburn 7192: my @differences = &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 7193: if (@differences > 0) {
7194: if (@newnotified > 0) {
7195: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
7196: } else {
7197: $changes{'internal.selfenroll_notifylist'} = '';
7198: }
7199: }
7200: }
1.237 raeburn 7201: } else {
7202: my $curr_val =
7203: $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$item};
7204: my $newval = $env{'form.selfenroll_'.$item};
7205: if ($item eq 'section') {
7206: $newval = $env{'form.sections'};
1.241 raeburn 7207: if (defined($curr_groups{$newval})) {
1.237 raeburn 7208: $newval = $curr_val;
7209: $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');
7210: } elsif ($newval eq 'all') {
7211: $newval = $curr_val;
1.274 bisitz 7212: $warning{$item} = &mt('Section for self-enrolled users unchanged, as "all" is a reserved section name.');
1.237 raeburn 7213: }
7214: if ($newval eq '') {
7215: $newval = 'none';
7216: }
7217: }
7218: if ($newval ne $curr_val) {
7219: $changes{'internal.selfenroll_'.$item} = $newval;
7220: }
1.241 raeburn 7221: }
1.237 raeburn 7222: }
7223: if (keys(%warning) > 0) {
7224: foreach my $item (@{$row}) {
7225: if (exists($warning{$item})) {
7226: $r->print($warning{$item}.'<br />');
7227: }
7228: }
7229: }
7230: if (keys(%changes) > 0) {
7231: my $putresult = &Apache::lonnet::put('environment',\%changes,$cdom,$cnum);
7232: if ($putresult eq 'ok') {
7233: if ((exists($changes{'internal.selfenroll_types'})) ||
7234: (exists($changes{'internal.selfenroll_start_date'})) ||
7235: (exists($changes{'internal.selfenroll_end_date'}))) {
7236: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',
7237: $cnum,undef,undef,'Course');
7238: my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
7239: if (ref($crsinfo{$env{'request.course.id'}}) eq 'HASH') {
7240: foreach my $item ('selfenroll_types','selfenroll_start_date','selfenroll_end_date') {
7241: if (exists($changes{'internal.'.$item})) {
7242: $crsinfo{$env{'request.course.id'}}{$item} =
7243: $changes{'internal.'.$item};
7244: }
7245: }
7246: my $crsputresult =
7247: &Apache::lonnet::courseidput($cdom,\%crsinfo,
7248: $chome,'notime');
7249: }
7250: }
7251: $r->print(&mt('The following changes were made to self-enrollment settings:').'<ul>');
7252: foreach my $item (@{$row}) {
7253: my $title = $item;
7254: if (ref($lt) eq 'HASH') {
7255: $title = $lt->{$item};
7256: }
7257: if ($item eq 'enroll_dates') {
7258: foreach my $type ('start','end') {
7259: if (exists($changes{'internal.selfenroll_'.$type.'_date'})) {
7260: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_date'});
1.244 bisitz 7261: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 7262: $title,$type,$newdate).'</li>');
7263: }
7264: }
7265: } elsif ($item eq 'access_dates') {
7266: foreach my $type ('start','end') {
7267: if (exists($changes{'internal.selfenroll_'.$type.'_access'})) {
7268: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_access'});
1.244 bisitz 7269: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 7270: $title,$type,$newdate).'</li>');
7271: }
7272: }
1.276 raeburn 7273: } elsif ($item eq 'limit') {
7274: if ((exists($changes{'internal.selfenroll_limit'})) ||
7275: (exists($changes{'internal.selfenroll_cap'}))) {
7276: my ($newval,$newcap);
7277: if ($changes{'internal.selfenroll_cap'} ne '') {
7278: $newcap = $changes{'internal.selfenroll_cap'}
7279: } else {
7280: $newcap = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_cap'};
7281: }
7282: if ($changes{'internal.selfenroll_limit'} eq 'none') {
7283: $newval = &mt('No limit');
7284: } elsif ($changes{'internal.selfenroll_limit'} eq
7285: 'allstudents') {
7286: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
7287: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
7288: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
7289: } else {
7290: my $currlimit = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_limit'};
7291: if ($currlimit eq 'allstudents') {
7292: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
7293: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
1.308 raeburn 7294: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
1.276 raeburn 7295: }
7296: }
7297: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
7298: }
7299: } elsif ($item eq 'approval') {
7300: if ((exists($changes{'internal.selfenroll_approval'})) ||
7301: (exists($changes{'internal.selfenroll_notifylist'}))) {
7302: my ($newval,$newnotify);
7303: if (exists($changes{'internal.selfenroll_notifylist'})) {
7304: $newnotify = $changes{'internal.selfenroll_notifylist'};
7305: } else {
7306: $newnotify = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_notifylist'};
7307: }
7308: if ($changes{'internal.selfenroll_approval'}) {
7309: $newval = &mt('Yes');
7310: } elsif ($changes{'internal.selfenroll_approval'} eq '0') {
7311: $newval = &mt('No');
7312: } else {
7313: my $currapproval =
7314: $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'};
7315: if ($currapproval) {
7316: $newval = &mt('Yes');
7317: } else {
7318: $newval = &mt('No');
7319: }
7320: }
7321: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval));
7322: if ($newnotify) {
1.277 raeburn 7323: $r->print('<br />'.&mt('The following will be notified when an enrollment request needs approval, or has been approved: [_1].',$newnotify));
1.276 raeburn 7324: } else {
1.277 raeburn 7325: $r->print('<br />'.&mt('No notifications sent when an enrollment request needs approval, or has been approved.'));
1.276 raeburn 7326: }
7327: $r->print('</li>'."\n");
7328: }
1.237 raeburn 7329: } else {
7330: if (exists($changes{'internal.selfenroll_'.$item})) {
1.241 raeburn 7331: my $newval = $changes{'internal.selfenroll_'.$item};
7332: if ($item eq 'types') {
7333: if ($newval eq '') {
7334: $newval = &mt('None');
7335: } elsif ($newval eq '*') {
7336: $newval = &mt('Any user in any domain');
7337: }
1.245 raeburn 7338: } elsif ($item eq 'registered') {
7339: if ($newval eq '1') {
7340: $newval = &mt('Yes');
7341: } elsif ($newval eq '0') {
7342: $newval = &mt('No');
7343: }
1.241 raeburn 7344: }
1.244 bisitz 7345: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
1.237 raeburn 7346: }
7347: }
7348: }
7349: $r->print('</ul>');
7350: my %newenvhash;
7351: foreach my $key (keys(%changes)) {
7352: $newenvhash{'course.'.$env{'request.course.id'}.'.'.$key} = $changes{$key};
7353: }
1.238 raeburn 7354: &Apache::lonnet::appenv(\%newenvhash);
1.237 raeburn 7355: } else {
7356: $r->print(&mt('An error occurred when saving changes to self-enrollment settings in this course.').'<br />'.&mt('The error was: [_1].',$putresult));
7357: }
7358: } else {
1.249 raeburn 7359: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.237 raeburn 7360: }
7361: } else {
1.249 raeburn 7362: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.241 raeburn 7363: }
1.256 raeburn 7364: my ($visible,$cansetvis,$vismsgs,$visactions) = &visible_in_cat($cdom,$cnum);
7365: if (ref($visactions) eq 'HASH') {
7366: if (!$visible) {
1.366 bisitz 7367: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
1.256 raeburn 7368: '<br />');
7369: if (ref($vismsgs) eq 'ARRAY') {
7370: $r->print('<br />'.$visactions->{'take'}.'<ul>');
7371: foreach my $item (@{$vismsgs}) {
7372: $r->print('<li>'.$visactions->{$item}.'</li>');
7373: }
7374: $r->print('</ul>');
7375: }
7376: $r->print($cansetvis);
7377: }
7378: }
1.237 raeburn 7379: return;
7380: }
7381:
7382: sub get_selfenroll_titles {
1.276 raeburn 7383: my @row = ('types','registered','enroll_dates','access_dates','section',
7384: 'approval','limit');
1.237 raeburn 7385: my %lt = &Apache::lonlocal::texthash (
7386: types => 'Users allowed to self-enroll in this course',
1.245 raeburn 7387: registered => 'Restrict self-enrollment to students officially registered for the course',
1.237 raeburn 7388: enroll_dates => 'Dates self-enrollment available',
1.256 raeburn 7389: access_dates => 'Course access dates assigned to self-enrolling users',
7390: section => 'Section assigned to self-enrolling users',
1.276 raeburn 7391: approval => 'Self-enrollment requests need approval?',
7392: limit => 'Enrollment limit',
1.237 raeburn 7393: );
7394: return (\@row,\%lt);
7395: }
7396:
1.27 matthew 7397: #---------------------------------------------- end functions for &phase_two
1.29 matthew 7398:
7399: #--------------------------------- functions for &phase_two and &phase_three
7400:
7401: #--------------------------end of functions for &phase_two and &phase_three
1.372 raeburn 7402:
1.1 www 7403: 1;
7404: __END__
1.2 www 7405:
7406:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>