Annotation of loncom/interface/loncreateuser.pm, revision 1.382
1.20 harris41 1: # The LearningOnline Network with CAPA
1.1 www 2: # Create a user
3: #
1.382 ! raeburn 4: # $Id: loncreateuser.pm,v 1.381 2013/07/19 18:24:17 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",
171: author => "Disk space allocated to user's authoring space (if role assigned)",
172: );
173: foreach my $name ('portfolio','author') {
174: my ($currquota,$quotatype,$inststatus,$defquota) =
175: &Apache::loncommon::get_user_quota($ccuname,$ccdomain,$name);
176: if ($longinsttype eq '') {
177: if ($inststatus ne '') {
178: if ($usertypes->{$inststatus} ne '') {
179: $longinsttype = $usertypes->{$inststatus};
180: }
181: }
182: }
183: my ($showquota,$custom_on,$custom_off,$defaultinfo);
184: $custom_on = ' ';
185: $custom_off = ' checked="checked" ';
186: if ($quotatype eq 'custom') {
187: $custom_on = $custom_off;
188: $custom_off = ' ';
189: $showquota = $currquota;
190: if ($longinsttype eq '') {
191: $defaultinfo = &mt('For this user, the default quota would be [_1]'
192: .' Mb.',$defquota);
193: } else {
194: $defaultinfo = &mt("For this user, the default quota would be [_1]".
195: " Mb, as determined by the user's institutional".
196: " affiliation ([_2]).",$defquota,$longinsttype);
197: }
198: } else {
199: if ($longinsttype eq '') {
200: $defaultinfo = &mt('For this user, the default quota is [_1]'
201: .' Mb.',$defquota);
202: } else {
203: $defaultinfo = &mt("For this user, the default quota of [_1]".
204: " Mb, is determined by the user's institutional".
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'}.': '.
215: $currquota.' Mb. '.
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.378 raeburn 223: ' />'.$lt{'defa'}.' ('.$defquota.' Mb).</label> '.
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.378 raeburn 229: ' /> Mb</span></td>'."\n".
230: &Apache::loncommon::end_data_table_row()."\n";
231: }
232: }
1.267 raeburn 233: $output .= &Apache::loncommon::end_data_table();
1.134 raeburn 234: return $output;
235: }
236:
1.275 raeburn 237: sub build_tools_display {
238: my ($ccuname,$ccdomain,$context) = @_;
1.306 raeburn 239: my (@usertools,%userenv,$output,@options,%validations,%reqtitles,%reqdisplay,
1.332 raeburn 240: $colspan,$isadv,%domconfig);
1.275 raeburn 241: my %lt = &Apache::lonlocal::texthash (
242: 'blog' => "Personal User Blog",
243: 'aboutme' => "Personal Information Page",
1.361 raeburn 244: 'webdav' => "WebDAV access to authoring spaces (if SSL and author/co-author)",
1.275 raeburn 245: 'portfolio' => "Personal User Portfolio",
246: 'avai' => "Available",
247: 'cusa' => "availability",
248: 'chse' => "Change setting",
249: 'usde' => "Use default",
250: 'uscu' => "Use custom",
251: 'official' => 'Can request creation of official courses',
1.299 raeburn 252: 'unofficial' => 'Can request creation of unofficial courses',
253: 'community' => 'Can request creation of communities',
1.362 raeburn 254: 'requestauthor' => 'Can request author space',
1.275 raeburn 255: );
1.279 raeburn 256: if ($context eq 'requestcourses') {
1.275 raeburn 257: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
1.299 raeburn 258: 'requestcourses.official','requestcourses.unofficial',
259: 'requestcourses.community');
260: @usertools = ('official','unofficial','community');
1.309 raeburn 261: @options =('norequest','approval','autolimit','validate');
1.306 raeburn 262: %validations = &Apache::lonnet::auto_courserequest_checks($ccdomain);
263: %reqtitles = &courserequest_titles();
264: %reqdisplay = &courserequest_display();
265: $colspan = ' colspan="2"';
1.332 raeburn 266: %domconfig =
267: &Apache::lonnet::get_dom('configuration',['requestcourses'],$ccdomain);
268: $isadv = &Apache::lonnet::is_advanced_user($ccuname,$ccdomain);
1.362 raeburn 269: } elsif ($context eq 'requestauthor') {
270: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
271: 'requestauthor');
272: @usertools = ('requestauthor');
273: @options =('norequest','approval','automatic');
274: %reqtitles = &requestauthor_titles();
275: %reqdisplay = &requestauthor_display();
276: $colspan = ' colspan="2"';
277: %domconfig =
278: &Apache::lonnet::get_dom('configuration',['requestauthor'],$ccdomain);
1.275 raeburn 279: } else {
280: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
1.361 raeburn 281: 'tools.aboutme','tools.portfolio','tools.blog',
282: 'tools.webdav');
283: @usertools = ('aboutme','blog','webdav','portfolio');
1.275 raeburn 284: }
285: foreach my $item (@usertools) {
1.306 raeburn 286: my ($custom_access,$curr_access,$cust_on,$cust_off,$tool_on,$tool_off,
287: $currdisp,$custdisp,$custradio);
1.275 raeburn 288: $cust_off = 'checked="checked" ';
289: $tool_on = 'checked="checked" ';
290: $curr_access =
291: &Apache::lonnet::usertools_access($ccuname,$ccdomain,$item,undef,
292: $context);
1.362 raeburn 293: if ($context eq 'requestauthor') {
294: if ($userenv{$context} ne '') {
295: $cust_on = ' checked="checked" ';
296: $cust_off = '';
297: }
298: } elsif ($userenv{$context.'.'.$item} ne '') {
1.306 raeburn 299: $cust_on = ' checked="checked" ';
300: $cust_off = '';
301: }
302: if ($context eq 'requestcourses') {
303: if ($userenv{$context.'.'.$item} eq '') {
1.314 raeburn 304: $custom_access = &mt('Currently from default setting.');
1.306 raeburn 305: } else {
306: $custom_access = &mt('Currently from custom setting.');
1.275 raeburn 307: }
1.362 raeburn 308: } elsif ($context eq 'requestauthor') {
309: if ($userenv{$context} eq '') {
310: $custom_access = &mt('Currently from default setting.');
311: } else {
312: $custom_access = &mt('Currently from custom setting.');
313: }
1.275 raeburn 314: } else {
1.306 raeburn 315: if ($userenv{$context.'.'.$item} eq '') {
1.314 raeburn 316: $custom_access =
1.306 raeburn 317: &mt('Availability determined currently from default setting.');
318: if (!$curr_access) {
319: $tool_off = 'checked="checked" ';
320: $tool_on = '';
321: }
322: } else {
1.314 raeburn 323: $custom_access =
1.306 raeburn 324: &mt('Availability determined currently from custom setting.');
325: if ($userenv{$context.'.'.$item} == 0) {
326: $tool_off = 'checked="checked" ';
327: $tool_on = '';
328: }
1.275 raeburn 329: }
330: }
331: $output .= ' <tr class="LC_info_row">'."\n".
1.306 raeburn 332: ' <td'.$colspan.'>'.$lt{$item}.'</td>'."\n".
1.275 raeburn 333: ' </tr>'."\n".
1.306 raeburn 334: &Apache::loncommon::start_data_table_row()."\n";
1.362 raeburn 335: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.306 raeburn 336: my ($curroption,$currlimit);
1.362 raeburn 337: my $envkey = $context.'.'.$item;
338: if ($context eq 'requestauthor') {
339: $envkey = $context;
340: }
341: if ($userenv{$envkey} ne '') {
342: $curroption = $userenv{$envkey};
1.332 raeburn 343: } else {
344: my (@inststatuses);
1.362 raeburn 345: if ($context eq 'requestcourses') {
346: $curroption =
347: &Apache::loncoursequeueadmin::get_processtype('course',$ccuname,$ccdomain,
348: $isadv,$ccdomain,$item,
349: \@inststatuses,\%domconfig);
350: } else {
351: $curroption =
352: &Apache::loncoursequeueadmin::get_processtype('requestauthor',$ccuname,$ccdomain,
353: $isadv,$ccdomain,undef,
354: \@inststatuses,\%domconfig);
355: }
1.332 raeburn 356: }
1.306 raeburn 357: if (!$curroption) {
358: $curroption = 'norequest';
359: }
360: if ($curroption =~ /^autolimit=(\d*)$/) {
361: $currlimit = $1;
1.314 raeburn 362: if ($currlimit eq '') {
363: $currdisp = &mt('Yes, automatic creation');
364: } else {
365: $currdisp = &mt('Yes, up to [quant,_1,request]/user',$currlimit);
366: }
1.306 raeburn 367: } else {
368: $currdisp = $reqdisplay{$curroption};
369: }
370: $custdisp = '<table>';
371: foreach my $option (@options) {
372: my $val = $option;
373: if ($option eq 'norequest') {
374: $val = 0;
375: }
376: if ($option eq 'validate') {
377: my $canvalidate = 0;
378: if (ref($validations{$item}) eq 'HASH') {
379: if ($validations{$item}{'_custom_'}) {
380: $canvalidate = 1;
381: }
382: }
383: next if (!$canvalidate);
384: }
385: my $checked = '';
386: if ($option eq $curroption) {
387: $checked = ' checked="checked"';
388: } elsif ($option eq 'autolimit') {
389: if ($curroption =~ /^autolimit/) {
390: $checked = ' checked="checked"';
391: }
392: }
1.362 raeburn 393: my $name = 'crsreq_'.$item;
394: if ($context eq 'requestauthor') {
395: $name = $item;
396: }
1.306 raeburn 397: $custdisp .= '<tr><td><span class="LC_nobreak"><label>'.
1.362 raeburn 398: '<input type="radio" name="'.$name.'" '.
399: 'value="'.$val.'"'.$checked.' />'.
1.306 raeburn 400: $reqtitles{$option}.'</label> ';
401: if ($option eq 'autolimit') {
1.362 raeburn 402: $custdisp .= '<input type="text" name="'.$name.
403: '_limit" size="1" '.
1.314 raeburn 404: 'value="'.$currlimit.'" /></span><br />'.
405: $reqtitles{'unlimited'};
1.362 raeburn 406: } else {
407: $custdisp .= '</span>';
408: }
409: $custdisp .= '</td></tr>';
1.306 raeburn 410: }
411: $custdisp .= '</table>';
412: $custradio = '</span></td><td>'.&mt('Custom setting').'<br />'.$custdisp;
413: } else {
414: $currdisp = ($curr_access?&mt('Yes'):&mt('No'));
1.362 raeburn 415: my $name = $context.'_'.$item;
416: if ($context eq 'requestauthor') {
417: $name = $context;
418: }
1.306 raeburn 419: $custdisp = '<span class="LC_nobreak"><label>'.
1.362 raeburn 420: '<input type="radio" name="'.$name.'"'.
1.361 raeburn 421: ' value="1" '.$tool_on.'/>'.&mt('On').'</label> <label>'.
1.362 raeburn 422: '<input type="radio" name="'.$name.'" value="0" '.
1.306 raeburn 423: $tool_off.'/>'.&mt('Off').'</label></span>';
424: $custradio = (' 'x2).'--'.$lt{'cusa'}.': '.$custdisp.
425: '</span>';
426: }
427: $output .= ' <td'.$colspan.'>'.$custom_access.(' 'x4).
428: $lt{'avai'}.': '.$currdisp.'</td>'."\n".
1.275 raeburn 429: &Apache::loncommon::end_data_table_row()."\n".
430: &Apache::loncommon::start_data_table_row()."\n".
1.306 raeburn 431: ' <td style="vertical-align:top;"><span class="LC_nobreak">'.
432: $lt{'chse'}.': <label>'.
1.275 raeburn 433: '<input type="radio" name="custom'.$item.'" value="0" '.
1.306 raeburn 434: $cust_off.'/>'.$lt{'usde'}.'</label>'.(' ' x3).
435: '<label><input type="radio" name="custom'.$item.'" value="1" '.
436: $cust_on.'/>'.$lt{'uscu'}.'</label>'.$custradio.'</td>'.
1.275 raeburn 437: &Apache::loncommon::end_data_table_row()."\n";
438: }
439: return $output;
440: }
441:
1.300 raeburn 442: sub coursereq_externaluser {
443: my ($ccuname,$ccdomain,$cdom) = @_;
1.306 raeburn 444: my (@usertools,@options,%validations,%userenv,$output);
1.300 raeburn 445: my %lt = &Apache::lonlocal::texthash (
446: 'official' => 'Can request creation of official courses',
447: 'unofficial' => 'Can request creation of unofficial courses',
448: 'community' => 'Can request creation of communities',
449: );
450:
451: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
452: 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
453: 'reqcrsotherdom.community');
454: @usertools = ('official','unofficial','community');
1.309 raeburn 455: @options = ('approval','validate','autolimit');
1.306 raeburn 456: %validations = &Apache::lonnet::auto_courserequest_checks($cdom);
457: my $optregex = join('|',@options);
458: my %reqtitles = &courserequest_titles();
1.300 raeburn 459: foreach my $item (@usertools) {
1.306 raeburn 460: my ($curroption,$currlimit,$tooloff);
1.300 raeburn 461: if ($userenv{'reqcrsotherdom.'.$item} ne '') {
462: my @curr = split(',',$userenv{'reqcrsotherdom.'.$item});
1.314 raeburn 463: foreach my $req (@curr) {
464: if ($req =~ /^\Q$cdom\E\:($optregex)=?(\d*)$/) {
465: $curroption = $1;
466: $currlimit = $2;
467: last;
1.306 raeburn 468: }
469: }
1.314 raeburn 470: if (!$curroption) {
471: $curroption = 'norequest';
472: $tooloff = ' checked="checked"';
473: }
1.306 raeburn 474: } else {
475: $curroption = 'norequest';
476: $tooloff = ' checked="checked"';
477: }
478: $output.= &Apache::loncommon::start_data_table_row()."\n".
1.314 raeburn 479: ' <td><span class="LC_nobreak">'.$lt{$item}.': </span></td><td>'.
480: '<table><tr><td valign="top">'."\n".
1.306 raeburn 481: '<label><input type="radio" name="reqcrsotherdom_'.$item.
1.314 raeburn 482: '" value=""'.$tooloff.' />'.$reqtitles{'norequest'}.
483: '</label></td>';
1.306 raeburn 484: foreach my $option (@options) {
485: if ($option eq 'validate') {
486: my $canvalidate = 0;
487: if (ref($validations{$item}) eq 'HASH') {
488: if ($validations{$item}{'_external_'}) {
489: $canvalidate = 1;
490: }
491: }
492: next if (!$canvalidate);
493: }
494: my $checked = '';
495: if ($option eq $curroption) {
496: $checked = ' checked="checked"';
497: }
1.314 raeburn 498: $output .= '<td valign="top"><span class="LC_nobreak"><label>'.
1.306 raeburn 499: '<input type="radio" name="reqcrsotherdom_'.$item.
500: '" value="'.$option.'"'.$checked.' />'.
1.314 raeburn 501: $reqtitles{$option}.'</label>';
1.306 raeburn 502: if ($option eq 'autolimit') {
1.314 raeburn 503: $output .= ' <input type="text" name="reqcrsotherdom_'.
1.306 raeburn 504: $item.'_limit" size="1" '.
1.314 raeburn 505: 'value="'.$currlimit.'" /></span>'.
506: '<br />'.$reqtitles{'unlimited'};
507: } else {
508: $output .= '</span>';
1.300 raeburn 509: }
1.314 raeburn 510: $output .= '</td>';
1.300 raeburn 511: }
1.314 raeburn 512: $output .= '</td></tr></table></td>'."\n".
1.300 raeburn 513: &Apache::loncommon::end_data_table_row()."\n";
514: }
515: return $output;
516: }
517:
1.362 raeburn 518: sub domainrole_req {
519: my ($ccuname,$ccdomain) = @_;
520: return '<br /><h3>'.
521: &mt('User Can Request Assignment of Domain Roles?').
522: '</h3>'."\n".
523: &Apache::loncommon::start_data_table().
524: &build_tools_display($ccuname,$ccdomain,
525: 'requestauthor').
526: &Apache::loncommon::end_data_table();
527: }
528:
1.306 raeburn 529: sub courserequest_titles {
530: my %titles = &Apache::lonlocal::texthash (
531: official => 'Official',
532: unofficial => 'Unofficial',
533: community => 'Communities',
534: norequest => 'Not allowed',
1.309 raeburn 535: approval => 'Approval by Dom. Coord.',
1.306 raeburn 536: validate => 'With validation',
537: autolimit => 'Numerical limit',
1.314 raeburn 538: unlimited => '(blank for unlimited)',
1.306 raeburn 539: );
540: return %titles;
541: }
542:
543: sub courserequest_display {
544: my %titles = &Apache::lonlocal::texthash (
1.309 raeburn 545: approval => 'Yes, need approval',
1.306 raeburn 546: validate => 'Yes, with validation',
547: norequest => 'No',
548: );
549: return %titles;
550: }
551:
1.362 raeburn 552: sub requestauthor_titles {
553: my %titles = &Apache::lonlocal::texthash (
554: norequest => 'Not allowed',
555: approval => 'Approval by Dom. Coord.',
556: automatic => 'Automatic approval',
557: );
558: return %titles;
559:
560: }
561:
562: sub requestauthor_display {
563: my %titles = &Apache::lonlocal::texthash (
564: approval => 'Yes, need approval',
565: automatic => 'Yes, automatic approval',
566: norequest => 'No',
567: );
568: return %titles;
569: }
570:
571: sub curr_requestauthor {
572: my ($uname,$udom,$isadv,$inststatuses,$domconfig) = @_;
573: return unless ((ref($inststatuses) eq 'ARRAY') && (ref($domconfig) eq 'HASH'));
574: if ($uname eq '' || $udom eq '') {
575: $uname = $env{'user.name'};
576: $udom = $env{'user.domain'};
577: $isadv = $env{'user.adv'};
578: }
579: my (%userenv,%settings,$val);
580: my @options = ('automatic','approval');
581: %userenv =
582: &Apache::lonnet::userenvironment($udom,$uname,'requestauthor','inststatus');
583: if ($userenv{'requestauthor'}) {
584: $val = $userenv{'requestauthor'};
585: @{$inststatuses} = ('_custom_');
586: } else {
587: my %alltasks;
588: if (ref($domconfig->{'requestauthor'}) eq 'HASH') {
589: %settings = %{$domconfig->{'requestauthor'}};
590: if (($isadv) && ($settings{'_LC_adv'} ne '')) {
591: $val = $settings{'_LC_adv'};
592: @{$inststatuses} = ('_LC_adv_');
593: } else {
594: if ($userenv{'inststatus'} ne '') {
595: @{$inststatuses} = split(',',$userenv{'inststatus'});
596: } else {
597: @{$inststatuses} = ('default');
598: }
599: foreach my $status (@{$inststatuses}) {
600: if (exists($settings{$status})) {
601: my $value = $settings{$status};
602: next unless ($value);
603: unless (exists($alltasks{$value})) {
604: if (ref($alltasks{$value}) eq 'ARRAY') {
605: unless(grep(/^\Q$status\E$/,@{$alltasks{$value}})) {
606: push(@{$alltasks{$value}},$status);
607: }
608: } else {
609: @{$alltasks{$value}} = ($status);
610: }
611: }
612: }
613: }
614: foreach my $option (@options) {
615: if ($alltasks{$option}) {
616: $val = $option;
617: last;
618: }
619: }
620: }
621: }
622: }
623: return $val;
624: }
625:
1.2 www 626: # =================================================================== Phase one
1.1 www 627:
1.42 matthew 628: sub print_username_entry_form {
1.351 raeburn 629: my ($r,$context,$response,$srch,$forcenewuser,$crstype,$brcrum) = @_;
1.101 albertel 630: my $defdom=$env{'request.role.domain'};
1.160 raeburn 631: my $formtoset = 'crtuser';
632: if (exists($env{'form.startrolename'})) {
633: $formtoset = 'docustom';
634: $env{'form.rolename'} = $env{'form.startrolename'};
1.207 raeburn 635: } elsif ($env{'form.origform'} eq 'crtusername') {
636: $formtoset = $env{'form.origform'};
1.160 raeburn 637: }
638:
639: my ($jsback,$elements) = &crumb_utilities();
640:
641: my $jscript = &Apache::loncommon::studentbrowser_javascript()."\n".
1.165 albertel 642: '<script type="text/javascript">'."\n".
1.301 bisitz 643: '// <![CDATA['."\n".
644: &Apache::lonhtmlcommon::set_form_elements($elements->{$formtoset})."\n".
645: '// ]]>'."\n".
1.162 raeburn 646: '</script>'."\n";
1.160 raeburn 647:
1.324 raeburn 648: my %existingroles=&Apache::lonuserutils::my_custom_roles($crstype);
649: if (($env{'form.action'} eq 'custom') && (keys(%existingroles) > 0)
650: && (&Apache::lonnet::allowed('mcr','/'))) {
651: $jscript .= &customrole_javascript();
652: }
1.224 raeburn 653: my $helpitem = 'Course_Change_Privileges';
654: if ($env{'form.action'} eq 'custom') {
655: $helpitem = 'Course_Editing_Custom_Roles';
656: } elsif ($env{'form.action'} eq 'singlestudent') {
657: $helpitem = 'Course_Add_Student';
658: }
1.351 raeburn 659: my %breadcrumb_text = &singleuser_breadcrumb($crstype);
660: if ($env{'form.action'} eq 'custom') {
661: push(@{$brcrum},
662: {href=>"javascript:backPage(document.crtuser)",
663: text=>"Pick custom role",
664: help => $helpitem,}
665: );
666: } else {
667: push (@{$brcrum},
668: {href => "javascript:backPage(document.crtuser)",
669: text => $breadcrumb_text{'search'},
670: help => $helpitem,
671: faq => 282,
672: bug => 'Instructor Interface',}
673: );
674: }
675: my %loaditems = (
676: 'onload' => "javascript:setFormElements(document.$formtoset)",
677: );
678: my $args = {bread_crumbs => $brcrum,
679: bread_crumbs_component => 'User Management',
680: add_entries => \%loaditems,};
681: $r->print(&Apache::loncommon::start_page('User Management',$jscript,$args));
682:
1.71 sakharuk 683: my %lt=&Apache::lonlocal::texthash(
1.229 raeburn 684: 'srst' => 'Search for a user and enroll as a student',
1.318 raeburn 685: 'srme' => 'Search for a user and enroll as a member',
1.229 raeburn 686: 'srad' => 'Search for a user and modify/add user information or roles',
1.71 sakharuk 687: 'usr' => "Username",
688: 'dom' => "Domain",
1.324 raeburn 689: 'ecrp' => "Define or Edit Custom Role",
690: 'nr' => "role name",
1.282 schafran 691: 'cre' => "Next",
1.71 sakharuk 692: );
1.351 raeburn 693:
1.214 raeburn 694: if ($env{'form.action'} eq 'custom') {
1.190 raeburn 695: if (&Apache::lonnet::allowed('mcr','/')) {
1.324 raeburn 696: my $newroletext = &mt('Define new custom role:');
697: $r->print('<form action="/adm/createuser" method="post" name="docustom">'.
698: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
699: '<input type="hidden" name="phase" value="selected_custom_edit" />'.
700: '<h3>'.$lt{'ecrp'}.'</h3>'.
701: &Apache::loncommon::start_data_table().
702: &Apache::loncommon::start_data_table_row().
703: '<td>');
704: if (keys(%existingroles) > 0) {
705: $r->print('<br /><label><input type="radio" name="customroleaction" value="new" checked="checked" onclick="setCustomFields();" /><b>'.$newroletext.'</b></label>');
706: } else {
707: $r->print('<br /><input type="hidden" name="customroleaction" value="new" /><b>'.$newroletext.'</b>');
708: }
709: $r->print('</td><td align="center">'.$lt{'nr'}.'<br /><input type="text" size="15" name="newrolename" onfocus="setCustomAction('."'new'".');" /></td>'.
710: &Apache::loncommon::end_data_table_row());
711: if (keys(%existingroles) > 0) {
712: $r->print(&Apache::loncommon::start_data_table_row().'<td><br />'.
713: '<label><input type="radio" name="customroleaction" value="edit" onclick="setCustomFields();"/><b>'.
714: &mt('View/Modify existing role:').'</b></label></td>'.
715: '<td align="center"><br />'.
716: '<select name="rolename" onchange="setCustomAction('."'edit'".');">'.
1.326 raeburn 717: '<option value="" selected="selected">'.
1.324 raeburn 718: &mt('Select'));
719: foreach my $role (sort(keys(%existingroles))) {
1.326 raeburn 720: $r->print('<option value="'.$role.'">'.$role.'</option>');
1.324 raeburn 721: }
722: $r->print('</select>'.
723: '</td>'.
724: &Apache::loncommon::end_data_table_row());
725: }
726: $r->print(&Apache::loncommon::end_data_table().'<p>'.
727: '<input name="customeditor" type="submit" value="'.
728: $lt{'cre'}.'" /></p>'.
729: '</form>');
1.190 raeburn 730: }
1.213 raeburn 731: } else {
1.229 raeburn 732: my $actiontext = $lt{'srad'};
1.213 raeburn 733: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 734: if ($crstype eq 'Community') {
735: $actiontext = $lt{'srme'};
736: } else {
737: $actiontext = $lt{'srst'};
738: }
1.213 raeburn 739: }
1.324 raeburn 740: $r->print("<h3>$actiontext</h3>");
1.213 raeburn 741: if ($env{'form.origform'} ne 'crtusername') {
742: $r->print("\n".$response);
743: }
1.318 raeburn 744: $r->print(&entry_form($defdom,$srch,$forcenewuser,$context,$response,$crstype));
1.107 www 745: }
1.110 albertel 746: }
747:
1.324 raeburn 748: sub customrole_javascript {
749: my $js = <<"END";
750: <script type="text/javascript">
751: // <![CDATA[
752:
753: function setCustomFields() {
754: if (document.docustom.customroleaction.length > 0) {
755: for (var i=0; i<document.docustom.customroleaction.length; i++) {
756: if (document.docustom.customroleaction[i].checked) {
757: if (document.docustom.customroleaction[i].value == 'new') {
758: document.docustom.rolename.selectedIndex = 0;
759: } else {
760: document.docustom.newrolename.value = '';
761: }
762: }
763: }
764: }
765: return;
766: }
767:
768: function setCustomAction(caller) {
769: if (document.docustom.customroleaction.length > 0) {
770: for (var i=0; i<document.docustom.customroleaction.length; i++) {
771: if (document.docustom.customroleaction[i].value == caller) {
772: document.docustom.customroleaction[i].checked = true;
773: }
774: }
775: }
776: setCustomFields();
777: return;
778: }
779:
780: // ]]>
781: </script>
782: END
783: return $js;
784: }
785:
1.160 raeburn 786: sub entry_form {
1.318 raeburn 787: my ($dom,$srch,$forcenewuser,$context,$responsemsg,$crstype) = @_;
1.229 raeburn 788: my ($usertype,$inexact);
1.214 raeburn 789: if (ref($srch) eq 'HASH') {
790: if (($srch->{'srchin'} eq 'dom') &&
791: ($srch->{'srchby'} eq 'uname') &&
792: ($srch->{'srchtype'} eq 'exact') &&
793: ($srch->{'srchdomain'} ne '') &&
794: ($srch->{'srchterm'} ne '')) {
1.353 raeburn 795: my (%curr_rules,%got_rules);
1.214 raeburn 796: my ($rules,$ruleorder) =
797: &Apache::lonnet::inst_userrules($srch->{'srchdomain'},'username');
1.353 raeburn 798: $usertype = &Apache::lonuserutils::check_usertype($srch->{'srchdomain'},$srch->{'srchterm'},$rules,\%curr_rules,\%got_rules);
1.229 raeburn 799: } else {
800: $inexact = 1;
1.214 raeburn 801: }
1.207 raeburn 802: }
1.214 raeburn 803: my $cancreate =
804: &Apache::lonuserutils::can_create_user($dom,$context,$usertype);
1.160 raeburn 805: my $userpicker =
1.179 raeburn 806: &Apache::loncommon::user_picker($dom,$srch,$forcenewuser,
1.214 raeburn 807: 'document.crtuser',$cancreate,$usertype);
1.160 raeburn 808: my $srchbutton = &mt('Search');
1.229 raeburn 809: if ($env{'form.action'} eq 'singlestudent') {
810: $srchbutton = &mt('Search and Enroll');
811: } elsif ($cancreate && $responsemsg ne '' && $inexact) {
812: $srchbutton = &mt('Search or Add New User');
813: }
1.207 raeburn 814: my $output = <<"ENDBLOCK";
1.160 raeburn 815: <form action="/adm/createuser" method="post" name="crtuser">
1.190 raeburn 816: <input type="hidden" name="action" value="$env{'form.action'}" />
1.160 raeburn 817: <input type="hidden" name="phase" value="get_user_info" />
818: $userpicker
1.179 raeburn 819: <input name="userrole" type="button" value="$srchbutton" onclick="javascript:validateEntry(document.crtuser)" />
1.160 raeburn 820: </form>
1.207 raeburn 821: ENDBLOCK
1.229 raeburn 822: if ($env{'form.phase'} eq '') {
1.207 raeburn 823: my $defdom=$env{'request.role.domain'};
824: my $domform = &Apache::loncommon::select_dom_form($defdom,'srchdomain');
825: my %lt=&Apache::lonlocal::texthash(
1.229 raeburn 826: 'enro' => 'Enroll one student',
1.318 raeburn 827: 'enrm' => 'Enroll one member',
1.229 raeburn 828: 'admo' => 'Add/modify a single user',
829: 'crea' => 'create new user if required',
830: 'uskn' => "username is known",
1.207 raeburn 831: 'crnu' => 'Create a new user',
832: 'usr' => 'Username',
833: 'dom' => 'in domain',
1.229 raeburn 834: 'enrl' => 'Enroll',
835: 'cram' => 'Create/Modify user',
1.207 raeburn 836: );
1.229 raeburn 837: my $sellink=&Apache::loncommon::selectstudent_link('crtusername','srchterm','srchdomain');
838: my ($title,$buttontext,$showresponse);
1.318 raeburn 839: if ($env{'form.action'} eq 'singlestudent') {
840: if ($crstype eq 'Community') {
841: $title = $lt{'enrm'};
842: } else {
843: $title = $lt{'enro'};
844: }
1.229 raeburn 845: $buttontext = $lt{'enrl'};
846: } else {
847: $title = $lt{'admo'};
848: $buttontext = $lt{'cram'};
849: }
850: if ($cancreate) {
851: $title .= ' <span class="LC_cusr_subheading">('.$lt{'crea'}.')</span>';
852: } else {
853: $title .= ' <span class="LC_cusr_subheading">('.$lt{'uskn'}.')</span>';
854: }
855: if ($env{'form.origform'} eq 'crtusername') {
856: $showresponse = $responsemsg;
857: }
1.207 raeburn 858: $output .= <<"ENDDOCUMENT";
1.229 raeburn 859: <br />
1.207 raeburn 860: <form action="/adm/createuser" method="post" name="crtusername">
861: <input type="hidden" name="action" value="$env{'form.action'}" />
862: <input type="hidden" name="phase" value="createnewuser" />
863: <input type="hidden" name="srchtype" value="exact" />
1.233 raeburn 864: <input type="hidden" name="srchby" value="uname" />
1.207 raeburn 865: <input type="hidden" name="srchin" value="dom" />
866: <input type="hidden" name="forcenewuser" value="1" />
867: <input type="hidden" name="origform" value="crtusername" />
1.229 raeburn 868: <h3>$title</h3>
869: $showresponse
1.207 raeburn 870: <table>
871: <tr>
872: <td>$lt{'usr'}:</td>
873: <td><input type="text" size="15" name="srchterm" /></td>
874: <td> $lt{'dom'}:</td><td>$domform</td>
1.229 raeburn 875: <td> $sellink </td>
876: <td> <input name="userrole" type="submit" value="$buttontext" /></td>
1.207 raeburn 877: </tr>
878: </table>
879: </form>
1.160 raeburn 880: ENDDOCUMENT
1.207 raeburn 881: }
1.160 raeburn 882: return $output;
883: }
1.110 albertel 884:
885: sub user_modification_js {
1.113 raeburn 886: my ($pjump_def,$dc_setcourse_code,$nondc_setsection_code,$groupslist)=@_;
887:
1.110 albertel 888: return <<END;
889: <script type="text/javascript" language="Javascript">
1.301 bisitz 890: // <![CDATA[
1.314 raeburn 891:
1.110 albertel 892: $pjump_def
893: $dc_setcourse_code
894:
895: function dateset() {
896: eval("document.cu."+document.cu.pres_marker.value+
897: ".value=document.cu.pres_value.value");
1.359 www 898: modalWindow.close();
1.110 albertel 899: }
900:
1.113 raeburn 901: $nondc_setsection_code
1.301 bisitz 902: // ]]>
1.110 albertel 903: </script>
904: END
1.2 www 905: }
906:
907: # =================================================================== Phase two
1.160 raeburn 908: sub print_user_selection_page {
1.351 raeburn 909: my ($r,$response,$srch,$srch_results,$srcharray,$context,$opener_elements,$crstype,$brcrum) = @_;
1.160 raeburn 910: my @fields = ('username','domain','lastname','firstname','permanentemail');
911: my $sortby = $env{'form.sortby'};
912:
913: if (!grep(/^\Q$sortby\E$/,@fields)) {
914: $sortby = 'lastname';
915: }
916:
917: my ($jsback,$elements) = &crumb_utilities();
918:
919: my $jscript = (<<ENDSCRIPT);
920: <script type="text/javascript">
1.301 bisitz 921: // <![CDATA[
1.160 raeburn 922: function pickuser(uname,udom) {
923: document.usersrchform.seluname.value=uname;
924: document.usersrchform.seludom.value=udom;
925: document.usersrchform.phase.value="userpicked";
926: document.usersrchform.submit();
927: }
928:
929: $jsback
1.301 bisitz 930: // ]]>
1.160 raeburn 931: </script>
932: ENDSCRIPT
933:
934: my %lt=&Apache::lonlocal::texthash(
1.179 raeburn 935: 'usrch' => "User Search to add/modify roles",
936: 'stusrch' => "User Search to enroll student",
1.318 raeburn 937: 'memsrch' => "User Search to enroll member",
1.179 raeburn 938: 'usel' => "Select a user to add/modify roles",
1.318 raeburn 939: 'stusel' => "Select a user to enroll as a student",
940: 'memsel' => "Select a user to enroll as a member",
1.160 raeburn 941: 'username' => "username",
942: 'domain' => "domain",
943: 'lastname' => "last name",
944: 'firstname' => "first name",
945: 'permanentemail' => "permanent e-mail",
946: );
1.302 raeburn 947: if ($context eq 'requestcrs') {
948: $r->print('<div>');
949: } else {
1.318 raeburn 950: my %breadcrumb_text = &singleuser_breadcrumb($crstype);
1.351 raeburn 951: my $helpitem;
952: if ($env{'form.action'} eq 'singleuser') {
953: $helpitem = 'Course_Change_Privileges';
954: } elsif ($env{'form.action'} eq 'singlestudent') {
955: $helpitem = 'Course_Add_Student';
956: }
957: push (@{$brcrum},
958: {href => "javascript:backPage(document.usersrchform,'','')",
959: text => $breadcrumb_text{'search'},
960: faq => 282,
961: bug => 'Instructor Interface',},
962: {href => "javascript:backPage(document.usersrchform,'get_user_info','select')",
963: text => $breadcrumb_text{'userpicked'},
964: faq => 282,
965: bug => 'Instructor Interface',
966: help => $helpitem}
967: );
968: $r->print(&Apache::loncommon::start_page('User Management',$jscript,{bread_crumbs => $brcrum}));
1.302 raeburn 969: if ($env{'form.action'} eq 'singleuser') {
970: $r->print("<b>$lt{'usrch'}</b><br />");
1.318 raeburn 971: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,$crstype));
1.302 raeburn 972: $r->print('<h3>'.$lt{'usel'}.'</h3>');
973: } elsif ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 974: $r->print($jscript."<b>");
975: if ($crstype eq 'Community') {
976: $r->print($lt{'memsrch'});
977: } else {
978: $r->print($lt{'stusrch'});
979: }
980: $r->print("</b><br />");
981: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,$crstype));
982: $r->print('</form><h3>');
983: if ($crstype eq 'Community') {
984: $r->print($lt{'memsel'});
985: } else {
986: $r->print($lt{'stusel'});
987: }
988: $r->print('</h3>');
1.302 raeburn 989: }
1.179 raeburn 990: }
1.380 bisitz 991: $r->print('<form name="usersrchform" method="post" action="">'.
1.160 raeburn 992: &Apache::loncommon::start_data_table()."\n".
993: &Apache::loncommon::start_data_table_header_row()."\n".
994: ' <th> </th>'."\n");
995: foreach my $field (@fields) {
996: $r->print(' <th><a href="javascript:document.usersrchform.sortby.value='.
997: "'".$field."'".';document.usersrchform.submit();">'.
998: $lt{$field}.'</a></th>'."\n");
999: }
1000: $r->print(&Apache::loncommon::end_data_table_header_row());
1001:
1002: my @sorted_users = sort {
1.167 albertel 1003: lc($srch_results->{$a}->{$sortby}) cmp lc($srch_results->{$b}->{$sortby})
1.160 raeburn 1004: ||
1.167 albertel 1005: lc($srch_results->{$a}->{lastname}) cmp lc($srch_results->{$b}->{lastname})
1.160 raeburn 1006: ||
1007: lc($srch_results->{$a}->{firstname}) cmp lc($srch_results->{$b}->{firstname})
1.167 albertel 1008: ||
1009: lc($a) cmp lc($b)
1.160 raeburn 1010: } (keys(%$srch_results));
1011:
1012: foreach my $user (@sorted_users) {
1013: my ($uname,$udom) = split(/:/,$user);
1.302 raeburn 1014: my $onclick;
1015: if ($context eq 'requestcrs') {
1.314 raeburn 1016: $onclick =
1.302 raeburn 1017: 'onclick="javascript:gochoose('."'$uname','$udom',".
1018: "'$srch_results->{$user}->{firstname}',".
1019: "'$srch_results->{$user}->{lastname}',".
1020: "'$srch_results->{$user}->{permanentemail}'".');"';
1021: } else {
1.314 raeburn 1022: $onclick =
1.302 raeburn 1023: ' onclick="javascript:pickuser('."'".$uname."'".','."'".$udom."'".');"';
1024: }
1.160 raeburn 1025: $r->print(&Apache::loncommon::start_data_table_row().
1.302 raeburn 1026: '<td><input type="button" name="seluser" value="'.&mt('Select').'" '.
1027: $onclick.' /></td>'.
1.160 raeburn 1028: '<td><tt>'.$uname.'</tt></td>'.
1029: '<td><tt>'.$udom.'</tt></td>');
1030: foreach my $field ('lastname','firstname','permanentemail') {
1031: $r->print('<td>'.$srch_results->{$user}->{$field}.'</td>');
1032: }
1033: $r->print(&Apache::loncommon::end_data_table_row());
1034: }
1035: $r->print(&Apache::loncommon::end_data_table().'<br /><br />');
1.179 raeburn 1036: if (ref($srcharray) eq 'ARRAY') {
1037: foreach my $item (@{$srcharray}) {
1038: $r->print('<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n");
1039: }
1040: }
1.160 raeburn 1041: $r->print(' <input type="hidden" name="sortby" value="'.$sortby.'" />'."\n".
1042: ' <input type="hidden" name="seluname" value="" />'."\n".
1043: ' <input type="hidden" name="seludom" value="" />'."\n".
1.179 raeburn 1044: ' <input type="hidden" name="currstate" value="select" />'."\n".
1.190 raeburn 1045: ' <input type="hidden" name="phase" value="get_user_info" />'."\n".
1.214 raeburn 1046: ' <input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n");
1.302 raeburn 1047: if ($context eq 'requestcrs') {
1048: $r->print($opener_elements.'</form></div>');
1049: } else {
1.351 raeburn 1050: $r->print($response.'</form>');
1.302 raeburn 1051: }
1.160 raeburn 1052: }
1053:
1054: sub print_user_query_page {
1.351 raeburn 1055: my ($r,$caller,$brcrum) = @_;
1.160 raeburn 1056: # FIXME - this is for a network-wide name search (similar to catalog search)
1057: # To use frames with similar behavior to catalog/portfolio search.
1058: # To be implemented.
1059: return;
1060: }
1061:
1.42 matthew 1062: sub print_user_modification_page {
1.375 raeburn 1063: my ($r,$ccuname,$ccdomain,$srch,$response,$context,$permission,$crstype,
1064: $brcrum,$showcredits) = @_;
1.185 raeburn 1065: if (($ccuname eq '') || ($ccdomain eq '')) {
1.215 raeburn 1066: my $usermsg = &mt('No username and/or domain provided.');
1067: $env{'form.phase'} = '';
1.351 raeburn 1068: &print_username_entry_form($r,$context,$usermsg,'','',$crstype,$brcrum);
1.58 www 1069: return;
1070: }
1.213 raeburn 1071: my ($form,$formname);
1072: if ($env{'form.action'} eq 'singlestudent') {
1073: $form = 'document.enrollstudent';
1074: $formname = 'enrollstudent';
1075: } else {
1076: $form = 'document.cu';
1077: $formname = 'cu';
1078: }
1.188 raeburn 1079: my %abv_auth = &auth_abbrev();
1.227 raeburn 1080: my (%rulematch,%inst_results,$newuser,%alerts,%curr_rules,%got_rules);
1.185 raeburn 1081: my $uhome=&Apache::lonnet::homeserver($ccuname,$ccdomain);
1082: if ($uhome eq 'no_host') {
1.215 raeburn 1083: my $usertype;
1084: my ($rules,$ruleorder) =
1085: &Apache::lonnet::inst_userrules($ccdomain,'username');
1086: $usertype =
1.353 raeburn 1087: &Apache::lonuserutils::check_usertype($ccdomain,$ccuname,$rules,
1.362 raeburn 1088: \%curr_rules,\%got_rules);
1.215 raeburn 1089: my $cancreate =
1090: &Apache::lonuserutils::can_create_user($ccdomain,$context,
1091: $usertype);
1092: if (!$cancreate) {
1.292 bisitz 1093: my $helplink = 'javascript:helpMenu('."'display'".')';
1.215 raeburn 1094: my %usertypetext = (
1095: official => 'institutional',
1096: unofficial => 'non-institutional',
1097: );
1098: my $response;
1099: if ($env{'form.origform'} eq 'crtusername') {
1.362 raeburn 1100: $response = '<span class="LC_warning">'.
1101: &mt('No match found for the username [_1] in LON-CAPA domain: [_2]',
1102: '<b>'.$ccuname.'</b>',$ccdomain).
1.215 raeburn 1103: '</span><br />';
1104: }
1.292 bisitz 1105: $response .= '<p class="LC_warning">'
1106: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
1107: .' '
1108: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
1109: ,'<a href="'.$helplink.'">','</a>')
1110: .'</p><br />';
1.215 raeburn 1111: $env{'form.phase'} = '';
1.351 raeburn 1112: &print_username_entry_form($r,$context,$response,undef,undef,$crstype,$brcrum);
1.215 raeburn 1113: return;
1114: }
1.188 raeburn 1115: $newuser = 1;
1.193 raeburn 1116: my $checkhash;
1117: my $checks = { 'username' => 1 };
1.196 raeburn 1118: $checkhash->{$ccuname.':'.$ccdomain} = { 'newuser' => $newuser };
1.193 raeburn 1119: &Apache::loncommon::user_rule_check($checkhash,$checks,
1.196 raeburn 1120: \%alerts,\%rulematch,\%inst_results,\%curr_rules,\%got_rules);
1121: if (ref($alerts{'username'}) eq 'HASH') {
1122: if (ref($alerts{'username'}{$ccdomain}) eq 'HASH') {
1123: my $domdesc =
1.193 raeburn 1124: &Apache::lonnet::domain($ccdomain,'description');
1.196 raeburn 1125: if ($alerts{'username'}{$ccdomain}{$ccuname}) {
1126: my $userchkmsg;
1127: if (ref($curr_rules{$ccdomain}) eq 'HASH') {
1128: $userchkmsg =
1129: &Apache::loncommon::instrule_disallow_msg('username',
1.193 raeburn 1130: $domdesc,1).
1131: &Apache::loncommon::user_rule_formats($ccdomain,
1132: $domdesc,$curr_rules{$ccdomain}{'username'},
1133: 'username');
1.196 raeburn 1134: }
1.215 raeburn 1135: $env{'form.phase'} = '';
1.351 raeburn 1136: &print_username_entry_form($r,$context,$userchkmsg,undef,undef,$crstype,$brcrum);
1.196 raeburn 1137: return;
1.215 raeburn 1138: }
1.193 raeburn 1139: }
1.185 raeburn 1140: }
1.187 raeburn 1141: } else {
1.188 raeburn 1142: $newuser = 0;
1.185 raeburn 1143: }
1.160 raeburn 1144: if ($response) {
1.215 raeburn 1145: $response = '<br />'.$response;
1.160 raeburn 1146: }
1.149 raeburn 1147:
1.52 matthew 1148: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
1.88 raeburn 1149: my $dc_setcourse_code = '';
1.119 raeburn 1150: my $nondc_setsection_code = '';
1.112 albertel 1151: my %loaditem;
1.114 albertel 1152:
1.216 raeburn 1153: my $groupslist = &Apache::lonuserutils::get_groupslist();
1.88 raeburn 1154:
1.375 raeburn 1155: my $js = &validation_javascript($context,$ccdomain,$pjump_def,$crstype,
1.216 raeburn 1156: $groupslist,$newuser,$formname,\%loaditem);
1.318 raeburn 1157: my %breadcrumb_text = &singleuser_breadcrumb($crstype);
1.224 raeburn 1158: my $helpitem = 'Course_Change_Privileges';
1159: if ($env{'form.action'} eq 'singlestudent') {
1160: $helpitem = 'Course_Add_Student';
1161: }
1.351 raeburn 1162: push (@{$brcrum},
1163: {href => "javascript:backPage($form)",
1164: text => $breadcrumb_text{'search'},
1165: faq => 282,
1166: bug => 'Instructor Interface',});
1167: if ($env{'form.phase'} eq 'userpicked') {
1168: push(@{$brcrum},
1169: {href => "javascript:backPage($form,'get_user_info','select')",
1170: text => $breadcrumb_text{'userpicked'},
1171: faq => 282,
1172: bug => 'Instructor Interface',});
1173: }
1174: push(@{$brcrum},
1175: {href => "javascript:backPage($form,'$env{'form.phase'}','modify')",
1176: text => $breadcrumb_text{'modify'},
1177: faq => 282,
1178: bug => 'Instructor Interface',
1179: help => $helpitem});
1180: my $args = {'add_entries' => \%loaditem,
1181: 'bread_crumbs' => $brcrum,
1182: 'bread_crumbs_component' => 'User Management'};
1183: if ($env{'form.popup'}) {
1184: $args->{'no_nav_bar'} = 1;
1185: }
1186: my $start_page =
1187: &Apache::loncommon::start_page('User Management',$js,$args);
1.3 www 1188:
1.25 matthew 1189: my $forminfo =<<"ENDFORMINFO";
1.216 raeburn 1190: <form action="/adm/createuser" method="post" name="$formname">
1.190 raeburn 1191: <input type="hidden" name="phase" value="update_user_data" />
1.188 raeburn 1192: <input type="hidden" name="ccuname" value="$ccuname" />
1193: <input type="hidden" name="ccdomain" value="$ccdomain" />
1.157 albertel 1194: <input type="hidden" name="pres_value" value="" />
1195: <input type="hidden" name="pres_type" value="" />
1196: <input type="hidden" name="pres_marker" value="" />
1.25 matthew 1197: ENDFORMINFO
1.375 raeburn 1198: my (%inccourses,$roledom,$defaultcredits);
1.329 raeburn 1199: if ($context eq 'course') {
1200: $inccourses{$env{'request.course.id'}}=1;
1201: $roledom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1.375 raeburn 1202: if ($showcredits) {
1203: $defaultcredits = &Apache::lonuserutils::get_defaultcredits();
1204: }
1.329 raeburn 1205: } elsif ($context eq 'author') {
1206: $roledom = $env{'request.role.domain'};
1207: } elsif ($context eq 'domain') {
1208: foreach my $key (keys(%env)) {
1209: $roledom = $env{'request.role.domain'};
1210: if ($key=~/^user\.priv\.cm\.\/($roledom)\/($match_username)/) {
1211: $inccourses{$1.'_'.$2}=1;
1212: }
1213: }
1214: } else {
1215: foreach my $key (keys(%env)) {
1216: if ($key=~/^user\.priv\.cm\.\/($match_domain)\/($match_username)/) {
1217: $inccourses{$1.'_'.$2}=1;
1218: }
1.2 www 1219: }
1.24 matthew 1220: }
1.216 raeburn 1221: if ($newuser) {
1.362 raeburn 1222: my ($portfolioform,$domroleform);
1.267 raeburn 1223: if ((&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) ||
1224: (&Apache::lonnet::allowed('mut',$env{'request.role.domain'}))) {
1225: # Current user has quota or user tools modification privileges
1.378 raeburn 1226: $portfolioform = '<br />'.&user_quotas($ccuname,$ccdomain);
1.134 raeburn 1227: }
1.362 raeburn 1228: if (&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) {
1229: $domroleform = '<br />'.&domainrole_req($ccuname,$ccdomain);
1230: }
1.227 raeburn 1231: &initialize_authen_forms($ccdomain,$formname);
1.188 raeburn 1232: my %lt=&Apache::lonlocal::texthash(
1233: 'cnu' => 'Create New User',
1.213 raeburn 1234: 'ast' => 'as a student',
1.318 raeburn 1235: 'ame' => 'as a member',
1.188 raeburn 1236: 'ind' => 'in domain',
1237: 'lg' => 'Login Data',
1.190 raeburn 1238: 'hs' => "Home Server",
1.188 raeburn 1239: );
1.185 raeburn 1240: $r->print(<<ENDTITLE);
1.110 albertel 1241: $start_page
1.160 raeburn 1242: $response
1.25 matthew 1243: $forminfo
1.31 matthew 1244: <script type="text/javascript" language="Javascript">
1.301 bisitz 1245: // <![CDATA[
1.20 harris41 1246: $loginscript
1.301 bisitz 1247: // ]]>
1.31 matthew 1248: </script>
1.20 harris41 1249: <input type='hidden' name='makeuser' value='1' />
1.216 raeburn 1250: <h2>$lt{'cnu'} "$ccuname" $lt{'ind'} $ccdomain
1.185 raeburn 1251: ENDTITLE
1.213 raeburn 1252: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1253: if ($crstype eq 'Community') {
1254: $r->print(' ('.$lt{'ame'}.')');
1255: } else {
1256: $r->print(' ('.$lt{'ast'}.')');
1257: }
1.213 raeburn 1258: }
1259: $r->print('</h2>'."\n".'<div class="LC_left_float">');
1.206 raeburn 1260: my $personal_table =
1.210 raeburn 1261: &personal_data_display($ccuname,$ccdomain,$newuser,$context,
1262: $inst_results{$ccuname.':'.$ccdomain});
1.206 raeburn 1263: $r->print($personal_table);
1.187 raeburn 1264: my ($home_server_pick,$numlib) =
1265: &Apache::loncommon::home_server_form_item($ccdomain,'hserver',
1266: 'default','hide');
1267: if ($numlib > 1) {
1268: $r->print("
1.185 raeburn 1269: <br />
1.187 raeburn 1270: $lt{'hs'}: $home_server_pick
1271: <br />");
1272: } else {
1273: $r->print($home_server_pick);
1274: }
1.304 raeburn 1275: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.362 raeburn 1276: $r->print('<br /><h3>'.
1277: &mt('User Can Request Creation of Courses/Communities in this Domain?').'</h3>'.
1.304 raeburn 1278: &Apache::loncommon::start_data_table().
1279: &build_tools_display($ccuname,$ccdomain,
1280: 'requestcourses').
1281: &Apache::loncommon::end_data_table());
1282: }
1.188 raeburn 1283: $r->print('</div>'."\n".'<div class="LC_left_float"><h3>'.
1284: $lt{'lg'}.'</h3>');
1.185 raeburn 1285: my ($fixedauth,$varauth,$authmsg);
1.193 raeburn 1286: if (ref($rulematch{$ccuname.':'.$ccdomain}) eq 'HASH') {
1287: my $matchedrule = $rulematch{$ccuname.':'.$ccdomain}{'username'};
1288: my ($rules,$ruleorder) =
1289: &Apache::lonnet::inst_userrules($ccdomain,'username');
1.185 raeburn 1290: if (ref($rules) eq 'HASH') {
1.193 raeburn 1291: if (ref($rules->{$matchedrule}) eq 'HASH') {
1292: my $authtype = $rules->{$matchedrule}{'authtype'};
1.185 raeburn 1293: if ($authtype !~ /^(krb4|krb5|int|fsys|loc)$/) {
1.190 raeburn 1294: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.275 raeburn 1295: } else {
1.193 raeburn 1296: my $authparm = $rules->{$matchedrule}{'authparm'};
1.273 raeburn 1297: $authmsg = $rules->{$matchedrule}{'authmsg'};
1.185 raeburn 1298: if ($authtype =~ /^krb(4|5)$/) {
1299: my $ver = $1;
1300: if ($authparm ne '') {
1301: $fixedauth = <<"KERB";
1302: <input type="hidden" name="login" value="krb" />
1303: <input type="hidden" name="krbver" value="$ver" />
1304: <input type="hidden" name="krbarg" value="$authparm" />
1305: KERB
1306: }
1307: } else {
1308: $fixedauth =
1309: '<input type="hidden" name="login" value="'.$authtype.'" />'."\n";
1.193 raeburn 1310: if ($rules->{$matchedrule}{'authparmfixed'}) {
1.185 raeburn 1311: $fixedauth .=
1312: '<input type="hidden" name="'.$authtype.'arg" value="'.$authparm.'" />'."\n";
1313: } else {
1.273 raeburn 1314: if ($authtype eq 'int') {
1315: $varauth = '<br />'.
1.301 bisitz 1316: &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 1317: } elsif ($authtype eq 'loc') {
1318: $varauth = '<br />'.
1319: &mt('[_1] Local Authentication with argument [_2]','','<input type="text" name="'.$authtype.'arg" value="" />')."\n";
1320: } else {
1321: $varauth =
1.185 raeburn 1322: '<input type="text" name="'.$authtype.'arg" value="" />'."\n";
1.273 raeburn 1323: }
1.185 raeburn 1324: }
1325: }
1326: }
1327: } else {
1.190 raeburn 1328: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.185 raeburn 1329: }
1330: }
1331: if ($authmsg) {
1332: $r->print(<<ENDAUTH);
1333: $fixedauth
1334: $authmsg
1335: $varauth
1336: ENDAUTH
1337: }
1338: } else {
1.190 raeburn 1339: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.187 raeburn 1340: }
1.362 raeburn 1341: $r->print($portfolioform.$domroleform);
1.215 raeburn 1342: if ($env{'form.action'} eq 'singlestudent') {
1343: $r->print(&date_sections_select($context,$newuser,$formname,
1.375 raeburn 1344: $permission,$crstype,$ccuname,
1345: $ccdomain,$showcredits));
1.215 raeburn 1346: }
1347: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.216 raeburn 1348: } else { # user already exists
1.79 albertel 1349: my %lt=&Apache::lonlocal::texthash(
1.191 raeburn 1350: 'cup' => "Modify existing user: ",
1.213 raeburn 1351: 'ens' => "Enroll one student: ",
1.318 raeburn 1352: 'enm' => "Enroll one member: ",
1.72 sakharuk 1353: 'id' => "in domain",
1354: );
1.26 matthew 1355: $r->print(<<ENDCHANGEUSER);
1.110 albertel 1356: $start_page
1.25 matthew 1357: $forminfo
1.213 raeburn 1358: <h2>
1.26 matthew 1359: ENDCHANGEUSER
1.213 raeburn 1360: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1361: if ($crstype eq 'Community') {
1362: $r->print($lt{'enm'});
1363: } else {
1364: $r->print($lt{'ens'});
1365: }
1.213 raeburn 1366: } else {
1367: $r->print($lt{'cup'});
1368: }
1369: $r->print(' "'.$ccuname.'" '.$lt{'id'}.' "'.$ccdomain.'"</h2>'.
1370: "\n".'<div class="LC_left_float">');
1.206 raeburn 1371: my ($personal_table,$showforceid) =
1.210 raeburn 1372: &personal_data_display($ccuname,$ccdomain,$newuser,$context,
1373: $inst_results{$ccuname.':'.$ccdomain});
1.206 raeburn 1374: $r->print($personal_table);
1375: if ($showforceid) {
1.362 raeburn 1376: $r->print('<table>'.&Apache::lonuserutils::forceid_change($context).'</table>');
1.199 raeburn 1377: }
1.275 raeburn 1378: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.362 raeburn 1379: $r->print('<br /><h3>'.&mt('User Can Request Creation of Courses/Communities in this Domain?').'</h3>'.
1.300 raeburn 1380: &Apache::loncommon::start_data_table());
1.314 raeburn 1381: if ($env{'request.role.domain'} eq $ccdomain) {
1.300 raeburn 1382: $r->print(&build_tools_display($ccuname,$ccdomain,'requestcourses'));
1383: } else {
1384: $r->print(&coursereq_externaluser($ccuname,$ccdomain,
1385: $env{'request.role.domain'}));
1386: }
1387: $r->print(&Apache::loncommon::end_data_table());
1.275 raeburn 1388: }
1.199 raeburn 1389: $r->print('</div>');
1.362 raeburn 1390: my @order = ('auth','quota','tools','requestauthor');
1391: my %user_text;
1392: my ($isadv,$isauthor) =
1393: &Apache::lonnet::is_advanced_user($ccuname,$ccdomain);
1394: if ((!$isauthor) &&
1395: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
1396: $user_text{'requestauthor'} = &domainrole_req($ccuname,$ccdomain);
1397: }
1398: $user_text{'auth'} = &user_authentication($ccuname,$ccdomain,$formname);
1.267 raeburn 1399: if ((&Apache::lonnet::allowed('mpq',$ccdomain)) ||
1400: (&Apache::lonnet::allowed('mut',$ccdomain))) {
1.188 raeburn 1401: # Current user has quota modification privileges
1.378 raeburn 1402: $user_text{'quota'} = &user_quotas($ccuname,$ccdomain);
1.267 raeburn 1403: }
1404: if (!&Apache::lonnet::allowed('mpq',$ccdomain)) {
1405: if (&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) {
1406: my %lt=&Apache::lonlocal::texthash(
1.378 raeburn 1407: 'dska' => "Disk quotas for user's portfolio and authoring space",
1408: 'youd' => "You do not have privileges to modify the portfolio and/or authoring space quotas for this user.",
1.267 raeburn 1409: 'ichr' => "If a change is required, contact a domain coordinator for the domain",
1410: );
1.362 raeburn 1411: $user_text{'quota'} = <<ENDNOPORTPRIV;
1.188 raeburn 1412: <h3>$lt{'dska'}</h3>
1413: $lt{'youd'} $lt{'ichr'}: $ccdomain
1414: ENDNOPORTPRIV
1.267 raeburn 1415: }
1416: }
1417: if (!&Apache::lonnet::allowed('mut',$ccdomain)) {
1418: if (&Apache::lonnet::allowed('mut',$env{'request.role.domain'})) {
1419: my %lt=&Apache::lonlocal::texthash(
1420: 'utav' => "User Tools Availability",
1.361 raeburn 1421: 'yodo' => "You do not have privileges to modify Portfolio, Blog, WebDAV, or Personal Information Page settings for this user.",
1.267 raeburn 1422: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
1423: );
1.362 raeburn 1424: $user_text{'tools'} = <<ENDNOTOOLSPRIV;
1.267 raeburn 1425: <h3>$lt{'utav'}</h3>
1426: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1427: ENDNOTOOLSPRIV
1428: }
1.188 raeburn 1429: }
1.362 raeburn 1430: my $gotdiv = 0;
1431: foreach my $item (@order) {
1432: if ($user_text{$item} ne '') {
1433: unless ($gotdiv) {
1434: $r->print('<div class="LC_left_float">');
1435: $gotdiv = 1;
1436: }
1437: $r->print('<br />'.$user_text{$item});
1438: }
1439: }
1440: if ($env{'form.action'} eq 'singlestudent') {
1441: unless ($gotdiv) {
1442: $r->print('<div class="LC_left_float">');
1.213 raeburn 1443: }
1.375 raeburn 1444: my $credits;
1445: if ($showcredits) {
1446: $credits = &get_user_credits($ccuname,$ccdomain,$defaultcredits);
1447: if ($credits eq '') {
1448: $credits = $defaultcredits;
1449: }
1450: }
1.374 raeburn 1451: $r->print(&date_sections_select($context,$newuser,$formname,
1.375 raeburn 1452: $permission,$crstype,$ccuname,
1453: $ccdomain,$showcredits));
1.374 raeburn 1454: }
1.362 raeburn 1455: if ($gotdiv) {
1456: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.188 raeburn 1457: }
1.217 raeburn 1458: if ($env{'form.action'} ne 'singlestudent') {
1.329 raeburn 1459: &display_existing_roles($r,$ccuname,$ccdomain,\%inccourses,$context,
1460: $roledom,$crstype);
1.217 raeburn 1461: }
1.25 matthew 1462: } ## End of new user/old user logic
1.218 raeburn 1463: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1464: my $btntxt;
1465: if ($crstype eq 'Community') {
1466: $btntxt = &mt('Enroll Member');
1467: } else {
1468: $btntxt = &mt('Enroll Student');
1469: }
1470: $r->print('<br /><input type="button" value="'.$btntxt.'" onclick="setSections(this.form)" />'."\n");
1.218 raeburn 1471: } else {
1.375 raeburn 1472: $r->print('<fieldset><legend>'.&mt('Add Roles').'</legend>');
1.218 raeburn 1473: my $addrolesdisplay = 0;
1474: if ($context eq 'domain' || $context eq 'author') {
1475: $addrolesdisplay = &new_coauthor_roles($r,$ccuname,$ccdomain);
1476: }
1477: if ($context eq 'domain') {
1.357 raeburn 1478: my $add_domainroles = &new_domain_roles($r,$ccdomain);
1.218 raeburn 1479: if (!$addrolesdisplay) {
1480: $addrolesdisplay = $add_domainroles;
1.2 www 1481: }
1.375 raeburn 1482: $r->print(&course_level_dc($env{'request.role.domain'},$showcredits));
1483: $r->print('</fieldset><br /><input type="button" value="'.&mt('Save').'" onclick="setCourse()" />'."\n");
1.218 raeburn 1484: } elsif ($context eq 'author') {
1485: if ($addrolesdisplay) {
1.375 raeburn 1486: $r->print('</fieldset><br /><input type="button" value="'.&mt('Save').'"');
1.218 raeburn 1487: if ($newuser) {
1.301 bisitz 1488: $r->print(' onclick="auth_check()" \>'."\n");
1.218 raeburn 1489: } else {
1.301 bisitz 1490: $r->print('onclick="this.form.submit()" \>'."\n");
1.218 raeburn 1491: }
1.188 raeburn 1492: } else {
1.375 raeburn 1493: $r->print('</fieldset><br /><a href="javascript:backPage(document.cu)">'.
1.218 raeburn 1494: &mt('Back to previous page').'</a>');
1.188 raeburn 1495: }
1496: } else {
1.375 raeburn 1497: $r->print(&course_level_table(\%inccourses,$showcredits,$defaultcredits));
1498: $r->print('</fieldset><br /><input type="button" value="'.&mt('Save').'" onclick="setSections(this.form)" />'."\n");
1.188 raeburn 1499: }
1.88 raeburn 1500: }
1.188 raeburn 1501: $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','userrole','ccdomain','prevphase','currstate','ccuname','ccdomain']));
1.179 raeburn 1502: $r->print('<input type="hidden" name="currstate" value="" />');
1.352 raeburn 1503: $r->print('<input type="hidden" name="prevphase" value="'.$env{'form.phase'}.'" /></form>');
1.218 raeburn 1504: return;
1.2 www 1505: }
1.1 www 1506:
1.213 raeburn 1507: sub singleuser_breadcrumb {
1.318 raeburn 1508: my ($crstype) = @_;
1.213 raeburn 1509: my %breadcrumb_text;
1510: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1511: if ($crstype eq 'Community') {
1512: $breadcrumb_text{'search'} = 'Enroll a member';
1513: } else {
1514: $breadcrumb_text{'search'} = 'Enroll a student';
1515: }
1.213 raeburn 1516: $breadcrumb_text{'userpicked'} = 'Select a user',
1517: $breadcrumb_text{'modify'} = 'Set section/dates',
1518: } else {
1.229 raeburn 1519: $breadcrumb_text{'search'} = 'Create/modify a user';
1.213 raeburn 1520: $breadcrumb_text{'userpicked'} = 'Select a user',
1521: $breadcrumb_text{'modify'} = 'Set user role',
1522: }
1523: return %breadcrumb_text;
1524: }
1525:
1526: sub date_sections_select {
1.375 raeburn 1527: my ($context,$newuser,$formname,$permission,$crstype,$ccuname,$ccdomain,
1528: $showcredits) = @_;
1529: my $credits;
1530: if ($showcredits) {
1531: my $defaultcredits = &Apache::lonuserutils::get_defaultcredits();
1532: $credits = &get_user_credits($ccuname,$ccdomain,$defaultcredits);
1533: if ($credits eq '') {
1534: $credits = $defaultcredits;
1535: }
1536: }
1.213 raeburn 1537: my $cid = $env{'request.course.id'};
1538: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity($cid);
1539: my $date_table = '<h3>'.&mt('Starting and Ending Dates').'</h3>'."\n".
1540: &Apache::lonuserutils::date_setting_table(undef,undef,$context,
1541: undef,$formname,$permission);
1542: my $rowtitle = 'Section';
1.375 raeburn 1543: my $secbox = '<h3>'.&mt('Section and Credits').'</h3>'."\n".
1.213 raeburn 1544: &Apache::lonuserutils::section_picker($cdom,$cnum,'st',$rowtitle,
1.375 raeburn 1545: $permission,$context,'',$crstype,
1546: $showcredits,$credits);
1.213 raeburn 1547: my $output = $date_table.$secbox;
1548: return $output;
1549: }
1550:
1.216 raeburn 1551: sub validation_javascript {
1.375 raeburn 1552: my ($context,$ccdomain,$pjump_def,$crstype,$groupslist,$newuser,$formname,
1.216 raeburn 1553: $loaditem) = @_;
1554: my $dc_setcourse_code = '';
1555: my $nondc_setsection_code = '';
1556: if ($context eq 'domain') {
1557: my $dcdom = $env{'request.role.domain'};
1558: $loaditem->{'onload'} = "document.cu.coursedesc.value='';";
1.227 raeburn 1559: $dc_setcourse_code =
1560: &Apache::lonuserutils::dc_setcourse_js('cu','singleuser',$context);
1.216 raeburn 1561: } else {
1.227 raeburn 1562: my $checkauth;
1563: if (($newuser) || (&Apache::lonnet::allowed('mau',$ccdomain))) {
1564: $checkauth = 1;
1565: }
1566: if ($context eq 'course') {
1567: $nondc_setsection_code =
1568: &Apache::lonuserutils::setsections_javascript($formname,$groupslist,
1.375 raeburn 1569: undef,$checkauth,
1570: $crstype);
1.227 raeburn 1571: }
1572: if ($checkauth) {
1573: $nondc_setsection_code .=
1574: &Apache::lonuserutils::verify_authen($formname,$context);
1575: }
1.216 raeburn 1576: }
1577: my $js = &user_modification_js($pjump_def,$dc_setcourse_code,
1578: $nondc_setsection_code,$groupslist);
1579: my ($jsback,$elements) = &crumb_utilities();
1580: $js .= "\n".
1.301 bisitz 1581: '<script type="text/javascript">'."\n".
1582: '// <![CDATA['."\n".
1583: $jsback."\n".
1584: '// ]]>'."\n".
1585: '</script>'."\n";
1.216 raeburn 1586: return $js;
1587: }
1588:
1.217 raeburn 1589: sub display_existing_roles {
1.375 raeburn 1590: my ($r,$ccuname,$ccdomain,$inccourses,$context,$roledom,$crstype,
1591: $showcredits) = @_;
1.329 raeburn 1592: my $now=time;
1593: my %lt=&Apache::lonlocal::texthash(
1.217 raeburn 1594: 'rer' => "Existing Roles",
1595: 'rev' => "Revoke",
1596: 'del' => "Delete",
1597: 'ren' => "Re-Enable",
1598: 'rol' => "Role",
1599: 'ext' => "Extent",
1.375 raeburn 1600: 'crd' => "Credits",
1.217 raeburn 1601: 'sta' => "Start",
1602: 'end' => "End",
1603: );
1.329 raeburn 1604: my (%rolesdump,%roletext,%sortrole,%roleclass,%rolepriv);
1605: if ($context eq 'course' || $context eq 'author') {
1606: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
1607: my %roleshash =
1608: &Apache::lonnet::get_my_roles($ccuname,$ccdomain,'userroles',
1609: ['active','previous','future'],\@roles,$roledom,1);
1610: foreach my $key (keys(%roleshash)) {
1611: my ($start,$end) = split(':',$roleshash{$key});
1612: next if ($start eq '-1' || $end eq '-1');
1613: my ($rnum,$rdom,$role,$sec) = split(':',$key);
1614: if ($context eq 'course') {
1615: next unless (($rnum eq $env{'course.'.$env{'request.course.id'}.'.num'})
1616: && ($rdom eq $env{'course.'.$env{'request.course.id'}.'.domain'}));
1617: } elsif ($context eq 'author') {
1618: next unless (($rnum eq $env{'user.name'}) && ($rdom eq $env{'request.role.domain'}));
1619: }
1620: my ($newkey,$newvalue,$newrole);
1621: $newkey = '/'.$rdom.'/'.$rnum;
1622: if ($sec ne '') {
1623: $newkey .= '/'.$sec;
1624: }
1625: $newvalue = $role;
1626: if ($role =~ /^cr/) {
1627: $newrole = 'cr';
1628: } else {
1629: $newrole = $role;
1630: }
1631: $newkey .= '_'.$newrole;
1632: if ($start ne '' && $end ne '') {
1633: $newvalue .= '_'.$end.'_'.$start;
1.335 raeburn 1634: } elsif ($end ne '') {
1635: $newvalue .= '_'.$end;
1.329 raeburn 1636: }
1637: $rolesdump{$newkey} = $newvalue;
1638: }
1639: } else {
1.360 raeburn 1640: %rolesdump=&Apache::lonnet::dump('roles',$ccdomain,$ccuname);
1.329 raeburn 1641: }
1642: # Build up table of user roles to allow revocation and re-enabling of roles.
1643: my ($tmp) = keys(%rolesdump);
1644: return if ($tmp =~ /^(con_lost|error)/i);
1645: foreach my $area (sort { my $a1=join('_',(split('_',$a))[1,0]);
1646: my $b1=join('_',(split('_',$b))[1,0]);
1647: return $a1 cmp $b1;
1648: } keys(%rolesdump)) {
1649: next if ($area =~ /^rolesdef/);
1650: my $envkey=$area;
1651: my $role = $rolesdump{$area};
1652: my $thisrole=$area;
1653: $area =~ s/\_\w\w$//;
1654: my ($role_code,$role_end_time,$role_start_time) =
1655: split(/_/,$role);
1.217 raeburn 1656: # Is this a custom role? Get role owner and title.
1.329 raeburn 1657: my ($croleudom,$croleuname,$croletitle)=
1658: ($role_code=~m{^cr/($match_domain)/($match_username)/(\w+)$});
1659: my $allowed=0;
1660: my $delallowed=0;
1661: my $sortkey=$role_code;
1662: my $class='Unknown';
1.375 raeburn 1663: my $credits='';
1.329 raeburn 1664: if ($area =~ m{^/($match_domain)/($match_courseid)} ) {
1665: $class='Course';
1666: my ($coursedom,$coursedir) = ($1,$2);
1667: my $cid = $1.'_'.$2;
1668: # $1.'_'.$2 is the course id (eg. 103_12345abcef103l3).
1669: my %coursedata=
1670: &Apache::lonnet::coursedescription($cid);
1671: if ($coursedir =~ /^$match_community$/) {
1672: $class='Community';
1673: }
1674: $sortkey.="\0$coursedom";
1675: my $carea;
1676: if (defined($coursedata{'description'})) {
1677: $carea=$coursedata{'description'}.
1678: '<br />'.&mt('Domain').': '.$coursedom.(' 'x8).
1679: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$coursedir,$coursedom);
1680: $sortkey.="\0".$coursedata{'description'};
1681: } else {
1682: if ($class eq 'Community') {
1683: $carea=&mt('Unavailable community').': '.$area;
1684: $sortkey.="\0".&mt('Unavailable community').': '.$area;
1.217 raeburn 1685: } else {
1686: $carea=&mt('Unavailable course').': '.$area;
1687: $sortkey.="\0".&mt('Unavailable course').': '.$area;
1688: }
1.329 raeburn 1689: }
1690: $sortkey.="\0$coursedir";
1691: $inccourses->{$cid}=1;
1.375 raeburn 1692: if (($showcredits) && ($class eq 'Course') && ($role_code eq 'st')) {
1693: my $defaultcredits = $coursedata{'internal.defaultcredits'};
1694: $credits =
1695: &get_user_credits($ccuname,$ccdomain,$defaultcredits,
1696: $coursedom,$coursedir);
1697: if ($credits eq '') {
1698: $credits = $defaultcredits;
1699: }
1700: }
1.329 raeburn 1701: if ((&Apache::lonnet::allowed('c'.$role_code,$coursedom.'/'.$coursedir)) ||
1702: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
1703: $allowed=1;
1704: }
1705: unless ($allowed) {
1.365 raeburn 1706: my $isowner = &Apache::lonuserutils::is_courseowner($cid,$coursedata{'internal.courseowner'});
1.329 raeburn 1707: if ($isowner) {
1708: if (($role_code eq 'co') && ($class eq 'Community')) {
1709: $allowed = 1;
1710: } elsif (($role_code eq 'cc') && ($class eq 'Course')) {
1711: $allowed = 1;
1712: }
1.217 raeburn 1713: }
1.329 raeburn 1714: }
1715: if ((&Apache::lonnet::allowed('dro',$coursedom)) ||
1716: (&Apache::lonnet::allowed('dro',$ccdomain))) {
1717: $delallowed=1;
1718: }
1.217 raeburn 1719: # - custom role. Needs more info, too
1.329 raeburn 1720: if ($croletitle) {
1721: if (&Apache::lonnet::allowed('ccr',$coursedom.'/'.$coursedir)) {
1722: $allowed=1;
1723: $thisrole.='.'.$role_code;
1.217 raeburn 1724: }
1.329 raeburn 1725: }
1726: if ($area=~m{^/($match_domain)/($match_courseid)/(\w+)}) {
1.373 bisitz 1727: $carea.='<br />'.&mt('Section: [_1]',$3);
1.329 raeburn 1728: $sortkey.="\0$3";
1729: if (!$allowed) {
1730: if ($env{'request.course.sec'} eq $3) {
1731: if (&Apache::lonnet::allowed('c'.$role_code,$1.'/'.$2.'/'.$3)) {
1732: $allowed = 1;
1.217 raeburn 1733: }
1734: }
1735: }
1.329 raeburn 1736: }
1737: $area=$carea;
1738: } else {
1739: $sortkey.="\0".$area;
1740: # Determine if current user is able to revoke privileges
1741: if ($area=~m{^/($match_domain)/}) {
1742: if ((&Apache::lonnet::allowed('c'.$role_code,$1)) ||
1743: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
1744: $allowed=1;
1.217 raeburn 1745: }
1.329 raeburn 1746: if (((&Apache::lonnet::allowed('dro',$1)) ||
1747: (&Apache::lonnet::allowed('dro',$ccdomain))) &&
1748: ($role_code ne 'dc')) {
1749: $delallowed=1;
1.217 raeburn 1750: }
1.329 raeburn 1751: } else {
1752: if (&Apache::lonnet::allowed('c'.$role_code,'/')) {
1.217 raeburn 1753: $allowed=1;
1754: }
1755: }
1.363 raeburn 1756: if ($role_code eq 'ca' || $role_code eq 'au' || $role_code eq 'aa') {
1.377 raeburn 1757: $class='Authoring Space';
1.329 raeburn 1758: } elsif ($role_code eq 'su') {
1759: $class='System';
1.217 raeburn 1760: } else {
1.329 raeburn 1761: $class='Domain';
1.217 raeburn 1762: }
1.329 raeburn 1763: }
1764: if (($role_code eq 'ca') || ($role_code eq 'aa')) {
1765: $area=~m{/($match_domain)/($match_username)};
1766: if (&Apache::lonuserutils::authorpriv($2,$1)) {
1767: $allowed=1;
1.217 raeburn 1768: } else {
1.329 raeburn 1769: $allowed=0;
1.217 raeburn 1770: }
1.329 raeburn 1771: }
1772: my $row = '';
1773: $row.= '<td>';
1774: my $active=1;
1775: $active=0 if (($role_end_time) && ($now>$role_end_time));
1776: if (($active) && ($allowed)) {
1777: $row.= '<input type="checkbox" name="rev:'.$thisrole.'" />';
1778: } else {
1779: if ($active) {
1780: $row.=' ';
1.217 raeburn 1781: } else {
1.329 raeburn 1782: $row.=&mt('expired or revoked');
1.217 raeburn 1783: }
1.329 raeburn 1784: }
1785: $row.='</td><td>';
1786: if ($allowed && !$active) {
1787: $row.= '<input type="checkbox" name="ren:'.$thisrole.'" />';
1788: } else {
1789: $row.=' ';
1790: }
1791: $row.='</td><td>';
1792: if ($delallowed) {
1793: $row.= '<input type="checkbox" name="del:'.$thisrole.'" />';
1794: } else {
1795: $row.=' ';
1796: }
1797: my $plaintext='';
1798: if (!$croletitle) {
1.375 raeburn 1799: $plaintext=&Apache::lonnet::plaintext($role_code,$class);
1800: if (($showcredits) && ($credits ne '')) {
1801: $plaintext .= '<br/ ><span class="LC_nobreak">'.
1802: '<span class="LC_fontsize_small">'.
1803: &mt('Credits: [_1]',$credits).
1804: '</span></span>';
1805: }
1.329 raeburn 1806: } else {
1807: $plaintext=
1.346 bisitz 1808: &mt('Customrole [_1][_2]defined by [_3]',
1809: '"'.$croletitle.'"',
1810: '<br />',
1811: $croleuname.':'.$croleudom);
1.329 raeburn 1812: }
1813: $row.= '</td><td>'.$plaintext.
1814: '</td><td>'.$area.
1815: '</td><td>'.($role_start_time?&Apache::lonlocal::locallocaltime($role_start_time)
1816: : ' ' ).
1817: '</td><td>'.($role_end_time ?&Apache::lonlocal::locallocaltime($role_end_time)
1818: : ' ' )
1819: ."</td>";
1820: $sortrole{$sortkey}=$envkey;
1821: $roletext{$envkey}=$row;
1822: $roleclass{$envkey}=$class;
1823: $rolepriv{$envkey}=$allowed;
1824: } # end of foreach (table building loop)
1825:
1826: my $rolesdisplay = 0;
1827: my %output = ();
1.377 raeburn 1828: foreach my $type ('Authoring Space','Course','Community','Domain','System','Unknown') {
1.329 raeburn 1829: $output{$type} = '';
1830: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
1831: if ( ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/ ) && ($rolepriv{$sortrole{$which}}) ) {
1832: $output{$type}.=
1833: &Apache::loncommon::start_data_table_row().
1834: $roletext{$sortrole{$which}}.
1835: &Apache::loncommon::end_data_table_row();
1.217 raeburn 1836: }
1.329 raeburn 1837: }
1838: unless($output{$type} eq '') {
1839: $output{$type} = '<tr class="LC_info_row">'.
1840: "<td align='center' colspan='7'>".&mt($type)."</td></tr>".
1841: $output{$type};
1842: $rolesdisplay = 1;
1843: }
1844: }
1845: if ($rolesdisplay == 1) {
1846: my $contextrole='';
1847: if ($env{'request.course.id'}) {
1848: if (&Apache::loncommon::course_type() eq 'Community') {
1849: $contextrole = &mt('Existing Roles in this Community');
1.290 bisitz 1850: } else {
1.329 raeburn 1851: $contextrole = &mt('Existing Roles in this Course');
1.290 bisitz 1852: }
1.329 raeburn 1853: } elsif ($env{'request.role'} =~ /^au\./) {
1.377 raeburn 1854: $contextrole = &mt('Existing Co-Author Roles in your Authoring Space');
1.329 raeburn 1855: } else {
1856: $contextrole = &mt('Existing Roles in this Domain');
1857: }
1.375 raeburn 1858: $r->print('<div>'.
1859: '<fieldset><legend>'.$contextrole.'</legend>'.
1.217 raeburn 1860: &Apache::loncommon::start_data_table("LC_createuser").
1861: &Apache::loncommon::start_data_table_header_row().
1862: '<th>'.$lt{'rev'}.'</th><th>'.$lt{'ren'}.'</th><th>'.$lt{'del'}.
1863: '</th><th>'.$lt{'rol'}.'</th><th>'.$lt{'ext'}.
1864: '</th><th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
1865: &Apache::loncommon::end_data_table_header_row());
1.377 raeburn 1866: foreach my $type ('Authoring Space','Course','Community','Domain','System','Unknown') {
1.329 raeburn 1867: if ($output{$type}) {
1868: $r->print($output{$type}."\n");
1.217 raeburn 1869: }
1870: }
1.375 raeburn 1871: $r->print(&Apache::loncommon::end_data_table().
1872: '</fieldset></div>');
1.329 raeburn 1873: }
1.217 raeburn 1874: return;
1875: }
1876:
1.218 raeburn 1877: sub new_coauthor_roles {
1878: my ($r,$ccuname,$ccdomain) = @_;
1879: my $addrolesdisplay = 0;
1880: #
1881: # Co-Author
1882: #
1883: if (&Apache::lonuserutils::authorpriv($env{'user.name'},
1884: $env{'request.role.domain'}) &&
1885: ($env{'user.name'} ne $ccuname || $env{'user.domain'} ne $ccdomain)) {
1886: # No sense in assigning co-author role to yourself
1887: $addrolesdisplay = 1;
1888: my $cuname=$env{'user.name'};
1889: my $cudom=$env{'request.role.domain'};
1890: my %lt=&Apache::lonlocal::texthash(
1.377 raeburn 1891: 'cs' => "Authoring Space",
1.218 raeburn 1892: 'act' => "Activate",
1893: 'rol' => "Role",
1894: 'ext' => "Extent",
1895: 'sta' => "Start",
1896: 'end' => "End",
1897: 'cau' => "Co-Author",
1898: 'caa' => "Assistant Co-Author",
1899: 'ssd' => "Set Start Date",
1900: 'sed' => "Set End Date"
1901: );
1902: $r->print('<h4>'.$lt{'cs'}.'</h4>'."\n".
1903: &Apache::loncommon::start_data_table()."\n".
1904: &Apache::loncommon::start_data_table_header_row()."\n".
1905: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'.
1906: '<th>'.$lt{'ext'}.'</th><th>'.$lt{'sta'}.'</th>'.
1907: '<th>'.$lt{'end'}.'</th>'."\n".
1908: &Apache::loncommon::end_data_table_header_row()."\n".
1909: &Apache::loncommon::start_data_table_row().'
1910: <td>
1.291 bisitz 1911: <input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_ca" />
1.218 raeburn 1912: </td>
1913: <td>'.$lt{'cau'}.'</td>
1914: <td>'.$cudom.'_'.$cuname.'</td>
1915: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_ca" value="" />
1916: <a href=
1917: "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>
1918: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_ca" value="" />
1919: <a href=
1920: "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".
1921: &Apache::loncommon::end_data_table_row()."\n".
1922: &Apache::loncommon::start_data_table_row()."\n".
1.291 bisitz 1923: '<td><input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_aa" /></td>
1.218 raeburn 1924: <td>'.$lt{'caa'}.'</td>
1925: <td>'.$cudom.'_'.$cuname.'</td>
1926: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_aa" value="" />
1927: <a href=
1928: "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>
1929: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_aa" value="" />
1930: <a href=
1931: "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".
1932: &Apache::loncommon::end_data_table_row()."\n".
1933: &Apache::loncommon::end_data_table());
1934: } elsif ($env{'request.role'} =~ /^au\./) {
1935: if (!(&Apache::lonuserutils::authorpriv($env{'user.name'},
1936: $env{'request.role.domain'}))) {
1937: $r->print('<span class="LC_error">'.
1938: &mt('You do not have privileges to assign co-author roles.').
1939: '</span>');
1940: } elsif (($env{'user.name'} eq $ccuname) &&
1941: ($env{'user.domain'} eq $ccdomain)) {
1.377 raeburn 1942: $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 1943: }
1944: }
1945: return $addrolesdisplay;;
1946: }
1947:
1948: sub new_domain_roles {
1.357 raeburn 1949: my ($r,$ccdomain) = @_;
1.218 raeburn 1950: my $addrolesdisplay = 0;
1951: #
1952: # Domain level
1953: #
1954: my $num_domain_level = 0;
1955: my $domaintext =
1956: '<h4>'.&mt('Domain Level').'</h4>'.
1957: &Apache::loncommon::start_data_table().
1958: &Apache::loncommon::start_data_table_header_row().
1959: '<th>'.&mt('Activate').'</th><th>'.&mt('Role').'</th><th>'.
1960: &mt('Extent').'</th>'.
1961: '<th>'.&mt('Start').'</th><th>'.&mt('End').'</th>'.
1962: &Apache::loncommon::end_data_table_header_row();
1.312 raeburn 1963: my @allroles = &Apache::lonuserutils::roles_by_context('domain');
1.218 raeburn 1964: foreach my $thisdomain (sort(&Apache::lonnet::all_domains())) {
1.312 raeburn 1965: foreach my $role (@allroles) {
1966: next if ($role eq 'ad');
1.357 raeburn 1967: next if (($role eq 'au') && ($ccdomain ne $thisdomain));
1.218 raeburn 1968: if (&Apache::lonnet::allowed('c'.$role,$thisdomain)) {
1969: my $plrole=&Apache::lonnet::plaintext($role);
1970: my %lt=&Apache::lonlocal::texthash(
1971: 'ssd' => "Set Start Date",
1972: 'sed' => "Set End Date"
1973: );
1974: $num_domain_level ++;
1975: $domaintext .=
1976: &Apache::loncommon::start_data_table_row().
1.291 bisitz 1977: '<td><input type="checkbox" name="act_'.$thisdomain.'_'.$role.'" /></td>
1.218 raeburn 1978: <td>'.$plrole.'</td>
1979: <td>'.$thisdomain.'</td>
1980: <td><input type="hidden" name="start_'.$thisdomain.'_'.$role.'" value="" />
1981: <a href=
1982: "javascript:pjump('."'date_start','Start Date $plrole',document.cu.start_$thisdomain\_$role.value,'start_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'ssd'}.'</a></td>
1983: <td><input type="hidden" name="end_'.$thisdomain.'_'.$role.'" value="" />
1984: <a href=
1985: "javascript:pjump('."'date_end','End Date $plrole',document.cu.end_$thisdomain\_$role.value,'end_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'sed'}.'</a></td>'.
1986: &Apache::loncommon::end_data_table_row();
1987: }
1988: }
1989: }
1990: $domaintext.= &Apache::loncommon::end_data_table();
1991: if ($num_domain_level > 0) {
1992: $r->print($domaintext);
1993: $addrolesdisplay = 1;
1994: }
1995: return $addrolesdisplay;
1996: }
1997:
1.188 raeburn 1998: sub user_authentication {
1.227 raeburn 1999: my ($ccuname,$ccdomain,$formname) = @_;
1.188 raeburn 2000: my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
1.227 raeburn 2001: my $outcome;
1.188 raeburn 2002: # Check for a bad authentication type
2003: if ($currentauth !~ /^(krb4|krb5|unix|internal|localauth):/) {
2004: # bad authentication scheme
2005: my %lt=&Apache::lonlocal::texthash(
2006: 'err' => "ERROR",
2007: 'uuas' => "This user has an unrecognized authentication scheme",
2008: 'adcs' => "Please alert a domain coordinator of this situation",
2009: 'sldb' => "Please specify login data below",
2010: 'ld' => "Login Data"
2011: );
2012: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
1.227 raeburn 2013: &initialize_authen_forms($ccdomain,$formname);
2014:
1.190 raeburn 2015: my $choices = &Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc);
1.188 raeburn 2016: $outcome = <<ENDBADAUTH;
2017: <script type="text/javascript" language="Javascript">
1.301 bisitz 2018: // <![CDATA[
1.188 raeburn 2019: $loginscript
1.301 bisitz 2020: // ]]>
1.188 raeburn 2021: </script>
2022: <span class="LC_error">$lt{'err'}:
2023: $lt{'uuas'} ($currentauth). $lt{'sldb'}.</span>
2024: <h3>$lt{'ld'}</h3>
2025: $choices
2026: ENDBADAUTH
2027: } else {
2028: # This user is not allowed to modify the user's
2029: # authentication scheme, so just notify them of the problem
2030: $outcome = <<ENDBADAUTH;
2031: <span class="LC_error"> $lt{'err'}:
2032: $lt{'uuas'} ($currentauth). $lt{'adcs'}.
2033: </span>
2034: ENDBADAUTH
2035: }
2036: } else { # Authentication type is valid
1.227 raeburn 2037: &initialize_authen_forms($ccdomain,$formname,$currentauth,'modifyuser');
1.205 raeburn 2038: my ($authformcurrent,$can_modify,@authform_others) =
1.188 raeburn 2039: &modify_login_block($ccdomain,$currentauth);
2040: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
2041: # Current user has login modification privileges
2042: my %lt=&Apache::lonlocal::texthash (
2043: 'ld' => "Login Data",
2044: 'ccld' => "Change Current Login Data",
2045: 'enld' => "Enter New Login Data"
2046: );
2047: $outcome =
2048: '<script type="text/javascript" language="Javascript">'."\n".
1.301 bisitz 2049: '// <![CDATA['."\n".
1.188 raeburn 2050: $loginscript."\n".
1.301 bisitz 2051: '// ]]>'."\n".
1.188 raeburn 2052: '</script>'."\n".
2053: '<h3>'.$lt{'ld'}.'</h3>'.
2054: &Apache::loncommon::start_data_table().
1.205 raeburn 2055: &Apache::loncommon::start_data_table_row().
1.188 raeburn 2056: '<td>'.$authformnop;
2057: if ($can_modify) {
2058: $outcome .= '</td>'."\n".
2059: &Apache::loncommon::end_data_table_row().
2060: &Apache::loncommon::start_data_table_row().
2061: '<td>'.$authformcurrent.'</td>'.
2062: &Apache::loncommon::end_data_table_row()."\n";
2063: } else {
1.200 raeburn 2064: $outcome .= ' ('.$authformcurrent.')</td>'.
2065: &Apache::loncommon::end_data_table_row()."\n";
1.188 raeburn 2066: }
1.205 raeburn 2067: foreach my $item (@authform_others) {
2068: $outcome .= &Apache::loncommon::start_data_table_row().
2069: '<td>'.$item.'</td>'.
2070: &Apache::loncommon::end_data_table_row()."\n";
1.188 raeburn 2071: }
1.205 raeburn 2072: $outcome .= &Apache::loncommon::end_data_table();
1.188 raeburn 2073: } else {
2074: if (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
2075: my %lt=&Apache::lonlocal::texthash(
2076: 'ccld' => "Change Current Login Data",
2077: 'yodo' => "You do not have privileges to modify the authentication configuration for this user.",
2078: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
2079: );
2080: $outcome .= <<ENDNOPRIV;
2081: <h3>$lt{'ccld'}</h3>
2082: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1.235 raeburn 2083: <input type="hidden" name="login" value="nochange" />
1.188 raeburn 2084: ENDNOPRIV
2085: }
2086: }
2087: } ## End of "check for bad authentication type" logic
2088: return $outcome;
2089: }
2090:
1.187 raeburn 2091: sub modify_login_block {
2092: my ($dom,$currentauth) = @_;
2093: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2094: my ($authnum,%can_assign) =
2095: &Apache::loncommon::get_assignable_auth($dom);
1.205 raeburn 2096: my ($authformcurrent,@authform_others,$show_override_msg);
1.187 raeburn 2097: if ($currentauth=~/^krb(4|5):/) {
2098: $authformcurrent=$authformkrb;
2099: if ($can_assign{'int'}) {
1.205 raeburn 2100: push(@authform_others,$authformint);
1.187 raeburn 2101: }
2102: if ($can_assign{'loc'}) {
1.205 raeburn 2103: push(@authform_others,$authformloc);
1.187 raeburn 2104: }
2105: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
2106: $show_override_msg = 1;
2107: }
2108: } elsif ($currentauth=~/^internal:/) {
2109: $authformcurrent=$authformint;
2110: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2111: push(@authform_others,$authformkrb);
1.187 raeburn 2112: }
2113: if ($can_assign{'loc'}) {
1.205 raeburn 2114: push(@authform_others,$authformloc);
1.187 raeburn 2115: }
2116: if ($can_assign{'int'}) {
2117: $show_override_msg = 1;
2118: }
2119: } elsif ($currentauth=~/^unix:/) {
2120: $authformcurrent=$authformfsys;
2121: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2122: push(@authform_others,$authformkrb);
1.187 raeburn 2123: }
2124: if ($can_assign{'int'}) {
1.205 raeburn 2125: push(@authform_others,$authformint);
1.187 raeburn 2126: }
2127: if ($can_assign{'loc'}) {
1.205 raeburn 2128: push(@authform_others,$authformloc);
1.187 raeburn 2129: }
2130: if ($can_assign{'fsys'}) {
2131: $show_override_msg = 1;
2132: }
2133: } elsif ($currentauth=~/^localauth:/) {
2134: $authformcurrent=$authformloc;
2135: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2136: push(@authform_others,$authformkrb);
1.187 raeburn 2137: }
2138: if ($can_assign{'int'}) {
1.205 raeburn 2139: push(@authform_others,$authformint);
1.187 raeburn 2140: }
2141: if ($can_assign{'loc'}) {
2142: $show_override_msg = 1;
2143: }
2144: }
2145: if ($show_override_msg) {
1.205 raeburn 2146: $authformcurrent = '<table><tr><td colspan="3">'.$authformcurrent.
2147: '</td></tr>'."\n".
2148: '<tr><td> </td>'.
2149: '<td><b>'.&mt('Currently in use').'</b></td>'.
2150: '<td align="right"><span class="LC_cusr_emph">'.
1.187 raeburn 2151: &mt('will override current values').
1.205 raeburn 2152: '</span></td></tr></table>';
1.187 raeburn 2153: }
1.205 raeburn 2154: return ($authformcurrent,$show_override_msg,@authform_others);
1.187 raeburn 2155: }
2156:
1.188 raeburn 2157: sub personal_data_display {
1.252 raeburn 2158: my ($ccuname,$ccdomain,$newuser,$context,$inst_results,$rolesarray) = @_;
1.286 raeburn 2159: my ($output,$showforceid,%userenv,%canmodify,%canmodify_status);
1.219 raeburn 2160: my @userinfo = ('firstname','middlename','lastname','generation',
2161: 'permanentemail','id');
1.252 raeburn 2162: my $rowcount = 0;
2163: my $editable = 0;
1.286 raeburn 2164: %canmodify_status =
2165: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
2166: ['inststatus'],$rolesarray);
1.253 raeburn 2167: if (!$newuser) {
1.188 raeburn 2168: # Get the users information
2169: %userenv = &Apache::lonnet::get('environment',
2170: ['firstname','middlename','lastname','generation',
1.286 raeburn 2171: 'permanentemail','id','inststatus'],$ccdomain,$ccuname);
1.219 raeburn 2172: %canmodify =
2173: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
1.252 raeburn 2174: \@userinfo,$rolesarray);
1.257 raeburn 2175: } elsif ($context eq 'selfcreate') {
2176: %canmodify = &selfcreate_canmodify($context,$ccdomain,\@userinfo,
2177: $inst_results,$rolesarray);
1.188 raeburn 2178: }
2179: my %lt=&Apache::lonlocal::texthash(
2180: 'pd' => "Personal Data",
2181: 'firstname' => "First Name",
2182: 'middlename' => "Middle Name",
2183: 'lastname' => "Last Name",
2184: 'generation' => "Generation",
2185: 'permanentemail' => "Permanent e-mail address",
1.259 bisitz 2186: 'id' => "Student/Employee ID",
1.286 raeburn 2187: 'lg' => "Login Data",
2188: 'inststatus' => "Affiliation",
1.188 raeburn 2189: );
2190: my %textboxsize = (
2191: firstname => '15',
2192: middlename => '15',
2193: lastname => '15',
2194: generation => '5',
2195: permanentemail => '25',
2196: id => '15',
2197: );
2198: my $genhelp=&Apache::loncommon::help_open_topic('Generation');
2199: $output = '<h3>'.$lt{'pd'}.'</h3>'.
2200: &Apache::lonhtmlcommon::start_pick_box();
2201: foreach my $item (@userinfo) {
2202: my $rowtitle = $lt{$item};
1.252 raeburn 2203: my $hiderow = 0;
1.188 raeburn 2204: if ($item eq 'generation') {
2205: $rowtitle = $genhelp.$rowtitle;
2206: }
1.252 raeburn 2207: my $row = &Apache::lonhtmlcommon::row_title($rowtitle,undef,'LC_oddrow_value')."\n";
1.188 raeburn 2208: if ($newuser) {
1.210 raeburn 2209: if (ref($inst_results) eq 'HASH') {
2210: if ($inst_results->{$item} ne '') {
1.252 raeburn 2211: $row .= '<input type="hidden" name="c'.$item.'" value="'.$inst_results->{$item}.'" />'.$inst_results->{$item};
1.210 raeburn 2212: } else {
1.252 raeburn 2213: if ($context eq 'selfcreate') {
2214: if ($canmodify{$item}) {
2215: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
2216: $editable ++;
2217: } else {
2218: $hiderow = 1;
2219: }
1.253 raeburn 2220: } else {
2221: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1.252 raeburn 2222: }
1.210 raeburn 2223: }
1.188 raeburn 2224: } else {
1.252 raeburn 2225: if ($context eq 'selfcreate') {
1.287 raeburn 2226: if (($item eq 'permanentemail') && ($newuser eq 'email')) {
2227: $row .= $ccuname;
1.252 raeburn 2228: } else {
1.287 raeburn 2229: if ($canmodify{$item}) {
2230: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
2231: $editable ++;
2232: } else {
2233: $hiderow = 1;
2234: }
1.252 raeburn 2235: }
1.253 raeburn 2236: } else {
2237: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1.252 raeburn 2238: }
1.188 raeburn 2239: }
2240: } else {
1.219 raeburn 2241: if ($canmodify{$item}) {
1.252 raeburn 2242: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="'.$userenv{$item}.'" />';
1.188 raeburn 2243: } else {
1.252 raeburn 2244: $row .= $userenv{$item};
1.188 raeburn 2245: }
1.206 raeburn 2246: if ($item eq 'id') {
1.219 raeburn 2247: $showforceid = $canmodify{$item};
2248: }
1.188 raeburn 2249: }
1.252 raeburn 2250: $row .= &Apache::lonhtmlcommon::row_closure(1);
2251: if (!$hiderow) {
2252: $output .= $row;
2253: $rowcount ++;
2254: }
1.188 raeburn 2255: }
1.286 raeburn 2256: if (($canmodify_status{'inststatus'}) || ($context ne 'selfcreate')) {
2257: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($ccdomain);
2258: if (ref($types) eq 'ARRAY') {
2259: if (@{$types} > 0) {
2260: my ($hiderow,$shown);
2261: if ($canmodify_status{'inststatus'}) {
2262: $shown = &pick_inst_statuses($userenv{'inststatus'},$usertypes,$types);
2263: } else {
2264: if ($userenv{'inststatus'} eq '') {
2265: $hiderow = 1;
1.334 raeburn 2266: } else {
2267: my @showitems;
2268: foreach my $item ( map { &unescape($_); } split(':',$userenv{'inststatus'})) {
2269: if (exists($usertypes->{$item})) {
2270: push(@showitems,$usertypes->{$item});
2271: } else {
2272: push(@showitems,$item);
2273: }
2274: }
2275: if (@showitems) {
2276: $shown = join(', ',@showitems);
2277: } else {
2278: $hiderow = 1;
2279: }
1.286 raeburn 2280: }
2281: }
2282: if (!$hiderow) {
2283: my $row = &Apache::lonhtmlcommon::row_title(&mt('Affliations'),undef,'LC_oddrow_value')."\n".
2284: $shown.&Apache::lonhtmlcommon::row_closure(1);
2285: if ($context eq 'selfcreate') {
2286: $rowcount ++;
2287: }
2288: $output .= $row;
2289: }
2290: }
2291: }
2292: }
1.188 raeburn 2293: $output .= &Apache::lonhtmlcommon::end_pick_box();
1.206 raeburn 2294: if (wantarray) {
1.252 raeburn 2295: if ($context eq 'selfcreate') {
2296: return($output,$rowcount,$editable);
2297: } else {
2298: return ($output,$showforceid);
2299: }
1.206 raeburn 2300: } else {
2301: return $output;
2302: }
1.188 raeburn 2303: }
2304:
1.286 raeburn 2305: sub pick_inst_statuses {
2306: my ($curr,$usertypes,$types) = @_;
2307: my ($output,$rem,@currtypes);
2308: if ($curr ne '') {
2309: @currtypes = map { &unescape($_); } split(/:/,$curr);
2310: }
2311: my $numinrow = 2;
2312: if (ref($types) eq 'ARRAY') {
2313: $output = '<table>';
2314: my $lastcolspan;
2315: for (my $i=0; $i<@{$types}; $i++) {
2316: if (defined($usertypes->{$types->[$i]})) {
2317: my $rem = $i%($numinrow);
2318: if ($rem == 0) {
2319: if ($i<@{$types}-1) {
2320: if ($i > 0) {
2321: $output .= '</tr>';
2322: }
2323: $output .= '<tr>';
2324: }
2325: } elsif ($i==@{$types}-1) {
2326: my $colsleft = $numinrow - $rem;
2327: if ($colsleft > 1) {
2328: $lastcolspan = ' colspan="'.$colsleft.'"';
2329: }
2330: }
2331: my $check = ' ';
2332: if (grep(/^\Q$types->[$i]\E$/,@currtypes)) {
2333: $check = ' checked="checked" ';
2334: }
2335: $output .= '<td class="LC_left_item"'.$lastcolspan.'>'.
2336: '<span class="LC_nobreak"><label>'.
2337: '<input type="checkbox" name="inststatus" '.
2338: 'value="'.$types->[$i].'"'.$check.'/>'.
2339: $usertypes->{$types->[$i]}.'</label></span></td>';
2340: }
2341: }
2342: $output .= '</tr></table>';
2343: }
2344: return $output;
2345: }
2346:
1.257 raeburn 2347: sub selfcreate_canmodify {
2348: my ($context,$dom,$userinfo,$inst_results,$rolesarray) = @_;
2349: if (ref($inst_results) eq 'HASH') {
2350: my @inststatuses = &get_inststatuses($inst_results);
2351: if (@inststatuses == 0) {
2352: @inststatuses = ('default');
2353: }
2354: $rolesarray = \@inststatuses;
2355: }
2356: my %canmodify =
2357: &Apache::lonuserutils::can_modify_userinfo($context,$dom,$userinfo,
2358: $rolesarray);
2359: return %canmodify;
2360: }
2361:
1.252 raeburn 2362: sub get_inststatuses {
2363: my ($insthashref) = @_;
2364: my @inststatuses = ();
2365: if (ref($insthashref) eq 'HASH') {
2366: if (ref($insthashref->{'inststatus'}) eq 'ARRAY') {
2367: @inststatuses = @{$insthashref->{'inststatus'}};
2368: }
2369: }
2370: return @inststatuses;
2371: }
2372:
1.4 www 2373: # ================================================================= Phase Three
1.42 matthew 2374: sub update_user_data {
1.375 raeburn 2375: my ($r,$context,$crstype,$brcrum,$showcredits) = @_;
1.101 albertel 2376: my $uhome=&Apache::lonnet::homeserver($env{'form.ccuname'},
2377: $env{'form.ccdomain'});
1.27 matthew 2378: # Error messages
1.188 raeburn 2379: my $error = '<span class="LC_error">'.&mt('Error').': ';
1.193 raeburn 2380: my $end = '</span><br /><br />';
2381: my $rtnlink = '<a href="javascript:backPage(document.userupdate,'.
1.188 raeburn 2382: "'$env{'form.prevphase'}','modify')".'" />'.
1.219 raeburn 2383: &mt('Return to previous page').'</a>'.
2384: &Apache::loncommon::end_page();
2385: my $now = time;
1.40 www 2386: my $title;
1.101 albertel 2387: if (exists($env{'form.makeuser'})) {
1.40 www 2388: $title='Set Privileges for New User';
2389: } else {
2390: $title='Modify User Privileges';
2391: }
1.213 raeburn 2392: my $newuser = 0;
1.160 raeburn 2393: my ($jsback,$elements) = &crumb_utilities();
2394: my $jscript = '<script type="text/javascript">'."\n".
1.301 bisitz 2395: '// <![CDATA['."\n".
2396: $jsback."\n".
2397: '// ]]>'."\n".
2398: '</script>'."\n";
1.318 raeburn 2399: my %breadcrumb_text = &singleuser_breadcrumb($crstype);
1.351 raeburn 2400: push (@{$brcrum},
2401: {href => "javascript:backPage(document.userupdate)",
2402: text => $breadcrumb_text{'search'},
2403: faq => 282,
2404: bug => 'Instructor Interface',}
2405: );
2406: if ($env{'form.prevphase'} eq 'userpicked') {
2407: push(@{$brcrum},
2408: {href => "javascript:backPage(document.userupdate,'get_user_info','select')",
2409: text => $breadcrumb_text{'userpicked'},
2410: faq => 282,
2411: bug => 'Instructor Interface',});
1.233 raeburn 2412: }
1.224 raeburn 2413: my $helpitem = 'Course_Change_Privileges';
2414: if ($env{'form.action'} eq 'singlestudent') {
2415: $helpitem = 'Course_Add_Student';
2416: }
1.351 raeburn 2417: push(@{$brcrum},
2418: {href => "javascript:backPage(document.userupdate,'$env{'form.prevphase'}','modify')",
2419: text => $breadcrumb_text{'modify'},
2420: faq => 282,
2421: bug => 'Instructor Interface',},
2422: {href => "/adm/createuser",
2423: text => "Result",
2424: faq => 282,
2425: bug => 'Instructor Interface',
2426: help => $helpitem});
2427: my $args = {bread_crumbs => $brcrum,
2428: bread_crumbs_component => 'User Management'};
2429: if ($env{'form.popup'}) {
2430: $args->{'no_nav_bar'} = 1;
2431: }
2432: $r->print(&Apache::loncommon::start_page($title,$jscript,$args));
1.188 raeburn 2433: $r->print(&update_result_form($uhome));
1.27 matthew 2434: # Check Inputs
1.101 albertel 2435: if (! $env{'form.ccuname'} ) {
1.193 raeburn 2436: $r->print($error.&mt('No login name specified').'.'.$end.$rtnlink);
1.27 matthew 2437: return;
2438: }
1.138 albertel 2439: if ( $env{'form.ccuname'} ne
2440: &LONCAPA::clean_username($env{'form.ccuname'}) ) {
1.281 bisitz 2441: $r->print($error.&mt('Invalid login name.').' '.
2442: &mt('Only letters, numbers, periods, dashes, @, and underscores are valid.').
1.193 raeburn 2443: $end.$rtnlink);
1.27 matthew 2444: return;
2445: }
1.101 albertel 2446: if (! $env{'form.ccdomain'} ) {
1.193 raeburn 2447: $r->print($error.&mt('No domain specified').'.'.$end.$rtnlink);
1.27 matthew 2448: return;
2449: }
1.138 albertel 2450: if ( $env{'form.ccdomain'} ne
2451: &LONCAPA::clean_domain($env{'form.ccdomain'}) ) {
1.281 bisitz 2452: $r->print($error.&mt('Invalid domain name.').' '.
2453: &mt('Only letters, numbers, periods, dashes, and underscores are valid.').
1.193 raeburn 2454: $end.$rtnlink);
1.27 matthew 2455: return;
2456: }
1.219 raeburn 2457: if ($uhome eq 'no_host') {
2458: $newuser = 1;
2459: }
1.101 albertel 2460: if (! exists($env{'form.makeuser'})) {
1.29 matthew 2461: # Modifying an existing user, so check the validity of the name
2462: if ($uhome eq 'no_host') {
1.73 sakharuk 2463: $r->print($error.&mt('Unable to determine home server for ').
1.101 albertel 2464: $env{'form.ccuname'}.&mt(' in domain ').
2465: $env{'form.ccdomain'}.'.');
1.29 matthew 2466: return;
2467: }
2468: }
1.27 matthew 2469: # Determine authentication method and password for the user being modified
2470: my $amode='';
2471: my $genpwd='';
1.101 albertel 2472: if ($env{'form.login'} eq 'krb') {
1.41 albertel 2473: $amode='krb';
1.101 albertel 2474: $amode.=$env{'form.krbver'};
2475: $genpwd=$env{'form.krbarg'};
2476: } elsif ($env{'form.login'} eq 'int') {
1.27 matthew 2477: $amode='internal';
1.101 albertel 2478: $genpwd=$env{'form.intarg'};
2479: } elsif ($env{'form.login'} eq 'fsys') {
1.27 matthew 2480: $amode='unix';
1.101 albertel 2481: $genpwd=$env{'form.fsysarg'};
2482: } elsif ($env{'form.login'} eq 'loc') {
1.27 matthew 2483: $amode='localauth';
1.101 albertel 2484: $genpwd=$env{'form.locarg'};
1.27 matthew 2485: $genpwd=" " if (!$genpwd);
1.101 albertel 2486: } elsif (($env{'form.login'} eq 'nochange') ||
2487: ($env{'form.login'} eq '' )) {
1.34 matthew 2488: # There is no need to tell the user we did not change what they
2489: # did not ask us to change.
1.35 matthew 2490: # If they are creating a new user but have not specified login
2491: # information this will be caught below.
1.30 matthew 2492: } else {
1.367 golterma 2493: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
2494: return;
1.27 matthew 2495: }
1.164 albertel 2496:
1.188 raeburn 2497: $r->print('<h3>'.&mt('User [_1] in domain [_2]',
1.367 golterma 2498: $env{'form.ccuname'}.' ('.&Apache::loncommon::plainname($env{'form.ccuname'},
2499: $env{'form.ccdomain'}).')', $env{'form.ccdomain'}).'</h3>');
2500: my %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($r,2);
1.344 bisitz 2501:
1.193 raeburn 2502: my (%alerts,%rulematch,%inst_results,%curr_rules);
1.334 raeburn 2503: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
1.361 raeburn 2504: my @usertools = ('aboutme','blog','webdav','portfolio');
1.299 raeburn 2505: my @requestcourses = ('official','unofficial','community');
1.362 raeburn 2506: my @requestauthor = ('requestauthor');
1.286 raeburn 2507: my ($othertitle,$usertypes,$types) =
2508: &Apache::loncommon::sorted_inst_types($env{'form.ccdomain'});
1.334 raeburn 2509: my %canmodify_status =
2510: &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},
2511: ['inststatus']);
1.101 albertel 2512: if ($env{'form.makeuser'}) {
1.164 albertel 2513: $r->print('<h3>'.&mt('Creating new account.').'</h3>');
1.27 matthew 2514: # Check for the authentication mode and password
2515: if (! $amode || ! $genpwd) {
1.193 raeburn 2516: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
1.27 matthew 2517: return;
1.18 albertel 2518: }
1.29 matthew 2519: # Determine desired host
1.101 albertel 2520: my $desiredhost = $env{'form.hserver'};
1.29 matthew 2521: if (lc($desiredhost) eq 'default') {
2522: $desiredhost = undef;
2523: } else {
1.147 albertel 2524: my %home_servers =
2525: &Apache::lonnet::get_servers($env{'form.ccdomain'},'library');
1.29 matthew 2526: if (! exists($home_servers{$desiredhost})) {
1.193 raeburn 2527: $r->print($error.&mt('Invalid home server specified').$end.$rtnlink);
2528: return;
2529: }
2530: }
2531: # Check ID format
2532: my %checkhash;
2533: my %checks = ('id' => 1);
2534: %{$checkhash{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}}} = (
1.219 raeburn 2535: 'newuser' => $newuser,
1.196 raeburn 2536: 'id' => $env{'form.cid'},
1.193 raeburn 2537: );
1.196 raeburn 2538: if ($env{'form.cid'} ne '') {
2539: &Apache::loncommon::user_rule_check(\%checkhash,\%checks,\%alerts,
2540: \%rulematch,\%inst_results,\%curr_rules);
2541: if (ref($alerts{'id'}) eq 'HASH') {
2542: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
2543: my $domdesc =
2544: &Apache::lonnet::domain($env{'form.ccdomain'},'description');
2545: if ($alerts{'id'}{$env{'form.ccdomain'}}{$env{'form.cid'}}) {
2546: my $userchkmsg;
2547: if (ref($curr_rules{$env{'form.ccdomain'}}) eq 'HASH') {
2548: $userchkmsg =
2549: &Apache::loncommon::instrule_disallow_msg('id',
2550: $domdesc,1).
2551: &Apache::loncommon::user_rule_formats($env{'form.ccdomain'},
2552: $domdesc,$curr_rules{$env{'form.ccdomain'}}{'id'},'id');
2553: }
2554: $r->print($error.&mt('Invalid ID format').$end.
2555: $userchkmsg.$rtnlink);
2556: return;
2557: }
2558: }
1.29 matthew 2559: }
2560: }
1.367 golterma 2561: &Apache::lonhtmlcommon::Increment_PrgWin($r, \%prog_state);
1.27 matthew 2562: # Call modifyuser
2563: my $result = &Apache::lonnet::modifyuser
1.193 raeburn 2564: ($env{'form.ccdomain'},$env{'form.ccuname'},$env{'form.cid'},
1.188 raeburn 2565: $amode,$genpwd,$env{'form.cfirstname'},
2566: $env{'form.cmiddlename'},$env{'form.clastname'},
2567: $env{'form.cgeneration'},undef,$desiredhost,
2568: $env{'form.cpermanentemail'});
1.77 www 2569: $r->print(&mt('Generating user').': '.$result);
1.219 raeburn 2570: $uhome = &Apache::lonnet::homeserver($env{'form.ccuname'},
1.101 albertel 2571: $env{'form.ccdomain'});
1.334 raeburn 2572: my (%changeHash,%newcustom,%changed,%changedinfo);
1.267 raeburn 2573: if ($uhome ne 'no_host') {
1.334 raeburn 2574: if ($context eq 'domain') {
1.378 raeburn 2575: foreach my $name ('portfolio','author') {
2576: if ($env{'form.custom_'.$name.'quota'} == 1) {
2577: if ($env{'form.'.$name.'quota'} eq '') {
2578: $newcustom{$name.'quota'} = 0;
2579: } else {
2580: $newcustom{$name.'quota'} = $env{'form.'.$name.'quota'};
2581: $newcustom{$name.'quota'} =~ s/[^\d\.]//g;
2582: }
2583: if ("a_admin($newcustom{$name.'quota'},\%changeHash,$name)) {
2584: $changed{$name.'quota'} = 1;
2585: }
1.334 raeburn 2586: }
2587: }
2588: foreach my $item (@usertools) {
2589: if ($env{'form.custom'.$item} == 1) {
2590: $newcustom{$item} = $env{'form.tools_'.$item};
2591: $changed{$item} = &tool_admin($item,$newcustom{$item},
2592: \%changeHash,'tools');
2593: }
1.267 raeburn 2594: }
1.334 raeburn 2595: foreach my $item (@requestcourses) {
1.341 raeburn 2596: if ($env{'form.custom'.$item} == 1) {
2597: $newcustom{$item} = $env{'form.crsreq_'.$item};
2598: if ($env{'form.crsreq_'.$item} eq 'autolimit') {
2599: $newcustom{$item} .= '=';
2600: unless ($env{'form.crsreq_'.$item.'_limit'} =~ /\D/) {
2601: $newcustom{$item} .= $env{'form.crsreq_'.$item.'_limit'};
2602: }
1.334 raeburn 2603: }
1.341 raeburn 2604: $changed{$item} = &tool_admin($item,$newcustom{$item},
2605: \%changeHash,'requestcourses');
1.334 raeburn 2606: }
1.275 raeburn 2607: }
1.362 raeburn 2608: if ($env{'form.customrequestauthor'} == 1) {
2609: $newcustom{'requestauthor'} = $env{'form.requestauthor'};
2610: $changed{'requestauthor'} = &tool_admin('requestauthor',
2611: $newcustom{'requestauthor'},
2612: \%changeHash,'requestauthor');
2613: }
1.275 raeburn 2614: }
1.334 raeburn 2615: if ($canmodify_status{'inststatus'}) {
2616: if (exists($env{'form.inststatus'})) {
2617: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
2618: if (@inststatuses > 0) {
2619: $changeHash{'inststatus'} = join(',',@inststatuses);
2620: $changed{'inststatus'} = $changeHash{'inststatus'};
1.306 raeburn 2621: }
2622: }
1.232 raeburn 2623: }
1.334 raeburn 2624: if (keys(%changed)) {
2625: foreach my $item (@userinfo) {
2626: $changeHash{$item} = $env{'form.c'.$item};
1.286 raeburn 2627: }
1.267 raeburn 2628: my $chgresult =
2629: &Apache::lonnet::put('environment',\%changeHash,
2630: $env{'form.ccdomain'},$env{'form.ccuname'});
2631: }
1.232 raeburn 2632: }
1.219 raeburn 2633: $r->print('<br />'.&mt('Home server').': '.$uhome.' '.
2634: &Apache::lonnet::hostname($uhome));
1.101 albertel 2635: } elsif (($env{'form.login'} ne 'nochange') &&
2636: ($env{'form.login'} ne '' )) {
1.27 matthew 2637: # Modify user privileges
2638: if (! $amode || ! $genpwd) {
1.193 raeburn 2639: $r->print($error.'Invalid login mode or password'.$end.$rtnlink);
1.27 matthew 2640: return;
1.20 harris41 2641: }
1.27 matthew 2642: # Only allow authentification modification if the person has authority
1.101 albertel 2643: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.20 harris41 2644: $r->print('Modifying authentication: '.
1.31 matthew 2645: &Apache::lonnet::modifyuserauth(
1.101 albertel 2646: $env{'form.ccdomain'},$env{'form.ccuname'},
1.21 harris41 2647: $amode,$genpwd));
1.102 albertel 2648: $r->print('<br />'.&mt('Home server').': '.&Apache::lonnet::homeserver
1.101 albertel 2649: ($env{'form.ccuname'},$env{'form.ccdomain'}));
1.4 www 2650: } else {
1.27 matthew 2651: # Okay, this is a non-fatal error.
1.193 raeburn 2652: $r->print($error.&mt('You do not have the authority to modify this users authentification information').'.'.$end);
1.27 matthew 2653: }
1.28 matthew 2654: }
1.344 bisitz 2655: $r->rflush(); # Finish display of header before time consuming actions start
1.367 golterma 2656: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state);
1.28 matthew 2657: ##
1.375 raeburn 2658: my (@userroles,%userupdate,$cnum,$cdom,$defaultcredits,%namechanged);
1.213 raeburn 2659: if ($context eq 'course') {
1.375 raeburn 2660: ($cnum,$cdom) =
2661: &Apache::lonuserutils::get_course_identity();
1.318 raeburn 2662: $crstype = &Apache::loncommon::course_type($cdom.'_'.$cnum);
1.375 raeburn 2663: if ($showcredits) {
2664: $defaultcredits = &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
2665: }
1.213 raeburn 2666: }
1.101 albertel 2667: if (! $env{'form.makeuser'} ) {
1.28 matthew 2668: # Check for need to change
2669: my %userenv = &Apache::lonnet::get
1.134 raeburn 2670: ('environment',['firstname','middlename','lastname','generation',
1.378 raeburn 2671: 'id','permanentemail','portfolioquota','authorquota','inststatus',
2672: 'tools.aboutme','tools.blog','tools.webdav','tools.portfolio',
1.361 raeburn 2673: 'requestcourses.official','requestcourses.unofficial',
2674: 'requestcourses.community','reqcrsotherdom.official',
1.362 raeburn 2675: 'reqcrsotherdom.unofficial','reqcrsotherdom.community',
2676: 'requestauthor'],
1.160 raeburn 2677: $env{'form.ccdomain'},$env{'form.ccuname'});
1.28 matthew 2678: my ($tmp) = keys(%userenv);
2679: if ($tmp =~ /^(con_lost|error)/i) {
2680: %userenv = ();
2681: }
1.206 raeburn 2682: my $no_forceid_alert;
2683: # Check to see if user information can be changed
2684: my %domconfig =
2685: &Apache::lonnet::get_dom('configuration',['usermodification'],
2686: $env{'form.ccdomain'});
1.213 raeburn 2687: my @statuses = ('active','future');
2688: my %roles = &Apache::lonnet::get_my_roles($env{'form.ccuname'},$env{'form.ccdomain'},'userroles',\@statuses,undef,$env{'request.role.domain'});
2689: my ($auname,$audom);
1.220 raeburn 2690: if ($context eq 'author') {
1.206 raeburn 2691: $auname = $env{'user.name'};
2692: $audom = $env{'user.domain'};
2693: }
2694: foreach my $item (keys(%roles)) {
1.220 raeburn 2695: my ($rolenum,$roledom,$role) = split(/:/,$item,-1);
1.206 raeburn 2696: if ($context eq 'course') {
2697: if ($cnum ne '' && $cdom ne '') {
2698: if ($rolenum eq $cnum && $roledom eq $cdom) {
2699: if (!grep(/^\Q$role\E$/,@userroles)) {
2700: push(@userroles,$role);
2701: }
2702: }
2703: }
2704: } elsif ($context eq 'author') {
2705: if ($rolenum eq $auname && $roledom eq $audom) {
2706: if (!grep(/^\Q$role\E$/,@userroles)) {
2707: push(@userroles,$role);
2708: }
2709: }
2710: }
2711: }
1.220 raeburn 2712: if ($env{'form.action'} eq 'singlestudent') {
2713: if (!grep(/^st$/,@userroles)) {
2714: push(@userroles,'st');
2715: }
2716: } else {
2717: # Check for course or co-author roles being activated or re-enabled
2718: if ($context eq 'author' || $context eq 'course') {
2719: foreach my $key (keys(%env)) {
2720: if ($context eq 'author') {
2721: if ($key=~/^form\.act_\Q$audom\E_\Q$auname\E_([^_]+)/) {
2722: if (!grep(/^\Q$1\E$/,@userroles)) {
2723: push(@userroles,$1);
2724: }
2725: } elsif ($key =~/^form\.ren\:\Q$audom\E\/\Q$auname\E_([^_]+)/) {
2726: if (!grep(/^\Q$1\E$/,@userroles)) {
2727: push(@userroles,$1);
2728: }
1.206 raeburn 2729: }
1.220 raeburn 2730: } elsif ($context eq 'course') {
2731: if ($key=~/^form\.act_\Q$cdom\E_\Q$cnum\E_([^_]+)/) {
2732: if (!grep(/^\Q$1\E$/,@userroles)) {
2733: push(@userroles,$1);
2734: }
2735: } elsif ($key =~/^form\.ren\:\Q$cdom\E\/\Q$cnum\E(\/?\w*)_([^_]+)/) {
2736: if (!grep(/^\Q$1\E$/,@userroles)) {
2737: push(@userroles,$1);
2738: }
1.206 raeburn 2739: }
2740: }
2741: }
2742: }
2743: }
2744: #Check to see if we can change personal data for the user
2745: my (@mod_disallowed,@longroles);
2746: foreach my $role (@userroles) {
2747: if ($role eq 'cr') {
2748: push(@longroles,'Custom');
2749: } else {
1.318 raeburn 2750: push(@longroles,&Apache::lonnet::plaintext($role,$crstype));
1.206 raeburn 2751: }
2752: }
1.219 raeburn 2753: my %canmodify = &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},\@userinfo,\@userroles);
2754: foreach my $item (@userinfo) {
1.28 matthew 2755: # Strip leading and trailing whitespace
1.203 raeburn 2756: $env{'form.c'.$item} =~ s/(\s+$|^\s+)//g;
1.219 raeburn 2757: if (!$canmodify{$item}) {
1.207 raeburn 2758: if (defined($env{'form.c'.$item})) {
2759: if ($env{'form.c'.$item} ne $userenv{$item}) {
2760: push(@mod_disallowed,$item);
2761: }
1.206 raeburn 2762: }
2763: $env{'form.c'.$item} = $userenv{$item};
2764: }
1.28 matthew 2765: }
1.259 bisitz 2766: # Check to see if we can change the Student/Employee ID
1.196 raeburn 2767: my $forceid = $env{'form.forceid'};
2768: my $recurseid = $env{'form.recurseid'};
2769: my (%alerts,%rulematch,%idinst_results,%curr_rules,%got_rules);
1.203 raeburn 2770: my %uidhash = &Apache::lonnet::idrget($env{'form.ccdomain'},
2771: $env{'form.ccuname'});
2772: if (($uidhash{$env{'form.ccuname'}}) &&
2773: ($uidhash{$env{'form.ccuname'}}!~/error\:/) &&
2774: (!$forceid)) {
2775: if ($env{'form.cid'} ne $uidhash{$env{'form.ccuname'}}) {
2776: $env{'form.cid'} = $userenv{'id'};
1.293 bisitz 2777: $no_forceid_alert = &mt('New student/employee ID does not match existing ID for this user.')
1.259 bisitz 2778: .'<br />'
2779: .&mt("Change is not permitted without checking the 'Force ID change' checkbox on the previous page.")
2780: .'<br />'."\n";
1.203 raeburn 2781: }
2782: }
2783: if ($env{'form.cid'} ne $userenv{'id'}) {
1.196 raeburn 2784: my $checkhash;
2785: my $checks = { 'id' => 1 };
2786: $checkhash->{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}} =
2787: { 'newuser' => $newuser,
2788: 'id' => $env{'form.cid'},
2789: };
2790: &Apache::loncommon::user_rule_check($checkhash,$checks,
2791: \%alerts,\%rulematch,\%idinst_results,\%curr_rules,\%got_rules);
2792: if (ref($alerts{'id'}) eq 'HASH') {
2793: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
1.203 raeburn 2794: $env{'form.cid'} = $userenv{'id'};
1.196 raeburn 2795: }
2796: }
2797: }
1.378 raeburn 2798: my (%quotachanged,%oldquota,%newquota,%olddefquota,%newdefquota,
2799: $oldinststatus,$newinststatus,%oldisdefault,%newisdefault,%oldsettings,
1.339 raeburn 2800: %oldsettingstext,%newsettings,%newsettingstext,@disporder,
1.378 raeburn 2801: %oldsettingstatus,%newsettingstatus);
1.334 raeburn 2802: @disporder = ('inststatus');
2803: if ($env{'request.role.domain'} eq $env{'form.ccdomain'}) {
1.362 raeburn 2804: push(@disporder,'requestcourses','requestauthor');
1.334 raeburn 2805: } else {
2806: push(@disporder,'reqcrsotherdom');
2807: }
2808: push(@disporder,('quota','tools'));
1.338 raeburn 2809: $oldinststatus = $userenv{'inststatus'};
1.378 raeburn 2810: foreach my $name ('portfolio','author') {
2811: ($olddefquota{$name},$oldsettingstatus{$name}) =
2812: &Apache::loncommon::default_quota($env{'form.ccdomain'},$oldinststatus,$name);
2813: ($newdefquota{$name},$newsettingstatus{$name}) = ($olddefquota{$name},$oldsettingstatus{$name});
2814: }
1.334 raeburn 2815: my %canshow;
1.220 raeburn 2816: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
1.334 raeburn 2817: $canshow{'quota'} = 1;
1.220 raeburn 2818: }
1.267 raeburn 2819: if (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
1.334 raeburn 2820: $canshow{'tools'} = 1;
1.267 raeburn 2821: }
1.275 raeburn 2822: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
1.334 raeburn 2823: $canshow{'requestcourses'} = 1;
1.300 raeburn 2824: } elsif (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.334 raeburn 2825: $canshow{'reqcrsotherdom'} = 1;
1.275 raeburn 2826: }
1.286 raeburn 2827: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.334 raeburn 2828: $canshow{'inststatus'} = 1;
1.286 raeburn 2829: }
1.362 raeburn 2830: if (&Apache::lonnet::allowed('cau',$env{'form.ccdomain'})) {
2831: $canshow{'requestauthor'} = 1;
2832: }
1.267 raeburn 2833: my (%changeHash,%changed);
1.286 raeburn 2834: if ($oldinststatus eq '') {
1.334 raeburn 2835: $oldsettings{'inststatus'} = $othertitle;
1.286 raeburn 2836: } else {
2837: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 2838: $oldsettings{'inststatus'} = join(', ',map{ $usertypes->{ &unescape($_) }; } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 2839: } else {
1.334 raeburn 2840: $oldsettings{'inststatus'} = join(', ',map{ &unescape($_); } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 2841: }
2842: }
2843: $changeHash{'inststatus'} = $userenv{'inststatus'};
1.334 raeburn 2844: if ($canmodify_status{'inststatus'}) {
2845: $canshow{'inststatus'} = 1;
1.286 raeburn 2846: if (exists($env{'form.inststatus'})) {
2847: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
2848: if (@inststatuses > 0) {
2849: $newinststatus = join(':',map { &escape($_); } @inststatuses);
2850: $changeHash{'inststatus'} = $newinststatus;
2851: if ($newinststatus ne $oldinststatus) {
2852: $changed{'inststatus'} = $newinststatus;
1.378 raeburn 2853: foreach my $name ('portfolio','author') {
2854: ($newdefquota{$name},$newsettingstatus{$name}) =
2855: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
2856: }
1.286 raeburn 2857: }
2858: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 2859: $newsettings{'inststatus'} = join(', ',map{ $usertypes->{$_}; } (@inststatuses));
1.286 raeburn 2860: } else {
1.337 raeburn 2861: $newsettings{'inststatus'} = join(', ',@inststatuses);
1.286 raeburn 2862: }
1.334 raeburn 2863: }
2864: } else {
2865: $newinststatus = '';
2866: $changeHash{'inststatus'} = $newinststatus;
2867: $newsettings{'inststatus'} = $othertitle;
2868: if ($newinststatus ne $oldinststatus) {
2869: $changed{'inststatus'} = $changeHash{'inststatus'};
1.378 raeburn 2870: foreach my $name ('portfolio','author') {
2871: ($newdefquota{$name},$newsettingstatus{$name}) =
2872: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
2873: }
1.286 raeburn 2874: }
2875: }
1.334 raeburn 2876: } elsif ($context ne 'selfcreate') {
2877: $canshow{'inststatus'} = 1;
1.337 raeburn 2878: $newsettings{'inststatus'} = $oldsettings{'inststatus'};
1.286 raeburn 2879: }
1.378 raeburn 2880: foreach my $name ('portfolio','author') {
2881: $changeHash{$name.'quota'} = $userenv{$name.'quota'};
2882: }
1.334 raeburn 2883: if ($context eq 'domain') {
1.378 raeburn 2884: foreach my $name ('portfolio','author') {
2885: if ($userenv{$name.'quota'} ne '') {
2886: $oldquota{$name} = $userenv{$name.'quota'};
2887: if ($env{'form.custom_'.$name.'quota'} == 1) {
2888: if ($env{'form.'.$name.'quota'} eq '') {
2889: $newquota{$name} = 0;
2890: } else {
2891: $newquota{$name} = $env{'form.'.$name.'quota'};
2892: $newquota{$name} =~ s/[^\d\.]//g;
2893: }
2894: if ($newquota{$name} != $oldquota{$name}) {
2895: if ("a_admin($newquota{$name},\%changeHash,$name)) {
2896: $changed{$name.'quota'} = 1;
2897: }
2898: }
1.334 raeburn 2899: } else {
1.378 raeburn 2900: if ("a_admin('',\%changeHash,$name)) {
2901: $changed{$name.'quota'} = 1;
2902: $newquota{$name} = $newdefquota{$name};
2903: $newisdefault{$name} = 1;
2904: }
1.334 raeburn 2905: }
1.149 raeburn 2906: } else {
1.378 raeburn 2907: $oldisdefault{$name} = 1;
2908: $oldquota{$name} = $olddefquota{$name};
2909: if ($env{'form.custom_'.$name.'quota'} == 1) {
2910: if ($env{'form.'.$name.'quota'} eq '') {
2911: $newquota{$name} = 0;
2912: } else {
2913: $newquota{$name} = $env{'form.'.$name.'quota'};
2914: $newquota{$name} =~ s/[^\d\.]//g;
2915: }
2916: if ("a_admin($newquota{$name},\%changeHash,$name)) {
2917: $changed{$name.'quota'} = 1;
2918: }
1.334 raeburn 2919: } else {
1.378 raeburn 2920: $newquota{$name} = $newdefquota{$name};
2921: $newisdefault{$name} = 1;
1.334 raeburn 2922: }
1.378 raeburn 2923: }
2924: if ($oldisdefault{$name}) {
2925: $oldsettingstext{'quota'}{$name} = &get_defaultquota_text($oldsettingstatus{$name});
2926: }
2927: if ($newisdefault{$name}) {
2928: $newsettingstext{'quota'}{$name} = &get_defaultquota_text($newsettingstatus{$name});
1.134 raeburn 2929: }
2930: }
1.334 raeburn 2931: &tool_changes('tools',\@usertools,\%oldsettings,\%oldsettingstext,\%userenv,
2932: \%changeHash,\%changed,\%newsettings,\%newsettingstext);
2933: if ($env{'form.ccdomain'} eq $env{'request.role.domain'}) {
2934: &tool_changes('requestcourses',\@requestcourses,\%oldsettings,\%oldsettingstext,
2935: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.362 raeburn 2936: &tool_changes('requestauthor',\@requestauthor,\%oldsettings,\%oldsettingstext,\%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 2937: } else {
1.334 raeburn 2938: &tool_changes('reqcrsotherdom',\@requestcourses,\%oldsettings,\%oldsettingstext,
2939: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 2940: }
2941: }
1.334 raeburn 2942: foreach my $item (@userinfo) {
2943: if ($env{'form.c'.$item} ne $userenv{$item}) {
2944: $namechanged{$item} = 1;
2945: }
1.204 raeburn 2946: }
1.378 raeburn 2947: foreach my $name ('portfolio','author') {
2948: $oldsettings{'quota'}{$name} = $oldquota{$name}.' Mb';
2949: $newsettings{'quota'}{$name} = $newquota{$name}.' Mb';
2950: }
1.334 raeburn 2951: if ((keys(%namechanged) > 0) || (keys(%changed) > 0)) {
1.267 raeburn 2952: my ($chgresult,$namechgresult);
2953: if (keys(%changed) > 0) {
2954: $chgresult =
1.204 raeburn 2955: &Apache::lonnet::put('environment',\%changeHash,
2956: $env{'form.ccdomain'},$env{'form.ccuname'});
1.267 raeburn 2957: if ($chgresult eq 'ok') {
2958: if (($env{'user.name'} eq $env{'form.ccuname'}) &&
2959: ($env{'user.domain'} eq $env{'form.ccdomain'})) {
1.270 raeburn 2960: my %newenvhash;
2961: foreach my $key (keys(%changed)) {
1.299 raeburn 2962: if (($key eq 'official') || ($key eq 'unofficial')
2963: || ($key eq 'community')) {
1.279 raeburn 2964: $newenvhash{'environment.requestcourses.'.$key} =
2965: $changeHash{'requestcourses.'.$key};
1.362 raeburn 2966: if ($changeHash{'requestcourses.'.$key}) {
1.332 raeburn 2967: $newenvhash{'environment.canrequest.'.$key} = 1;
1.279 raeburn 2968: } else {
2969: $newenvhash{'environment.canrequest.'.$key} =
2970: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
2971: $key,'reload','requestcourses');
2972: }
1.362 raeburn 2973: } elsif ($key eq 'requestauthor') {
2974: $newenvhash{'environment.'.$key} = $changeHash{$key};
2975: if ($changeHash{$key}) {
2976: $newenvhash{'environment.canrequest.author'} = 1;
2977: } else {
2978: $newenvhash{'environment.canrequest.author'} =
2979: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
2980: $key,'reload','requestauthor');
2981: }
1.275 raeburn 2982: } elsif ($key ne 'quota') {
1.270 raeburn 2983: $newenvhash{'environment.tools.'.$key} =
2984: $changeHash{'tools.'.$key};
1.279 raeburn 2985: if ($changeHash{'tools.'.$key} ne '') {
2986: $newenvhash{'environment.availabletools.'.$key} =
2987: $changeHash{'tools.'.$key};
2988: } else {
2989: $newenvhash{'environment.availabletools.'.$key} =
1.367 golterma 2990: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
2991: $key,'reload','tools');
1.279 raeburn 2992: }
1.270 raeburn 2993: }
2994: }
1.271 raeburn 2995: if (keys(%newenvhash)) {
2996: &Apache::lonnet::appenv(\%newenvhash);
2997: }
1.267 raeburn 2998: }
2999: }
1.204 raeburn 3000: }
1.334 raeburn 3001: if (keys(%namechanged) > 0) {
1.337 raeburn 3002: foreach my $field (@userinfo) {
3003: $changeHash{$field} = $env{'form.c'.$field};
3004: }
3005: # Make the change
1.204 raeburn 3006: $namechgresult =
3007: &Apache::lonnet::modifyuser($env{'form.ccdomain'},
3008: $env{'form.ccuname'},$changeHash{'id'},undef,undef,
3009: $changeHash{'firstname'},$changeHash{'middlename'},
3010: $changeHash{'lastname'},$changeHash{'generation'},
1.337 raeburn 3011: $changeHash{'id'},undef,$changeHash{'permanentemail'},undef,\@userinfo);
1.220 raeburn 3012: %userupdate = (
3013: lastname => $env{'form.clastname'},
3014: middlename => $env{'form.cmiddlename'},
3015: firstname => $env{'form.cfirstname'},
3016: generation => $env{'form.cgeneration'},
3017: id => $env{'form.cid'},
3018: );
1.204 raeburn 3019: }
1.334 raeburn 3020: if (((keys(%namechanged) > 0) && $namechgresult eq 'ok') ||
1.267 raeburn 3021: ((keys(%changed) > 0) && $chgresult eq 'ok')) {
1.28 matthew 3022: # Tell the user we changed the name
1.334 raeburn 3023: &display_userinfo($r,1,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 3024: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,
1.334 raeburn 3025: \%oldsettings, \%oldsettingstext,\%newsettings,
3026: \%newsettingstext);
1.203 raeburn 3027: if ($env{'form.cid'} ne $userenv{'id'}) {
3028: &Apache::lonnet::idput($env{'form.ccdomain'},
3029: ($env{'form.ccuname'} => $env{'form.cid'}));
3030: if (($recurseid) &&
3031: (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}))) {
3032: my $idresult =
3033: &Apache::lonuserutils::propagate_id_change(
3034: $env{'form.ccuname'},$env{'form.ccdomain'},
3035: \%userupdate);
3036: $r->print('<br />'.$idresult.'<br />');
3037: }
1.196 raeburn 3038: }
1.149 raeburn 3039: if (($env{'form.ccdomain'} eq $env{'user.domain'}) &&
3040: ($env{'form.ccuname'} eq $env{'user.name'})) {
3041: my %newenvhash;
3042: foreach my $key (keys(%changeHash)) {
3043: $newenvhash{'environment.'.$key} = $changeHash{$key};
3044: }
1.238 raeburn 3045: &Apache::lonnet::appenv(\%newenvhash);
1.149 raeburn 3046: }
1.28 matthew 3047: } else { # error occurred
1.188 raeburn 3048: $r->print('<span class="LC_error">'.&mt('Unable to successfully change environment for').' '.
3049: $env{'form.ccuname'}.' '.&mt('in domain').' '.
1.206 raeburn 3050: $env{'form.ccdomain'}.'</span><br />');
1.28 matthew 3051: }
1.334 raeburn 3052: } else { # End of if ($env ... ) logic
1.275 raeburn 3053: # They did not want to change the users name, quota, tool availability,
3054: # or ability to request creation of courses,
1.267 raeburn 3055: # but we can still tell them what the name and quota and availabilities are
1.334 raeburn 3056: &display_userinfo($r,undef,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 3057: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,\%oldsettings,
1.334 raeburn 3058: \%oldsettingstext,\%newsettings,\%newsettingstext);
1.28 matthew 3059: }
1.206 raeburn 3060: if (@mod_disallowed) {
3061: my ($rolestr,$contextname);
3062: if (@longroles > 0) {
3063: $rolestr = join(', ',@longroles);
3064: } else {
3065: $rolestr = &mt('No roles');
3066: }
3067: if ($context eq 'course') {
3068: $contextname = &mt('course');
3069: } elsif ($context eq 'author') {
3070: $contextname = &mt('co-author');
3071: }
3072: $r->print(&mt('The following fields were not updated: ').'<ul>');
3073: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
3074: foreach my $field (@mod_disallowed) {
3075: $r->print('<li>'.$fieldtitles{$field}.'</li>'."\n");
3076: }
1.207 raeburn 3077: $r->print('</ul>');
3078: if (@mod_disallowed == 1) {
3079: $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));
3080: } else {
3081: $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));
3082: }
1.292 bisitz 3083: my $helplink = 'javascript:helpMenu('."'display'".')';
3084: $r->print('<span class="LC_cusr_emph">'.$rolestr.'</span><br />'
3085: .&mt('Please contact your [_1]helpdesk[_2] for more information.'
3086: ,'<a href="'.$helplink.'">','</a>')
3087: .'<br />');
1.206 raeburn 3088: }
1.259 bisitz 3089: $r->print('<span class="LC_warning">'
3090: .$no_forceid_alert
3091: .&Apache::lonuserutils::print_namespacing_alerts($env{'form.ccdomain'},\%alerts,\%curr_rules)
3092: .'</span>');
1.4 www 3093: }
1.367 golterma 3094: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1.220 raeburn 3095: if ($env{'form.action'} eq 'singlestudent') {
1.375 raeburn 3096: &enroll_single_student($r,$uhome,$amode,$genpwd,$now,$newuser,$context,
3097: $crstype,$showcredits,$defaultcredits);
1.318 raeburn 3098: $r->print('<p><a href="javascript:backPage(document.userupdate)">');
3099: if ($crstype eq 'Community') {
3100: $r->print(&mt('Enroll Another Member'));
3101: } else {
3102: $r->print(&mt('Enroll Another Student'));
3103: }
3104: $r->print('</a></p>');
1.220 raeburn 3105: } else {
1.375 raeburn 3106: my @rolechanges = &update_roles($r,$context,$showcredits);
1.334 raeburn 3107: if (keys(%namechanged) > 0) {
1.220 raeburn 3108: if ($context eq 'course') {
3109: if (@userroles > 0) {
1.225 raeburn 3110: if ((@rolechanges == 0) ||
3111: (!(grep(/^st$/,@rolechanges)))) {
3112: if (grep(/^st$/,@userroles)) {
3113: my $classlistupdated =
3114: &Apache::lonuserutils::update_classlist($cdom,
1.220 raeburn 3115: $cnum,$env{'form.ccdomain'},
3116: $env{'form.ccuname'},\%userupdate);
1.225 raeburn 3117: }
1.220 raeburn 3118: }
3119: }
3120: }
3121: }
1.226 raeburn 3122: my $userinfo = &Apache::loncommon::plainname($env{'form.ccuname'},
1.233 raeburn 3123: $env{'form.ccdomain'});
3124: if ($env{'form.popup'}) {
3125: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
3126: } else {
1.367 golterma 3127: $r->print('<br />'.&Apache::lonhtmlcommon::actionbox(['<a href="javascript:backPage(document.userupdate,'."'$env{'form.prevphase'}','modify'".')">'
3128: .&mt('Modify this user: [_1]','<span class="LC_cusr_emph">'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.' ('.$userinfo.')</span>').'</a>',
3129: '<a href="javascript:backPage(document.userupdate)">'.&mt('Create/Modify Another User').'</a>']));
1.233 raeburn 3130: }
1.220 raeburn 3131: }
3132: }
3133:
1.334 raeburn 3134: sub display_userinfo {
1.362 raeburn 3135: my ($r,$changed,$order,$canshow,$requestcourses,$usertools,$requestauthor,
3136: $userenv,$changedhash,$namechangedhash,$oldsetting,$oldsettingtext,
1.334 raeburn 3137: $newsetting,$newsettingtext) = @_;
3138: return unless (ref($order) eq 'ARRAY' &&
3139: ref($canshow) eq 'HASH' &&
3140: ref($requestcourses) eq 'ARRAY' &&
1.362 raeburn 3141: ref($requestauthor) eq 'ARRAY' &&
1.334 raeburn 3142: ref($usertools) eq 'ARRAY' &&
3143: ref($userenv) eq 'HASH' &&
3144: ref($changedhash) eq 'HASH' &&
3145: ref($oldsetting) eq 'HASH' &&
3146: ref($oldsettingtext) eq 'HASH' &&
3147: ref($newsetting) eq 'HASH' &&
3148: ref($newsettingtext) eq 'HASH');
3149: my %lt=&Apache::lonlocal::texthash(
1.372 raeburn 3150: 'ui' => 'User Information',
1.334 raeburn 3151: 'uic' => 'User Information Changed',
3152: 'firstname' => 'First Name',
3153: 'middlename' => 'Middle Name',
3154: 'lastname' => 'Last Name',
3155: 'generation' => 'Generation',
3156: 'id' => 'Student/Employee ID',
3157: 'permanentemail' => 'Permanent e-mail address',
1.378 raeburn 3158: 'portfolioquota' => 'Disk space allocated to portfolio files',
3159: 'authorquota' => 'Disk space allocated to authoring space',
1.334 raeburn 3160: 'blog' => 'Blog Availability',
1.361 raeburn 3161: 'webdav' => 'WebDAV Availability',
1.334 raeburn 3162: 'aboutme' => 'Personal Information Page Availability',
3163: 'portfolio' => 'Portfolio Availability',
3164: 'official' => 'Can Request Official Courses',
3165: 'unofficial' => 'Can Request Unofficial Courses',
3166: 'community' => 'Can Request Communities',
1.362 raeburn 3167: 'requestauthor' => 'Can Request Author Role',
1.334 raeburn 3168: 'inststatus' => "Affiliation",
3169: 'prvs' => 'Previous Value:',
3170: 'chto' => 'Changed To:'
3171: );
3172: if ($changed) {
1.372 raeburn 3173: $r->print('<h3>'.$lt{'uic'}.'</h3>'.
1.367 golterma 3174: &Apache::loncommon::start_data_table().
3175: &Apache::loncommon::start_data_table_header_row());
1.334 raeburn 3176: $r->print("<th> </th>\n");
1.367 golterma 3177: $r->print('<th><b>'.$lt{'prvs'}.'</b></th>');
3178: $r->print('<th><span class="LC_nobreak"><b>'.$lt{'chto'}.'</b></span></th>');
3179: $r->print(&Apache::loncommon::end_data_table_header_row());
3180: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
3181:
3182:
1.334 raeburn 3183: foreach my $item (@userinfo) {
3184: my $value = $env{'form.c'.$item};
1.367 golterma 3185: #show changes only:
3186: unless($value eq $userenv->{$item}){
3187: $r->print(&Apache::loncommon::start_data_table_row());
3188:
3189: $r->print("<td>$lt{$item}</td>\n");
3190: $r->print('<td>'.$userenv->{$item}.' </td>');
3191: $r->print("<td>$value </td>\n");
3192:
3193: $r->print(&Apache::loncommon::end_data_table_row());
1.334 raeburn 3194: }
3195: }
3196: foreach my $entry (@{$order}) {
1.367 golterma 3197: if ($canshow->{$entry} && ($newsetting->{$entry} ne $newsetting->{$entry})) {
3198: $r->print(&Apache::loncommon::start_data_table_row());
1.334 raeburn 3199: if (($entry eq 'requestcourses') || ($entry eq 'reqcrsotherdom')) {
3200: foreach my $item (@{$requestcourses}) {
1.367 golterma 3201: $r->print("<td>$lt{$item}</td>\n");
3202: $r->print("<td>$oldsetting->{$item} $oldsettingtext->{$item}</td>\n");
1.334 raeburn 3203: my $value = $newsetting->{$item}.' '.$newsettingtext->{$item};
3204: if ($changedhash->{$item}) {
3205: $value = '<span class="LC_cusr_emph">'.$value.'</span>';
3206: }
3207: $r->print("<td>$value </td>\n");
3208: }
3209: } elsif ($entry eq 'tools') {
3210: foreach my $item (@{$usertools}) {
1.367 golterma 3211: $r->print("<td>$lt{$item}</td>\n");
3212: $r->print("<td>$oldsetting->{$item} $oldsettingtext->{$item}</td>\n");
1.334 raeburn 3213: my $value = $newsetting->{$item}.' '.$newsettingtext->{$item};
3214: if ($changedhash->{$item}) {
3215: $value = '<span class="LC_cusr_emph">'.$value.'</span>';
3216: }
3217: $r->print("<td>$value </td>\n");
3218: }
1.378 raeburn 3219: } elsif ($entry eq 'quota') {
3220: if ((ref($oldsetting->{$entry}) eq 'HASH') && (ref($oldsettingtext->{$entry}) eq 'HASH') &&
3221: (ref($newsetting->{$entry}) eq 'HASH') && (ref($newsettingtext->{$entry}) eq 'HASH')) {
3222: foreach my $name ('portfolio','author') {
3223: $r->print("<td>$lt{$name.$entry}</td>\n");
3224: $r->print("<td>$oldsetting->{$entry}->{$name} $oldsettingtext->{$entry}->{$name} </td>\n");
3225: my $value = $newsetting->{$entry}->{$name}.' '.$newsettingtext->{$entry}->{$name};
3226: if ($changedhash->{$entry}) {
3227: $value = '<span class="LC_cusr_emph">'.$value.'</span>';
3228: }
3229: $r->print("<td>$value </td>\n");
3230: }
3231: }
1.334 raeburn 3232: } else {
1.367 golterma 3233: $r->print("<td>$lt{$entry}</td>\n");
3234: $r->print("<td>$oldsetting->{$entry} $oldsettingtext->{$entry} </td>\n");
1.334 raeburn 3235: my $value = $newsetting->{$entry}.' '.$newsettingtext->{$entry};
3236: if ($changedhash->{$entry}) {
3237: $value = '<span class="LC_cusr_emph">'.$value.'</span>';
3238: }
3239: $r->print("<td>$value </td>\n");
3240: }
1.367 golterma 3241: $r->print(&Apache::loncommon::end_data_table_row());
1.334 raeburn 3242: }
3243: }
1.367 golterma 3244: $r->print(&Apache::loncommon::end_data_table().'<br />');
1.372 raeburn 3245: } else {
3246: $r->print('<h3>'.$lt{'ui'}.'</h3>'.
3247: '<p>'.&mt('No changes made to user information').'</p>');
1.334 raeburn 3248: }
3249: return;
3250: }
3251:
1.275 raeburn 3252: sub tool_changes {
3253: my ($context,$usertools,$oldaccess,$oldaccesstext,$userenv,$changeHash,
3254: $changed,$newaccess,$newaccesstext) = @_;
3255: if (!((ref($usertools) eq 'ARRAY') && (ref($oldaccess) eq 'HASH') &&
3256: (ref($oldaccesstext) eq 'HASH') && (ref($userenv) eq 'HASH') &&
3257: (ref($changeHash) eq 'HASH') && (ref($changed) eq 'HASH') &&
3258: (ref($newaccess) eq 'HASH') && (ref($newaccesstext) eq 'HASH'))) {
3259: return;
3260: }
1.300 raeburn 3261: if ($context eq 'reqcrsotherdom') {
1.309 raeburn 3262: my @options = ('approval','validate','autolimit');
1.306 raeburn 3263: my $optregex = join('|',@options);
3264: my %reqdisplay = &courserequest_display();
1.300 raeburn 3265: my $cdom = $env{'request.role.domain'};
3266: foreach my $tool (@{$usertools}) {
1.314 raeburn 3267: $oldaccesstext->{$tool} = &mt('No');
3268: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
1.300 raeburn 3269: $changeHash->{$context.'.'.$tool} = $userenv->{$context.'.'.$tool};
1.314 raeburn 3270: my $newop;
3271: if ($env{'form.'.$context.'_'.$tool}) {
3272: $newop = $env{'form.'.$context.'_'.$tool};
3273: if ($newop eq 'autolimit') {
3274: my $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
3275: $limit =~ s/\D+//g;
3276: $newop .= '='.$limit;
3277: }
3278: }
1.300 raeburn 3279: if ($userenv->{$context.'.'.$tool} eq '') {
1.314 raeburn 3280: if ($newop) {
3281: $changed->{$tool}=&tool_admin($tool,$cdom.':'.$newop,
1.300 raeburn 3282: $changeHash,$context);
3283: if ($changed->{$tool}) {
1.314 raeburn 3284: $newaccesstext->{$tool} = &mt('Yes');
1.300 raeburn 3285: } else {
3286: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3287: }
3288: }
3289: } else {
3290: my @curr = split(',',$userenv->{$context.'.'.$tool});
3291: my @new;
3292: my $changedoms;
1.314 raeburn 3293: foreach my $req (@curr) {
3294: if ($req =~ /^\Q$cdom\E\:($optregex\=?\d*)$/) {
3295: $oldaccesstext->{$tool} = &mt('Yes');
3296: my $oldop = $1;
3297: if ($oldop ne $newop) {
3298: $changedoms = 1;
3299: foreach my $item (@curr) {
3300: my ($reqdom,$option) = split(':',$item);
3301: unless ($reqdom eq $cdom) {
3302: push(@new,$item);
3303: }
3304: }
3305: if ($newop) {
3306: push(@new,$cdom.':'.$newop);
1.300 raeburn 3307: }
1.314 raeburn 3308: @new = sort(@new);
1.300 raeburn 3309: }
1.314 raeburn 3310: last;
1.300 raeburn 3311: }
1.314 raeburn 3312: }
3313: if ((!$changedoms) && ($newop)) {
1.300 raeburn 3314: $changedoms = 1;
1.306 raeburn 3315: @new = sort(@curr,$cdom.':'.$newop);
1.300 raeburn 3316: }
3317: if ($changedoms) {
1.314 raeburn 3318: my $newdomstr;
1.300 raeburn 3319: if (@new) {
3320: $newdomstr = join(',',@new);
3321: }
3322: $changed->{$tool}=&tool_admin($tool,$newdomstr,$changeHash,
3323: $context);
3324: if ($changed->{$tool}) {
3325: if ($env{'form.'.$context.'_'.$tool}) {
1.306 raeburn 3326: if ($env{'form.'.$context.'_'.$tool} eq 'autolimit') {
1.314 raeburn 3327: my $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
3328: $limit =~ s/\D+//g;
3329: if ($limit) {
3330: $newaccesstext->{$tool} = &mt('Yes, up to limit of [quant,_1,request] per user.',$limit);
3331: } else {
1.306 raeburn 3332: $newaccesstext->{$tool} = &mt('Yes, processed automatically');
3333: }
1.314 raeburn 3334: } else {
1.306 raeburn 3335: $newaccesstext->{$tool} = $reqdisplay{$env{'form.'.$context.'_'.$tool}};
3336: }
1.300 raeburn 3337: } else {
1.306 raeburn 3338: $newaccesstext->{$tool} = &mt('No');
1.300 raeburn 3339: }
3340: }
3341: }
3342: }
3343: }
3344: return;
3345: }
1.275 raeburn 3346: foreach my $tool (@{$usertools}) {
1.362 raeburn 3347: my ($newval,$envkey);
3348: $envkey = $context.'.'.$tool;
1.306 raeburn 3349: if ($context eq 'requestcourses') {
3350: $newval = $env{'form.crsreq_'.$tool};
3351: if ($newval eq 'autolimit') {
3352: $newval .= '='.$env{'form.crsreq_'.$tool.'_limit'};
3353: }
1.362 raeburn 3354: } elsif ($context eq 'requestauthor') {
3355: $newval = $env{'form.'.$context};
3356: $envkey = $context;
1.314 raeburn 3357: } else {
1.306 raeburn 3358: $newval = $env{'form.'.$context.'_'.$tool};
3359: }
1.362 raeburn 3360: if ($userenv->{$envkey} ne '') {
1.275 raeburn 3361: $oldaccess->{$tool} = &mt('custom');
1.362 raeburn 3362: if ($userenv->{$envkey}) {
1.275 raeburn 3363: $oldaccesstext->{$tool} = &mt("availability set to 'on'");
3364: } else {
3365: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
3366: }
1.362 raeburn 3367: $changeHash->{$envkey} = $userenv->{$envkey};
1.275 raeburn 3368: if ($env{'form.custom'.$tool} == 1) {
1.362 raeburn 3369: if ($newval ne $userenv->{$envkey}) {
1.306 raeburn 3370: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
3371: $context);
1.275 raeburn 3372: if ($changed->{$tool}) {
3373: $newaccess->{$tool} = &mt('custom');
1.306 raeburn 3374: if ($newval) {
1.275 raeburn 3375: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3376: } else {
3377: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3378: }
3379: } else {
3380: $newaccess->{$tool} = $oldaccess->{$tool};
3381: if ($userenv->{$context.'.'.$tool}) {
3382: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3383: } else {
3384: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3385: }
3386: }
3387: } else {
3388: $newaccess->{$tool} = $oldaccess->{$tool};
3389: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3390: }
3391: } else {
3392: $changed->{$tool} = &tool_admin($tool,'',$changeHash,$context);
3393: if ($changed->{$tool}) {
3394: $newaccess->{$tool} = &mt('default');
3395: } else {
3396: $newaccess->{$tool} = $oldaccess->{$tool};
3397: if ($userenv->{$context.'.'.$tool}) {
1.300 raeburn 3398: $newaccesstext->{$tool} = &mt("availability set to 'on'");
1.275 raeburn 3399: } else {
1.300 raeburn 3400: $newaccesstext->{$tool} = &mt("availability set to 'off'");
1.275 raeburn 3401: }
3402: }
3403: }
3404: } else {
3405: $oldaccess->{$tool} = &mt('default');
3406: if ($env{'form.custom'.$tool} == 1) {
1.306 raeburn 3407: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
3408: $context);
1.275 raeburn 3409: if ($changed->{$tool}) {
3410: $newaccess->{$tool} = &mt('custom');
1.306 raeburn 3411: if ($newval) {
1.275 raeburn 3412: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3413: } else {
3414: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3415: }
3416: } else {
3417: $newaccess->{$tool} = $oldaccess->{$tool};
3418: }
3419: } else {
3420: $newaccess->{$tool} = $oldaccess->{$tool};
3421: }
3422: }
3423: }
3424: return;
3425: }
3426:
1.220 raeburn 3427: sub update_roles {
1.375 raeburn 3428: my ($r,$context,$showcredits) = @_;
1.4 www 3429: my $now=time;
1.225 raeburn 3430: my @rolechanges;
1.220 raeburn 3431: my %disallowed;
1.73 sakharuk 3432: $r->print('<h3>'.&mt('Modifying Roles').'</h3>');
1.135 raeburn 3433: foreach my $key (keys (%env)) {
3434: next if (! $env{$key});
1.190 raeburn 3435: next if ($key eq 'form.action');
1.27 matthew 3436: # Revoke roles
1.135 raeburn 3437: if ($key=~/^form\.rev/) {
3438: if ($key=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) {
1.64 www 3439: # Revoke standard role
1.170 albertel 3440: my ($scope,$role) = ($1,$2);
3441: my $result =
3442: &Apache::lonnet::revokerole($env{'form.ccdomain'},
3443: $env{'form.ccuname'},
1.239 raeburn 3444: $scope,$role,'','',$context);
1.367 golterma 3445: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 3446: &mt('Revoking [_1] in [_2]',
3447: &Apache::lonnet::plaintext($role),
1.372 raeburn 3448: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 3449: $result ne "ok").'<br />');
3450: if ($result ne "ok") {
3451: $r->print(&mt('Error: [_1]',$result).'<br />');
3452: }
1.170 albertel 3453: if ($role eq 'st') {
1.202 raeburn 3454: my $result =
1.198 raeburn 3455: &Apache::lonuserutils::classlist_drop($scope,
3456: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 3457: $now);
1.367 golterma 3458: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.53 www 3459: }
1.225 raeburn 3460: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3461: push(@rolechanges,$role);
3462: }
1.196 raeburn 3463: }
1.195 raeburn 3464: if ($key=~m{^form\.rev\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}s) {
1.64 www 3465: # Revoke custom role
1.369 bisitz 3466: my $result = &Apache::lonnet::revokecustomrole(
3467: $env{'form.ccdomain'},$env{'form.ccuname'},$1,$2,$3,$4,'','',$context);
1.367 golterma 3468: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 3469: &mt('Revoking custom role [_1] by [_2] in [_3]',
1.372 raeburn 3470: $4,$3.':'.$2,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 3471: $result ne 'ok').'<br />');
3472: if ($result ne "ok") {
3473: $r->print(&mt('Error: [_1]',$result).'<br />');
3474: }
1.225 raeburn 3475: if (!grep(/^cr$/,@rolechanges)) {
3476: push(@rolechanges,'cr');
3477: }
1.64 www 3478: }
1.135 raeburn 3479: } elsif ($key=~/^form\.del/) {
3480: if ($key=~/^form\.del\:([^\_]+)\_([^\_\.]+)$/) {
1.116 raeburn 3481: # Delete standard role
1.170 albertel 3482: my ($scope,$role) = ($1,$2);
3483: my $result =
3484: &Apache::lonnet::assignrole($env{'form.ccdomain'},
3485: $env{'form.ccuname'},
1.239 raeburn 3486: $scope,$role,$now,0,1,'',
3487: $context);
1.367 golterma 3488: $r->print(&Apache::lonhtmlcommon::confirm_success(
3489: &mt('Deleting [_1] in [_2]',
1.369 bisitz 3490: &Apache::lonnet::plaintext($role),
1.372 raeburn 3491: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 3492: $result ne 'ok').'<br />');
3493: if ($result ne "ok") {
3494: $r->print(&mt('Error: [_1]',$result).'<br />');
3495: }
1.367 golterma 3496:
1.170 albertel 3497: if ($role eq 'st') {
1.202 raeburn 3498: my $result =
1.198 raeburn 3499: &Apache::lonuserutils::classlist_drop($scope,
3500: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 3501: $now);
1.369 bisitz 3502: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.81 albertel 3503: }
1.225 raeburn 3504: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3505: push(@rolechanges,$role);
3506: }
1.116 raeburn 3507: }
1.139 albertel 3508: if ($key=~m{^form\.del\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 3509: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
3510: # Delete custom role
1.369 bisitz 3511: my $result =
3512: &Apache::lonnet::assigncustomrole($env{'form.ccdomain'},
3513: $env{'form.ccuname'},$url,$rdom,$rnam,$rolename,$now,
3514: 0,1,$context);
3515: $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('Deleting custom role [_1] by [_2] in [_3]',
1.372 raeburn 3516: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 3517: $result ne "ok").'<br />');
3518: if ($result ne "ok") {
3519: $r->print(&mt('Error: [_1]',$result).'<br />');
3520: }
1.367 golterma 3521:
1.225 raeburn 3522: if (!grep(/^cr$/,@rolechanges)) {
3523: push(@rolechanges,'cr');
3524: }
1.116 raeburn 3525: }
1.135 raeburn 3526: } elsif ($key=~/^form\.ren/) {
1.101 albertel 3527: my $udom = $env{'form.ccdomain'};
3528: my $uname = $env{'form.ccuname'};
1.116 raeburn 3529: # Re-enable standard role
1.135 raeburn 3530: if ($key=~/^form\.ren\:([^\_]+)\_([^\_\.]+)$/) {
1.89 raeburn 3531: my $url = $1;
3532: my $role = $2;
3533: my $logmsg;
3534: my $output;
3535: if ($role eq 'st') {
1.141 albertel 3536: if ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
1.374 raeburn 3537: my ($cdom,$cnum,$csec) = ($1,$2,$3);
1.375 raeburn 3538: my $credits;
3539: if ($showcredits) {
3540: my $defaultcredits =
3541: &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
3542: $credits = &get_user_credits($defaultcredits,$cdom,$cnum);
3543: }
3544: my $result = &Apache::loncommon::commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$cdom,$cnum,$csec,$context,$credits);
1.220 raeburn 3545: if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course') || ($result eq 'refused')) {
1.223 raeburn 3546: if ($result eq 'refused' && $logmsg) {
3547: $output = $logmsg;
3548: } else {
1.369 bisitz 3549: $output = &mt('Error: [_1]',$result)."\n";
1.223 raeburn 3550: }
1.89 raeburn 3551: } else {
1.372 raeburn 3552: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Assigning [_1] in [_2] starting [_3]',
3553: &Apache::lonnet::plaintext($role),
3554: &Apache::loncommon::show_role_extent($url,$context,'st'),
3555: &Apache::lonlocal::locallocaltime($now))).'<br />'.$logmsg.'<br />';
1.89 raeburn 3556: }
3557: }
3558: } else {
1.101 albertel 3559: my $result=&Apache::lonnet::assignrole($env{'form.ccdomain'},
1.239 raeburn 3560: $env{'form.ccuname'},$url,$role,0,$now,'','',
3561: $context);
1.367 golterma 3562: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Re-enabling [_1] in [_2]',
1.372 raeburn 3563: &Apache::lonnet::plaintext($role),
3564: &Apache::loncommon::show_role_extent($url,$context,$role)),$result ne "ok").'<br />';
1.369 bisitz 3565: if ($result ne "ok") {
3566: $output .= &mt('Error: [_1]',$result).'<br />';
3567: }
3568: }
1.89 raeburn 3569: $r->print($output);
1.225 raeburn 3570: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3571: push(@rolechanges,$role);
3572: }
1.113 raeburn 3573: }
1.116 raeburn 3574: # Re-enable custom role
1.139 albertel 3575: if ($key=~m{^form\.ren\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 3576: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
3577: my $result = &Apache::lonnet::assigncustomrole(
3578: $env{'form.ccdomain'}, $env{'form.ccuname'},
1.240 raeburn 3579: $url,$rdom,$rnam,$rolename,0,$now,undef,$context);
1.369 bisitz 3580: $r->print(&Apache::lonhtmlcommon::confirm_success(
3581: &mt('Re-enabling custom role [_1] by [_2] in [_3]',
1.372 raeburn 3582: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 3583: $result ne "ok").'<br />');
3584: if ($result ne "ok") {
3585: $r->print(&mt('Error: [_1]',$result).'<br />');
3586: }
1.225 raeburn 3587: if (!grep(/^cr$/,@rolechanges)) {
3588: push(@rolechanges,'cr');
3589: }
1.116 raeburn 3590: }
1.135 raeburn 3591: } elsif ($key=~/^form\.act/) {
1.101 albertel 3592: my $udom = $env{'form.ccdomain'};
3593: my $uname = $env{'form.ccuname'};
1.141 albertel 3594: if ($key=~/^form\.act\_($match_domain)\_($match_courseid)\_cr_cr_($match_domain)_($match_username)_([^\_]+)$/) {
1.65 www 3595: # Activate a custom role
1.83 albertel 3596: my ($one,$two,$three,$four,$five)=($1,$2,$3,$4,$5);
3597: my $url='/'.$one.'/'.$two;
3598: my $full=$one.'_'.$two.'_cr_cr_'.$three.'_'.$four.'_'.$five;
1.65 www 3599:
1.101 albertel 3600: my $start = ( $env{'form.start_'.$full} ?
3601: $env{'form.start_'.$full} :
1.88 raeburn 3602: $now );
1.101 albertel 3603: my $end = ( $env{'form.end_'.$full} ?
3604: $env{'form.end_'.$full} :
1.88 raeburn 3605: 0 );
3606:
3607: # split multiple sections
3608: my %sections = ();
1.101 albertel 3609: my $num_sections = &build_roles($env{'form.sec_'.$full},\%sections,$5);
1.88 raeburn 3610: if ($num_sections == 0) {
1.240 raeburn 3611: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end,$context));
1.88 raeburn 3612: } else {
1.114 albertel 3613: my %curr_groups =
1.117 raeburn 3614: &Apache::longroup::coursegroups($one,$two);
1.113 raeburn 3615: foreach my $sec (sort {$a cmp $b} keys %sections) {
3616: if (($sec eq 'none') || ($sec eq 'all') ||
3617: exists($curr_groups{$sec})) {
3618: $disallowed{$sec} = $url;
3619: next;
3620: }
3621: my $securl = $url.'/'.$sec;
1.240 raeburn 3622: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end,$context));
1.88 raeburn 3623: }
3624: }
1.225 raeburn 3625: if (!grep(/^cr$/,@rolechanges)) {
3626: push(@rolechanges,'cr');
3627: }
1.142 raeburn 3628: } elsif ($key=~/^form\.act\_($match_domain)\_($match_name)\_([^\_]+)$/) {
1.27 matthew 3629: # Activate roles for sections with 3 id numbers
3630: # set start, end times, and the url for the class
1.83 albertel 3631: my ($one,$two,$three)=($1,$2,$3);
1.101 albertel 3632: my $start = ( $env{'form.start_'.$one.'_'.$two.'_'.$three} ?
3633: $env{'form.start_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 3634: $now );
1.101 albertel 3635: my $end = ( $env{'form.end_'.$one.'_'.$two.'_'.$three} ?
3636: $env{'form.end_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 3637: 0 );
1.83 albertel 3638: my $url='/'.$one.'/'.$two;
1.88 raeburn 3639: my $type = 'three';
3640: # split multiple sections
3641: my %sections = ();
1.101 albertel 3642: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections,$three);
1.375 raeburn 3643: my $credits;
3644: if ($three eq 'st') {
3645: if ($showcredits) {
3646: my $defaultcredits =
3647: &Apache::lonuserutils::get_defaultcredits($one,$two);
3648: $credits = $env{'form.credits_'.$one.'_'.$two.'_'.$three};
3649: $credits =~ s/[^\d\.]//g;
3650: if ($credits eq $defaultcredits) {
3651: undef($credits);
3652: }
3653: }
3654: }
1.88 raeburn 3655: if ($num_sections == 0) {
1.375 raeburn 3656: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 3657: } else {
1.114 albertel 3658: my %curr_groups =
1.117 raeburn 3659: &Apache::longroup::coursegroups($one,$two);
1.88 raeburn 3660: my $emptysec = 0;
3661: foreach my $sec (sort {$a cmp $b} keys %sections) {
3662: $sec =~ s/\W//g;
1.113 raeburn 3663: if ($sec ne '') {
3664: if (($sec eq 'none') || ($sec eq 'all') ||
3665: exists($curr_groups{$sec})) {
3666: $disallowed{$sec} = $url;
3667: next;
3668: }
1.88 raeburn 3669: my $securl = $url.'/'.$sec;
1.375 raeburn 3670: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec,$context,$credits));
1.88 raeburn 3671: } else {
3672: $emptysec = 1;
3673: }
3674: }
3675: if ($emptysec) {
1.375 raeburn 3676: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 3677: }
1.225 raeburn 3678: }
3679: if (!grep(/^\Q$three\E$/,@rolechanges)) {
3680: push(@rolechanges,$three);
3681: }
1.135 raeburn 3682: } elsif ($key=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
1.27 matthew 3683: # Activate roles for sections with two id numbers
3684: # set start, end times, and the url for the class
1.101 albertel 3685: my $start = ( $env{'form.start_'.$1.'_'.$2} ?
3686: $env{'form.start_'.$1.'_'.$2} :
1.27 matthew 3687: $now );
1.101 albertel 3688: my $end = ( $env{'form.end_'.$1.'_'.$2} ?
3689: $env{'form.end_'.$1.'_'.$2} :
1.27 matthew 3690: 0 );
1.225 raeburn 3691: my $one = $1;
3692: my $two = $2;
3693: my $url='/'.$one.'/';
1.88 raeburn 3694: # split multiple sections
3695: my %sections = ();
1.225 raeburn 3696: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two},\%sections,$two);
1.88 raeburn 3697: if ($num_sections == 0) {
1.240 raeburn 3698: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 3699: } else {
3700: my $emptysec = 0;
3701: foreach my $sec (sort {$a cmp $b} keys %sections) {
3702: if ($sec ne '') {
3703: my $securl = $url.'/'.$sec;
1.240 raeburn 3704: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$two,$start,$end,$one,undef,$sec,$context));
1.88 raeburn 3705: } else {
3706: $emptysec = 1;
3707: }
3708: }
3709: if ($emptysec) {
1.240 raeburn 3710: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 3711: }
3712: }
1.225 raeburn 3713: if (!grep(/^\Q$two\E$/,@rolechanges)) {
3714: push(@rolechanges,$two);
3715: }
1.64 www 3716: } else {
1.190 raeburn 3717: $r->print('<p><span class="LC_error">'.&mt('ERROR').': '.&mt('Unknown command').' <tt>'.$key.'</tt></span></p><br />');
1.64 www 3718: }
1.113 raeburn 3719: foreach my $key (sort(keys(%disallowed))) {
1.274 bisitz 3720: $r->print('<p class="LC_warning">');
1.113 raeburn 3721: if (($key eq 'none') || ($key eq 'all')) {
1.274 bisitz 3722: $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 3723: } else {
1.274 bisitz 3724: $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 3725: }
1.274 bisitz 3726: $r->print('</p><p>'
3727: .&mt('Please [_1]go back[_2] and choose a different section name.'
3728: ,'<a href="javascript:history.go(-1)'
3729: ,'</a>')
3730: .'</p><br />'
3731: );
1.113 raeburn 3732: }
3733: }
1.101 albertel 3734: } # End of foreach (keys(%env))
1.75 www 3735: # Flush the course logs so reverse user roles immediately updated
1.349 raeburn 3736: $r->register_cleanup(\&Apache::lonnet::flushcourselogs);
1.225 raeburn 3737: if (@rolechanges == 0) {
1.372 raeburn 3738: $r->print('<p>'.&mt('No roles to modify').'</p>');
1.193 raeburn 3739: }
1.225 raeburn 3740: return @rolechanges;
1.220 raeburn 3741: }
3742:
1.375 raeburn 3743: sub get_user_credits {
3744: my ($uname,$udom,$defaultcredits,$cdom,$cnum) = @_;
3745: if ($cdom eq '' || $cnum eq '') {
3746: return unless ($env{'request.course.id'});
3747: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
3748: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
3749: }
3750: my $credits;
3751: my %currhash =
3752: &Apache::lonnet::get('classlist',[$uname.':'.$udom],$cdom,$cnum);
3753: if (keys(%currhash) > 0) {
3754: my @items = split(/:/,$currhash{$uname.':'.$udom});
3755: my $crdidx = &Apache::loncoursedata::CL_CREDITS() - 3;
3756: $credits = $items[$crdidx];
3757: $credits =~ s/[^\d\.]//g;
3758: }
3759: if ($credits eq $defaultcredits) {
3760: undef($credits);
3761: }
3762: return $credits;
3763: }
3764:
1.220 raeburn 3765: sub enroll_single_student {
1.375 raeburn 3766: my ($r,$uhome,$amode,$genpwd,$now,$newuser,$context,$crstype,
3767: $showcredits,$defaultcredits) = @_;
1.318 raeburn 3768: $r->print('<h3>');
3769: if ($crstype eq 'Community') {
3770: $r->print(&mt('Enrolling Member'));
3771: } else {
3772: $r->print(&mt('Enrolling Student'));
3773: }
3774: $r->print('</h3>');
1.220 raeburn 3775:
3776: # Remove non alphanumeric values from section
3777: $env{'form.sections'}=~s/\W//g;
3778:
1.375 raeburn 3779: my $credits;
3780: if (($showcredits) && ($env{'form.credits'} ne '')) {
3781: $credits = $env{'form.credits'};
3782: $credits =~ s/[^\d\.]//g;
3783: if ($credits ne '') {
3784: if ($credits eq $defaultcredits) {
3785: undef($credits);
3786: }
3787: }
3788: }
3789:
1.220 raeburn 3790: # Clean out any old student roles the user has in this class.
3791: &Apache::lonuserutils::modifystudent($env{'form.ccdomain'},
3792: $env{'form.ccuname'},$env{'request.course.id'},undef,$uhome);
3793: my ($startdate,$enddate) = &Apache::lonuserutils::get_dates_from_form();
3794: my $enroll_result =
3795: &Apache::lonnet::modify_student_enrollment($env{'form.ccdomain'},
3796: $env{'form.ccuname'},$env{'form.cid'},$env{'form.cfirstname'},
3797: $env{'form.cmiddlename'},$env{'form.clastname'},
3798: $env{'form.generation'},$env{'form.sections'},$enddate,
1.375 raeburn 3799: $startdate,'manual',undef,$env{'request.course.id'},'',$context,
3800: $credits);
1.220 raeburn 3801: if ($enroll_result =~ /^ok/) {
1.381 bisitz 3802: $r->print(&mt('[_1] enrolled','<b>'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.'</b>'));
1.220 raeburn 3803: if ($env{'form.sections'} ne '') {
3804: $r->print(' '.&mt('in section [_1]',$env{'form.sections'}));
3805: }
3806: my ($showstart,$showend);
3807: if ($startdate <= $now) {
3808: $showstart = &mt('Access starts immediately');
3809: } else {
3810: $showstart = &mt('Access starts: ').&Apache::lonlocal::locallocaltime($startdate);
3811: }
3812: if ($enddate == 0) {
3813: $showend = &mt('ends: no ending date');
3814: } else {
3815: $showend = &mt('ends: ').&Apache::lonlocal::locallocaltime($enddate);
3816: }
3817: $r->print('.<br />'.$showstart.'; '.$showend);
3818: if ($startdate <= $now && !$newuser) {
1.318 raeburn 3819: $r->print('<p> ');
3820: if ($crstype eq 'Community') {
3821: $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.'));
3822: } else {
3823: $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.'));
3824: }
3825: $r->print('</p>');
1.220 raeburn 3826: }
3827: } else {
3828: $r->print(&mt('unable to enroll').": ".$enroll_result);
3829: }
3830: return;
1.188 raeburn 3831: }
3832:
1.204 raeburn 3833: sub get_defaultquota_text {
3834: my ($settingstatus) = @_;
3835: my $defquotatext;
3836: if ($settingstatus eq '') {
3837: $defquotatext = &mt('(default)');
3838: } else {
3839: my ($usertypes,$order) =
3840: &Apache::lonnet::retrieve_inst_usertypes($env{'form.ccdomain'});
3841: if ($usertypes->{$settingstatus} eq '') {
3842: $defquotatext = &mt('(default)');
3843: } else {
3844: $defquotatext = &mt('(default for [_1])',$usertypes->{$settingstatus});
3845: }
3846: }
3847: return $defquotatext;
3848: }
3849:
1.188 raeburn 3850: sub update_result_form {
3851: my ($uhome) = @_;
3852: my $outcome =
1.367 golterma 3853: '<form name="userupdate" method="post" action="">'."\n";
1.160 raeburn 3854: foreach my $item ('srchby','srchin','srchtype','srchterm','srchdomain','ccuname','ccdomain') {
1.188 raeburn 3855: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 3856: }
1.207 raeburn 3857: if ($env{'form.origname'} ne '') {
3858: $outcome .= '<input type="hidden" name="origname" value="'.$env{'form.origname'}.'" />'."\n";
3859: }
1.160 raeburn 3860: foreach my $item ('sortby','seluname','seludom') {
3861: if (exists($env{'form.'.$item})) {
1.188 raeburn 3862: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 3863: }
3864: }
1.188 raeburn 3865: if ($uhome eq 'no_host') {
3866: $outcome .= '<input type="hidden" name="forcenewuser" value="1" />'."\n";
3867: }
3868: $outcome .= '<input type="hidden" name="phase" value="" />'."\n".
3869: '<input type ="hidden" name="currstate" value="" />'."\n".
1.220 raeburn 3870: '<input type ="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
1.188 raeburn 3871: '</form>';
3872: return $outcome;
1.4 www 3873: }
3874:
1.149 raeburn 3875: sub quota_admin {
1.378 raeburn 3876: my ($setquota,$changeHash,$name) = @_;
1.149 raeburn 3877: my $quotachanged;
3878: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
3879: # Current user has quota modification privileges
1.267 raeburn 3880: if (ref($changeHash) eq 'HASH') {
3881: $quotachanged = 1;
1.378 raeburn 3882: $changeHash->{$name.'quota'} = $setquota;
1.267 raeburn 3883: }
1.149 raeburn 3884: }
3885: return $quotachanged;
3886: }
3887:
1.267 raeburn 3888: sub tool_admin {
1.275 raeburn 3889: my ($tool,$settool,$changeHash,$context) = @_;
3890: my $canchange = 0;
1.279 raeburn 3891: if ($context eq 'requestcourses') {
1.275 raeburn 3892: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
3893: $canchange = 1;
3894: }
1.300 raeburn 3895: } elsif ($context eq 'reqcrsotherdom') {
3896: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
3897: $canchange = 1;
3898: }
1.362 raeburn 3899: } elsif ($context eq 'requestauthor') {
3900: if (&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) {
3901: $canchange = 1;
3902: }
1.275 raeburn 3903: } elsif (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
3904: # Current user has quota modification privileges
3905: $canchange = 1;
3906: }
1.267 raeburn 3907: my $toolchanged;
1.275 raeburn 3908: if ($canchange) {
1.267 raeburn 3909: if (ref($changeHash) eq 'HASH') {
3910: $toolchanged = 1;
1.362 raeburn 3911: if ($tool eq 'requestauthor') {
3912: $changeHash->{$context} = $settool;
3913: } else {
3914: $changeHash->{$context.'.'.$tool} = $settool;
3915: }
1.267 raeburn 3916: }
3917: }
3918: return $toolchanged;
3919: }
3920:
1.88 raeburn 3921: sub build_roles {
1.89 raeburn 3922: my ($sectionstr,$sections,$role) = @_;
1.88 raeburn 3923: my $num_sections = 0;
3924: if ($sectionstr=~ /,/) {
3925: my @secnums = split/,/,$sectionstr;
1.89 raeburn 3926: if ($role eq 'st') {
3927: $secnums[0] =~ s/\W//g;
3928: $$sections{$secnums[0]} = 1;
3929: $num_sections = 1;
3930: } else {
3931: foreach my $sec (@secnums) {
3932: $sec =~ ~s/\W//g;
1.150 banghart 3933: if (!($sec eq "")) {
1.89 raeburn 3934: if (exists($$sections{$sec})) {
3935: $$sections{$sec} ++;
3936: } else {
3937: $$sections{$sec} = 1;
3938: $num_sections ++;
3939: }
1.88 raeburn 3940: }
3941: }
3942: }
3943: } else {
3944: $sectionstr=~s/\W//g;
3945: unless ($sectionstr eq '') {
3946: $$sections{$sectionstr} = 1;
3947: $num_sections ++;
3948: }
3949: }
1.129 albertel 3950:
1.88 raeburn 3951: return $num_sections;
3952: }
3953:
1.58 www 3954: # ========================================================== Custom Role Editor
3955:
3956: sub custom_role_editor {
1.351 raeburn 3957: my ($r,$brcrum) = @_;
1.324 raeburn 3958: my $action = $env{'form.customroleaction'};
3959: my $rolename;
3960: if ($action eq 'new') {
3961: $rolename=$env{'form.newrolename'};
3962: } else {
3963: $rolename=$env{'form.rolename'};
1.59 www 3964: }
3965:
1.324 raeburn 3966: my ($crstype,$context);
3967: if ($env{'request.course.id'}) {
3968: $crstype = &Apache::loncommon::course_type();
3969: $context = 'course';
3970: } else {
3971: $context = 'domain';
3972: $crstype = $env{'form.templatecrstype'};
3973: }
1.351 raeburn 3974:
3975: $rolename=~s/[^A-Za-z0-9]//gs;
3976: if (!$rolename || $env{'form.phase'} eq 'pickrole') {
3977: &print_username_entry_form($r,undef,undef,undef,undef,$crstype,$brcrum);
3978: return;
3979: }
3980:
1.153 banghart 3981: # ------------------------------------------------------- What can be assigned?
3982: my %full=();
3983: my %courselevel=();
3984: my %courselevelcurrent=();
1.61 www 3985: my $syspriv='';
3986: my $dompriv='';
3987: my $coursepriv='';
1.153 banghart 3988: my $body_top;
1.59 www 3989: my ($rdummy,$roledef)=
3990: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
1.60 www 3991: # ------------------------------------------------------- Does this role exist?
1.153 banghart 3992: $body_top .= '<h2>';
1.59 www 3993: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.153 banghart 3994: $body_top .= &mt('Existing Role').' "';
1.61 www 3995: # ------------------------------------------------- Get current role privileges
3996: ($syspriv,$dompriv,$coursepriv)=split(/\_/,$roledef);
1.324 raeburn 3997: if ($crstype eq 'Community') {
3998: $syspriv =~ s/bre\&S//;
3999: }
1.59 www 4000: } else {
1.153 banghart 4001: $body_top .= &mt('New Role').' "';
1.59 www 4002: $roledef='';
4003: }
1.153 banghart 4004: $body_top .= $rolename.'"</h2>';
1.135 raeburn 4005: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
4006: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 4007: if (!$restrict) { $restrict='F'; }
1.60 www 4008: $courselevel{$priv}=$restrict;
1.61 www 4009: if ($coursepriv=~/\:$priv/) {
4010: $courselevelcurrent{$priv}=1;
4011: }
1.60 www 4012: $full{$priv}=1;
4013: }
4014: my %domainlevel=();
1.61 www 4015: my %domainlevelcurrent=();
1.135 raeburn 4016: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
4017: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 4018: if (!$restrict) { $restrict='F'; }
1.60 www 4019: $domainlevel{$priv}=$restrict;
1.61 www 4020: if ($dompriv=~/\:$priv/) {
4021: $domainlevelcurrent{$priv}=1;
4022: }
1.60 www 4023: $full{$priv}=1;
4024: }
1.61 www 4025: my %systemlevel=();
4026: my %systemlevelcurrent=();
1.135 raeburn 4027: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
4028: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 4029: if (!$restrict) { $restrict='F'; }
1.61 www 4030: $systemlevel{$priv}=$restrict;
4031: if ($syspriv=~/\:$priv/) {
4032: $systemlevelcurrent{$priv}=1;
4033: }
4034: $full{$priv}=1;
4035: }
1.160 raeburn 4036: my ($jsback,$elements) = &crumb_utilities();
1.154 banghart 4037: my $button_code = "\n";
1.153 banghart 4038: my $head_script = "\n";
1.301 bisitz 4039: $head_script .= '<script type="text/javascript">'."\n"
4040: .'// <![CDATA['."\n";
1.324 raeburn 4041: my @template_roles = ("in","ta","ep");
4042: if ($context eq 'domain') {
4043: push(@template_roles,"ad");
1.318 raeburn 4044: }
1.324 raeburn 4045: push(@template_roles,"st");
1.318 raeburn 4046: if ($crstype eq 'Community') {
4047: unshift(@template_roles,'co');
4048: } else {
4049: unshift(@template_roles,'cc');
4050: }
1.154 banghart 4051: foreach my $role (@template_roles) {
1.324 raeburn 4052: $head_script .= &make_script_template($role,$crstype);
1.318 raeburn 4053: $button_code .= &make_button_code($role,$crstype).' ';
1.154 banghart 4054: }
1.324 raeburn 4055: my $context_code;
4056: if ($context eq 'domain') {
4057: my $checkedCommunity = '';
4058: my $checkedCourse = ' checked="checked"';
4059: if ($env{'form.templatecrstype'} eq 'Community') {
4060: $checkedCommunity = $checkedCourse;
4061: $checkedCourse = '';
4062: }
4063: $context_code = '<label>'.
4064: '<input type="radio" name="templatecrstype" value="Course"'.$checkedCourse.' onclick="this.form.submit();">'.
4065: &mt('Course').
4066: '</label>'.(' ' x2).
4067: '<label>'.
4068: '<input type="radio" name="templatecrstype" value="Community"'.$checkedCommunity.' onclick="this.form.submit();">'.
4069: &mt('Community').
4070: '</label>'.
4071: '</fieldset>'.
4072: '<input type="hidden" name="customroleaction" value="'.
4073: $action.'" />';
4074: if ($env{'form.customroleaction'} eq 'new') {
4075: $context_code .= '<input type="hidden" name="newrolename" value="'.
4076: $rolename.'" />';
4077: } else {
4078: $context_code .= '<input type="hidden" name="rolename" value="'.
4079: $rolename.'" />';
4080: }
4081: $context_code .= '<input type="hidden" name="action" value="custom" />'.
4082: '<input type="hidden" name="phase" value="selected_custom_edit" />';
4083: }
4084:
1.301 bisitz 4085: $head_script .= "\n".$jsback."\n"
4086: .'// ]]>'."\n"
4087: .'</script>'."\n";
1.351 raeburn 4088: push (@{$brcrum},
4089: {href => "javascript:backPage(document.form1,'pickrole','')",
4090: text => "Pick custom role",
4091: faq => 282,bug=>'Instructor Interface',},
4092: {href => "javascript:backPage(document.form1,'','')",
4093: text => "Edit custom role",
4094: faq => 282,
4095: bug => 'Instructor Interface',
4096: help => 'Course_Editing_Custom_Roles'}
4097: );
4098: my $args = { bread_crumbs => $brcrum,
4099: bread_crumbs_component => 'User Management'};
4100:
4101: $r->print(&Apache::loncommon::start_page('Custom Role Editor',
4102: $head_script,$args).
4103: $body_top);
1.73 sakharuk 4104: my %lt=&Apache::lonlocal::texthash(
4105: 'prv' => "Privilege",
1.131 raeburn 4106: 'crl' => "Course Level",
1.73 sakharuk 4107: 'dml' => "Domain Level",
1.150 banghart 4108: 'ssl' => "System Level");
1.264 bisitz 4109:
1.324 raeburn 4110: $r->print('<div class="LC_left_float">'
1.264 bisitz 4111: .'<form action=""><fieldset>'
4112: .'<legend>'.&mt('Select a Template').'</legend>'
4113: .$button_code
1.324 raeburn 4114: .'</fieldset></form></div>');
4115: if ($context_code) {
4116: $r->print('<div class="LC_left_float">'
4117: .'<form action="/adm/createuser" method="post"><fieldset>'
4118: .'<legend>'.&mt('Context').'</legend>'
4119: .$context_code
4120: .'</form>'
4121: .'</div>'
4122: );
4123: }
4124: $r->print('<br clear="all" />');
1.264 bisitz 4125:
1.61 www 4126: $r->print(<<ENDCCF);
1.380 bisitz 4127: <form name="form1" method="post" action="">
1.61 www 4128: <input type="hidden" name="phase" value="set_custom_roles" />
4129: <input type="hidden" name="rolename" value="$rolename" />
4130: ENDCCF
1.135 raeburn 4131: $r->print(&Apache::loncommon::start_data_table().
4132: &Apache::loncommon::start_data_table_header_row().
4133: '<th>'.$lt{'prv'}.'</th><th>'.$lt{'crl'}.'</th><th>'.$lt{'dml'}.
4134: '</th><th>'.$lt{'ssl'}.'</th>'.
4135: &Apache::loncommon::end_data_table_header_row());
1.324 raeburn 4136: foreach my $priv (sort(keys(%full))) {
1.318 raeburn 4137: my $privtext = &Apache::lonnet::plaintext($priv,$crstype);
1.135 raeburn 4138: $r->print(&Apache::loncommon::start_data_table_row().
4139: '<td>'.$privtext.'</td><td>'.
1.288 bisitz 4140: ($courselevel{$priv}?'<input type="checkbox" name="'.$priv.'_c"'.
4141: ($courselevelcurrent{$priv}?' checked="checked"':'').' />':' ').
1.61 www 4142: '</td><td>'.
1.288 bisitz 4143: ($domainlevel{$priv}?'<input type="checkbox" name="'.$priv.'_d"'.
4144: ($domainlevelcurrent{$priv}?' checked="checked"':'').' />':' ').
1.324 raeburn 4145: '</td><td>');
4146: if ($priv eq 'bre' && $crstype eq 'Community') {
4147: $r->print(' ');
4148: } else {
4149: $r->print($systemlevel{$priv}?'<input type="checkbox" name="'.$priv.'_s"'.
4150: ($systemlevelcurrent{$priv}?' checked="checked"':'').' />':' ');
4151: }
4152: $r->print('</td>'.
4153: &Apache::loncommon::end_data_table_row());
1.60 www 4154: }
1.135 raeburn 4155: $r->print(&Apache::loncommon::end_data_table().
1.190 raeburn 4156: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
1.160 raeburn 4157: '<input type="hidden" name="startrolename" value="'.$env{'form.rolename'}.
1.179 raeburn 4158: '" />'."\n".'<input type="hidden" name="currstate" value="" />'."\n".
1.160 raeburn 4159: '<input type="reset" value="'.&mt("Reset").'" />'."\n".
1.351 raeburn 4160: '<input type="submit" value="'.&mt('Save').'" /></form>');
1.61 www 4161: }
1.153 banghart 4162: # --------------------------------------------------------
4163: sub make_script_template {
1.324 raeburn 4164: my ($role,$crstype) = @_;
1.153 banghart 4165: my %full_c=();
4166: my %full_d=();
4167: my %full_s=();
4168: my $return_script;
4169: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
4170: my ($priv,$restrict)=split(/\&/,$item);
4171: $full_c{$priv}=1;
4172: }
4173: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
4174: my ($priv,$restrict)=split(/\&/,$item);
4175: $full_d{$priv}=1;
4176: }
1.154 banghart 4177: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
1.324 raeburn 4178: next if (($crstype eq 'Community') && ($item eq 'bre&S'));
1.153 banghart 4179: my ($priv,$restrict)=split(/\&/,$item);
4180: $full_s{$priv}=1;
4181: }
4182: $return_script .= 'function set_'.$role.'() {'."\n";
4183: my @temp = split(/:/,$Apache::lonnet::pr{$role.':c'});
4184: my %role_c;
1.155 banghart 4185: foreach my $priv (@temp) {
1.153 banghart 4186: my ($priv_item, $dummy) = split(/\&/,$priv);
4187: $role_c{$priv_item} = 1;
4188: }
1.269 raeburn 4189: my %role_d;
4190: @temp = split(/:/,$Apache::lonnet::pr{$role.':d'});
4191: foreach my $priv(@temp) {
4192: my ($priv_item, $dummy) = split(/\&/,$priv);
4193: $role_d{$priv_item} = 1;
4194: }
4195: my %role_s;
4196: @temp = split(/:/,$Apache::lonnet::pr{$role.':s'});
4197: foreach my $priv(@temp) {
4198: my ($priv_item, $dummy) = split(/\&/,$priv);
4199: $role_s{$priv_item} = 1;
4200: }
1.153 banghart 4201: foreach my $priv_item (keys(%full_c)) {
4202: my ($priv, $dummy) = split(/\&/,$priv_item);
1.269 raeburn 4203: if ((exists($role_c{$priv})) || (exists($role_d{$priv})) ||
4204: (exists($role_s{$priv}))) {
1.153 banghart 4205: $return_script .= "document.form1.$priv"."_c.checked = true;\n";
4206: } else {
4207: $return_script .= "document.form1.$priv"."_c.checked = false;\n";
4208: }
4209: }
1.154 banghart 4210: foreach my $priv_item (keys(%full_d)) {
4211: my ($priv, $dummy) = split(/\&/,$priv_item);
1.269 raeburn 4212: if ((exists($role_d{$priv})) || (exists($role_s{$priv}))) {
1.154 banghart 4213: $return_script .= "document.form1.$priv"."_d.checked = true;\n";
4214: } else {
4215: $return_script .= "document.form1.$priv"."_d.checked = false;\n";
4216: }
4217: }
4218: foreach my $priv_item (keys(%full_s)) {
1.153 banghart 4219: my ($priv, $dummy) = split(/\&/,$priv_item);
1.154 banghart 4220: if (exists($role_s{$priv})) {
4221: $return_script .= "document.form1.$priv"."_s.checked = true;\n";
4222: } else {
4223: $return_script .= "document.form1.$priv"."_s.checked = false;\n";
4224: }
1.153 banghart 4225: }
4226: $return_script .= '}'."\n";
1.154 banghart 4227: return ($return_script);
4228: }
4229: # ----------------------------------------------------------
4230: sub make_button_code {
1.318 raeburn 4231: my ($role,$crstype) = @_;
4232: my $label = &Apache::lonnet::plaintext($role,$crstype);
1.301 bisitz 4233: my $button_code = '<input type="button" onclick="set_'.$role.'()" value="'.$label.'" />';
1.154 banghart 4234: return ($button_code);
1.153 banghart 4235: }
1.61 www 4236: # ---------------------------------------------------------- Call to definerole
4237: sub set_custom_role {
1.351 raeburn 4238: my ($r,$context,$brcrum) = @_;
1.101 albertel 4239: my $rolename=$env{'form.rolename'};
1.63 www 4240: $rolename=~s/[^A-Za-z0-9]//gs;
1.150 banghart 4241: if (!$rolename) {
1.351 raeburn 4242: &custom_role_editor($r,$brcrum);
1.61 www 4243: return;
4244: }
1.160 raeburn 4245: my ($jsback,$elements) = &crumb_utilities();
1.301 bisitz 4246: my $jscript = '<script type="text/javascript">'
4247: .'// <![CDATA['."\n"
4248: .$jsback."\n"
4249: .'// ]]>'."\n"
4250: .'</script>'."\n";
1.352 raeburn 4251: push(@{$brcrum},
4252: {href => "javascript:backPage(document.customresult,'pickrole','')",
4253: text => "Pick custom role",
4254: faq => 282,
4255: bug => 'Instructor Interface',},
4256: {href => "javascript:backPage(document.customresult,'selected_custom_edit','')",
4257: text => "Edit custom role",
4258: faq => 282,
4259: bug => 'Instructor Interface',},
4260: {href => "javascript:backPage(document.customresult,'set_custom_roles','')",
4261: text => "Result",
4262: faq => 282,
4263: bug => 'Instructor Interface',
4264: help => 'Course_Editing_Custom_Roles'},
4265: );
4266: my $args = { bread_crumbs => $brcrum,
1.351 raeburn 4267: bread_crumbs_component => 'User Management'};
4268: $r->print(&Apache::loncommon::start_page('Save Custom Role',$jscript,$args));
1.160 raeburn 4269:
1.61 www 4270: my ($rdummy,$roledef)=
1.110 albertel 4271: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
4272:
1.61 www 4273: # ------------------------------------------------------- Does this role exist?
1.188 raeburn 4274: $r->print('<h3>');
1.61 www 4275: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.73 sakharuk 4276: $r->print(&mt('Existing Role').' "');
1.61 www 4277: } else {
1.73 sakharuk 4278: $r->print(&mt('New Role').' "');
1.61 www 4279: $roledef='';
4280: }
1.188 raeburn 4281: $r->print($rolename.'"</h3>');
1.61 www 4282: # ------------------------------------------------------- What can be assigned?
4283: my $sysrole='';
4284: my $domrole='';
4285: my $courole='';
4286:
1.135 raeburn 4287: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
4288: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 4289: if (!$restrict) { $restrict=''; }
4290: if ($env{'form.'.$priv.'_c'}) {
1.135 raeburn 4291: $courole.=':'.$item;
1.61 www 4292: }
4293: }
4294:
1.135 raeburn 4295: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
4296: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 4297: if (!$restrict) { $restrict=''; }
4298: if ($env{'form.'.$priv.'_d'}) {
1.135 raeburn 4299: $domrole.=':'.$item;
1.61 www 4300: }
4301: }
4302:
1.135 raeburn 4303: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
4304: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 4305: if (!$restrict) { $restrict=''; }
4306: if ($env{'form.'.$priv.'_s'}) {
1.135 raeburn 4307: $sysrole.=':'.$item;
1.61 www 4308: }
4309: }
1.63 www 4310: $r->print('<br />Defining Role: '.
1.61 www 4311: &Apache::lonnet::definerole($rolename,$sysrole,$domrole,$courole));
1.101 albertel 4312: if ($env{'request.course.id'}) {
4313: my $url='/'.$env{'request.course.id'};
1.63 www 4314: $url=~s/\_/\//g;
1.73 sakharuk 4315: $r->print('<br />'.&mt('Assigning Role to Self').': '.
1.101 albertel 4316: &Apache::lonnet::assigncustomrole($env{'user.domain'},
4317: $env{'user.name'},
1.63 www 4318: $url,
1.101 albertel 4319: $env{'user.domain'},
4320: $env{'user.name'},
1.240 raeburn 4321: $rolename,undef,undef,undef,$context));
1.63 www 4322: }
1.380 bisitz 4323: $r->print(
4324: '<p><a href="javascript:backPage(document.customresult,'."'pickrole'".')">'
4325: .&mt('Create or edit another custom role')
4326: .'</a></p>'
4327: .'<form name="customresult" method="post" action="">'
4328: .&Apache::lonhtmlcommon::echo_form_input([]).'</form>'
4329: );
1.58 www 4330: }
4331:
1.2 www 4332: # ================================================================ Main Handler
4333: sub handler {
4334: my $r = shift;
4335: if ($r->header_only) {
1.68 www 4336: &Apache::loncommon::content_type($r,'text/html');
1.2 www 4337: $r->send_http_header;
4338: return OK;
4339: }
1.318 raeburn 4340: my ($context,$crstype);
1.190 raeburn 4341: if ($env{'request.course.id'}) {
4342: $context = 'course';
1.318 raeburn 4343: $crstype = &Apache::loncommon::course_type();
1.190 raeburn 4344: } elsif ($env{'request.role'} =~ /^au\./) {
1.206 raeburn 4345: $context = 'author';
1.190 raeburn 4346: } else {
4347: $context = 'domain';
4348: }
1.375 raeburn 4349:
1.190 raeburn 4350: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.233 raeburn 4351: ['action','state','callingform','roletype','showrole','bulkaction','popup','phase',
4352: 'username','domain','srchterm','srchdomain','srchin','srchby','srchtype']);
1.190 raeburn 4353: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.351 raeburn 4354: my $args;
4355: my $brcrum = [];
4356: my $bread_crumbs_component = 'User Management';
1.202 raeburn 4357: if ($env{'form.action'} ne 'dateselect') {
1.351 raeburn 4358: $brcrum = [{href=>"/adm/createuser",
4359: text=>"User Management",
4360: 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'}
4361: ];
1.202 raeburn 4362: }
1.289 droeschl 4363: #SD Following files not added to help, because the corresponding .tex-files seem to
4364: #be missing: Course_Approve_Selfenroll,Course_User_Logs,
1.209 raeburn 4365: my ($permission,$allowed) =
1.318 raeburn 4366: &Apache::lonuserutils::get_permission($context,$crstype);
1.190 raeburn 4367: if (!$allowed) {
1.358 raeburn 4368: if ($context eq 'course') {
4369: $r->internal_redirect('/adm/viewclasslist');
4370: return OK;
4371: }
1.190 raeburn 4372: $env{'user.error.msg'}=
4373: "/adm/createuser:cst:0:0:Cannot create/modify user data ".
4374: "or view user status.";
4375: return HTTP_NOT_ACCEPTABLE;
4376: }
4377:
4378: &Apache::loncommon::content_type($r,'text/html');
4379: $r->send_http_header;
4380:
1.375 raeburn 4381: my $showcredits;
4382: if ((($context eq 'course') && ($crstype eq 'Course')) ||
4383: ($context eq 'domain')) {
4384: my %domdefaults =
4385: &Apache::lonnet::get_domain_defaults($env{'request.role.domain'});
4386: if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'}) {
4387: $showcredits = 1;
4388: }
4389: }
4390:
1.190 raeburn 4391: # Main switch on form.action and form.state, as appropriate
4392: if (! exists($env{'form.action'})) {
1.351 raeburn 4393: $args = {bread_crumbs => $brcrum,
4394: bread_crumbs_component => $bread_crumbs_component};
4395: $r->print(&header(undef,$args));
1.318 raeburn 4396: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 4397: } elsif ($env{'form.action'} eq 'upload' && $permission->{'cusr'}) {
1.351 raeburn 4398: push(@{$brcrum},
4399: { href => '/adm/createuser?action=upload&state=',
4400: text => 'Upload Users List',
4401: help => 'Course_Create_Class_List',
4402: });
4403: $bread_crumbs_component = 'Upload Users List';
4404: $args = {bread_crumbs => $brcrum,
4405: bread_crumbs_component => $bread_crumbs_component};
4406: $r->print(&header(undef,$args));
1.190 raeburn 4407: $r->print('<form name="studentform" method="post" '.
4408: 'enctype="multipart/form-data" '.
4409: ' action="/adm/createuser">'."\n");
4410: if (! exists($env{'form.state'})) {
4411: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4412: } elsif ($env{'form.state'} eq 'got_file') {
1.375 raeburn 4413: &Apache::lonuserutils::print_upload_manager_form($r,$context,$permission,
4414: $crstype,$showcredits);
1.190 raeburn 4415: } elsif ($env{'form.state'} eq 'enrolling') {
4416: if ($env{'form.datatoken'}) {
1.375 raeburn 4417: &Apache::lonuserutils::upfile_drop_add($r,$context,$permission,
4418: $showcredits);
1.190 raeburn 4419: }
4420: } else {
4421: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4422: }
1.213 raeburn 4423: } elsif ((($env{'form.action'} eq 'singleuser') || ($env{'form.action'}
4424: eq 'singlestudent')) && ($permission->{'cusr'})) {
1.190 raeburn 4425: my $phase = $env{'form.phase'};
4426: my @search = ('srchterm','srchby','srchin','srchtype','srchdomain');
1.192 albertel 4427: &Apache::loncreateuser::restore_prev_selections();
4428: my $srch;
4429: foreach my $item (@search) {
4430: $srch->{$item} = $env{'form.'.$item};
4431: }
1.207 raeburn 4432: if (($phase eq 'get_user_info') || ($phase eq 'userpicked') ||
4433: ($phase eq 'createnewuser')) {
4434: if ($env{'form.phase'} eq 'createnewuser') {
4435: my $response;
4436: if ($env{'form.srchterm'} !~ /^$match_username$/) {
1.366 bisitz 4437: my $response =
4438: '<span class="LC_warning">'
4439: .&mt('You must specify a valid username. Only the following are allowed:'
4440: .' letters numbers - . @')
4441: .'</span>';
1.221 raeburn 4442: $env{'form.phase'} = '';
1.375 raeburn 4443: &print_username_entry_form($r,$context,$response,$srch,undef,
4444: $crstype,$brcrum,$showcredits);
1.207 raeburn 4445: } else {
4446: my $ccuname =&LONCAPA::clean_username($srch->{'srchterm'});
4447: my $ccdomain=&LONCAPA::clean_domain($srch->{'srchdomain'});
4448: &print_user_modification_page($r,$ccuname,$ccdomain,
1.221 raeburn 4449: $srch,$response,$context,
1.375 raeburn 4450: $permission,$crstype,$brcrum,
4451: $showcredits);
1.207 raeburn 4452: }
4453: } elsif ($env{'form.phase'} eq 'get_user_info') {
1.190 raeburn 4454: my ($currstate,$response,$forcenewuser,$results) =
1.221 raeburn 4455: &user_search_result($context,$srch);
1.190 raeburn 4456: if ($env{'form.currstate'} eq 'modify') {
4457: $currstate = $env{'form.currstate'};
4458: }
4459: if ($currstate eq 'select') {
4460: &print_user_selection_page($r,$response,$srch,$results,
1.351 raeburn 4461: \@search,$context,undef,$crstype,
4462: $brcrum);
1.190 raeburn 4463: } elsif ($currstate eq 'modify') {
4464: my ($ccuname,$ccdomain);
4465: if (($srch->{'srchby'} eq 'uname') &&
4466: ($srch->{'srchtype'} eq 'exact')) {
4467: $ccuname = $srch->{'srchterm'};
4468: $ccdomain= $srch->{'srchdomain'};
4469: } else {
4470: my @matchedunames = keys(%{$results});
4471: ($ccuname,$ccdomain) = split(/:/,$matchedunames[0]);
4472: }
4473: $ccuname =&LONCAPA::clean_username($ccuname);
4474: $ccdomain=&LONCAPA::clean_domain($ccdomain);
4475: if ($env{'form.forcenewuser'}) {
4476: $response = '';
4477: }
4478: &print_user_modification_page($r,$ccuname,$ccdomain,
1.221 raeburn 4479: $srch,$response,$context,
1.351 raeburn 4480: $permission,$crstype,$brcrum);
1.190 raeburn 4481: } elsif ($currstate eq 'query') {
1.351 raeburn 4482: &print_user_query_page($r,'createuser',$brcrum);
1.190 raeburn 4483: } else {
1.229 raeburn 4484: $env{'form.phase'} = '';
1.207 raeburn 4485: &print_username_entry_form($r,$context,$response,$srch,
1.351 raeburn 4486: $forcenewuser,$crstype,$brcrum);
1.190 raeburn 4487: }
4488: } elsif ($env{'form.phase'} eq 'userpicked') {
4489: my $ccuname = &LONCAPA::clean_username($env{'form.seluname'});
4490: my $ccdomain = &LONCAPA::clean_domain($env{'form.seludom'});
1.196 raeburn 4491: &print_user_modification_page($r,$ccuname,$ccdomain,$srch,'',
1.351 raeburn 4492: $context,$permission,$crstype,
4493: $brcrum);
1.190 raeburn 4494: }
4495: } elsif ($env{'form.phase'} eq 'update_user_data') {
1.375 raeburn 4496: &update_user_data($r,$context,$crstype,$brcrum,$showcredits);
1.190 raeburn 4497: } else {
1.351 raeburn 4498: &print_username_entry_form($r,$context,undef,$srch,undef,$crstype,
4499: $brcrum);
1.190 raeburn 4500: }
4501: } elsif ($env{'form.action'} eq 'custom' && $permission->{'custom'}) {
4502: if ($env{'form.phase'} eq 'set_custom_roles') {
1.351 raeburn 4503: &set_custom_role($r,$context,$brcrum);
1.190 raeburn 4504: } else {
1.351 raeburn 4505: &custom_role_editor($r,$brcrum);
1.190 raeburn 4506: }
1.362 raeburn 4507: } elsif (($env{'form.action'} eq 'processauthorreq') &&
4508: ($permission->{'cusr'}) &&
4509: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
4510: push(@{$brcrum},
4511: {href => '/adm/createuser?action=processauthorreq',
4512: text => 'Authoring space requests',
4513: help => 'Domain_Role_Approvals'});
4514: $bread_crumbs_component = 'Authoring requests';
4515: if ($env{'form.state'} eq 'done') {
4516: push(@{$brcrum},
4517: {href => '/adm/createuser?action=authorreqqueue',
4518: text => 'Result',
4519: help => 'Domain_Role_Approvals'});
4520: $bread_crumbs_component = 'Authoring request result';
4521: }
4522: $args = { bread_crumbs => $brcrum,
4523: bread_crumbs_component => $bread_crumbs_component};
4524: $r->print(&header(undef,$args));
4525: if (!exists($env{'form.state'})) {
4526: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestauthor',
4527: $env{'request.role.domain'}));
4528: } elsif ($env{'form.state'} eq 'done') {
4529: $r->print('<h3>'.&mt('Authoring request processing').'</h3>'."\n");
4530: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestauthor',
4531: $env{'request.role.domain'}));
4532: }
1.207 raeburn 4533: } elsif (($env{'form.action'} eq 'listusers') &&
4534: ($permission->{'view'} || $permission->{'cusr'})) {
1.202 raeburn 4535: if ($env{'form.phase'} eq 'bulkchange') {
1.351 raeburn 4536: push(@{$brcrum},
4537: {href => '/adm/createuser?action=listusers',
4538: text => "List Users"},
4539: {href => "/adm/createuser",
4540: text => "Result",
4541: help => 'Course_View_Class_List'});
4542: $bread_crumbs_component = 'Update Users';
4543: $args = {bread_crumbs => $brcrum,
4544: bread_crumbs_component => $bread_crumbs_component};
4545: $r->print(&header(undef,$args));
1.202 raeburn 4546: my $setting = $env{'form.roletype'};
4547: my $choice = $env{'form.bulkaction'};
4548: if ($permission->{'cusr'}) {
1.336 raeburn 4549: &Apache::lonuserutils::update_user_list($r,$context,$setting,$choice,$crstype);
1.221 raeburn 4550: } else {
4551: $r->print(&mt('You are not authorized to make bulk changes to user roles'));
1.223 raeburn 4552: $r->print('<p><a href="/adm/createuser?action=listusers">'.&mt('Display User Lists').'</a>');
1.202 raeburn 4553: }
4554: } else {
1.351 raeburn 4555: push(@{$brcrum},
4556: {href => '/adm/createuser?action=listusers',
4557: text => "List Users",
4558: help => 'Course_View_Class_List'});
4559: $bread_crumbs_component = 'List Users';
4560: $args = {bread_crumbs => $brcrum,
4561: bread_crumbs_component => $bread_crumbs_component};
1.202 raeburn 4562: my ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles);
4563: my $formname = 'studentform';
1.364 raeburn 4564: my $hidecall = "hide_searching();";
1.321 raeburn 4565: if (($context eq 'domain') && (($env{'form.roletype'} eq 'course') ||
4566: ($env{'form.roletype'} eq 'community'))) {
4567: if ($env{'form.roletype'} eq 'course') {
4568: ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles) =
4569: &Apache::lonuserutils::courses_selector($env{'request.role.domain'},
4570: $formname);
4571: } elsif ($env{'form.roletype'} eq 'community') {
4572: $cb_jscript =
4573: &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
4574: my %elements = (
4575: coursepick => 'radio',
4576: coursetotal => 'text',
4577: courselist => 'text',
4578: );
4579: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements);
4580: }
1.364 raeburn 4581: $jscript .= &verify_user_display($context)."\n".
4582: &Apache::loncommon::check_uncheck_jscript();
1.202 raeburn 4583: my $js = &add_script($jscript).$cb_jscript;
4584: my $loadcode =
4585: &Apache::lonuserutils::course_selector_loadcode($formname);
4586: if ($loadcode ne '') {
1.364 raeburn 4587: $args->{add_entries} = {onload => "$loadcode;$hidecall"};
4588: } else {
4589: $args->{add_entries} = {onload => $hidecall};
1.202 raeburn 4590: }
1.351 raeburn 4591: $r->print(&header($js,$args));
1.191 raeburn 4592: } else {
1.364 raeburn 4593: $args->{add_entries} = {onload => $hidecall};
4594: $jscript = &verify_user_display($context).
4595: &Apache::loncommon::check_uncheck_jscript();
4596: $r->print(&header(&add_script($jscript),$args));
1.191 raeburn 4597: }
1.202 raeburn 4598: &Apache::lonuserutils::print_userlist($r,undef,$permission,$context,
1.375 raeburn 4599: $formname,$totcodes,$codetitles,$idlist,$idlist_titles,
4600: $showcredits);
1.191 raeburn 4601: }
1.213 raeburn 4602: } elsif ($env{'form.action'} eq 'drop' && $permission->{'cusr'}) {
1.318 raeburn 4603: my $brtext;
4604: if ($crstype eq 'Community') {
4605: $brtext = 'Drop Members';
4606: } else {
4607: $brtext = 'Drop Students';
4608: }
1.351 raeburn 4609: push(@{$brcrum},
4610: {href => '/adm/createuser?action=drop',
4611: text => $brtext,
4612: help => 'Course_Drop_Student'});
4613: if ($env{'form.state'} eq 'done') {
4614: push(@{$brcrum},
4615: {href=>'/adm/createuser?action=drop',
4616: text=>"Result"});
4617: }
4618: $bread_crumbs_component = $brtext;
4619: $args = {bread_crumbs => $brcrum,
4620: bread_crumbs_component => $bread_crumbs_component};
4621: $r->print(&header(undef,$args));
1.213 raeburn 4622: if (!exists($env{'form.state'})) {
1.318 raeburn 4623: &Apache::lonuserutils::print_drop_menu($r,$context,$permission,$crstype);
1.213 raeburn 4624: } elsif ($env{'form.state'} eq 'done') {
4625: &Apache::lonuserutils::update_user_list($r,$context,undef,
4626: $env{'form.action'});
4627: }
1.202 raeburn 4628: } elsif ($env{'form.action'} eq 'dateselect') {
4629: if ($permission->{'cusr'}) {
1.351 raeburn 4630: $r->print(&header(undef,{'no_nav_bar' => 1}).
1.375 raeburn 4631: &Apache::lonuserutils::date_section_selector($context,$permission,
4632: $crstype,$showcredits));
1.202 raeburn 4633: } else {
1.351 raeburn 4634: $r->print(&header(undef,{'no_nav_bar' => 1}).
4635: '<span class="LC_error">'.&mt('You do not have permission to modify dates or sections for users').'</span>');
1.202 raeburn 4636: }
1.237 raeburn 4637: } elsif ($env{'form.action'} eq 'selfenroll') {
1.351 raeburn 4638: push(@{$brcrum},
4639: {href => '/adm/createuser?action=selfenroll',
4640: text => "Configure Self-enrollment",
4641: help => 'Course_Self_Enrollment'});
1.237 raeburn 4642: if (!exists($env{'form.state'})) {
1.351 raeburn 4643: $args = { bread_crumbs => $brcrum,
4644: bread_crumbs_component => 'Configure Self-enrollment'};
4645: $r->print(&header(undef,$args));
1.241 raeburn 4646: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
1.237 raeburn 4647: &print_selfenroll_menu($r,$context,$permission);
4648: } elsif ($env{'form.state'} eq 'done') {
1.351 raeburn 4649: push (@{$brcrum},
4650: {href=>'/adm/createuser?action=selfenroll',
4651: text=>"Result"});
4652: $args = { bread_crumbs => $brcrum,
4653: bread_crumbs_component => 'Self-enrollment result'};
4654: $r->print(&header(undef,$args));
1.241 raeburn 4655: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
4656: &update_selfenroll_config($r,$context,$permission);
1.237 raeburn 4657: }
1.277 raeburn 4658: } elsif ($env{'form.action'} eq 'selfenrollqueue') {
1.351 raeburn 4659: push(@{$brcrum},
4660: {href => '/adm/createuser?action=selfenrollqueue',
4661: text => 'Enrollment requests',
4662: help => 'Course_Self_Enrollment'});
4663: $bread_crumbs_component = 'Enrollment requests';
4664: if ($env{'form.state'} eq 'done') {
4665: push(@{$brcrum},
4666: {href => '/adm/createuser?action=selfenrollqueue',
4667: text => 'Result',
4668: help => 'Course_Self_Enrollment'});
4669: $bread_crumbs_component = 'Enrollment result';
4670: }
4671: $args = { bread_crumbs => $brcrum,
4672: bread_crumbs_component => $bread_crumbs_component};
4673: $r->print(&header(undef,$args));
1.277 raeburn 4674: my $cid = $env{'request.course.id'};
4675: my $cdom = $env{'course.'.$cid.'.domain'};
4676: my $cnum = $env{'course.'.$cid.'.num'};
1.307 raeburn 4677: my $coursedesc = $env{'course.'.$cid.'.description'};
1.277 raeburn 4678: if (!exists($env{'form.state'})) {
4679: $r->print('<h3>'.&mt('Pending enrollment requests').'</h3>'."\n");
1.307 raeburn 4680: $r->print(&Apache::loncoursequeueadmin::display_queued_requests($context,
4681: $cdom,$cnum));
1.277 raeburn 4682: } elsif ($env{'form.state'} eq 'done') {
4683: $r->print('<h3>'.&mt('Enrollment request processing').'</h3>'."\n");
1.307 raeburn 4684: $r->print(&Apache::loncoursequeueadmin::update_request_queue($context,
4685: $cdom,$cnum,$coursedesc));
1.277 raeburn 4686: }
1.239 raeburn 4687: } elsif ($env{'form.action'} eq 'changelogs') {
1.363 raeburn 4688: my $helpitem;
4689: if ($context eq 'course') {
4690: $helpitem = 'Course_User_Logs';
4691: }
1.351 raeburn 4692: push (@{$brcrum},
4693: {href => '/adm/createuser?action=changelogs',
4694: text => 'User Management Logs',
1.363 raeburn 4695: help => $helpitem});
1.351 raeburn 4696: $bread_crumbs_component = 'User Changes';
4697: $args = { bread_crumbs => $brcrum,
4698: bread_crumbs_component => $bread_crumbs_component};
4699: $r->print(&header(undef,$args));
4700: &print_userchangelogs_display($r,$context,$permission);
1.190 raeburn 4701: } else {
1.351 raeburn 4702: $bread_crumbs_component = 'User Management';
4703: $args = { bread_crumbs => $brcrum,
4704: bread_crumbs_component => $bread_crumbs_component};
4705: $r->print(&header(undef,$args));
1.318 raeburn 4706: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 4707: }
1.351 raeburn 4708: $r->print(&Apache::loncommon::end_page());
1.190 raeburn 4709: return OK;
4710: }
4711:
4712: sub header {
1.351 raeburn 4713: my ($jscript,$args) = @_;
1.190 raeburn 4714: my $start_page;
1.351 raeburn 4715: if (ref($args) eq 'HASH') {
4716: $start_page=&Apache::loncommon::start_page('User Management',$jscript,$args);
1.190 raeburn 4717: } else {
1.351 raeburn 4718: $start_page=&Apache::loncommon::start_page('User Management',$jscript);
1.190 raeburn 4719: }
4720: return $start_page;
4721: }
1.2 www 4722:
1.191 raeburn 4723: sub add_script {
4724: my ($js) = @_;
1.301 bisitz 4725: return '<script type="text/javascript">'."\n"
4726: .'// <![CDATA['."\n"
4727: .$js."\n"
4728: .'// ]]>'."\n"
4729: .'</script>'."\n";
1.191 raeburn 4730: }
4731:
1.202 raeburn 4732: sub verify_user_display {
1.364 raeburn 4733: my ($context) = @_;
1.374 raeburn 4734: my %lt = &Apache::lonlocal::texthash (
4735: course => 'course(s): description, section(s), status',
4736: community => 'community(s): description, section(s), status',
4737: author => 'author',
4738: );
1.364 raeburn 4739: my $photos;
4740: if (($context eq 'course') && $env{'request.course.id'}) {
4741: $photos = $env{'course.'.$env{'request.course.id'}.'.internal.showphoto'};
4742: }
1.202 raeburn 4743: my $output = <<"END";
4744:
1.364 raeburn 4745: function hide_searching() {
4746: if (document.getElementById('searching')) {
4747: document.getElementById('searching').style.display = 'none';
4748: }
4749: return;
4750: }
4751:
1.202 raeburn 4752: function display_update() {
4753: document.studentform.action.value = 'listusers';
4754: document.studentform.phase.value = 'display';
4755: document.studentform.submit();
4756: }
4757:
1.364 raeburn 4758: function updateCols(caller) {
4759: var context = '$context';
4760: var photos = '$photos';
4761: if (caller == 'Status') {
1.374 raeburn 4762: if ((context == 'domain') &&
4763: ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
4764: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community'))) {
1.364 raeburn 4765: document.getElementById('showcolstatus').checked = false;
4766: document.getElementById('showcolstatus').disabled = 'disabled';
4767: document.getElementById('showcolstart').checked = false;
4768: document.getElementById('showcolend').checked = false;
1.374 raeburn 4769: } else {
4770: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
4771: document.getElementById('showcolstatus').checked = true;
4772: document.getElementById('showcolstatus').disabled = '';
4773: document.getElementById('showcolstart').checked = true;
4774: document.getElementById('showcolend').checked = true;
4775: } else {
4776: document.getElementById('showcolstatus').checked = false;
4777: document.getElementById('showcolstatus').disabled = 'disabled';
4778: document.getElementById('showcolstart').checked = false;
4779: document.getElementById('showcolend').checked = false;
4780: }
1.364 raeburn 4781: }
4782: }
4783: if (caller == 'output') {
4784: if (photos == 1) {
4785: if (document.getElementById('showcolphoto')) {
4786: var photoitem = document.getElementById('showcolphoto');
4787: if (document.studentform.output.options[document.studentform.output.selectedIndex].value == 'html') {
4788: photoitem.checked = true;
4789: photoitem.disabled = '';
4790: } else {
4791: photoitem.checked = false;
4792: photoitem.disabled = 'disabled';
4793: }
4794: }
4795: }
4796: }
4797: if (caller == 'showrole') {
1.371 raeburn 4798: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any') ||
4799: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'cr')) {
1.364 raeburn 4800: document.getElementById('showcolrole').checked = true;
4801: document.getElementById('showcolrole').disabled = '';
4802: } else {
4803: document.getElementById('showcolrole').checked = false;
4804: document.getElementById('showcolrole').disabled = 'disabled';
4805: }
1.374 raeburn 4806: if (context == 'domain') {
1.382 ! raeburn 4807: var quotausageshow = 0;
1.374 raeburn 4808: if ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
4809: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community')) {
4810: document.getElementById('showcolstatus').checked = false;
4811: document.getElementById('showcolstatus').disabled = 'disabled';
4812: document.getElementById('showcolstart').checked = false;
4813: document.getElementById('showcolend').checked = false;
4814: } else {
4815: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
4816: document.getElementById('showcolstatus').checked = true;
4817: document.getElementById('showcolstatus').disabled = '';
4818: document.getElementById('showcolstart').checked = true;
4819: document.getElementById('showcolend').checked = true;
4820: }
4821: }
4822: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'domain') {
4823: document.getElementById('showcolextent').disabled = 'disabled';
4824: document.getElementById('showcolextent').checked = 'false';
4825: document.getElementById('showextent').style.display='none';
4826: document.getElementById('showcoltextextent').innerHTML = '';
1.382 ! raeburn 4827: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'au') ||
! 4828: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any')) {
! 4829: if (document.getElementById('showcolauthorusage')) {
! 4830: document.getElementById('showcolauthorusage').disabled = '';
! 4831: }
! 4832: if (document.getElementById('showcolauthorquota')) {
! 4833: document.getElementById('showcolauthorquota').disabled = '';
! 4834: }
! 4835: quotausageshow = 1;
! 4836: }
1.374 raeburn 4837: } else {
4838: document.getElementById('showextent').style.display='block';
4839: document.getElementById('showextent').style.textAlign='left';
4840: document.getElementById('showextent').style.textFace='normal';
4841: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'author') {
4842: document.getElementById('showcolextent').disabled = '';
4843: document.getElementById('showcolextent').checked = 'true';
4844: document.getElementById('showcoltextextent').innerHTML="$lt{'author'}";
4845: } else {
4846: document.getElementById('showcolextent').disabled = '';
4847: document.getElementById('showcolextent').checked = 'true';
4848: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community') {
4849: document.getElementById('showcoltextextent').innerHTML="$lt{'community'}";
4850: } else {
4851: document.getElementById('showcoltextextent').innerHTML="$lt{'course'}";
4852: }
4853: }
4854: }
1.382 ! raeburn 4855: if (quotausageshow == 0) {
! 4856: if (document.getElementById('showcolauthorusage')) {
! 4857: document.getElementById('showcolauthorusage').checked = false;
! 4858: document.getElementById('showcolauthorusage').disabled = 'disabled';
! 4859: }
! 4860: if (document.getElementById('showcolauthorquota')) {
! 4861: document.getElementById('showcolauthorquota').checked = false;
! 4862: document.getElementById('showcolauthorquota').disabled = 'disabled';
! 4863: }
! 4864: }
1.374 raeburn 4865: }
1.364 raeburn 4866: }
4867: return;
4868: }
4869:
1.202 raeburn 4870: END
4871: return $output;
4872:
4873: }
4874:
1.190 raeburn 4875: ###############################################################
4876: ###############################################################
4877: # Menu Phase One
4878: sub print_main_menu {
1.318 raeburn 4879: my ($permission,$context,$crstype) = @_;
4880: my $linkcontext = $context;
4881: my $stuterm = lc(&Apache::lonnet::plaintext('st',$crstype));
4882: if (($context eq 'course') && ($crstype eq 'Community')) {
4883: $linkcontext = lc($crstype);
4884: $stuterm = 'Members';
4885: }
1.208 raeburn 4886: my %links = (
1.298 droeschl 4887: domain => {
4888: upload => 'Upload a File of Users',
4889: singleuser => 'Add/Modify a User',
4890: listusers => 'Manage Users',
4891: },
4892: author => {
4893: upload => 'Upload a File of Co-authors',
4894: singleuser => 'Add/Modify a Co-author',
4895: listusers => 'Manage Co-authors',
4896: },
4897: course => {
4898: upload => 'Upload a File of Course Users',
4899: singleuser => 'Add/Modify a Course User',
1.354 www 4900: listusers => 'List and Modify Multiple Course Users',
1.298 droeschl 4901: },
1.318 raeburn 4902: community => {
4903: upload => 'Upload a File of Community Users',
4904: singleuser => 'Add/Modify a Community User',
1.354 www 4905: listusers => 'List and Modify Multiple Community Users',
1.318 raeburn 4906: },
4907: );
4908: my %linktitles = (
4909: domain => {
4910: singleuser => 'Add a user to the domain, and/or a course or community in the domain.',
4911: listusers => 'Show and manage users in this domain.',
4912: },
4913: author => {
4914: singleuser => 'Add a user with a co- or assistant author role.',
4915: listusers => 'Show and manage co- or assistant authors.',
4916: },
4917: course => {
4918: singleuser => 'Add a user with a certain role to this course.',
4919: listusers => 'Show and manage users in this course.',
4920: },
4921: community => {
4922: singleuser => 'Add a user with a certain role to this community.',
4923: listusers => 'Show and manage users in this community.',
4924: },
1.298 droeschl 4925: );
4926: my @menu = ( {categorytitle => 'Single Users',
4927: items =>
4928: [
4929: {
1.318 raeburn 4930: linktext => $links{$linkcontext}{'singleuser'},
1.298 droeschl 4931: icon => 'edit-redo.png',
4932: #help => 'Course_Change_Privileges',
4933: url => '/adm/createuser?action=singleuser',
4934: permission => $permission->{'cusr'},
1.318 raeburn 4935: linktitle => $linktitles{$linkcontext}{'singleuser'},
1.298 droeschl 4936: },
4937: ]},
4938:
4939: {categorytitle => 'Multiple Users',
4940: items =>
4941: [
4942: {
1.318 raeburn 4943: linktext => $links{$linkcontext}{'upload'},
1.340 wenzelju 4944: icon => 'uplusr.png',
1.298 droeschl 4945: #help => 'Course_Create_Class_List',
4946: url => '/adm/createuser?action=upload',
4947: permission => $permission->{'cusr'},
4948: linktitle => 'Upload a CSV or a text file containing users.',
4949: },
4950: {
1.318 raeburn 4951: linktext => $links{$linkcontext}{'listusers'},
1.340 wenzelju 4952: icon => 'mngcu.png',
1.298 droeschl 4953: #help => 'Course_View_Class_List',
4954: url => '/adm/createuser?action=listusers',
4955: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.318 raeburn 4956: linktitle => $linktitles{$linkcontext}{'listusers'},
1.298 droeschl 4957: },
4958:
4959: ]},
4960:
4961: {categorytitle => 'Administration',
4962: items => [ ]},
4963: );
4964:
1.265 mielkec 4965: if ($context eq 'domain'){
1.298 droeschl 4966:
4967: push(@{ $menu[2]->{items} }, #Category: Administration
4968: {
4969: linktext => 'Custom Roles',
4970: icon => 'emblem-photos.png',
4971: #help => 'Course_Editing_Custom_Roles',
4972: url => '/adm/createuser?action=custom',
4973: permission => $permission->{'custom'},
4974: linktitle => 'Configure a custom role.',
4975: },
1.362 raeburn 4976: {
4977: linktext => 'Authoring Space Requests',
4978: icon => 'selfenrl-queue.png',
4979: #help => 'Domain_Role_Approvals',
4980: url => '/adm/createuser?action=processauthorreq',
4981: permission => $permission->{'cusr'},
4982: linktitle => 'Approve or reject author role requests',
4983: },
1.363 raeburn 4984: {
4985: linktext => 'Change Log',
4986: icon => 'document-properties.png',
4987: #help => 'Course_User_Logs',
4988: url => '/adm/createuser?action=changelogs',
4989: permission => $permission->{'cusr'},
4990: linktitle => 'View change log.',
4991: },
1.298 droeschl 4992: );
4993:
1.265 mielkec 4994: }elsif ($context eq 'course'){
1.298 droeschl 4995: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity();
1.318 raeburn 4996:
4997: my %linktext = (
4998: 'Course' => {
4999: single => 'Add/Modify a Student',
5000: drop => 'Drop Students',
5001: groups => 'Course Groups',
5002: },
5003: 'Community' => {
5004: single => 'Add/Modify a Member',
5005: drop => 'Drop Members',
5006: groups => 'Community Groups',
5007: },
5008: );
5009:
5010: my %linktitle = (
5011: 'Course' => {
5012: single => 'Add a user with the role of student to this course',
5013: drop => 'Remove a student from this course.',
5014: groups => 'Manage course groups',
5015: },
5016: 'Community' => {
5017: single => 'Add a user with the role of member to this community',
5018: drop => 'Remove a member from this community.',
5019: groups => 'Manage community groups',
5020: },
5021: );
5022:
1.298 droeschl 5023: push(@{ $menu[0]->{items} }, #Category: Single Users
5024: {
1.318 raeburn 5025: linktext => $linktext{$crstype}{'single'},
1.298 droeschl 5026: #help => 'Course_Add_Student',
5027: icon => 'list-add.png',
5028: url => '/adm/createuser?action=singlestudent',
5029: permission => $permission->{'cusr'},
1.318 raeburn 5030: linktitle => $linktitle{$crstype}{'single'},
1.298 droeschl 5031: },
5032: );
5033:
5034: push(@{ $menu[1]->{items} }, #Category: Multiple Users
5035: {
1.318 raeburn 5036: linktext => $linktext{$crstype}{'drop'},
1.298 droeschl 5037: icon => 'edit-undo.png',
5038: #help => 'Course_Drop_Student',
5039: url => '/adm/createuser?action=drop',
5040: permission => $permission->{'cusr'},
1.318 raeburn 5041: linktitle => $linktitle{$crstype}{'drop'},
1.298 droeschl 5042: },
5043: );
5044: push(@{ $menu[2]->{items} }, #Category: Administration
5045: {
5046: linktext => 'Custom Roles',
5047: icon => 'emblem-photos.png',
5048: #help => 'Course_Editing_Custom_Roles',
5049: url => '/adm/createuser?action=custom',
5050: permission => $permission->{'custom'},
5051: linktitle => 'Configure a custom role.',
5052: },
5053: {
1.318 raeburn 5054: linktext => $linktext{$crstype}{'groups'},
1.333 wenzelju 5055: icon => 'grps.png',
1.298 droeschl 5056: #help => 'Course_Manage_Group',
5057: url => '/adm/coursegroups?refpage=cusr',
5058: permission => $permission->{'grp_manage'},
1.318 raeburn 5059: linktitle => $linktitle{$crstype}{'groups'},
1.298 droeschl 5060: },
5061: {
1.328 wenzelju 5062: linktext => 'Change Log',
1.298 droeschl 5063: icon => 'document-properties.png',
5064: #help => 'Course_User_Logs',
5065: url => '/adm/createuser?action=changelogs',
5066: permission => $permission->{'cusr'},
5067: linktitle => 'View change log.',
5068: },
5069: );
1.277 raeburn 5070: if ($env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'}) {
1.298 droeschl 5071: push(@{ $menu[2]->{items} },
5072: {
5073: linktext => 'Enrollment Requests',
5074: icon => 'selfenrl-queue.png',
5075: #help => 'Course_Approve_Selfenroll',
5076: url => '/adm/createuser?action=selfenrollqueue',
5077: permission => $permission->{'cusr'},
5078: linktitle =>'Approve or reject enrollment requests.',
5079: },
5080: );
1.277 raeburn 5081: }
1.298 droeschl 5082:
1.265 mielkec 5083: if (!exists($permission->{'cusr_section'})){
1.320 raeburn 5084: if ($crstype ne 'Community') {
5085: push(@{ $menu[2]->{items} },
5086: {
5087: linktext => 'Automated Enrollment',
5088: icon => 'roles.png',
5089: #help => 'Course_Automated_Enrollment',
5090: permission => (&Apache::lonnet::auto_run($cnum,$cdom)
5091: && $permission->{'cusr'}),
5092: url => '/adm/populate',
5093: linktitle => 'Automated enrollment manager.',
5094: }
5095: );
5096: }
5097: push(@{ $menu[2]->{items} },
1.298 droeschl 5098: {
5099: linktext => 'User Self-Enrollment',
1.342 wenzelju 5100: icon => 'self_enroll.png',
1.298 droeschl 5101: #help => 'Course_Self_Enrollment',
5102: url => '/adm/createuser?action=selfenroll',
5103: permission => $permission->{'cusr'},
1.317 bisitz 5104: linktitle => 'Configure user self-enrollment.',
1.298 droeschl 5105: },
5106: );
5107: }
1.363 raeburn 5108: } elsif ($context eq 'author') {
1.370 raeburn 5109: push(@{ $menu[2]->{items} }, #Category: Administration
1.363 raeburn 5110: {
5111: linktext => 'Change Log',
5112: icon => 'document-properties.png',
5113: #help => 'Course_User_Logs',
5114: url => '/adm/createuser?action=changelogs',
5115: permission => $permission->{'cusr'},
5116: linktitle => 'View change log.',
5117: },
1.370 raeburn 5118: );
1.363 raeburn 5119: }
5120: return Apache::lonhtmlcommon::generate_menu(@menu);
1.250 raeburn 5121: # { text => 'View Log-in History',
5122: # help => 'Course_User_Logins',
5123: # action => 'logins',
5124: # permission => $permission->{'cusr'},
5125: # });
1.190 raeburn 5126: }
5127:
1.189 albertel 5128: sub restore_prev_selections {
5129: my %saveable_parameters = ('srchby' => 'scalar',
5130: 'srchin' => 'scalar',
5131: 'srchtype' => 'scalar',
5132: );
5133: &Apache::loncommon::store_settings('user','user_picker',
5134: \%saveable_parameters);
5135: &Apache::loncommon::restore_settings('user','user_picker',
5136: \%saveable_parameters);
5137: }
5138:
1.237 raeburn 5139: sub print_selfenroll_menu {
5140: my ($r,$context,$permission) = @_;
1.322 raeburn 5141: my $crstype = &Apache::loncommon::course_type();
1.237 raeburn 5142: my $formname = 'enrollstudent';
5143: my $nolink = 1;
5144: my ($row,$lt) = &get_selfenroll_titles();
5145: my $groupslist = &Apache::lonuserutils::get_groupslist();
5146: my $setsec_js =
5147: &Apache::lonuserutils::setsections_javascript($formname,$groupslist);
1.249 raeburn 5148: my %alerts = &Apache::lonlocal::texthash(
5149: acto => 'Activation of self-enrollment was selected for the following domain(s)',
5150: butn => 'but no user types have been checked.',
5151: wilf => "Please uncheck 'activate' or check at least one type.",
5152: );
5153: my $selfenroll_js = <<"ENDSCRIPT";
5154: function update_types(caller,num) {
5155: var delidx = getIndexByName('selfenroll_delete');
5156: var actidx = getIndexByName('selfenroll_activate');
5157: if (caller == 'selfenroll_all') {
5158: var selall;
5159: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5160: if (document.$formname.selfenroll_all[i].checked) {
5161: selall = document.$formname.selfenroll_all[i].value;
5162: }
5163: }
5164: if (selall == 1) {
5165: if (delidx != -1) {
5166: if (document.$formname.selfenroll_delete.length) {
5167: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
5168: document.$formname.selfenroll_delete[j].checked = true;
5169: }
5170: } else {
5171: document.$formname.elements[delidx].checked = true;
5172: }
5173: }
5174: if (actidx != -1) {
5175: if (document.$formname.selfenroll_activate.length) {
5176: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5177: document.$formname.selfenroll_activate[j].checked = false;
5178: }
5179: } else {
5180: document.$formname.elements[actidx].checked = false;
5181: }
5182: }
5183: document.$formname.selfenroll_newdom.selectedIndex = 0;
5184: }
5185: }
5186: if (caller == 'selfenroll_activate') {
5187: if (document.$formname.selfenroll_activate.length) {
5188: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5189: if (document.$formname.selfenroll_activate[j].value == num) {
5190: if (document.$formname.selfenroll_activate[j].checked) {
5191: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5192: if (document.$formname.selfenroll_all[i].value == '1') {
5193: document.$formname.selfenroll_all[i].checked = false;
5194: }
5195: if (document.$formname.selfenroll_all[i].value == '0') {
5196: document.$formname.selfenroll_all[i].checked = true;
5197: }
5198: }
5199: }
5200: }
5201: }
5202: } else {
5203: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5204: if (document.$formname.selfenroll_all[i].value == '1') {
5205: document.$formname.selfenroll_all[i].checked = false;
5206: }
5207: if (document.$formname.selfenroll_all[i].value == '0') {
5208: document.$formname.selfenroll_all[i].checked = true;
5209: }
5210: }
5211: }
5212: }
5213: if (caller == 'selfenroll_delete') {
5214: if (document.$formname.selfenroll_delete.length) {
5215: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
5216: if (document.$formname.selfenroll_delete[j].value == num) {
5217: if (document.$formname.selfenroll_delete[j].checked) {
5218: var delindex = getIndexByName('selfenroll_types_'+num);
5219: if (delindex != -1) {
5220: if (document.$formname.elements[delindex].length) {
5221: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
5222: document.$formname.elements[delindex][k].checked = false;
5223: }
5224: } else {
5225: document.$formname.elements[delindex].checked = false;
5226: }
5227: }
5228: }
5229: }
5230: }
5231: } else {
5232: if (document.$formname.selfenroll_delete.checked) {
5233: var delindex = getIndexByName('selfenroll_types_'+num);
5234: if (delindex != -1) {
5235: if (document.$formname.elements[delindex].length) {
5236: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
5237: document.$formname.elements[delindex][k].checked = false;
5238: }
5239: } else {
5240: document.$formname.elements[delindex].checked = false;
5241: }
5242: }
5243: }
5244: }
5245: }
5246: return;
5247: }
5248:
5249: function validate_types(form) {
5250: var needaction = new Array();
5251: var countfail = 0;
5252: var actidx = getIndexByName('selfenroll_activate');
5253: if (actidx != -1) {
5254: if (document.$formname.selfenroll_activate.length) {
5255: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5256: var num = document.$formname.selfenroll_activate[j].value;
5257: if (document.$formname.selfenroll_activate[j].checked) {
5258: countfail = check_types(num,countfail,needaction)
5259: }
5260: }
5261: } else {
5262: if (document.$formname.selfenroll_activate.checked) {
5263: var num = document.enrollstudent.selfenroll_activate.value;
5264: countfail = check_types(num,countfail,needaction)
5265: }
5266: }
5267: }
5268: if (countfail > 0) {
5269: var msg = "$alerts{'acto'}\\n";
5270: var loopend = needaction.length -1;
5271: if (loopend > 0) {
5272: for (var m=0; m<loopend; m++) {
5273: msg += needaction[m]+", ";
5274: }
5275: }
5276: msg += needaction[loopend]+"\\n$alerts{'butn'}\\n$alerts{'wilf'}";
5277: alert(msg);
5278: return;
5279: }
5280: setSections(form);
5281: }
5282:
5283: function check_types(num,countfail,needaction) {
5284: var typeidx = getIndexByName('selfenroll_types_'+num);
5285: var count = 0;
5286: if (typeidx != -1) {
5287: if (document.$formname.elements[typeidx].length) {
5288: for (var k=0; k<document.$formname.elements[typeidx].length; k++) {
5289: if (document.$formname.elements[typeidx][k].checked) {
5290: count ++;
5291: }
5292: }
5293: } else {
5294: if (document.$formname.elements[typeidx].checked) {
5295: count ++;
5296: }
5297: }
5298: if (count == 0) {
5299: var domidx = getIndexByName('selfenroll_dom_'+num);
5300: if (domidx != -1) {
5301: var domname = document.$formname.elements[domidx].value;
5302: needaction[countfail] = domname;
5303: countfail ++;
5304: }
5305: }
5306: }
5307: return countfail;
5308: }
5309:
5310: function getIndexByName(item) {
5311: for (var i=0;i<document.$formname.elements.length;i++) {
5312: if (document.$formname.elements[i].name == item) {
5313: return i;
5314: }
5315: }
5316: return -1;
5317: }
5318: ENDSCRIPT
1.256 raeburn 5319: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
5320: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
5321:
1.237 raeburn 5322: my $output = '<script type="text/javascript">'."\n".
1.301 bisitz 5323: '// <![CDATA['."\n".
1.249 raeburn 5324: $setsec_js."\n".$selfenroll_js."\n".
1.301 bisitz 5325: '// ]]>'."\n".
1.237 raeburn 5326: '</script>'."\n".
1.256 raeburn 5327: '<h3>'.$lt->{'selfenroll'}.'</h3>'."\n";
5328: my ($visible,$cansetvis,$vismsgs,$visactions) = &visible_in_cat($cdom,$cnum);
5329: if (ref($visactions) eq 'HASH') {
5330: if ($visible) {
1.283 bisitz 5331: $output .= '<p class="LC_info">'.$visactions->{'vis'}.'</p>';
1.256 raeburn 5332: } else {
1.283 bisitz 5333: $output .= '<p class="LC_warning">'.$visactions->{'miss'}.'</p>'
5334: .$visactions->{'yous'}.
1.256 raeburn 5335: '<p>'.$visactions->{'gen'}.'<br />'.$visactions->{'coca'};
5336: if (ref($vismsgs) eq 'ARRAY') {
5337: $output .= '<br />'.$visactions->{'make'}.'<ul>';
5338: foreach my $item (@{$vismsgs}) {
5339: $output .= '<li>'.$visactions->{$item}.'</li>';
5340: }
5341: $output .= '</ul>';
5342: }
5343: $output .= '</p>';
5344: }
5345: }
5346: $output .= '<form name="'.$formname.'" method="post" action="/adm/createuser">'."\n".
5347: &Apache::lonhtmlcommon::start_pick_box();
1.237 raeburn 5348: if (ref($row) eq 'ARRAY') {
5349: foreach my $item (@{$row}) {
5350: my $title = $item;
5351: if (ref($lt) eq 'HASH') {
5352: $title = $lt->{$item};
5353: }
1.297 bisitz 5354: $output .= &Apache::lonhtmlcommon::row_title($title);
1.237 raeburn 5355: if ($item eq 'types') {
5356: my $curr_types = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_types'};
1.241 raeburn 5357: my $showdomdesc = 1;
5358: my $includeempty = 1;
5359: my $num = 0;
5360: $output .= &Apache::loncommon::start_data_table().
5361: &Apache::loncommon::start_data_table_row()
5362: .'<td colspan="2"><span class="LC_nobreak"><label>'
5363: .&mt('Any user in any domain:')
5364: .' <input type="radio" name="selfenroll_all" value="1" ';
5365: if ($curr_types eq '*') {
5366: $output .= ' checked="checked" ';
5367: }
1.249 raeburn 5368: $output .= 'onchange="javascript:update_types('.
5369: "'selfenroll_all'".');" />'.&mt('Yes').'</label>'.
5370: ' <input type="radio" name="selfenroll_all" value="0" ';
1.241 raeburn 5371: if ($curr_types ne '*') {
5372: $output .= ' checked="checked" ';
5373: }
1.249 raeburn 5374: $output .= ' onchange="javascript:update_types('.
5375: "'selfenroll_all'".');"/>'.&mt('No').'</label></td>'.
5376: &Apache::loncommon::end_data_table_row().
5377: &Apache::loncommon::end_data_table().
5378: &mt('Or').'<br />'.
5379: &Apache::loncommon::start_data_table();
1.241 raeburn 5380: my %currdoms;
1.249 raeburn 5381: if ($curr_types eq '') {
1.241 raeburn 5382: $output .= &new_selfenroll_dom_row($cdom,'0');
5383: } elsif ($curr_types ne '*') {
5384: my @entries = split(/;/,$curr_types);
5385: if (@entries > 0) {
5386: foreach my $entry (@entries) {
5387: my ($currdom,$typestr) = split(/:/,$entry);
5388: $currdoms{$currdom} = 1;
5389: my $domdesc = &Apache::lonnet::domain($currdom);
1.249 raeburn 5390: my @currinsttypes = split(',',$typestr);
1.241 raeburn 5391: $output .= &Apache::loncommon::start_data_table_row()
5392: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').'<b>'
5393: .' '.$domdesc.' ('.$currdom.')'
5394: .'</b><input type="hidden" name="selfenroll_dom_'.$num
5395: .'" value="'.$currdom.'" /></span><br />'
5396: .'<span class="LC_nobreak"><label><input type="checkbox" '
1.249 raeburn 5397: .'name="selfenroll_delete" value="'.$num.'" onchange="javascript:update_types('."'selfenroll_delete','$num'".');" />'
1.241 raeburn 5398: .&mt('Delete').'</label></span></td>';
1.249 raeburn 5399: $output .= '<td valign="top"> '.&mt('User types:').'<br />'
1.241 raeburn 5400: .&selfenroll_inst_types($num,$currdom,\@currinsttypes).'</td>'
5401: .&Apache::loncommon::end_data_table_row();
5402: $num ++;
5403: }
5404: }
5405: }
1.249 raeburn 5406: my $add_domtitle = &mt('Users in additional domain:');
1.241 raeburn 5407: if ($curr_types eq '*') {
1.249 raeburn 5408: $add_domtitle = &mt('Users in specific domain:');
1.241 raeburn 5409: } elsif ($curr_types eq '') {
1.249 raeburn 5410: $add_domtitle = &mt('Users in other domain:');
1.241 raeburn 5411: }
5412: $output .= &Apache::loncommon::start_data_table_row()
5413: .'<td colspan="2"><span class="LC_nobreak">'.$add_domtitle.'</span><br />'
5414: .&Apache::loncommon::select_dom_form('','selfenroll_newdom',
5415: $includeempty,$showdomdesc)
5416: .'<input type="hidden" name="selfenroll_types_total" value="'.$num.'" />'
5417: .'</td>'.&Apache::loncommon::end_data_table_row()
5418: .&Apache::loncommon::end_data_table();
1.237 raeburn 5419: } elsif ($item eq 'registered') {
5420: my ($regon,$regoff);
5421: if ($env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_registered'}) {
5422: $regon = ' checked="checked" ';
5423: $regoff = ' ';
5424: } else {
5425: $regon = ' ';
5426: $regoff = ' checked="checked" ';
5427: }
5428: $output .= '<label>'.
1.245 raeburn 5429: '<input type="radio" name="selfenroll_registered" value="1"'.$regon.'/>'.
1.244 bisitz 5430: &mt('Yes').'</label> <label>'.
1.245 raeburn 5431: '<input type="radio" name="selfenroll_registered" value="0"'.$regoff.'/>'.
1.244 bisitz 5432: &mt('No').'</label>';
1.237 raeburn 5433: } elsif ($item eq 'enroll_dates') {
5434: my $starttime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_start_date'};
5435: my $endtime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_end_date'};
5436: if ($starttime eq '') {
5437: $starttime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_start_date'};
5438: }
5439: if ($endtime eq '') {
5440: $endtime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_end_date'};
5441: }
5442: my $startform =
5443: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_date',$starttime,
5444: undef,undef,undef,undef,undef,undef,undef,$nolink);
5445: my $endform =
5446: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_date',$endtime,
5447: undef,undef,undef,undef,undef,undef,undef,$nolink);
5448: $output .= &selfenroll_date_forms($startform,$endform);
5449: } elsif ($item eq 'access_dates') {
5450: my $starttime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_start_access'};
5451: my $endtime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_end_access'};
5452: if ($starttime eq '') {
5453: $starttime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_start_date'};
5454: }
5455: if ($endtime eq '') {
5456: $endtime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_end_date'};
5457: }
5458: my $startform =
5459: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_access',$starttime,
5460: undef,undef,undef,undef,undef,undef,undef,$nolink);
5461: my $endform =
5462: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_access',$endtime,
5463: undef,undef,undef,undef,undef,undef,undef,$nolink);
5464: $output .= &selfenroll_date_forms($startform,$endform);
5465: } elsif ($item eq 'section') {
5466: my $currsec = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_section'};
5467: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
5468: my $newsecval;
5469: if ($currsec ne 'none' && $currsec ne '') {
5470: if (!defined($sections_count{$currsec})) {
5471: $newsecval = $currsec;
5472: }
5473: }
5474: my $sections_select =
5475: &Apache::lonuserutils::course_sections(\%sections_count,'st',$currsec);
5476: $output .= '<table class="LC_createuser">'."\n".
5477: '<tr class="LC_section_row">'."\n".
5478: '<td align="center">'.&mt('Existing sections')."\n".
5479: '<br />'.$sections_select.'</td><td align="center">'.
5480: &mt('New section').'<br />'."\n".
5481: '<input type="text" name="newsec" size="15" value="'.$newsecval.'" />'."\n".
5482: '<input type="hidden" name="sections" value="" />'."\n".
5483: '<input type="hidden" name="state" value="done" />'."\n".
5484: '</td></tr></table>'."\n";
1.276 raeburn 5485: } elsif ($item eq 'approval') {
5486: my ($appon,$appoff);
5487: my $cid = $env{'request.course.id'};
5488: my $currnotified = $env{'course.'.$cid.'.internal.selfenroll_notifylist'};
5489: if ($env{'course.'.$cid.'.internal.selfenroll_approval'}) {
5490: $appon = ' checked="checked" ';
5491: $appoff = ' ';
5492: } else {
5493: $appon = ' ';
5494: $appoff = ' checked="checked" ';
5495: }
5496: $output .= '<label>'.
5497: '<input type="radio" name="selfenroll_approval" value="1"'.$appon.'/>'.
5498: &mt('Yes').'</label> <label>'.
5499: '<input type="radio" name="selfenroll_approval" value="0"'.$appoff.'/>'.
5500: &mt('No').'</label>';
5501: my %advhash = &Apache::lonnet::get_course_adv_roles($cid,1);
5502: my (@ccs,%notified);
1.322 raeburn 5503: my $ccrole = 'cc';
5504: if ($crstype eq 'Community') {
5505: $ccrole = 'co';
5506: }
5507: if ($advhash{$ccrole}) {
5508: @ccs = split(/,/,$advhash{$ccrole});
1.276 raeburn 5509: }
5510: if ($currnotified) {
5511: foreach my $current (split(/,/,$currnotified)) {
5512: $notified{$current} = 1;
5513: if (!grep(/^\Q$current\E$/,@ccs)) {
5514: push(@ccs,$current);
5515: }
5516: }
5517: }
5518: if (@ccs) {
1.277 raeburn 5519: $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 5520: &Apache::loncommon::start_data_table_row();
5521: my $count = 0;
5522: my $numcols = 4;
5523: foreach my $cc (sort(@ccs)) {
5524: my $notifyon;
5525: my ($ccuname,$ccudom) = split(/:/,$cc);
5526: if ($notified{$cc}) {
5527: $notifyon = ' checked="checked" ';
5528: }
5529: if ($count && !$count%$numcols) {
5530: $output .= &Apache::loncommon::end_data_table_row().
5531: &Apache::loncommon::start_data_table_row()
5532: }
5533: $output .= '<td><span class="LC_nobreak"><label>'.
5534: '<input type="checkbox" name="selfenroll_notify"'.$notifyon.' value="'.$cc.'" />'.
5535: &Apache::loncommon::plainname($ccuname,$ccudom).
5536: '</label></span></td>';
1.343 raeburn 5537: $count ++;
1.276 raeburn 5538: }
5539: my $rem = $count%$numcols;
5540: if ($rem) {
5541: my $emptycols = $numcols - $rem;
5542: for (my $i=0; $i<$emptycols; $i++) {
5543: $output .= '<td> </td>';
5544: }
5545: }
5546: $output .= &Apache::loncommon::end_data_table_row().
5547: &Apache::loncommon::end_data_table();
5548: }
5549: } elsif ($item eq 'limit') {
5550: my ($crslimit,$selflimit,$nolimit);
5551: my $cid = $env{'request.course.id'};
5552: my $currlim = $env{'course.'.$cid.'.internal.selfenroll_limit'};
5553: my $currcap = $env{'course.'.$cid.'.internal.selfenroll_cap'};
1.343 raeburn 5554: $nolimit = ' checked="checked" ';
1.276 raeburn 5555: if ($currlim eq 'allstudents') {
5556: $crslimit = ' checked="checked" ';
5557: $selflimit = ' ';
5558: $nolimit = ' ';
5559: } elsif ($currlim eq 'selfenrolled') {
5560: $crslimit = ' ';
5561: $selflimit = ' checked="checked" ';
5562: $nolimit = ' ';
5563: } else {
5564: $crslimit = ' ';
5565: $selflimit = ' ';
5566: }
5567: $output .= '<table><tr><td><label>'.
1.278 raeburn 5568: '<input type="radio" name="selfenroll_limit" value="none"'.$nolimit.'/>'.
1.276 raeburn 5569: &mt('No limit').'</label></td><td><label>'.
5570: '<input type="radio" name="selfenroll_limit" value="allstudents"'.$crslimit.'/>'.
5571: &mt('Limit by total students').'</label></td><td><label>'.
5572: '<input type="radio" name="selfenroll_limit" value="selfenrolled"'.$selflimit.'/>'.
5573: &mt('Limit by total self-enrolled students').
5574: '</td></tr><tr>'.
5575: '<td> </td><td colspan="2"><span class="LC_nobreak">'.
5576: (' 'x3).&mt('Maximum number allowed: ').
5577: '<input type="text" name="selfenroll_cap" size = "5" value="'.$currcap.'" /></td></tr></table>';
1.237 raeburn 5578: }
5579: $output .= &Apache::lonhtmlcommon::row_closure(1);
5580: }
5581: }
5582: $output .= &Apache::lonhtmlcommon::end_pick_box().
1.241 raeburn 5583: '<br /><input type="button" name="selfenrollconf" value="'
1.282 schafran 5584: .&mt('Save').'" onclick="validate_types(this.form);" />'
1.241 raeburn 5585: .'<input type="hidden" name="action" value="selfenroll" /></form>';
1.237 raeburn 5586: $r->print($output);
5587: return;
5588: }
5589:
1.256 raeburn 5590: sub visible_in_cat {
5591: my ($cdom,$cnum) = @_;
5592: my %domconf = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
5593: my ($cathash,%settable,@vismsgs,$cansetvis);
5594: my %visactions = &Apache::lonlocal::texthash(
1.316 bisitz 5595: vis => 'Your course/community currently appears in the Course/Community Catalog for this domain.',
1.256 raeburn 5596: 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 5597: miss => 'Your course/community does not currently appear in the Course/Community Catalog for this domain.',
1.256 raeburn 5598: yous => 'You should remedy this if you plan to allow self-enrollment, otherwise students will have difficulty finding your course.',
5599: 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 5600: make => 'Make any changes to self-enrollment settings below, click "Save", then take action to include the course in the Catalog:',
1.256 raeburn 5601: take => 'Take the following action to ensure the course appears in the Catalog:',
5602: dc_unhide => 'Ask a domain coordinator to change the "Exclude from course catalog" setting.',
5603: dc_addinst => 'Ask a domain coordinator to enable display the catalog of "Official courses (with institutional codes)".',
5604: dc_instcode => 'Ask a domain coordinator to assign an institutional code (if this is an official course).',
5605: dc_catalog => 'Ask a domain coordinator to enable or create at least one course category in the domain.',
5606: dc_categories => 'Ask a domain coordinator to create a hierarchy of categories and sub categories for courses in the domain.',
5607: 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',
5608: dc_addcat => 'Ask a domain coordinator to assign a category to the course.',
5609: );
1.347 raeburn 5610: $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>"');
5611: $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>"');
5612: $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 5613: if (ref($domconf{'coursecategories'}) eq 'HASH') {
5614: if ($domconf{'coursecategories'}{'togglecats'} eq 'crs') {
5615: $settable{'togglecats'} = 1;
5616: }
5617: if ($domconf{'coursecategories'}{'categorize'} eq 'crs') {
5618: $settable{'categorize'} = 1;
5619: }
5620: $cathash = $domconf{'coursecategories'}{'cats'};
5621: }
1.260 raeburn 5622: if ($settable{'togglecats'} && $settable{'categorize'}) {
1.256 raeburn 5623: $cansetvis = &mt('You are able to both assign a course category and choose to exclude this course from the catalog.');
5624: } elsif ($settable{'togglecats'}) {
5625: $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 5626: } elsif ($settable{'categorize'}) {
1.256 raeburn 5627: $cansetvis = &mt('You may assign a course category, but only a Domain Coordinator may choose to exclude this course from the catalog.');
5628: } else {
5629: $cansetvis = &mt('Only a Domain Coordinator may assign a course category or choose to exclude this course from the catalog.');
5630: }
5631:
5632: my %currsettings =
5633: &Apache::lonnet::get('environment',['hidefromcat','categories','internal.coursecode'],
5634: $cdom,$cnum);
5635: my $visible = 0;
5636: if ($currsettings{'internal.coursecode'} ne '') {
5637: if (ref($domconf{'coursecategories'}) eq 'HASH') {
5638: $cathash = $domconf{'coursecategories'}{'cats'};
5639: if (ref($cathash) eq 'HASH') {
5640: if ($cathash->{'instcode::0'} eq '') {
5641: push(@vismsgs,'dc_addinst');
5642: } else {
5643: $visible = 1;
5644: }
5645: } else {
5646: $visible = 1;
5647: }
5648: } else {
5649: $visible = 1;
5650: }
5651: } else {
5652: if (ref($cathash) eq 'HASH') {
5653: if ($cathash->{'instcode::0'} ne '') {
5654: push(@vismsgs,'dc_instcode');
5655: }
5656: } else {
5657: push(@vismsgs,'dc_instcode');
5658: }
5659: }
5660: if ($currsettings{'categories'} ne '') {
5661: my $cathash;
5662: if (ref($domconf{'coursecategories'}) eq 'HASH') {
5663: $cathash = $domconf{'coursecategories'}{'cats'};
5664: if (ref($cathash) eq 'HASH') {
5665: if (keys(%{$cathash}) == 0) {
5666: push(@vismsgs,'dc_catalog');
5667: } elsif ((keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} ne '')) {
5668: push(@vismsgs,'dc_categories');
5669: } else {
5670: my @currcategories = split('&',$currsettings{'categories'});
5671: my $matched = 0;
5672: foreach my $cat (@currcategories) {
5673: if ($cathash->{$cat} ne '') {
5674: $visible = 1;
5675: $matched = 1;
5676: last;
5677: }
5678: }
5679: if (!$matched) {
1.260 raeburn 5680: if ($settable{'categorize'}) {
1.256 raeburn 5681: push(@vismsgs,'chgcat');
5682: } else {
5683: push(@vismsgs,'dc_chgcat');
5684: }
5685: }
5686: }
5687: }
5688: }
5689: } else {
5690: if (ref($cathash) eq 'HASH') {
5691: if ((keys(%{$cathash}) > 1) ||
5692: (keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} eq '')) {
1.260 raeburn 5693: if ($settable{'categorize'}) {
1.256 raeburn 5694: push(@vismsgs,'addcat');
5695: } else {
5696: push(@vismsgs,'dc_addcat');
5697: }
5698: }
5699: }
5700: }
5701: if ($currsettings{'hidefromcat'} eq 'yes') {
5702: $visible = 0;
5703: if ($settable{'togglecats'}) {
5704: unshift(@vismsgs,'unhide');
5705: } else {
5706: unshift(@vismsgs,'dc_unhide')
5707: }
5708: }
5709: return ($visible,$cansetvis,\@vismsgs,\%visactions);
5710: }
5711:
1.241 raeburn 5712: sub new_selfenroll_dom_row {
5713: my ($newdom,$num) = @_;
5714: my $domdesc = &Apache::lonnet::domain($newdom);
5715: my $output;
5716: if ($domdesc ne '') {
5717: $output .= &Apache::loncommon::start_data_table_row()
5718: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').' <b>'.$domdesc
5719: .' ('.$newdom.')</b><input type="hidden" name="selfenroll_dom_'.$num
1.249 raeburn 5720: .'" value="'.$newdom.'" /></span><br />'
5721: .'<span class="LC_nobreak"><label><input type="checkbox" '
5722: .'name="selfenroll_activate" value="'.$num.'" '
5723: .'onchange="javascript:update_types('
5724: ."'selfenroll_activate','$num'".');" />'
5725: .&mt('Activate').'</label></span></td>';
1.241 raeburn 5726: my @currinsttypes;
5727: $output .= '<td>'.&mt('User types:').'<br />'
5728: .&selfenroll_inst_types($num,$newdom,\@currinsttypes).'</td>'
5729: .&Apache::loncommon::end_data_table_row();
5730: }
5731: return $output;
5732: }
5733:
5734: sub selfenroll_inst_types {
5735: my ($num,$currdom,$currinsttypes) = @_;
5736: my $output;
5737: my $numinrow = 4;
5738: my $count = 0;
5739: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($currdom);
1.247 raeburn 5740: my $othervalue = 'any';
1.241 raeburn 5741: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
1.251 raeburn 5742: if (keys(%{$usertypes}) > 0) {
1.247 raeburn 5743: $othervalue = 'other';
5744: }
1.241 raeburn 5745: $output .= '<table><tr>';
5746: foreach my $type (@{$types}) {
5747: if (($count > 0) && ($count%$numinrow == 0)) {
5748: $output .= '</tr><tr>';
5749: }
5750: if (defined($usertypes->{$type})) {
1.257 raeburn 5751: my $esc_type = &escape($type);
1.241 raeburn 5752: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.
1.257 raeburn 5753: $esc_type.'" ';
1.241 raeburn 5754: if (ref($currinsttypes) eq 'ARRAY') {
5755: if (@{$currinsttypes} > 0) {
1.249 raeburn 5756: if (grep(/^any$/,@{$currinsttypes})) {
5757: $output .= 'checked="checked"';
1.257 raeburn 5758: } elsif (grep(/^\Q$esc_type\E$/,@{$currinsttypes})) {
1.241 raeburn 5759: $output .= 'checked="checked"';
5760: }
1.249 raeburn 5761: } else {
5762: $output .= 'checked="checked"';
1.241 raeburn 5763: }
5764: }
5765: $output .= ' name="selfenroll_types_'.$num.'" />'.$usertypes->{$type}.'</label></span></td>';
5766: }
5767: $count ++;
5768: }
5769: if (($count > 0) && ($count%$numinrow == 0)) {
5770: $output .= '</tr><tr>';
5771: }
1.249 raeburn 5772: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.$othervalue.'"';
1.241 raeburn 5773: if (ref($currinsttypes) eq 'ARRAY') {
5774: if (@{$currinsttypes} > 0) {
1.249 raeburn 5775: if (grep(/^any$/,@{$currinsttypes})) {
5776: $output .= ' checked="checked"';
5777: } elsif ($othervalue eq 'other') {
5778: if (grep(/^\Q$othervalue\E$/,@{$currinsttypes})) {
5779: $output .= ' checked="checked"';
5780: }
1.241 raeburn 5781: }
1.249 raeburn 5782: } else {
5783: $output .= ' checked="checked"';
1.241 raeburn 5784: }
1.249 raeburn 5785: } else {
5786: $output .= ' checked="checked"';
1.241 raeburn 5787: }
5788: $output .= ' name="selfenroll_types_'.$num.'" />'.$othertitle.'</label></span></td></tr></table>';
5789: }
5790: return $output;
5791: }
5792:
1.237 raeburn 5793: sub selfenroll_date_forms {
5794: my ($startform,$endform) = @_;
5795: my $output .= &Apache::lonhtmlcommon::start_pick_box()."\n".
1.244 bisitz 5796: &Apache::lonhtmlcommon::row_title(&mt('Start date'),
1.237 raeburn 5797: 'LC_oddrow_value')."\n".
5798: $startform."\n".
5799: &Apache::lonhtmlcommon::row_closure(1).
1.244 bisitz 5800: &Apache::lonhtmlcommon::row_title(&mt('End date'),
1.237 raeburn 5801: 'LC_oddrow_value')."\n".
5802: $endform."\n".
5803: &Apache::lonhtmlcommon::row_closure(1).
5804: &Apache::lonhtmlcommon::end_pick_box();
5805: return $output;
5806: }
5807:
1.239 raeburn 5808: sub print_userchangelogs_display {
5809: my ($r,$context,$permission) = @_;
1.363 raeburn 5810: my $formname = 'rolelog';
5811: my ($username,$domain,$crstype,%roleslog);
5812: if ($context eq 'domain') {
5813: $domain = $env{'request.role.domain'};
5814: %roleslog=&Apache::lonnet::dump_dom('nohist_rolelog',$domain);
5815: } else {
5816: if ($context eq 'course') {
5817: $domain = $env{'course.'.$env{'request.course.id'}.'.domain'};
5818: $username = $env{'course.'.$env{'request.course.id'}.'.num'};
5819: $crstype = &Apache::loncommon::course_type();
5820: my %saveable_parameters = ('show' => 'scalar',);
5821: &Apache::loncommon::store_course_settings('roles_log',
5822: \%saveable_parameters);
5823: &Apache::loncommon::restore_course_settings('roles_log',
5824: \%saveable_parameters);
5825: } elsif ($context eq 'author') {
5826: $domain = $env{'user.domain'};
5827: if ($env{'request.role'} =~ m{^au\./\Q$domain\E/$}) {
5828: $username = $env{'user.name'};
5829: } else {
5830: undef($domain);
5831: }
5832: }
5833: if ($domain ne '' && $username ne '') {
5834: %roleslog=&Apache::lonnet::dump('nohist_rolelog',$domain,$username);
5835: }
5836: }
1.239 raeburn 5837: if ((keys(%roleslog))[0]=~/^error\:/) { undef(%roleslog); }
5838:
5839: # set defaults
5840: my $now = time();
5841: my $defstart = $now - (7*24*3600); #7 days ago
5842: my %defaults = (
5843: page => '1',
5844: show => '10',
5845: role => 'any',
5846: chgcontext => 'any',
5847: rolelog_start_date => $defstart,
5848: rolelog_end_date => $now,
5849: );
5850: my $more_records = 0;
5851:
5852: # set current
5853: my %curr;
5854: foreach my $item ('show','page','role','chgcontext') {
5855: $curr{$item} = $env{'form.'.$item};
5856: }
5857: my ($startdate,$enddate) =
5858: &Apache::lonuserutils::get_dates_from_form('rolelog_start_date','rolelog_end_date');
5859: $curr{'rolelog_start_date'} = $startdate;
5860: $curr{'rolelog_end_date'} = $enddate;
5861: foreach my $key (keys(%defaults)) {
5862: if ($curr{$key} eq '') {
5863: $curr{$key} = $defaults{$key};
5864: }
5865: }
1.248 raeburn 5866: my (%whodunit,%changed,$version);
5867: ($version) = ($r->dir_config('lonVersion') =~ /^([\d\.]+)\-/);
1.239 raeburn 5868: my ($minshown,$maxshown);
1.255 raeburn 5869: $minshown = 1;
1.239 raeburn 5870: my $count = 0;
5871: if ($curr{'show'} ne &mt('all')) {
5872: $maxshown = $curr{'page'} * $curr{'show'};
5873: if ($curr{'page'} > 1) {
5874: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
5875: }
5876: }
1.301 bisitz 5877:
1.327 raeburn 5878: # Form Header
5879: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
1.363 raeburn 5880: &role_display_filter($context,$formname,$domain,$username,\%curr,
5881: $version,$crstype));
1.327 raeburn 5882:
5883: # Create navigation
5884: my ($nav_script,$nav_links) = &userlogdisplay_nav($formname,\%curr,$more_records);
5885: my $showntableheader = 0;
5886:
5887: # Table Header
5888: my $tableheader =
5889: &Apache::loncommon::start_data_table_header_row()
5890: .'<th> </th>'
5891: .'<th>'.&mt('When').'</th>'
5892: .'<th>'.&mt('Who made the change').'</th>'
5893: .'<th>'.&mt('Changed User').'</th>'
1.363 raeburn 5894: .'<th>'.&mt('Role').'</th>';
5895:
5896: if ($context eq 'course') {
5897: $tableheader .= '<th>'.&mt('Section').'</th>';
5898: }
5899: $tableheader .=
5900: '<th>'.&mt('Context').'</th>'
1.327 raeburn 5901: .'<th>'.&mt('Start').'</th>'
5902: .'<th>'.&mt('End').'</th>'
5903: .&Apache::loncommon::end_data_table_header_row();
5904:
5905: # Display user change log data
1.239 raeburn 5906: foreach my $id (sort { $roleslog{$b}{'exe_time'}<=>$roleslog{$a}{'exe_time'} } (keys(%roleslog))) {
5907: next if (($roleslog{$id}{'exe_time'} < $curr{'rolelog_start_date'}) ||
5908: ($roleslog{$id}{'exe_time'} > $curr{'rolelog_end_date'}));
5909: if ($curr{'show'} ne &mt('all')) {
5910: if ($count >= $curr{'page'} * $curr{'show'}) {
5911: $more_records = 1;
5912: last;
5913: }
5914: }
5915: if ($curr{'role'} ne 'any') {
5916: next if ($roleslog{$id}{'logentry'}{'role'} ne $curr{'role'});
5917: }
5918: if ($curr{'chgcontext'} ne 'any') {
5919: if ($curr{'chgcontext'} eq 'selfenroll') {
5920: next if (!$roleslog{$id}{'logentry'}{'selfenroll'});
5921: } else {
5922: next if ($roleslog{$id}{'logentry'}{'context'} ne $curr{'chgcontext'});
5923: }
5924: }
5925: $count ++;
5926: next if ($count < $minshown);
1.327 raeburn 5927: unless ($showntableheader) {
5928: $r->print($nav_script
5929: .$nav_links
5930: .&Apache::loncommon::start_data_table()
5931: .$tableheader);
5932: $r->rflush();
5933: $showntableheader = 1;
5934: }
1.239 raeburn 5935: if ($whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} eq '') {
5936: $whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} =
5937: &Apache::loncommon::plainname($roleslog{$id}{'exe_uname'},$roleslog{$id}{'exe_udom'});
5938: }
5939: if ($changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} eq '') {
5940: $changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} =
5941: &Apache::loncommon::plainname($roleslog{$id}{'uname'},$roleslog{$id}{'udom'});
5942: }
5943: my $sec = $roleslog{$id}{'logentry'}{'section'};
5944: if ($sec eq '') {
5945: $sec = &mt('None');
5946: }
5947: my ($rolestart,$roleend);
5948: if ($roleslog{$id}{'delflag'}) {
5949: $rolestart = &mt('deleted');
5950: $roleend = &mt('deleted');
5951: } else {
5952: $rolestart = $roleslog{$id}{'logentry'}{'start'};
5953: $roleend = $roleslog{$id}{'logentry'}{'end'};
5954: if ($rolestart eq '' || $rolestart == 0) {
5955: $rolestart = &mt('No start date');
5956: } else {
5957: $rolestart = &Apache::lonlocal::locallocaltime($rolestart);
5958: }
5959: if ($roleend eq '' || $roleend == 0) {
5960: $roleend = &mt('No end date');
5961: } else {
5962: $roleend = &Apache::lonlocal::locallocaltime($roleend);
5963: }
5964: }
5965: my $chgcontext = $roleslog{$id}{'logentry'}{'context'};
5966: if ($roleslog{$id}{'logentry'}{'selfenroll'}) {
5967: $chgcontext = 'selfenroll';
5968: }
1.363 raeburn 5969: my %lt = &rolechg_contexts($context,$crstype);
1.239 raeburn 5970: if ($chgcontext ne '' && $lt{$chgcontext} ne '') {
5971: $chgcontext = $lt{$chgcontext};
5972: }
1.327 raeburn 5973: $r->print(
1.301 bisitz 5974: &Apache::loncommon::start_data_table_row()
5975: .'<td>'.$count.'</td>'
5976: .'<td>'.&Apache::lonlocal::locallocaltime($roleslog{$id}{'exe_time'}).'</td>'
5977: .'<td>'.$whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}}.'</td>'
5978: .'<td>'.$changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}}.'</td>'
1.363 raeburn 5979: .'<td>'.&Apache::lonnet::plaintext($roleslog{$id}{'logentry'}{'role'},$crstype).'</td>');
5980: if ($context eq 'course') {
5981: $r->print('<td>'.$sec.'</td>');
5982: }
5983: $r->print(
5984: '<td>'.$chgcontext.'</td>'
1.301 bisitz 5985: .'<td>'.$rolestart.'</td>'
5986: .'<td>'.$roleend.'</td>'
1.327 raeburn 5987: .&Apache::loncommon::end_data_table_row()."\n");
1.301 bisitz 5988: }
5989:
1.327 raeburn 5990: if ($showntableheader) { # Table footer, if content displayed above
5991: $r->print(&Apache::loncommon::end_data_table()
5992: .$nav_links);
5993: } else { # No content displayed above
1.301 bisitz 5994: $r->print('<p class="LC_info">'
5995: .&mt('There are no records to display.')
5996: .'</p>'
5997: );
1.239 raeburn 5998: }
1.301 bisitz 5999:
1.327 raeburn 6000: # Form Footer
6001: $r->print(
6002: '<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
6003: .'<input type="hidden" name="action" value="changelogs" />'
6004: .'</form>');
6005: return;
6006: }
1.301 bisitz 6007:
1.327 raeburn 6008: sub userlogdisplay_nav {
6009: my ($formname,$curr,$more_records) = @_;
6010: my ($nav_script,$nav_links);
6011: if (ref($curr) eq 'HASH') {
6012: # Create Navigation:
6013: # Navigation Script
6014: $nav_script = <<"ENDSCRIPT";
1.239 raeburn 6015: <script type="text/javascript">
1.301 bisitz 6016: // <![CDATA[
1.239 raeburn 6017: function chgPage(caller) {
6018: if (caller == 'previous') {
6019: document.$formname.page.value --;
6020: }
6021: if (caller == 'next') {
6022: document.$formname.page.value ++;
6023: }
1.327 raeburn 6024: document.$formname.submit();
1.239 raeburn 6025: return;
6026: }
1.301 bisitz 6027: // ]]>
1.239 raeburn 6028: </script>
6029: ENDSCRIPT
1.327 raeburn 6030: # Navigation Buttons
6031: $nav_links = '<p>';
6032: if (($curr->{'page'} > 1) || ($more_records)) {
6033: if ($curr->{'page'} > 1) {
6034: $nav_links .= '<input type="button"'
6035: .' onclick="javascript:chgPage('."'previous'".');"'
6036: .' value="'.&mt('Previous [_1] changes',$curr->{'show'})
6037: .'" /> ';
6038: }
6039: if ($more_records) {
6040: $nav_links .= '<input type="button"'
6041: .' onclick="javascript:chgPage('."'next'".');"'
6042: .' value="'.&mt('Next [_1] changes',$curr->{'show'})
6043: .'" />';
6044: }
1.301 bisitz 6045: }
1.327 raeburn 6046: $nav_links .= '</p>';
1.301 bisitz 6047: }
1.327 raeburn 6048: return ($nav_script,$nav_links);
1.239 raeburn 6049: }
6050:
6051: sub role_display_filter {
1.363 raeburn 6052: my ($context,$formname,$cdom,$cnum,$curr,$version,$crstype) = @_;
6053: my $lctype;
6054: if ($context eq 'course') {
6055: $lctype = lc($crstype);
6056: }
1.239 raeburn 6057: my $nolink = 1;
6058: my $output = '<table><tr><td valign="top">'.
1.301 bisitz 6059: '<span class="LC_nobreak"><b>'.&mt('Changes/page:').'</b></span><br />'.
1.239 raeburn 6060: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
6061: (&mt('all'),5,10,20,50,100,1000,10000)).
6062: '</td><td> </td>';
6063: my $startform =
6064: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_start_date',
6065: $curr->{'rolelog_start_date'},undef,
6066: undef,undef,undef,undef,undef,undef,$nolink);
6067: my $endform =
6068: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_end_date',
6069: $curr->{'rolelog_end_date'},undef,
6070: undef,undef,undef,undef,undef,undef,$nolink);
1.363 raeburn 6071: my %lt = &rolechg_contexts($context,$crstype);
1.301 bisitz 6072: $output .= '<td valign="top"><b>'.&mt('Window during which changes occurred:').'</b><br />'.
6073: '<table><tr><td>'.&mt('After:').
6074: '</td><td>'.$startform.'</td></tr>'.
6075: '<tr><td>'.&mt('Before:').'</td>'.
6076: '<td>'.$endform.'</td></tr></table>'.
6077: '</td>'.
6078: '<td> </td>'.
1.239 raeburn 6079: '<td valign="top"><b>'.&mt('Role:').'</b><br />'.
6080: '<select name="role"><option value="any"';
6081: if ($curr->{'role'} eq 'any') {
6082: $output .= ' selected="selected"';
6083: }
6084: $output .= '>'.&mt('Any').'</option>'."\n";
1.363 raeburn 6085: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
1.239 raeburn 6086: foreach my $role (@roles) {
6087: my $plrole;
6088: if ($role eq 'cr') {
6089: $plrole = &mt('Custom Role');
6090: } else {
1.318 raeburn 6091: $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.239 raeburn 6092: }
6093: my $selstr = '';
6094: if ($role eq $curr->{'role'}) {
6095: $selstr = ' selected="selected"';
6096: }
6097: $output .= ' <option value="'.$role.'"'.$selstr.'>'.$plrole.'</option>';
6098: }
1.301 bisitz 6099: $output .= '</select></td>'.
6100: '<td> </td>'.
6101: '<td valign="top"><b>'.
1.239 raeburn 6102: &mt('Context:').'</b><br /><select name="chgcontext">';
1.363 raeburn 6103: my @posscontexts;
6104: if ($context eq 'course') {
1.376 raeburn 6105: @posscontexts = ('any','automated','updatenow','createcourse','course','domain','selfenroll','requestcourses');
1.363 raeburn 6106: } elsif ($context eq 'domain') {
6107: @posscontexts = ('any','domain','requestauthor','domconfig','server');
6108: } else {
6109: @posscontexts = ('any','author','domain');
6110: }
6111: foreach my $chgtype (@posscontexts) {
1.239 raeburn 6112: my $selstr = '';
6113: if ($curr->{'chgcontext'} eq $chgtype) {
1.301 bisitz 6114: $selstr = ' selected="selected"';
1.239 raeburn 6115: }
1.363 raeburn 6116: if ($context eq 'course') {
1.376 raeburn 6117: if (($chgtype eq 'automated') || ($chgtype eq 'updatenow')) {
1.363 raeburn 6118: next if (!&Apache::lonnet::auto_run($cnum,$cdom));
6119: }
1.239 raeburn 6120: }
6121: $output .= '<option value="'.$chgtype.'"'.$selstr.'>'.$lt{$chgtype}.'</option>'."\n";
1.248 raeburn 6122: }
1.303 bisitz 6123: $output .= '</select></td>'
6124: .'</tr></table>';
6125:
6126: # Update Display button
6127: $output .= '<p>'
6128: .'<input type="submit" value="'.&mt('Update Display').'" />'
6129: .'</p>';
6130:
6131: # Server version info
1.363 raeburn 6132: my $needsrev = '2.11.0';
6133: if ($context eq 'course') {
6134: $needsrev = '2.7.0';
6135: }
6136:
1.303 bisitz 6137: $output .= '<p class="LC_info">'
6138: .&mt('Only changes made from servers running LON-CAPA [_1] or later are displayed.'
1.363 raeburn 6139: ,$needsrev);
1.248 raeburn 6140: if ($version) {
1.303 bisitz 6141: $output .= ' '.&mt('This LON-CAPA server is version [_1]',$version);
6142: }
6143: $output .= '</p><hr />';
1.239 raeburn 6144: return $output;
6145: }
6146:
6147: sub rolechg_contexts {
1.363 raeburn 6148: my ($context,$crstype) = @_;
6149: my %lt;
6150: if ($context eq 'course') {
6151: %lt = &Apache::lonlocal::texthash (
1.239 raeburn 6152: any => 'Any',
1.376 raeburn 6153: automated => 'Automated Enrollment',
1.239 raeburn 6154: updatenow => 'Roster Update',
6155: createcourse => 'Course Creation',
6156: course => 'User Management in course',
6157: domain => 'User Management in domain',
1.313 raeburn 6158: selfenroll => 'Self-enrolled',
1.318 raeburn 6159: requestcourses => 'Course Request',
1.239 raeburn 6160: );
1.363 raeburn 6161: if ($crstype eq 'Community') {
6162: $lt{'createcourse'} = &mt('Community Creation');
6163: $lt{'course'} = &mt('User Management in community');
6164: $lt{'requestcourses'} = &mt('Community Request');
6165: }
6166: } elsif ($context eq 'domain') {
6167: %lt = &Apache::lonlocal::texthash (
6168: any => 'Any',
6169: domain => 'User Management in domain',
6170: requestauthor => 'Authoring Request',
6171: server => 'Command line script (DC role)',
6172: domconfig => 'Self-enrolled',
6173: );
6174: } else {
6175: %lt = &Apache::lonlocal::texthash (
6176: any => 'Any',
6177: domain => 'User Management in domain',
6178: author => 'User Management by author',
6179: );
6180: }
1.239 raeburn 6181: return %lt;
6182: }
6183:
1.27 matthew 6184: #-------------------------------------------------- functions for &phase_two
1.160 raeburn 6185: sub user_search_result {
1.221 raeburn 6186: my ($context,$srch) = @_;
1.160 raeburn 6187: my %allhomes;
6188: my %inst_matches;
6189: my %srch_results;
1.181 raeburn 6190: my ($response,$currstate,$forcenewuser,$dirsrchres);
1.183 raeburn 6191: $srch->{'srchterm'} =~ s/\s+/ /g;
1.176 raeburn 6192: if ($srch->{'srchby'} !~ /^(uname|lastname|lastfirst)$/) {
1.160 raeburn 6193: $response = &mt('Invalid search.');
6194: }
6195: if ($srch->{'srchin'} !~ /^(crs|dom|alc|instd)$/) {
6196: $response = &mt('Invalid search.');
6197: }
1.177 raeburn 6198: if ($srch->{'srchtype'} !~ /^(exact|contains|begins)$/) {
1.160 raeburn 6199: $response = &mt('Invalid search.');
6200: }
6201: if ($srch->{'srchterm'} eq '') {
6202: $response = &mt('You must enter a search term.');
6203: }
1.183 raeburn 6204: if ($srch->{'srchterm'} =~ /^\s+$/) {
6205: $response = &mt('Your search term must contain more than just spaces.');
6206: }
1.160 raeburn 6207: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'instd')) {
6208: if (($srch->{'srchdomain'} eq '') ||
1.163 albertel 6209: ! (&Apache::lonnet::domain($srch->{'srchdomain'}))) {
1.160 raeburn 6210: $response = &mt('You must specify a valid domain when searching in a domain or institutional directory.')
6211: }
6212: }
6213: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs') ||
6214: ($srch->{'srchin'} eq 'alc')) {
1.176 raeburn 6215: if ($srch->{'srchby'} eq 'uname') {
1.243 raeburn 6216: my $unamecheck = $srch->{'srchterm'};
6217: if ($srch->{'srchtype'} eq 'contains') {
6218: if ($unamecheck !~ /^\w/) {
6219: $unamecheck = 'a'.$unamecheck;
6220: }
6221: }
6222: if ($unamecheck !~ /^$match_username$/) {
1.176 raeburn 6223: $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
6224: }
1.160 raeburn 6225: }
6226: }
1.180 raeburn 6227: if ($response ne '') {
6228: $response = '<span class="LC_warning">'.$response.'</span>';
6229: }
1.160 raeburn 6230: if ($srch->{'srchin'} eq 'instd') {
6231: my $instd_chk = &directorysrch_check($srch);
6232: if ($instd_chk ne 'ok') {
1.180 raeburn 6233: $response = '<span class="LC_warning">'.$instd_chk.'</span>'.
6234: '<br />'.&mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').'<br /><br />';
1.160 raeburn 6235: }
6236: }
6237: if ($response ne '') {
1.180 raeburn 6238: return ($currstate,$response);
1.160 raeburn 6239: }
6240: if ($srch->{'srchby'} eq 'uname') {
6241: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs')) {
6242: if ($env{'form.forcenew'}) {
6243: if ($srch->{'srchdomain'} ne $env{'request.role.domain'}) {
6244: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
6245: if ($uhome eq 'no_host') {
6246: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
1.180 raeburn 6247: my $showdom = &display_domain_info($env{'request.role.domain'});
6248: $response = &mt('New users can only be created in the domain to which your current role belongs - [_1].',$showdom);
1.160 raeburn 6249: } else {
1.179 raeburn 6250: $currstate = 'modify';
1.160 raeburn 6251: }
6252: } else {
1.179 raeburn 6253: $currstate = 'modify';
1.160 raeburn 6254: }
6255: } else {
6256: if ($srch->{'srchin'} eq 'dom') {
1.162 raeburn 6257: if ($srch->{'srchtype'} eq 'exact') {
6258: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
6259: if ($uhome eq 'no_host') {
1.179 raeburn 6260: ($currstate,$response,$forcenewuser) =
1.221 raeburn 6261: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 6262: } else {
1.179 raeburn 6263: $currstate = 'modify';
1.310 raeburn 6264: my $uname = $srch->{'srchterm'};
6265: my $udom = $srch->{'srchdomain'};
6266: $srch_results{$uname.':'.$udom} =
6267: { &Apache::lonnet::get('environment',
6268: ['firstname',
6269: 'lastname',
6270: 'permanentemail'],
6271: $udom,$uname)
6272: };
1.162 raeburn 6273: }
6274: } else {
6275: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 6276: ($currstate,$response,$forcenewuser) =
1.221 raeburn 6277: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 6278: }
6279: } else {
1.167 albertel 6280: my $courseusers = &get_courseusers();
1.162 raeburn 6281: if ($srch->{'srchtype'} eq 'exact') {
1.167 albertel 6282: if (exists($courseusers->{$srch->{'srchterm'}.':'.$srch->{'srchdomain'}})) {
1.179 raeburn 6283: $currstate = 'modify';
1.162 raeburn 6284: } else {
1.179 raeburn 6285: ($currstate,$response,$forcenewuser) =
1.221 raeburn 6286: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 6287: }
1.160 raeburn 6288: } else {
1.167 albertel 6289: foreach my $user (keys(%$courseusers)) {
1.162 raeburn 6290: my ($cuname,$cudomain) = split(/:/,$user);
6291: if ($cudomain eq $srch->{'srchdomain'}) {
1.177 raeburn 6292: my $matched = 0;
6293: if ($srch->{'srchtype'} eq 'begins') {
6294: if ($cuname =~ /^\Q$srch->{'srchterm'}\E/i) {
6295: $matched = 1;
6296: }
6297: } else {
6298: if ($cuname =~ /\Q$srch->{'srchterm'}\E/i) {
6299: $matched = 1;
6300: }
6301: }
6302: if ($matched) {
1.167 albertel 6303: $srch_results{$user} =
6304: {&Apache::lonnet::get('environment',
6305: ['firstname',
6306: 'lastname',
1.194 albertel 6307: 'permanentemail'],
6308: $cudomain,$cuname)};
1.162 raeburn 6309: }
6310: }
6311: }
1.179 raeburn 6312: ($currstate,$response,$forcenewuser) =
1.221 raeburn 6313: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 6314: }
6315: }
6316: }
6317: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 6318: $currstate = 'query';
1.160 raeburn 6319: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 6320: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
6321: if ($dirsrchres eq 'ok') {
6322: ($currstate,$response,$forcenewuser) =
1.221 raeburn 6323: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 6324: } else {
6325: my $showdom = &display_domain_info($srch->{'srchdomain'});
6326: $response = '<span class="LC_warning">'.
6327: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
6328: '</span><br />'.
6329: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
6330: '<br /><br />';
6331: }
1.160 raeburn 6332: }
6333: } else {
6334: if ($srch->{'srchin'} eq 'dom') {
6335: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 6336: ($currstate,$response,$forcenewuser) =
1.221 raeburn 6337: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 6338: } elsif ($srch->{'srchin'} eq 'crs') {
1.167 albertel 6339: my $courseusers = &get_courseusers();
6340: foreach my $user (keys(%$courseusers)) {
1.160 raeburn 6341: my ($uname,$udom) = split(/:/,$user);
6342: my %names = &Apache::loncommon::getnames($uname,$udom);
6343: my %emails = &Apache::loncommon::getemails($uname,$udom);
6344: if ($srch->{'srchby'} eq 'lastname') {
6345: if ((($srch->{'srchtype'} eq 'exact') &&
6346: ($names{'lastname'} eq $srch->{'srchterm'})) ||
1.177 raeburn 6347: (($srch->{'srchtype'} eq 'begins') &&
6348: ($names{'lastname'} =~ /^\Q$srch->{'srchterm'}\E/i)) ||
1.160 raeburn 6349: (($srch->{'srchtype'} eq 'contains') &&
6350: ($names{'lastname'} =~ /\Q$srch->{'srchterm'}\E/i))) {
6351: $srch_results{$user} = {firstname => $names{'firstname'},
6352: lastname => $names{'lastname'},
6353: permanentemail => $emails{'permanentemail'},
6354: };
6355: }
6356: } elsif ($srch->{'srchby'} eq 'lastfirst') {
6357: my ($srchlast,$srchfirst) = split(/,/,$srch->{'srchterm'});
1.177 raeburn 6358: $srchlast =~ s/\s+$//;
6359: $srchfirst =~ s/^\s+//;
1.160 raeburn 6360: if ($srch->{'srchtype'} eq 'exact') {
6361: if (($names{'lastname'} eq $srchlast) &&
6362: ($names{'firstname'} eq $srchfirst)) {
6363: $srch_results{$user} = {firstname => $names{'firstname'},
6364: lastname => $names{'lastname'},
6365: permanentemail => $emails{'permanentemail'},
6366:
6367: };
6368: }
1.177 raeburn 6369: } elsif ($srch->{'srchtype'} eq 'begins') {
6370: if (($names{'lastname'} =~ /^\Q$srchlast\E/i) &&
6371: ($names{'firstname'} =~ /^\Q$srchfirst\E/i)) {
6372: $srch_results{$user} = {firstname => $names{'firstname'},
6373: lastname => $names{'lastname'},
6374: permanentemail => $emails{'permanentemail'},
6375: };
6376: }
6377: } else {
1.160 raeburn 6378: if (($names{'lastname'} =~ /\Q$srchlast\E/i) &&
6379: ($names{'firstname'} =~ /\Q$srchfirst\E/i)) {
6380: $srch_results{$user} = {firstname => $names{'firstname'},
6381: lastname => $names{'lastname'},
6382: permanentemail => $emails{'permanentemail'},
6383: };
6384: }
6385: }
6386: }
6387: }
1.179 raeburn 6388: ($currstate,$response,$forcenewuser) =
1.221 raeburn 6389: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 6390: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 6391: $currstate = 'query';
1.160 raeburn 6392: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 6393: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
6394: if ($dirsrchres eq 'ok') {
6395: ($currstate,$response,$forcenewuser) =
1.221 raeburn 6396: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 6397: } else {
6398: my $showdom = &display_domain_info($srch->{'srchdomain'}); $response = '<span class="LC_warning">'.
6399: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
6400: '</span><br />'.
6401: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
6402: '<br /><br />';
6403: }
1.160 raeburn 6404: }
6405: }
1.179 raeburn 6406: return ($currstate,$response,$forcenewuser,\%srch_results);
1.160 raeburn 6407: }
6408:
6409: sub directorysrch_check {
6410: my ($srch) = @_;
6411: my $can_search = 0;
6412: my $response;
6413: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
6414: ['directorysrch'],$srch->{'srchdomain'});
1.180 raeburn 6415: my $showdom = &display_domain_info($srch->{'srchdomain'});
1.160 raeburn 6416: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
6417: if (!$dom_inst_srch{'directorysrch'}{'available'}) {
1.180 raeburn 6418: return &mt('Institutional directory search is not available in domain: [_1]',$showdom);
1.160 raeburn 6419: }
6420: if ($dom_inst_srch{'directorysrch'}{'localonly'}) {
6421: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
1.180 raeburn 6422: return &mt('Institutional directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
1.160 raeburn 6423: }
6424: my @usertypes = split(/:/,$env{'environment.inststatus'});
6425: if (!@usertypes) {
6426: push(@usertypes,'default');
6427: }
6428: if (ref($dom_inst_srch{'directorysrch'}{'cansearch'}) eq 'ARRAY') {
6429: foreach my $type (@usertypes) {
6430: if (grep(/^\Q$type\E$/,@{$dom_inst_srch{'directorysrch'}{'cansearch'}})) {
6431: $can_search = 1;
6432: last;
6433: }
6434: }
6435: }
6436: if (!$can_search) {
6437: my ($insttypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($srch->{'srchdomain'});
6438: my @longtypes;
6439: foreach my $item (@usertypes) {
1.229 raeburn 6440: if (defined($insttypes->{$item})) {
6441: push (@longtypes,$insttypes->{$item});
6442: } elsif ($item eq 'default') {
6443: push (@longtypes,&mt('other'));
6444: }
1.160 raeburn 6445: }
6446: my $insttype_str = join(', ',@longtypes);
1.180 raeburn 6447: return &mt('Institutional directory search in domain: [_1] is not available to your user type: ',$showdom).$insttype_str;
1.229 raeburn 6448: }
1.160 raeburn 6449: } else {
6450: $can_search = 1;
6451: }
6452: } else {
1.180 raeburn 6453: return &mt('Institutional directory search has not been configured for domain: [_1]',$showdom);
1.160 raeburn 6454: }
6455: my %longtext = &Apache::lonlocal::texthash (
1.167 albertel 6456: uname => 'username',
1.160 raeburn 6457: lastfirst => 'last name, first name',
1.167 albertel 6458: lastname => 'last name',
1.172 raeburn 6459: contains => 'contains',
1.178 raeburn 6460: exact => 'as exact match to',
6461: begins => 'begins with',
1.160 raeburn 6462: );
6463: if ($can_search) {
6464: if (ref($dom_inst_srch{'directorysrch'}{'searchby'}) eq 'ARRAY') {
6465: if (!grep(/^\Q$srch->{'srchby'}\E$/,@{$dom_inst_srch{'directorysrch'}{'searchby'}})) {
1.180 raeburn 6466: return &mt('Institutional directory search in domain: [_1] is not available for searching by "[_2]"',$showdom,$longtext{$srch->{'srchby'}});
1.160 raeburn 6467: }
6468: } else {
1.180 raeburn 6469: return &mt('Institutional directory search in domain: [_1] is not available.', $showdom);
1.160 raeburn 6470: }
6471: }
6472: if ($can_search) {
1.178 raeburn 6473: if (ref($dom_inst_srch{'directorysrch'}{'searchtypes'}) eq 'ARRAY') {
6474: if (grep(/^\Q$srch->{'srchtype'}\E/,@{$dom_inst_srch{'directorysrch'}{'searchtypes'}})) {
6475: return 'ok';
6476: } else {
1.180 raeburn 6477: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 6478: }
6479: } else {
6480: if ((($dom_inst_srch{'directorysrch'}{'searchtypes'} eq 'specify') &&
6481: ($srch->{'srchtype'} eq 'exact' || $srch->{'srchtype'} eq 'contains')) ||
6482: ($dom_inst_srch{'directorysrch'}{'searchtypes'} eq $srch->{'srchtype'})) {
6483: return 'ok';
6484: } else {
1.180 raeburn 6485: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 6486: }
1.160 raeburn 6487: }
6488: }
6489: }
6490:
6491: sub get_courseusers {
6492: my %advhash;
1.167 albertel 6493: my $classlist = &Apache::loncoursedata::get_classlist();
1.160 raeburn 6494: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles();
6495: foreach my $role (sort(keys(%coursepersonnel))) {
6496: foreach my $user (split(/\,/,$coursepersonnel{$role})) {
1.167 albertel 6497: if (!exists($classlist->{$user})) {
6498: $classlist->{$user} = [];
6499: }
1.160 raeburn 6500: }
6501: }
1.167 albertel 6502: return $classlist;
1.160 raeburn 6503: }
6504:
6505: sub build_search_response {
1.221 raeburn 6506: my ($context,$srch,%srch_results) = @_;
1.179 raeburn 6507: my ($currstate,$response,$forcenewuser);
1.160 raeburn 6508: my %names = (
1.330 bisitz 6509: 'uname' => 'username',
6510: 'lastname' => 'last name',
1.160 raeburn 6511: 'lastfirst' => 'last name, first name',
1.330 bisitz 6512: 'crs' => 'this course',
6513: 'dom' => 'LON-CAPA domain',
6514: 'instd' => 'the institutional directory for domain',
1.160 raeburn 6515: );
6516:
6517: my %single = (
1.180 raeburn 6518: begins => 'A match',
1.160 raeburn 6519: contains => 'A match',
1.180 raeburn 6520: exact => 'An exact match',
1.160 raeburn 6521: );
6522: my %nomatch = (
1.180 raeburn 6523: begins => 'No match',
1.160 raeburn 6524: contains => 'No match',
1.180 raeburn 6525: exact => 'No exact match',
1.160 raeburn 6526: );
6527: if (keys(%srch_results) > 1) {
1.179 raeburn 6528: $currstate = 'select';
1.160 raeburn 6529: } else {
6530: if (keys(%srch_results) == 1) {
1.179 raeburn 6531: $currstate = 'modify';
1.180 raeburn 6532: $response = &mt("$single{$srch->{'srchtype'}} was found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}.",$srch->{'srchterm'});
6533: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 6534: $response .= ': '.&display_domain_info($srch->{'srchdomain'});
1.180 raeburn 6535: }
1.330 bisitz 6536: } else { # Search has nothing found. Prepare message to user.
6537: $response = '<span class="LC_warning">';
1.180 raeburn 6538: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 6539: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}: [_2]",
6540: '<b>'.$srch->{'srchterm'}.'</b>',
6541: &display_domain_info($srch->{'srchdomain'}));
6542: } else {
6543: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}.",
6544: '<b>'.$srch->{'srchterm'}.'</b>');
1.180 raeburn 6545: }
6546: $response .= '</span>';
1.330 bisitz 6547:
1.160 raeburn 6548: if ($srch->{'srchin'} ne 'alc') {
6549: $forcenewuser = 1;
6550: my $cansrchinst = 0;
6551: if ($srch->{'srchdomain'}) {
6552: my %domconfig = &Apache::lonnet::get_dom('configuration',['directorysrch'],$srch->{'srchdomain'});
6553: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
6554: if ($domconfig{'directorysrch'}{'available'}) {
6555: $cansrchinst = 1;
6556: }
6557: }
6558: }
1.180 raeburn 6559: if ((($srch->{'srchby'} eq 'lastfirst') ||
6560: ($srch->{'srchby'} eq 'lastname')) &&
6561: ($srch->{'srchin'} eq 'dom')) {
6562: if ($cansrchinst) {
6563: $response .= '<br />'.&mt('You may want to broaden your search to a search of the institutional directory for the domain.');
1.160 raeburn 6564: }
6565: }
1.180 raeburn 6566: if ($srch->{'srchin'} eq 'crs') {
6567: $response .= '<br />'.&mt('You may want to broaden your search to the selected LON-CAPA domain.');
6568: }
6569: }
1.305 raeburn 6570: my $createdom = $env{'request.role.domain'};
6571: if ($context eq 'requestcrs') {
6572: if ($env{'form.coursedom'} ne '') {
6573: $createdom = $env{'form.coursedom'};
6574: }
6575: }
6576: if (!($srch->{'srchby'} eq 'uname' && $srch->{'srchin'} eq 'dom' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchdomain'} eq $createdom)) {
1.221 raeburn 6577: my $cancreate =
1.305 raeburn 6578: &Apache::lonuserutils::can_create_user($createdom,$context);
6579: my $targetdom = '<span class="LC_cusr_emph">'.$createdom.'</span>';
1.221 raeburn 6580: if ($cancreate) {
1.305 raeburn 6581: my $showdom = &display_domain_info($createdom);
1.266 bisitz 6582: $response .= '<br /><br />'
6583: .'<b>'.&mt('To add a new user:').'</b>'
1.305 raeburn 6584: .'<br />';
6585: if ($context eq 'requestcrs') {
6586: $response .= &mt("(You can only define new users in the new course's domain - [_1])",$targetdom);
6587: } else {
6588: $response .= &mt("(You can only create new users in your current role's domain - [_1])",$targetdom);
6589: }
6590: $response .='<ul><li>'
1.266 bisitz 6591: .&mt("Set 'Domain/institution to search' to: [_1]",'<span class="LC_cusr_emph">'.$showdom.'</span>')
6592: .'</li><li>'
6593: .&mt("Set 'Search criteria' to: [_1]username is ..... in selected LON-CAPA domain[_2]",'<span class="LC_cusr_emph">','</span>')
6594: .'</li><li>'
6595: .&mt('Provide the proposed username')
6596: .'</li><li>'
6597: .&mt("Click 'Search'")
6598: .'</li></ul><br />';
1.221 raeburn 6599: } else {
6600: my $helplink = ' href="javascript:helpMenu('."'display'".')"';
1.305 raeburn 6601: $response .= '<br /><br />';
6602: if ($context eq 'requestcrs') {
1.314 raeburn 6603: $response .= &mt("You are not authorized to define new users in the new course's domain - [_1].",$targetdom);
1.305 raeburn 6604: } else {
6605: $response .= &mt("You are not authorized to create new users in your current role's domain - [_1].",$targetdom);
6606: }
6607: $response .= '<br />'
6608: .&mt('Please contact the [_1]helpdesk[_2] if you need to create a new user.'
1.266 bisitz 6609: ,' <a'.$helplink.'>'
6610: ,'</a>')
1.305 raeburn 6611: .'<br /><br />';
1.221 raeburn 6612: }
1.160 raeburn 6613: }
6614: }
6615: }
1.179 raeburn 6616: return ($currstate,$response,$forcenewuser);
1.160 raeburn 6617: }
6618:
1.180 raeburn 6619: sub display_domain_info {
6620: my ($dom) = @_;
6621: my $output = $dom;
6622: if ($dom ne '') {
6623: my $domdesc = &Apache::lonnet::domain($dom,'description');
6624: if ($domdesc ne '') {
6625: $output .= ' <span class="LC_cusr_emph">('.$domdesc.')</span>';
6626: }
6627: }
6628: return $output;
6629: }
6630:
1.160 raeburn 6631: sub crumb_utilities {
6632: my %elements = (
6633: crtuser => {
6634: srchterm => 'text',
1.172 raeburn 6635: srchin => 'selectbox',
1.160 raeburn 6636: srchby => 'selectbox',
6637: srchtype => 'selectbox',
6638: srchdomain => 'selectbox',
6639: },
1.207 raeburn 6640: crtusername => {
6641: srchterm => 'text',
6642: srchdomain => 'selectbox',
6643: },
1.160 raeburn 6644: docustom => {
6645: rolename => 'selectbox',
6646: newrolename => 'textbox',
6647: },
1.179 raeburn 6648: studentform => {
6649: srchterm => 'text',
6650: srchin => 'selectbox',
6651: srchby => 'selectbox',
6652: srchtype => 'selectbox',
6653: srchdomain => 'selectbox',
6654: },
1.160 raeburn 6655: );
6656:
6657: my $jsback .= qq|
6658: function backPage(formname,prevphase,prevstate) {
1.211 raeburn 6659: if (typeof prevphase == 'undefined') {
6660: formname.phase.value = '';
6661: }
6662: else {
6663: formname.phase.value = prevphase;
6664: }
6665: if (typeof prevstate == 'undefined') {
6666: formname.currstate.value = '';
6667: }
6668: else {
6669: formname.currstate.value = prevstate;
6670: }
1.160 raeburn 6671: formname.submit();
6672: }
6673: |;
6674: return ($jsback,\%elements);
6675: }
6676:
1.26 matthew 6677: sub course_level_table {
1.375 raeburn 6678: my ($inccourses,$showcredits,$defaultcredits) = @_;
6679: return unless (ref($inccourses) eq 'HASH');
1.26 matthew 6680: my $table = '';
1.62 www 6681: # Custom Roles?
6682:
1.190 raeburn 6683: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.89 raeburn 6684: my %lt=&Apache::lonlocal::texthash(
6685: 'exs' => "Existing sections",
6686: 'new' => "Define new section",
6687: 'ssd' => "Set Start Date",
6688: 'sed' => "Set End Date",
1.131 raeburn 6689: 'crl' => "Course Level",
1.89 raeburn 6690: 'act' => "Activate",
6691: 'rol' => "Role",
6692: 'ext' => "Extent",
1.113 raeburn 6693: 'grs' => "Section",
1.375 raeburn 6694: 'crd' => "Credits",
1.89 raeburn 6695: 'sta' => "Start",
6696: 'end' => "End"
6697: );
1.62 www 6698:
1.375 raeburn 6699: foreach my $protectedcourse (sort(keys(%{$inccourses}))) {
1.135 raeburn 6700: my $thiscourse=$protectedcourse;
1.26 matthew 6701: $thiscourse=~s:_:/:g;
6702: my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
1.365 raeburn 6703: my $isowner = &Apache::lonuserutils::is_courseowner($protectedcourse,$coursedata{'internal.courseowner'});
1.26 matthew 6704: my $area=$coursedata{'description'};
1.321 raeburn 6705: my $crstype=$coursedata{'type'};
1.135 raeburn 6706: if (!defined($area)) { $area=&mt('Unavailable course').': '.$protectedcourse; }
1.89 raeburn 6707: my ($domain,$cnum)=split(/\//,$thiscourse);
1.115 albertel 6708: my %sections_count;
1.101 albertel 6709: if (defined($env{'request.course.id'})) {
6710: if ($env{'request.course.id'} eq $domain.'_'.$cnum) {
1.115 albertel 6711: %sections_count =
6712: &Apache::loncommon::get_sections($domain,$cnum);
1.92 raeburn 6713: }
6714: }
1.321 raeburn 6715: my @roles = &Apache::lonuserutils::roles_by_context('course','',$crstype);
1.213 raeburn 6716: foreach my $role (@roles) {
1.321 raeburn 6717: my $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.329 raeburn 6718: if ((&Apache::lonnet::allowed('c'.$role,$thiscourse)) ||
6719: ((($role eq 'cc') || ($role eq 'co')) && ($isowner))) {
1.221 raeburn 6720: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 6721: $plrole,\%sections_count,\%lt,
6722: $defaultcredits,$crstype);
1.221 raeburn 6723: } elsif ($env{'request.course.sec'} ne '') {
6724: if (&Apache::lonnet::allowed('c'.$role,$thiscourse.'/'.
6725: $env{'request.course.sec'})) {
6726: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 6727: $plrole,\%sections_count,\%lt,
6728: $defaultcredits,$crstype);
1.26 matthew 6729: }
6730: }
6731: }
1.221 raeburn 6732: if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
1.324 raeburn 6733: foreach my $cust (sort(keys(%customroles))) {
6734: next if ($crstype eq 'Community' && $customroles{$cust} =~ /bre\&S/);
1.221 raeburn 6735: my $role = 'cr_cr_'.$env{'user.domain'}.'_'.$env{'user.name'}.'_'.$cust;
6736: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
6737: $cust,\%sections_count,\%lt);
6738: }
1.62 www 6739: }
1.26 matthew 6740: }
6741: return '' if ($table eq ''); # return nothing if there is nothing
6742: # in the table
1.188 raeburn 6743: my $result;
6744: if (!$env{'request.course.id'}) {
6745: $result = '<h4>'.$lt{'crl'}.'</h4>'."\n";
6746: }
6747: $result .=
1.136 raeburn 6748: &Apache::loncommon::start_data_table().
6749: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 6750: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
6751: '<th>'.$lt{'ext'}.'</th><th>'.$lt{'crd'}.'</th>'."\n".
6752: '<th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th>'."\n".
6753: '<th>'.$lt{'end'}.'</th>'.
1.136 raeburn 6754: &Apache::loncommon::end_data_table_header_row().
6755: $table.
6756: &Apache::loncommon::end_data_table();
1.26 matthew 6757: return $result;
6758: }
1.88 raeburn 6759:
1.221 raeburn 6760: sub course_level_row {
1.375 raeburn 6761: my ($protectedcourse,$role,$area,$domain,$plrole,$sections_count,
6762: $lt,$defaultcredits,$crstype) = @_;
6763: my $creditem;
1.222 raeburn 6764: my $row = &Apache::loncommon::start_data_table_row().
6765: ' <td><input type="checkbox" name="act_'.
6766: $protectedcourse.'_'.$role.'" /></td>'."\n".
6767: ' <td>'.$plrole.'</td>'."\n".
6768: ' <td>'.$area.'<br />Domain: '.$domain.'</td>'."\n";
1.375 raeburn 6769: if (($role eq 'st') && ($crstype eq 'Course')) {
6770: $row .=
6771: '<td><input type="text" name="credits_'.$protectedcourse.'_'.
6772: $role.'" size="3" value="'.$defaultcredits.'" /></td>';
6773: } else {
6774: $row .= '<td> </td>';
6775: }
1.322 raeburn 6776: if (($role eq 'cc') || ($role eq 'co')) {
1.222 raeburn 6777: $row .= '<td> </td>';
1.221 raeburn 6778: } elsif ($env{'request.course.sec'} ne '') {
1.222 raeburn 6779: $row .= ' <td><input type="hidden" value="'.
6780: $env{'request.course.sec'}.'" '.
6781: 'name="sec_'.$protectedcourse.'_'.$role.'" />'.
6782: $env{'request.course.sec'}.'</td>';
1.221 raeburn 6783: } else {
6784: if (ref($sections_count) eq 'HASH') {
6785: my $currsec =
6786: &Apache::lonuserutils::course_sections($sections_count,
6787: $protectedcourse.'_'.$role);
1.222 raeburn 6788: $row .= '<td><table class="LC_createuser">'."\n".
6789: '<tr class="LC_section_row">'."\n".
6790: ' <td valign="top">'.$lt->{'exs'}.'<br />'.
6791: $currsec.'</td>'."\n".
6792: ' <td> </td>'."\n".
6793: ' <td valign="top"> '.$lt->{'new'}.'<br />'.
1.221 raeburn 6794: '<input type="text" name="newsec_'.$protectedcourse.'_'.$role.
6795: '" value="" />'.
6796: '<input type="hidden" '.
6797: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n".
1.222 raeburn 6798: '</tr></table></td>'."\n";
1.221 raeburn 6799: } else {
1.222 raeburn 6800: $row .= '<td><input type="text" size="10" '.
1.375 raeburn 6801: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n";
1.221 raeburn 6802: }
6803: }
1.222 raeburn 6804: $row .= <<ENDTIMEENTRY;
6805: <td><input type="hidden" name="start_$protectedcourse\_$role" value="" />
1.221 raeburn 6806: <a href=
6807: "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 6808: <td><input type="hidden" name="end_$protectedcourse\_$role" value="" />
1.221 raeburn 6809: <a href=
6810: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$role.value,'end_$protectedcourse\_$role','cu.pres','dateset')">$lt->{'sed'}</a></td>
6811: ENDTIMEENTRY
1.222 raeburn 6812: $row .= &Apache::loncommon::end_data_table_row();
6813: return $row;
1.221 raeburn 6814: }
6815:
1.88 raeburn 6816: sub course_level_dc {
1.375 raeburn 6817: my ($dcdom,$showcredits) = @_;
1.190 raeburn 6818: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.213 raeburn 6819: my @roles = &Apache::lonuserutils::roles_by_context('course');
1.88 raeburn 6820: my $hiddenitems = '<input type="hidden" name="dcdomain" value="'.$dcdom.'" />'.
6821: '<input type="hidden" name="origdom" value="'.$dcdom.'" />'.
1.133 raeburn 6822: '<input type="hidden" name="dccourse" value="" />';
1.355 www 6823: my $courseform=&Apache::loncommon::selectcourse_link
1.356 raeburn 6824: ('cu','dccourse','dcdomain','coursedesc',undef,undef,'Select','crstype');
1.375 raeburn 6825: my $credit_elem;
6826: if ($showcredits) {
6827: $credit_elem = 'credits';
6828: }
6829: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,'currsec','cu','role','Course/Community Browser',$credit_elem);
1.88 raeburn 6830: my %lt=&Apache::lonlocal::texthash(
6831: 'rol' => "Role",
1.113 raeburn 6832: 'grs' => "Section",
1.88 raeburn 6833: 'exs' => "Existing sections",
6834: 'new' => "Define new section",
6835: 'sta' => "Start",
6836: 'end' => "End",
6837: 'ssd' => "Set Start Date",
1.355 www 6838: 'sed' => "Set End Date",
1.375 raeburn 6839: 'scc' => "Course/Community",
6840: 'crd' => "Credits",
1.88 raeburn 6841: );
1.323 raeburn 6842: my $header = '<h4>'.&mt('Course/Community Level').'</h4>'.
1.136 raeburn 6843: &Apache::loncommon::start_data_table().
6844: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 6845: '<th>'.$lt{'scc'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
6846: '<th>'.$lt{'grs'}.'</th><th>'.$lt{'crd'}.'</th>'."\n".
6847: '<th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'."\n".
1.136 raeburn 6848: &Apache::loncommon::end_data_table_header_row();
1.143 raeburn 6849: my $otheritems = &Apache::loncommon::start_data_table_row()."\n".
1.356 raeburn 6850: '<td><br /><span class="LC_nobreak"><input type="text" name="coursedesc" value="" onfocus="this.blur();opencrsbrowser('."'cu','dccourse','dcdomain','coursedesc','','','','crstype'".')" />'.
6851: $courseform.(' ' x4).'</span></td>'."\n".
1.323 raeburn 6852: '<td valign><br /><select name="role">'."\n";
1.213 raeburn 6853: foreach my $role (@roles) {
1.135 raeburn 6854: my $plrole=&Apache::lonnet::plaintext($role);
6855: $otheritems .= ' <option value="'.$role.'">'.$plrole;
1.88 raeburn 6856: }
6857: if ( keys %customroles > 0) {
1.135 raeburn 6858: foreach my $cust (sort keys %customroles) {
1.101 albertel 6859: my $custrole='cr_cr_'.$env{'user.domain'}.
1.135 raeburn 6860: '_'.$env{'user.name'}.'_'.$cust;
6861: $otheritems .= ' <option value="'.$custrole.'">'.$cust;
1.88 raeburn 6862: }
6863: }
6864: $otheritems .= '</select></td><td>'.
6865: '<table border="0" cellspacing="0" cellpadding="0">'.
6866: '<tr><td valign="top"><b>'.$lt{'exs'}.'</b><br /><select name="currsec">'.
6867: ' <option value=""><--'.&mt('Pick course first').'</select></td>'.
6868: '<td> </td>'.
6869: '<td valign="top"> <b>'.$lt{'new'}.'</b><br />'.
1.113 raeburn 6870: '<input type="text" name="newsec" value="" />'.
1.237 raeburn 6871: '<input type="hidden" name="section" value="" />'.
1.323 raeburn 6872: '<input type="hidden" name="groups" value="" />'.
6873: '<input type="hidden" name="crstype" value="" /></td>'.
1.375 raeburn 6874: '</tr></table></td>'."\n";
6875: if ($showcredits) {
6876: $otheritems .= '<td><br />'."\n".
6877: '<input type="text" size="3" name="credits" value="" />'."\n";
6878: }
1.88 raeburn 6879: $otheritems .= <<ENDTIMEENTRY;
1.323 raeburn 6880: <td><br /><input type="hidden" name="start" value='' />
1.88 raeburn 6881: <a href=
6882: "javascript:pjump('date_start','Start Date',document.cu.start.value,'start','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.323 raeburn 6883: <td><br /><input type="hidden" name="end" value='' />
1.88 raeburn 6884: <a href=
6885: "javascript:pjump('date_end','End Date',document.cu.end.value,'end','cu.pres','dateset')">$lt{'sed'}</a></td>
6886: ENDTIMEENTRY
1.136 raeburn 6887: $otheritems .= &Apache::loncommon::end_data_table_row().
6888: &Apache::loncommon::end_data_table()."\n";
1.88 raeburn 6889: return $cb_jscript.$header.$hiddenitems.$otheritems;
6890: }
6891:
1.237 raeburn 6892: sub update_selfenroll_config {
1.241 raeburn 6893: my ($r,$context,$permission) = @_;
1.237 raeburn 6894: my ($row,$lt) = &get_selfenroll_titles();
1.241 raeburn 6895: my %curr_groups = &Apache::longroup::coursegroups();
1.237 raeburn 6896: my (%changes,%warning);
6897: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
6898: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.241 raeburn 6899: my $curr_types;
1.237 raeburn 6900: if (ref($row) eq 'ARRAY') {
6901: foreach my $item (@{$row}) {
6902: if ($item eq 'enroll_dates') {
6903: my (%currenrolldate,%newenrolldate);
6904: foreach my $type ('start','end') {
6905: $currenrolldate{$type} = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$type.'_date'};
6906: $newenrolldate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_date');
6907: if ($newenrolldate{$type} ne $currenrolldate{$type}) {
6908: $changes{'internal.selfenroll_'.$type.'_date'} = $newenrolldate{$type};
6909: }
6910: }
6911: } elsif ($item eq 'access_dates') {
6912: my (%currdate,%newdate);
6913: foreach my $type ('start','end') {
6914: $currdate{$type} = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$type.'_access'};
6915: $newdate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_access');
6916: if ($newdate{$type} ne $currdate{$type}) {
6917: $changes{'internal.selfenroll_'.$type.'_access'} = $newdate{$type};
6918: }
6919: }
1.241 raeburn 6920: } elsif ($item eq 'types') {
6921: $curr_types =
6922: $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$item};
6923: if ($env{'form.selfenroll_all'}) {
6924: if ($curr_types ne '*') {
6925: $changes{'internal.selfenroll_types'} = '*';
6926: } else {
6927: next;
6928: }
6929: } else {
1.249 raeburn 6930: my %currdoms;
1.241 raeburn 6931: my @entries = split(/;/,$curr_types);
6932: my @deletedoms = &Apache::loncommon::get_env_multiple('form.selfenroll_delete');
1.249 raeburn 6933: my @activations = &Apache::loncommon::get_env_multiple('form.selfenroll_activate');
1.241 raeburn 6934: my $newnum = 0;
1.249 raeburn 6935: my @latesttypes;
6936: foreach my $num (@activations) {
6937: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$num);
6938: if (@types > 0) {
1.241 raeburn 6939: @types = sort(@types);
6940: my $typestr = join(',',@types);
1.249 raeburn 6941: my $typedom = $env{'form.selfenroll_dom_'.$num};
6942: $latesttypes[$newnum] = $typedom.':'.$typestr;
6943: $currdoms{$typedom} = 1;
1.241 raeburn 6944: $newnum ++;
6945: }
6946: }
1.338 raeburn 6947: for (my $j=0; $j<$env{'form.selfenroll_types_total'}; $j++) {
6948: if ((!grep(/^$j$/,@deletedoms)) && (!grep(/^$j$/,@activations))) {
1.249 raeburn 6949: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$j);
6950: if (@types > 0) {
6951: @types = sort(@types);
6952: my $typestr = join(',',@types);
6953: my $typedom = $env{'form.selfenroll_dom_'.$j};
6954: $latesttypes[$newnum] = $typedom.':'.$typestr;
6955: $currdoms{$typedom} = 1;
6956: $newnum ++;
6957: }
6958: }
6959: }
6960: if ($env{'form.selfenroll_newdom'} ne '') {
6961: my $typedom = $env{'form.selfenroll_newdom'};
6962: if ((!defined($currdoms{$typedom})) &&
6963: (&Apache::lonnet::domain($typedom) ne '')) {
6964: my $typestr;
6965: my ($othertitle,$usertypes,$types) =
6966: &Apache::loncommon::sorted_inst_types($typedom);
6967: my $othervalue = 'any';
6968: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
6969: if (@{$types} > 0) {
1.257 raeburn 6970: my @esc_types = map { &escape($_); } @{$types};
1.249 raeburn 6971: $othervalue = 'other';
1.258 raeburn 6972: $typestr = join(',',(@esc_types,$othervalue));
1.249 raeburn 6973: }
6974: $typestr = $othervalue;
6975: } else {
6976: $typestr = $othervalue;
6977: }
6978: $latesttypes[$newnum] = $typedom.':'.$typestr;
6979: $newnum ++ ;
6980: }
6981: }
1.241 raeburn 6982: my $selfenroll_types = join(';',@latesttypes);
6983: if ($selfenroll_types ne $curr_types) {
6984: $changes{'internal.selfenroll_types'} = $selfenroll_types;
6985: }
6986: }
1.276 raeburn 6987: } elsif ($item eq 'limit') {
6988: my $newlimit = $env{'form.selfenroll_limit'};
6989: my $newcap = $env{'form.selfenroll_cap'};
6990: $newcap =~s/\s+//g;
6991: my $currlimit = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_limit'};
6992: $currlimit = 'none' if ($currlimit eq '');
6993: my $currcap = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_cap'};
6994: if ($newlimit ne $currlimit) {
6995: if ($newlimit ne 'none') {
6996: if ($newcap =~ /^\d+$/) {
6997: if ($newcap ne $currcap) {
6998: $changes{'internal.selfenroll_cap'} = $newcap;
6999: }
7000: $changes{'internal.selfenroll_limit'} = $newlimit;
7001: } else {
7002: $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.');
7003: }
7004: } elsif ($currcap ne '') {
7005: $changes{'internal.selfenroll_cap'} = '';
7006: $changes{'internal.selfenroll_limit'} = $newlimit;
7007: }
7008: } elsif ($currlimit ne 'none') {
7009: if ($newcap =~ /^\d+$/) {
7010: if ($newcap ne $currcap) {
7011: $changes{'internal.selfenroll_cap'} = $newcap;
7012: }
7013: } else {
7014: $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.');
7015: }
7016: }
7017: } elsif ($item eq 'approval') {
7018: my (@currnotified,@newnotified);
7019: my $currapproval = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'};
7020: my $currnotifylist = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_notifylist'};
7021: if ($currnotifylist ne '') {
7022: @currnotified = split(/,/,$currnotifylist);
7023: @currnotified = sort(@currnotified);
7024: }
7025: my $newapproval = $env{'form.selfenroll_approval'};
7026: @newnotified = &Apache::loncommon::get_env_multiple('form.selfenroll_notify');
7027: @newnotified = sort(@newnotified);
7028: if ($newapproval ne $currapproval) {
7029: $changes{'internal.selfenroll_approval'} = $newapproval;
7030: if (!$newapproval) {
7031: if ($currnotifylist ne '') {
7032: $changes{'internal.selfenroll_notifylist'} = '';
7033: }
7034: } else {
7035: my @differences =
1.295 raeburn 7036: &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 7037: if (@differences > 0) {
7038: if (@newnotified > 0) {
7039: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
7040: } else {
7041: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
7042: }
7043: }
7044: }
7045: } else {
1.295 raeburn 7046: my @differences = &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 7047: if (@differences > 0) {
7048: if (@newnotified > 0) {
7049: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
7050: } else {
7051: $changes{'internal.selfenroll_notifylist'} = '';
7052: }
7053: }
7054: }
1.237 raeburn 7055: } else {
7056: my $curr_val =
7057: $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$item};
7058: my $newval = $env{'form.selfenroll_'.$item};
7059: if ($item eq 'section') {
7060: $newval = $env{'form.sections'};
1.241 raeburn 7061: if (defined($curr_groups{$newval})) {
1.237 raeburn 7062: $newval = $curr_val;
7063: $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');
7064: } elsif ($newval eq 'all') {
7065: $newval = $curr_val;
1.274 bisitz 7066: $warning{$item} = &mt('Section for self-enrolled users unchanged, as "all" is a reserved section name.');
1.237 raeburn 7067: }
7068: if ($newval eq '') {
7069: $newval = 'none';
7070: }
7071: }
7072: if ($newval ne $curr_val) {
7073: $changes{'internal.selfenroll_'.$item} = $newval;
7074: }
1.241 raeburn 7075: }
1.237 raeburn 7076: }
7077: if (keys(%warning) > 0) {
7078: foreach my $item (@{$row}) {
7079: if (exists($warning{$item})) {
7080: $r->print($warning{$item}.'<br />');
7081: }
7082: }
7083: }
7084: if (keys(%changes) > 0) {
7085: my $putresult = &Apache::lonnet::put('environment',\%changes,$cdom,$cnum);
7086: if ($putresult eq 'ok') {
7087: if ((exists($changes{'internal.selfenroll_types'})) ||
7088: (exists($changes{'internal.selfenroll_start_date'})) ||
7089: (exists($changes{'internal.selfenroll_end_date'}))) {
7090: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',
7091: $cnum,undef,undef,'Course');
7092: my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
7093: if (ref($crsinfo{$env{'request.course.id'}}) eq 'HASH') {
7094: foreach my $item ('selfenroll_types','selfenroll_start_date','selfenroll_end_date') {
7095: if (exists($changes{'internal.'.$item})) {
7096: $crsinfo{$env{'request.course.id'}}{$item} =
7097: $changes{'internal.'.$item};
7098: }
7099: }
7100: my $crsputresult =
7101: &Apache::lonnet::courseidput($cdom,\%crsinfo,
7102: $chome,'notime');
7103: }
7104: }
7105: $r->print(&mt('The following changes were made to self-enrollment settings:').'<ul>');
7106: foreach my $item (@{$row}) {
7107: my $title = $item;
7108: if (ref($lt) eq 'HASH') {
7109: $title = $lt->{$item};
7110: }
7111: if ($item eq 'enroll_dates') {
7112: foreach my $type ('start','end') {
7113: if (exists($changes{'internal.selfenroll_'.$type.'_date'})) {
7114: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_date'});
1.244 bisitz 7115: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 7116: $title,$type,$newdate).'</li>');
7117: }
7118: }
7119: } elsif ($item eq 'access_dates') {
7120: foreach my $type ('start','end') {
7121: if (exists($changes{'internal.selfenroll_'.$type.'_access'})) {
7122: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_access'});
1.244 bisitz 7123: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 7124: $title,$type,$newdate).'</li>');
7125: }
7126: }
1.276 raeburn 7127: } elsif ($item eq 'limit') {
7128: if ((exists($changes{'internal.selfenroll_limit'})) ||
7129: (exists($changes{'internal.selfenroll_cap'}))) {
7130: my ($newval,$newcap);
7131: if ($changes{'internal.selfenroll_cap'} ne '') {
7132: $newcap = $changes{'internal.selfenroll_cap'}
7133: } else {
7134: $newcap = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_cap'};
7135: }
7136: if ($changes{'internal.selfenroll_limit'} eq 'none') {
7137: $newval = &mt('No limit');
7138: } elsif ($changes{'internal.selfenroll_limit'} eq
7139: 'allstudents') {
7140: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
7141: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
7142: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
7143: } else {
7144: my $currlimit = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_limit'};
7145: if ($currlimit eq 'allstudents') {
7146: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
7147: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
1.308 raeburn 7148: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
1.276 raeburn 7149: }
7150: }
7151: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
7152: }
7153: } elsif ($item eq 'approval') {
7154: if ((exists($changes{'internal.selfenroll_approval'})) ||
7155: (exists($changes{'internal.selfenroll_notifylist'}))) {
7156: my ($newval,$newnotify);
7157: if (exists($changes{'internal.selfenroll_notifylist'})) {
7158: $newnotify = $changes{'internal.selfenroll_notifylist'};
7159: } else {
7160: $newnotify = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_notifylist'};
7161: }
7162: if ($changes{'internal.selfenroll_approval'}) {
7163: $newval = &mt('Yes');
7164: } elsif ($changes{'internal.selfenroll_approval'} eq '0') {
7165: $newval = &mt('No');
7166: } else {
7167: my $currapproval =
7168: $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'};
7169: if ($currapproval) {
7170: $newval = &mt('Yes');
7171: } else {
7172: $newval = &mt('No');
7173: }
7174: }
7175: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval));
7176: if ($newnotify) {
1.277 raeburn 7177: $r->print('<br />'.&mt('The following will be notified when an enrollment request needs approval, or has been approved: [_1].',$newnotify));
1.276 raeburn 7178: } else {
1.277 raeburn 7179: $r->print('<br />'.&mt('No notifications sent when an enrollment request needs approval, or has been approved.'));
1.276 raeburn 7180: }
7181: $r->print('</li>'."\n");
7182: }
1.237 raeburn 7183: } else {
7184: if (exists($changes{'internal.selfenroll_'.$item})) {
1.241 raeburn 7185: my $newval = $changes{'internal.selfenroll_'.$item};
7186: if ($item eq 'types') {
7187: if ($newval eq '') {
7188: $newval = &mt('None');
7189: } elsif ($newval eq '*') {
7190: $newval = &mt('Any user in any domain');
7191: }
1.245 raeburn 7192: } elsif ($item eq 'registered') {
7193: if ($newval eq '1') {
7194: $newval = &mt('Yes');
7195: } elsif ($newval eq '0') {
7196: $newval = &mt('No');
7197: }
1.241 raeburn 7198: }
1.244 bisitz 7199: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
1.237 raeburn 7200: }
7201: }
7202: }
7203: $r->print('</ul>');
7204: my %newenvhash;
7205: foreach my $key (keys(%changes)) {
7206: $newenvhash{'course.'.$env{'request.course.id'}.'.'.$key} = $changes{$key};
7207: }
1.238 raeburn 7208: &Apache::lonnet::appenv(\%newenvhash);
1.237 raeburn 7209: } else {
7210: $r->print(&mt('An error occurred when saving changes to self-enrollment settings in this course.').'<br />'.&mt('The error was: [_1].',$putresult));
7211: }
7212: } else {
1.249 raeburn 7213: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.237 raeburn 7214: }
7215: } else {
1.249 raeburn 7216: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.241 raeburn 7217: }
1.256 raeburn 7218: my ($visible,$cansetvis,$vismsgs,$visactions) = &visible_in_cat($cdom,$cnum);
7219: if (ref($visactions) eq 'HASH') {
7220: if (!$visible) {
1.366 bisitz 7221: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
1.256 raeburn 7222: '<br />');
7223: if (ref($vismsgs) eq 'ARRAY') {
7224: $r->print('<br />'.$visactions->{'take'}.'<ul>');
7225: foreach my $item (@{$vismsgs}) {
7226: $r->print('<li>'.$visactions->{$item}.'</li>');
7227: }
7228: $r->print('</ul>');
7229: }
7230: $r->print($cansetvis);
7231: }
7232: }
1.237 raeburn 7233: return;
7234: }
7235:
7236: sub get_selfenroll_titles {
1.276 raeburn 7237: my @row = ('types','registered','enroll_dates','access_dates','section',
7238: 'approval','limit');
1.237 raeburn 7239: my %lt = &Apache::lonlocal::texthash (
7240: types => 'Users allowed to self-enroll in this course',
1.245 raeburn 7241: registered => 'Restrict self-enrollment to students officially registered for the course',
1.237 raeburn 7242: enroll_dates => 'Dates self-enrollment available',
1.256 raeburn 7243: access_dates => 'Course access dates assigned to self-enrolling users',
7244: section => 'Section assigned to self-enrolling users',
1.276 raeburn 7245: approval => 'Self-enrollment requests need approval?',
7246: limit => 'Enrollment limit',
1.237 raeburn 7247: );
7248: return (\@row,\%lt);
7249: }
7250:
1.27 matthew 7251: #---------------------------------------------- end functions for &phase_two
1.29 matthew 7252:
7253: #--------------------------------- functions for &phase_two and &phase_three
7254:
7255: #--------------------------end of functions for &phase_two and &phase_three
1.372 raeburn 7256:
1.1 www 7257: 1;
7258: __END__
1.2 www 7259:
7260:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>