Annotation of loncom/interface/loncreateuser.pm, revision 1.295.2.35
1.20 harris41 1: # The LearningOnline Network with CAPA
1.1 www 2: # Create a user
3: #
1.295.2.35! raeburn 4: # $Id: loncreateuser.pm,v 1.295.2.34 2010/05/22 13:30:43 raeburn Exp $
1.22 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.20 harris41 28: ###
29:
1.1 www 30: package Apache::loncreateuser;
1.66 bowersj2 31:
32: =pod
33:
34: =head1 NAME
35:
1.263 jms 36: Apache::loncreateuser.pm
1.66 bowersj2 37:
38: =head1 SYNOPSIS
39:
1.263 jms 40: Handler to create users and custom roles
41:
42: Provides an Apache handler for creating users,
1.66 bowersj2 43: editing their login parameters, roles, and removing roles, and
44: also creating and assigning custom roles.
45:
46: =head1 OVERVIEW
47:
48: =head2 Custom Roles
49:
50: In LON-CAPA, roles are actually collections of privileges. "Teaching
51: Assistant", "Course Coordinator", and other such roles are really just
52: collection of privileges that are useful in many circumstances.
53:
1.295.2.24 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.295.2.24 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.295.2.7 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.295.2.12 raeburn 114: krb5 => 'krb',
1.188 raeburn 115: krb4 => 'krb',
116: internal => 'int',
117: localuth => 'loc',
118: unix => 'fsys',
119: );
120: return %abv_auth;
121: }
1.43 www 122:
1.134 raeburn 123: # ====================================================
124:
125: sub portfolio_quota {
126: my ($ccuname,$ccdomain) = @_;
127: my %lt = &Apache::lonlocal::texthash(
1.267 raeburn 128: 'usrt' => "User Tools",
129: 'disk' => "Disk space allocated to user's portfolio files",
130: 'cuqu' => "Current quota",
131: 'cust' => "Custom quota",
132: 'defa' => "Default",
133: 'chqu' => "Change quota",
1.134 raeburn 134: );
1.149 raeburn 135: my ($currquota,$quotatype,$inststatus,$defquota) =
136: &Apache::loncommon::get_user_quota($ccuname,$ccdomain);
137: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($ccdomain);
138: my ($longinsttype,$showquota,$custom_on,$custom_off,$defaultinfo);
139: if ($inststatus ne '') {
140: if ($usertypes->{$inststatus} ne '') {
141: $longinsttype = $usertypes->{$inststatus};
142: }
143: }
144: $custom_on = ' ';
145: $custom_off = ' checked="checked" ';
146: my $quota_javascript = <<"END_SCRIPT";
147: <script type="text/javascript">
1.295.2.4 raeburn 148: // <![CDATA[
1.149 raeburn 149: function quota_changes(caller) {
150: if (caller == "custom") {
151: if (document.cu.customquota[0].checked) {
152: document.cu.portfolioquota.value = "";
153: }
154: }
155: if (caller == "quota") {
156: document.cu.customquota[1].checked = true;
157: }
158: }
1.295.2.4 raeburn 159: // ]]>
1.149 raeburn 160: </script>
161: END_SCRIPT
162: if ($quotatype eq 'custom') {
163: $custom_on = $custom_off;
164: $custom_off = ' ';
165: $showquota = $currquota;
166: if ($longinsttype eq '') {
1.230 bisitz 167: $defaultinfo = &mt('For this user, the default quota would be [_1]'
168: .' Mb.',$defquota);
1.149 raeburn 169: } else {
1.231 raeburn 170: $defaultinfo = &mt("For this user, the default quota would be [_1]".
171: " Mb, as determined by the user's institutional".
172: " affiliation ([_2]).",$defquota,$longinsttype);
1.149 raeburn 173: }
174: } else {
175: if ($longinsttype eq '') {
1.230 bisitz 176: $defaultinfo = &mt('For this user, the default quota is [_1]'
177: .' Mb.',$defquota);
1.149 raeburn 178: } else {
1.231 raeburn 179: $defaultinfo = &mt("For this user, the default quota of [_1]".
180: " Mb, is determined by the user's institutional".
181: " affiliation ([_2]).",$defquota,$longinsttype);
1.149 raeburn 182: }
183: }
1.267 raeburn 184:
185: my $output = $quota_javascript."\n".
186: '<h3>'.$lt{'usrt'}.'</h3>'."\n".
187: &Apache::loncommon::start_data_table();
188:
189: if (&Apache::lonnet::allowed('mut',$ccdomain)) {
1.275 raeburn 190: $output .= &build_tools_display($ccuname,$ccdomain,'tools');
1.267 raeburn 191: }
192: if (&Apache::lonnet::allowed('mpq',$ccdomain)) {
193: $output .= '<tr class="LC_info_row">'."\n".
194: ' <td>'.$lt{'disk'}.'</td>'."\n".
195: ' </tr>'."\n".
196: &Apache::loncommon::start_data_table_row()."\n".
197: ' <td>'.$lt{'cuqu'}.': '.
198: $currquota.' Mb. '.
199: $defaultinfo.'</td>'."\n".
200: &Apache::loncommon::end_data_table_row()."\n".
201: &Apache::loncommon::start_data_table_row()."\n".
202: ' <td><span class="LC_nobreak">'.$lt{'chqu'}.
203: ': <label>'.
204: '<input type="radio" name="customquota" value="0" '.
205: $custom_off.' onchange="javascript:quota_changes('."'custom'".')"'.
206: ' />'.$lt{'defa'}.' ('.$defquota.' Mb).</label> '.
207: ' <label><input type="radio" name="customquota" value="1" '.
208: $custom_on.' onchange="javascript:quota_changes('."'custom'".')" />'.
209: $lt{'cust'}.':</label> '.
210: '<input type="text" name="portfolioquota" size ="5" value="'.
211: $showquota.'" onfocus="javascript:quota_changes('."'quota'".')" '.
212: '/> Mb</span></td>'."\n".
213: &Apache::loncommon::end_data_table_row()."\n";
214: }
215: $output .= &Apache::loncommon::end_data_table();
1.134 raeburn 216: return $output;
217: }
218:
1.275 raeburn 219: sub build_tools_display {
220: my ($ccuname,$ccdomain,$context) = @_;
1.295.2.7 raeburn 221: my (@usertools,%userenv,$output,@options,%validations,%reqtitles,%reqdisplay,
1.295.2.27 raeburn 222: $colspan,$isadv,%domconfig);
1.275 raeburn 223: my %lt = &Apache::lonlocal::texthash (
224: 'blog' => "Personal User Blog",
225: 'aboutme' => "Personal Information Page",
226: 'portfolio' => "Personal User Portfolio",
227: 'avai' => "Available",
228: 'cusa' => "availability",
229: 'chse' => "Change setting",
230: 'usde' => "Use default",
231: 'uscu' => "Use custom",
232: 'official' => 'Can request creation of official courses',
1.295.2.14 raeburn 233: 'unofficial' => 'Can request creation of unofficial courses',
1.295.2.29 raeburn 234: 'community' => 'Can request creation of communities',
1.275 raeburn 235: );
1.279 raeburn 236: if ($context eq 'requestcourses') {
1.275 raeburn 237: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
1.295.2.29 raeburn 238: 'requestcourses.official','requestcourses.unofficial',
239: 'requestcourses.community');
240: @usertools = ('official','unofficial','community');
1.295.2.10 raeburn 241: @options =('norequest','approval','autolimit','validate');
1.295.2.7 raeburn 242: %validations = &Apache::lonnet::auto_courserequest_checks($ccdomain);
243: %reqtitles = &courserequest_titles();
244: %reqdisplay = &courserequest_display();
245: $colspan = ' colspan="2"';
1.295.2.27 raeburn 246: %domconfig =
247: &Apache::lonnet::get_dom('configuration',['requestcourses'],$ccdomain);
248: $isadv = &Apache::lonnet::is_advanced_user($ccuname,$ccdomain);
1.275 raeburn 249: } else {
250: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
251: 'tools.aboutme','tools.portfolio','tools.blog');
252: @usertools = ('aboutme','blog','portfolio');
253: }
254: foreach my $item (@usertools) {
1.295.2.7 raeburn 255: my ($custom_access,$curr_access,$cust_on,$cust_off,$tool_on,$tool_off,
256: $currdisp,$custdisp,$custradio);
1.275 raeburn 257: $cust_off = 'checked="checked" ';
258: $tool_on = 'checked="checked" ';
259: $curr_access =
260: &Apache::lonnet::usertools_access($ccuname,$ccdomain,$item,undef,
261: $context);
1.295.2.7 raeburn 262: if ($userenv{$context.'.'.$item} ne '') {
1.275 raeburn 263: $cust_on = ' checked="checked" ';
264: $cust_off = '';
1.295.2.7 raeburn 265: }
266: if ($context eq 'requestcourses') {
267: if ($userenv{$context.'.'.$item} eq '') {
268: $custom_access = &mt('Currently from default setting.');
269: } else {
270: $custom_access = &mt('Currently from custom setting.');
271: }
272: } else {
273: if ($userenv{$context.'.'.$item} eq '') {
274: $custom_access =
275: &mt('Availability determined currently from default setting.');
276: if (!$curr_access) {
277: $tool_off = 'checked="checked" ';
278: $tool_on = '';
279: }
280: } else {
281: $custom_access =
282: &mt('Availability determined currently from custom setting.');
283: if ($userenv{$context.'.'.$item} == 0) {
284: $tool_off = 'checked="checked" ';
285: $tool_on = '';
286: }
1.275 raeburn 287: }
288: }
289: $output .= ' <tr class="LC_info_row">'."\n".
1.295.2.7 raeburn 290: ' <td'.$colspan.'>'.$lt{$item}.'</td>'."\n".
1.275 raeburn 291: ' </tr>'."\n".
1.295.2.7 raeburn 292: &Apache::loncommon::start_data_table_row()."\n";
293: if ($context eq 'requestcourses') {
294: my ($curroption,$currlimit);
1.295.2.27 raeburn 295: if ($userenv{$context.'.'.$item} ne '') {
296: $curroption = $userenv{$context.'.'.$item};
297: } else {
298: my (@inststatuses);
299: $curroption =
300: &Apache::loncoursequeueadmin::get_processtype($ccuname,$ccdomain,$isadv,$ccdomain,
301: $item,\@inststatuses,\%domconfig);
302: }
1.295.2.7 raeburn 303: if (!$curroption) {
304: $curroption = 'norequest';
305: }
306: if ($curroption =~ /^autolimit=(\d*)$/) {
307: $currlimit = $1;
1.295.2.14 raeburn 308: if ($currlimit eq '') {
309: $currdisp = &mt('Yes, automatic creation');
310: } else {
311: $currdisp = &mt('Yes, up to [quant,_1,request]/user',$currlimit);
312: }
1.295.2.7 raeburn 313: } else {
314: $currdisp = $reqdisplay{$curroption};
315: }
316: $custdisp = '<table>';
317: foreach my $option (@options) {
318: my $val = $option;
319: if ($option eq 'norequest') {
320: $val = 0;
321: }
322: if ($option eq 'validate') {
323: my $canvalidate = 0;
324: if (ref($validations{$item}) eq 'HASH') {
325: if ($validations{$item}{'_custom_'}) {
326: $canvalidate = 1;
327: }
328: }
329: next if (!$canvalidate);
330: }
331: my $checked = '';
332: if ($option eq $curroption) {
333: $checked = ' checked="checked"';
334: } elsif ($option eq 'autolimit') {
335: if ($curroption =~ /^autolimit/) {
336: $checked = ' checked="checked"';
337: }
338: }
339: $custdisp .= '<tr><td><span class="LC_nobreak"><label>'.
340: '<input type="radio" name="crsreq_'.$item.
341: '" value="'.$val.'"'.$checked.' />'.
342: $reqtitles{$option}.'</label> ';
343: if ($option eq 'autolimit') {
344: $custdisp .= '<input type="text" name="crsreq_'.
345: $item.'_limit" size="1" '.
1.295.2.14 raeburn 346: 'value="'.$currlimit.'" /></span><br />'.
347: $reqtitles{'unlimited'};
348: } else {
349: $custdisp .= '</span>';
1.295.2.7 raeburn 350: }
1.295.2.14 raeburn 351: $custdisp .= '</td></tr>';
1.295.2.7 raeburn 352: }
353: $custdisp .= '</table>';
354: $custradio = '</span></td><td>'.&mt('Custom setting').'<br />'.$custdisp;
355: } else {
356: $currdisp = ($curr_access?&mt('Yes'):&mt('No'));
357: $custdisp = '<span class="LC_nobreak"><label>'.
358: '<input type="radio" name="'.$context.'_'.$item.'"'.
359: ' value="1"'. $tool_on.'/>'.&mt('On').'</label> <label>'.
360: '<input type="radio" name="'.$context.'_'.$item.'" value="0" '.
361: $tool_off.'/>'.&mt('Off').'</label></span>';
362: $custradio = (' 'x2).'--'.$lt{'cusa'}.': '.$custdisp.
363: '</span>';
364: }
365: $output .= ' <td'.$colspan.'>'.$custom_access.(' 'x4).
366: $lt{'avai'}.': '.$currdisp.'</td>'."\n".
1.275 raeburn 367: &Apache::loncommon::end_data_table_row()."\n".
368: &Apache::loncommon::start_data_table_row()."\n".
1.295.2.7 raeburn 369: ' <td style="vertical-align:top;"><span class="LC_nobreak">'.
370: $lt{'chse'}.': <label>'.
1.275 raeburn 371: '<input type="radio" name="custom'.$item.'" value="0" '.
1.295.2.7 raeburn 372: $cust_off.'/>'.$lt{'usde'}.'</label>'.(' ' x3).
373: '<label><input type="radio" name="custom'.$item.'" value="1" '.
374: $cust_on.'/>'.$lt{'uscu'}.'</label>'.$custradio.'</td>'.
1.275 raeburn 375: &Apache::loncommon::end_data_table_row()."\n";
376: }
377: return $output;
378: }
379:
1.295.2.3 raeburn 380: sub coursereq_externaluser {
381: my ($ccuname,$ccdomain,$cdom) = @_;
382: my (@usertools,@options,%validations,%userenv,$output);
383: my %lt = &Apache::lonlocal::texthash (
384: 'official' => 'Can request creation of official courses',
385: 'unofficial' => 'Can request creation of unofficial courses',
386: 'community' => 'Can request creation of communities',
387: );
388:
389: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
390: 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
391: 'reqcrsotherdom.community');
392: @usertools = ('official','unofficial','community');
1.295.2.10 raeburn 393: @options = ('approval','validate','autolimit');
1.295.2.3 raeburn 394: %validations = &Apache::lonnet::auto_courserequest_checks($cdom);
395: my $optregex = join('|',@options);
396: my %reqtitles = &courserequest_titles();
397: foreach my $item (@usertools) {
398: my ($curroption,$currlimit,$tooloff);
399: if ($userenv{'reqcrsotherdom.'.$item} ne '') {
400: my @curr = split(',',$userenv{'reqcrsotherdom.'.$item});
1.295.2.14 raeburn 401: foreach my $req (@curr) {
402: if ($req =~ /^\Q$cdom\E\:($optregex)=?(\d*)$/) {
403: $curroption = $1;
404: $currlimit = $2;
405: last;
1.295.2.3 raeburn 406: }
407: }
1.295.2.14 raeburn 408: if (!$curroption) {
409: $curroption = 'norequest';
410: $tooloff = ' checked="checked"';
411: }
1.295.2.3 raeburn 412: } else {
413: $curroption = 'norequest';
414: $tooloff = ' checked="checked"';
415: }
416: $output.= &Apache::loncommon::start_data_table_row()."\n".
1.295.2.14 raeburn 417: ' <td><span class="LC_nobreak">'.$lt{$item}.': </span></td><td>'.
418: '<table><tr><td valign="top">'."\n".
1.295.2.3 raeburn 419: '<label><input type="radio" name="reqcrsotherdom_'.$item.
1.295.2.14 raeburn 420: '" value=""'.$tooloff.' />'.$reqtitles{'norequest'}.
421: '</label></td>';
1.295.2.3 raeburn 422: foreach my $option (@options) {
423: if ($option eq 'validate') {
424: my $canvalidate = 0;
425: if (ref($validations{$item}) eq 'HASH') {
426: if ($validations{$item}{'_external_'}) {
427: $canvalidate = 1;
428: }
429: }
430: next if (!$canvalidate);
431: }
432: my $checked = '';
433: if ($option eq $curroption) {
434: $checked = ' checked="checked"';
435: }
1.295.2.14 raeburn 436: $output .= '<td valign="top"><span class="LC_nobreak"><label>'.
1.295.2.3 raeburn 437: '<input type="radio" name="reqcrsotherdom_'.$item.
438: '" value="'.$option.'"'.$checked.' />'.
1.295.2.14 raeburn 439: $reqtitles{$option}.'</label>';
1.295.2.3 raeburn 440: if ($option eq 'autolimit') {
1.295.2.14 raeburn 441: $output .= ' <input type="text" name="reqcrsotherdom_'.
1.295.2.3 raeburn 442: $item.'_limit" size="1" '.
1.295.2.14 raeburn 443: 'value="'.$currlimit.'" /></span>'.
444: '<br />'.$reqtitles{'unlimited'};
445: } else {
446: $output .= '</span>';
1.295.2.3 raeburn 447: }
1.295.2.14 raeburn 448: $output .= '</td>';
1.295.2.3 raeburn 449: }
1.295.2.14 raeburn 450: $output .= '</td></tr></table></td>'."\n".
1.295.2.3 raeburn 451: &Apache::loncommon::end_data_table_row()."\n";
452: }
453: return $output;
454: }
455:
456: sub courserequest_titles {
457: my %titles = &Apache::lonlocal::texthash (
1.295.2.7 raeburn 458: official => 'Official',
459: unofficial => 'Unofficial',
460: community => 'Communities',
461: norequest => 'Not allowed',
1.295.2.10 raeburn 462: approval => 'Approval by Dom. Coord.',
1.295.2.3 raeburn 463: validate => 'With validation',
464: autolimit => 'Numerical limit',
1.295.2.14 raeburn 465: unlimited => '(blank for unlimited)',
1.295.2.3 raeburn 466: );
1.295.2.14 raeburn 467: return %titles;
468: }
469:
1.295.2.3 raeburn 470: sub courserequest_display {
471: my %titles = &Apache::lonlocal::texthash (
1.295.2.10 raeburn 472: approval => 'Yes, need approval',
1.295.2.3 raeburn 473: validate => 'Yes, with validation',
474: norequest => 'No',
1.295.2.14 raeburn 475: );
1.295.2.3 raeburn 476: return %titles;
477: }
478:
1.2 www 479: # =================================================================== Phase one
1.1 www 480:
1.42 matthew 481: sub print_username_entry_form {
1.295.2.18 raeburn 482: my ($r,$context,$response,$srch,$forcenewuser,$crstype) = @_;
1.101 albertel 483: my $defdom=$env{'request.role.domain'};
1.160 raeburn 484: my $formtoset = 'crtuser';
485: if (exists($env{'form.startrolename'})) {
486: $formtoset = 'docustom';
487: $env{'form.rolename'} = $env{'form.startrolename'};
1.207 raeburn 488: } elsif ($env{'form.origform'} eq 'crtusername') {
489: $formtoset = $env{'form.origform'};
1.160 raeburn 490: }
491:
492: my ($jsback,$elements) = &crumb_utilities();
493:
494: my $jscript = &Apache::loncommon::studentbrowser_javascript()."\n".
1.165 albertel 495: '<script type="text/javascript">'."\n".
1.295.2.4 raeburn 496: '// <![CDATA['."\n".
497: &Apache::lonhtmlcommon::set_form_elements($elements->{$formtoset})."\n".
498: '// ]]>'."\n".
1.162 raeburn 499: '</script>'."\n";
1.160 raeburn 500:
1.295.2.24 raeburn 501: my %existingroles=&Apache::lonuserutils::my_custom_roles($crstype);
502: if (($env{'form.action'} eq 'custom') && (keys(%existingroles) > 0)
503: && (&Apache::lonnet::allowed('mcr','/'))) {
504: $jscript .= &customrole_javascript();
505: }
1.160 raeburn 506: my %loaditems = (
507: 'onload' => "javascript:setFormElements(document.$formtoset)",
508: );
1.295.2.18 raeburn 509: my %breadcrumb_text = &singleuser_breadcrumb($crstype);
1.110 albertel 510: my $start_page =
1.190 raeburn 511: &Apache::loncommon::start_page('User Management',
1.160 raeburn 512: $jscript,{'add_entries' => \%loaditems,});
1.214 raeburn 513: if ($env{'form.action'} eq 'custom') {
514: &Apache::lonhtmlcommon::add_breadcrumb
515: ({href=>"javascript:backPage(document.crtuser)",
516: text=>"Pick custom role",});
517: } else {
1.190 raeburn 518: &Apache::lonhtmlcommon::add_breadcrumb
519: ({href=>"javascript:backPage(document.crtuser)",
1.229 raeburn 520: text=>$breadcrumb_text{'search'},
1.190 raeburn 521: faq=>282,bug=>'Instructor Interface',});
522: }
1.224 raeburn 523: my $helpitem = 'Course_Change_Privileges';
524: if ($env{'form.action'} eq 'custom') {
525: $helpitem = 'Course_Editing_Custom_Roles';
526: } elsif ($env{'form.action'} eq 'singlestudent') {
527: $helpitem = 'Course_Add_Student';
528: }
529: my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('User Management',
530: $helpitem);
1.71 sakharuk 531: my %lt=&Apache::lonlocal::texthash(
1.229 raeburn 532: 'srst' => 'Search for a user and enroll as a student',
1.295.2.18 raeburn 533: 'srme' => 'Search for a user and enroll as a member',
1.229 raeburn 534: 'srad' => 'Search for a user and modify/add user information or roles',
1.71 sakharuk 535: 'usr' => "Username",
536: 'dom' => "Domain",
1.295.2.24 raeburn 537: 'ecrp' => "Define or Edit Custom Role",
538: 'nr' => "role name",
1.282 schafran 539: 'cre' => "Next",
1.71 sakharuk 540: );
1.190 raeburn 541: $r->print($start_page."\n".$crumbs);
1.214 raeburn 542: if ($env{'form.action'} eq 'custom') {
1.190 raeburn 543: if (&Apache::lonnet::allowed('mcr','/')) {
1.295.2.24 raeburn 544: my $newroletext = &mt('Define new custom role:');
545: $r->print('<form action="/adm/createuser" method="post" name="docustom">'.
546: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
547: '<input type="hidden" name="phase" value="selected_custom_edit" />'.
548: '<h3>'.$lt{'ecrp'}.'</h3>'.
549: &Apache::loncommon::start_data_table().
550: &Apache::loncommon::start_data_table_row().
551: '<td>');
552: if (keys(%existingroles) > 0) {
553: $r->print('<br /><label><input type="radio" name="customroleaction" value="new" checked="checked" onclick="setCustomFields();" /><b>'.$newroletext.'</b></label>');
554: } else {
555: $r->print('<br /><input type="hidden" name="customroleaction" value="new" /><b>'.$newroletext.'</b>');
556: }
557: $r->print('</td><td align="center">'.$lt{'nr'}.'<br /><input type="text" size="15" name="newrolename" onfocus="setCustomAction('."'new'".');" /></td>'.
558: &Apache::loncommon::end_data_table_row());
559: if (keys(%existingroles) > 0) {
560: $r->print(&Apache::loncommon::start_data_table_row().'<td><br />'.
561: '<label><input type="radio" name="customroleaction" value="edit" onclick="setCustomFields();"/><b>'.
562: &mt('View/Modify existing role:').'</b></label></td>'.
563: '<td align="center"><br />'.
564: '<select name="rolename" onchange="setCustomAction('."'edit'".');">'.
565: '<option value="" selected="selected">'.
566: &mt('Select'));
567: foreach my $role (sort(keys(%existingroles))) {
568: $r->print('<option value="'.$role.'">'.$role.'</option>');
569: }
570: $r->print('</select>'.
571: '</td>'.
572: &Apache::loncommon::end_data_table_row());
573: }
574: $r->print(&Apache::loncommon::end_data_table().'<p>'.
575: '<input name="customeditor" type="submit" value="'.
576: $lt{'cre'}.'" /></p>'.
577: '</form>');
1.190 raeburn 578: }
1.213 raeburn 579: } else {
1.229 raeburn 580: my $actiontext = $lt{'srad'};
1.213 raeburn 581: if ($env{'form.action'} eq 'singlestudent') {
1.295.2.18 raeburn 582: if ($crstype eq 'Community') {
583: $actiontext = $lt{'srme'};
584: } else {
585: $actiontext = $lt{'srst'};
586: }
1.213 raeburn 587: }
1.295.2.18 raeburn 588: $r->print("<h3>$actiontext</h3>");
1.213 raeburn 589: if ($env{'form.origform'} ne 'crtusername') {
590: $r->print("\n".$response);
591: }
1.295.2.18 raeburn 592: $r->print(&entry_form($defdom,$srch,$forcenewuser,$context,$response,$crstype));
1.107 www 593: }
1.110 albertel 594: $r->print(&Apache::loncommon::end_page());
595: }
596:
1.295.2.24 raeburn 597: sub customrole_javascript {
598: my $js = <<"END";
599: <script type="text/javascript">
600: // <![CDATA[
601:
602: function setCustomFields() {
603: if (document.docustom.customroleaction.length > 0) {
604: for (var i=0; i<document.docustom.customroleaction.length; i++) {
605: if (document.docustom.customroleaction[i].checked) {
606: if (document.docustom.customroleaction[i].value == 'new') {
607: document.docustom.rolename.selectedIndex = 0;
608: } else {
609: document.docustom.newrolename.value = '';
610: }
611: }
612: }
613: }
614: return;
615: }
616:
617: function setCustomAction(caller) {
618: if (document.docustom.customroleaction.length > 0) {
619: for (var i=0; i<document.docustom.customroleaction.length; i++) {
620: if (document.docustom.customroleaction[i].value == caller) {
621: document.docustom.customroleaction[i].checked = true;
622: }
623: }
624: }
625: setCustomFields();
626: return;
627: }
628:
629: // ]]>
630: </script>
631: END
632: return $js;
633: }
634:
1.160 raeburn 635: sub entry_form {
1.295.2.18 raeburn 636: my ($dom,$srch,$forcenewuser,$context,$responsemsg,$crstype) = @_;
1.207 raeburn 637: my %domconf = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
1.229 raeburn 638: my ($usertype,$inexact);
1.214 raeburn 639: if (ref($srch) eq 'HASH') {
640: if (($srch->{'srchin'} eq 'dom') &&
641: ($srch->{'srchby'} eq 'uname') &&
642: ($srch->{'srchtype'} eq 'exact') &&
643: ($srch->{'srchdomain'} ne '') &&
644: ($srch->{'srchterm'} ne '')) {
645: my ($rules,$ruleorder) =
646: &Apache::lonnet::inst_userrules($srch->{'srchdomain'},'username');
647: $usertype = &Apache::lonuserutils::check_usertype($srch->{'srchdomain'},$srch->{'srchterm'},$rules);
1.229 raeburn 648: } else {
649: $inexact = 1;
1.214 raeburn 650: }
1.207 raeburn 651: }
1.214 raeburn 652: my $cancreate =
653: &Apache::lonuserutils::can_create_user($dom,$context,$usertype);
1.160 raeburn 654: my $userpicker =
1.179 raeburn 655: &Apache::loncommon::user_picker($dom,$srch,$forcenewuser,
1.214 raeburn 656: 'document.crtuser',$cancreate,$usertype);
1.160 raeburn 657: my $srchbutton = &mt('Search');
1.229 raeburn 658: if ($env{'form.action'} eq 'singlestudent') {
659: $srchbutton = &mt('Search and Enroll');
660: } elsif ($cancreate && $responsemsg ne '' && $inexact) {
661: $srchbutton = &mt('Search or Add New User');
662: }
1.207 raeburn 663: my $output = <<"ENDBLOCK";
1.160 raeburn 664: <form action="/adm/createuser" method="post" name="crtuser">
1.190 raeburn 665: <input type="hidden" name="action" value="$env{'form.action'}" />
1.160 raeburn 666: <input type="hidden" name="phase" value="get_user_info" />
667: $userpicker
1.179 raeburn 668: <input name="userrole" type="button" value="$srchbutton" onclick="javascript:validateEntry(document.crtuser)" />
1.160 raeburn 669: </form>
1.207 raeburn 670: ENDBLOCK
1.229 raeburn 671: if ($env{'form.phase'} eq '') {
1.207 raeburn 672: my $defdom=$env{'request.role.domain'};
673: my $domform = &Apache::loncommon::select_dom_form($defdom,'srchdomain');
674: my %lt=&Apache::lonlocal::texthash(
1.229 raeburn 675: 'enro' => 'Enroll one student',
1.295.2.18 raeburn 676: 'enrm' => 'Enroll one member',
1.229 raeburn 677: 'admo' => 'Add/modify a single user',
678: 'crea' => 'create new user if required',
679: 'uskn' => "username is known",
1.207 raeburn 680: 'crnu' => 'Create a new user',
681: 'usr' => 'Username',
682: 'dom' => 'in domain',
1.229 raeburn 683: 'enrl' => 'Enroll',
684: 'cram' => 'Create/Modify user',
1.207 raeburn 685: );
1.229 raeburn 686: my $sellink=&Apache::loncommon::selectstudent_link('crtusername','srchterm','srchdomain');
687: my ($title,$buttontext,$showresponse);
688: if ($env{'form.action'} eq 'singlestudent') {
1.295.2.18 raeburn 689: if ($crstype eq 'Community') {
690: $title = $lt{'enrm'};
691: } else {
692: $title = $lt{'enro'};
693: }
1.229 raeburn 694: $buttontext = $lt{'enrl'};
695: } else {
696: $title = $lt{'admo'};
697: $buttontext = $lt{'cram'};
698: }
699: if ($cancreate) {
700: $title .= ' <span class="LC_cusr_subheading">('.$lt{'crea'}.')</span>';
701: } else {
702: $title .= ' <span class="LC_cusr_subheading">('.$lt{'uskn'}.')</span>';
703: }
704: if ($env{'form.origform'} eq 'crtusername') {
705: $showresponse = $responsemsg;
706: }
1.207 raeburn 707: $output .= <<"ENDDOCUMENT";
1.229 raeburn 708: <br />
1.207 raeburn 709: <form action="/adm/createuser" method="post" name="crtusername">
710: <input type="hidden" name="action" value="$env{'form.action'}" />
711: <input type="hidden" name="phase" value="createnewuser" />
712: <input type="hidden" name="srchtype" value="exact" />
1.233 raeburn 713: <input type="hidden" name="srchby" value="uname" />
1.207 raeburn 714: <input type="hidden" name="srchin" value="dom" />
715: <input type="hidden" name="forcenewuser" value="1" />
716: <input type="hidden" name="origform" value="crtusername" />
1.229 raeburn 717: <h3>$title</h3>
718: $showresponse
1.207 raeburn 719: <table>
720: <tr>
721: <td>$lt{'usr'}:</td>
722: <td><input type="text" size="15" name="srchterm" /></td>
723: <td> $lt{'dom'}:</td><td>$domform</td>
1.229 raeburn 724: <td> $sellink </td>
725: <td> <input name="userrole" type="submit" value="$buttontext" /></td>
1.207 raeburn 726: </tr>
727: </table>
728: </form>
1.160 raeburn 729: ENDDOCUMENT
1.207 raeburn 730: }
1.160 raeburn 731: return $output;
732: }
1.110 albertel 733:
734: sub user_modification_js {
1.113 raeburn 735: my ($pjump_def,$dc_setcourse_code,$nondc_setsection_code,$groupslist)=@_;
736:
1.110 albertel 737: return <<END;
738: <script type="text/javascript" language="Javascript">
1.295.2.4 raeburn 739: // <![CDATA[
1.110 albertel 740:
741: function pclose() {
742: parmwin=window.open("/adm/rat/empty.html","LONCAPAparms",
743: "height=350,width=350,scrollbars=no,menubar=no");
744: parmwin.close();
745: }
746:
747: $pjump_def
748: $dc_setcourse_code
749:
750: function dateset() {
751: eval("document.cu."+document.cu.pres_marker.value+
752: ".value=document.cu.pres_value.value");
753: pclose();
754: }
755:
1.113 raeburn 756: $nondc_setsection_code
1.295.2.4 raeburn 757: // ]]>
1.110 albertel 758: </script>
759: END
1.2 www 760: }
761:
762: # =================================================================== Phase two
1.160 raeburn 763: sub print_user_selection_page {
1.295.2.18 raeburn 764: my ($r,$response,$srch,$srch_results,$srcharray,$context,$opener_elements,$crstype) = @_;
1.160 raeburn 765: my @fields = ('username','domain','lastname','firstname','permanentemail');
766: my $sortby = $env{'form.sortby'};
767:
768: if (!grep(/^\Q$sortby\E$/,@fields)) {
769: $sortby = 'lastname';
770: }
771:
772: my ($jsback,$elements) = &crumb_utilities();
773:
774: my $jscript = (<<ENDSCRIPT);
775: <script type="text/javascript">
1.295.2.4 raeburn 776: // <![CDATA[
1.160 raeburn 777: function pickuser(uname,udom) {
778: document.usersrchform.seluname.value=uname;
779: document.usersrchform.seludom.value=udom;
780: document.usersrchform.phase.value="userpicked";
781: document.usersrchform.submit();
782: }
783:
784: $jsback
1.295.2.4 raeburn 785: // ]]>
1.160 raeburn 786: </script>
787: ENDSCRIPT
788:
789: my %lt=&Apache::lonlocal::texthash(
1.179 raeburn 790: 'usrch' => "User Search to add/modify roles",
791: 'stusrch' => "User Search to enroll student",
1.295.2.18 raeburn 792: 'memsrch' => "User Search to enroll member",
1.179 raeburn 793: 'usel' => "Select a user to add/modify roles",
1.295.2.18 raeburn 794: 'stusel' => "Select a user to enroll as a student",
795: 'memsel' => "Select a user to enroll as a member",
1.160 raeburn 796: 'username' => "username",
797: 'domain' => "domain",
798: 'lastname' => "last name",
799: 'firstname' => "first name",
800: 'permanentemail' => "permanent e-mail",
801: );
1.295.2.7 raeburn 802: if ($context eq 'requestcrs') {
803: $r->print('<div>');
804: } else {
805: $r->print(&Apache::loncommon::start_page('User Management',$jscript));
1.229 raeburn 806:
1.295.2.18 raeburn 807: my %breadcrumb_text = &singleuser_breadcrumb($crstype);
1.295.2.7 raeburn 808: &Apache::lonhtmlcommon::add_breadcrumb
809: ({href=>"javascript:backPage(document.usersrchform,'','')",
810: text=>$breadcrumb_text{'search'},
811: faq=>282,bug=>'Instructor Interface',},
812: {href=>"javascript:backPage(document.usersrchform,'get_user_info','select')",
813: text=>$breadcrumb_text{'userpicked'},
814: faq=>282,bug=>'Instructor Interface',});
815: if ($env{'form.action'} eq 'singleuser') {
816: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management',
1.295.2.14 raeburn 817: 'Course_Change_Privileges'));
1.295.2.7 raeburn 818: $r->print("<b>$lt{'usrch'}</b><br />");
1.295.2.18 raeburn 819: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,$crstype));
1.295.2.7 raeburn 820: $r->print('<h3>'.$lt{'usel'}.'</h3>');
821: } elsif ($env{'form.action'} eq 'singlestudent') {
822: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management',
1.295.2.14 raeburn 823: 'Course_Add_Student'));
1.295.2.18 raeburn 824: $r->print($jscript."<b>");
825: if ($crstype eq 'Community') {
826: $r->print($lt{'memsrch'});
827: } else {
828: $r->print($lt{'stusrch'});
829: }
830: $r->print("</b><br />");
831: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,$crstype));
832: $r->print('</form><h3>');
833: if ($crstype eq 'Community') {
834: $r->print($lt{'memsel'});
835: } else {
836: $r->print($lt{'stusel'});
837: }
838: $r->print('</h3>');
1.295.2.7 raeburn 839: }
1.179 raeburn 840: }
1.160 raeburn 841: $r->print('<form name="usersrchform" method="post">'.
842: &Apache::loncommon::start_data_table()."\n".
843: &Apache::loncommon::start_data_table_header_row()."\n".
844: ' <th> </th>'."\n");
845: foreach my $field (@fields) {
846: $r->print(' <th><a href="javascript:document.usersrchform.sortby.value='.
847: "'".$field."'".';document.usersrchform.submit();">'.
848: $lt{$field}.'</a></th>'."\n");
849: }
850: $r->print(&Apache::loncommon::end_data_table_header_row());
851:
852: my @sorted_users = sort {
1.167 albertel 853: lc($srch_results->{$a}->{$sortby}) cmp lc($srch_results->{$b}->{$sortby})
1.160 raeburn 854: ||
1.167 albertel 855: lc($srch_results->{$a}->{lastname}) cmp lc($srch_results->{$b}->{lastname})
1.160 raeburn 856: ||
857: lc($srch_results->{$a}->{firstname}) cmp lc($srch_results->{$b}->{firstname})
1.167 albertel 858: ||
859: lc($a) cmp lc($b)
1.160 raeburn 860: } (keys(%$srch_results));
861:
862: foreach my $user (@sorted_users) {
863: my ($uname,$udom) = split(/:/,$user);
1.295.2.7 raeburn 864: my $onclick;
865: if ($context eq 'requestcrs') {
866: $onclick =
867: 'onclick="javascript:gochoose('."'$uname','$udom',".
868: "'$srch_results->{$user}->{firstname}',".
869: "'$srch_results->{$user}->{lastname}',".
870: "'$srch_results->{$user}->{permanentemail}'".');"';
871: } else {
872: $onclick =
873: ' onclick="javascript:pickuser('."'".$uname."'".','."'".$udom."'".');"';
874: }
1.160 raeburn 875: $r->print(&Apache::loncommon::start_data_table_row().
1.295.2.7 raeburn 876: '<td><input type="button" name="seluser" value="'.&mt('Select').'" '.
877: $onclick.' /></td>'.
1.160 raeburn 878: '<td><tt>'.$uname.'</tt></td>'.
879: '<td><tt>'.$udom.'</tt></td>');
880: foreach my $field ('lastname','firstname','permanentemail') {
881: $r->print('<td>'.$srch_results->{$user}->{$field}.'</td>');
882: }
883: $r->print(&Apache::loncommon::end_data_table_row());
884: }
885: $r->print(&Apache::loncommon::end_data_table().'<br /><br />');
1.179 raeburn 886: if (ref($srcharray) eq 'ARRAY') {
887: foreach my $item (@{$srcharray}) {
888: $r->print('<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n");
889: }
890: }
1.160 raeburn 891: $r->print(' <input type="hidden" name="sortby" value="'.$sortby.'" />'."\n".
892: ' <input type="hidden" name="seluname" value="" />'."\n".
893: ' <input type="hidden" name="seludom" value="" />'."\n".
1.179 raeburn 894: ' <input type="hidden" name="currstate" value="select" />'."\n".
1.190 raeburn 895: ' <input type="hidden" name="phase" value="get_user_info" />'."\n".
1.214 raeburn 896: ' <input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n");
1.295.2.7 raeburn 897: if ($context eq 'requestcrs') {
898: $r->print($opener_elements.'</form></div>');
899: } else {
900: $r->print($response.'</form>'.&Apache::loncommon::end_page());
901: }
1.160 raeburn 902: }
903:
904: sub print_user_query_page {
1.179 raeburn 905: my ($r,$caller) = @_;
1.160 raeburn 906: # FIXME - this is for a network-wide name search (similar to catalog search)
907: # To use frames with similar behavior to catalog/portfolio search.
908: # To be implemented.
909: return;
910: }
911:
1.42 matthew 912: sub print_user_modification_page {
1.295.2.18 raeburn 913: my ($r,$ccuname,$ccdomain,$srch,$response,$context,$permission,$crstype) = @_;
1.185 raeburn 914: if (($ccuname eq '') || ($ccdomain eq '')) {
1.215 raeburn 915: my $usermsg = &mt('No username and/or domain provided.');
916: $env{'form.phase'} = '';
1.295.2.18 raeburn 917: &print_username_entry_form($r,$context,$usermsg,'','',$crstype);
1.58 www 918: return;
919: }
1.213 raeburn 920: my ($form,$formname);
921: if ($env{'form.action'} eq 'singlestudent') {
922: $form = 'document.enrollstudent';
923: $formname = 'enrollstudent';
924: } else {
925: $form = 'document.cu';
926: $formname = 'cu';
927: }
1.188 raeburn 928: my %abv_auth = &auth_abbrev();
1.227 raeburn 929: my (%rulematch,%inst_results,$newuser,%alerts,%curr_rules,%got_rules);
1.185 raeburn 930: my $uhome=&Apache::lonnet::homeserver($ccuname,$ccdomain);
931: if ($uhome eq 'no_host') {
1.215 raeburn 932: my $usertype;
933: my ($rules,$ruleorder) =
934: &Apache::lonnet::inst_userrules($ccdomain,'username');
935: $usertype =
936: &Apache::lonuserutils::check_usertype($ccdomain,$ccuname,$rules);
937: my $cancreate =
938: &Apache::lonuserutils::can_create_user($ccdomain,$context,
939: $usertype);
940: if (!$cancreate) {
1.292 bisitz 941: my $helplink = 'javascript:helpMenu('."'display'".')';
1.215 raeburn 942: my %usertypetext = (
943: official => 'institutional',
944: unofficial => 'non-institutional',
945: );
946: my $response;
947: if ($env{'form.origform'} eq 'crtusername') {
1.295.2.31 raeburn 948: $response = '<span class="LC_warning">'.&mt('No match found for the username [_1] in LON-CAPA domain: [_2]','<b>'.$ccuname.'</b>',$ccdomain).
1.215 raeburn 949: '</span><br />';
950: }
1.292 bisitz 951: $response .= '<p class="LC_warning">'
952: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
953: .' '
954: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
955: ,'<a href="'.$helplink.'">','</a>')
956: .'</p><br />';
1.215 raeburn 957: $env{'form.phase'} = '';
1.295.2.18 raeburn 958: &print_username_entry_form($r,$context,$response,undef,undef,$crstype);
1.215 raeburn 959: return;
960: }
1.188 raeburn 961: $newuser = 1;
1.193 raeburn 962: my $checkhash;
963: my $checks = { 'username' => 1 };
1.196 raeburn 964: $checkhash->{$ccuname.':'.$ccdomain} = { 'newuser' => $newuser };
1.193 raeburn 965: &Apache::loncommon::user_rule_check($checkhash,$checks,
1.196 raeburn 966: \%alerts,\%rulematch,\%inst_results,\%curr_rules,\%got_rules);
967: if (ref($alerts{'username'}) eq 'HASH') {
968: if (ref($alerts{'username'}{$ccdomain}) eq 'HASH') {
969: my $domdesc =
1.193 raeburn 970: &Apache::lonnet::domain($ccdomain,'description');
1.196 raeburn 971: if ($alerts{'username'}{$ccdomain}{$ccuname}) {
972: my $userchkmsg;
973: if (ref($curr_rules{$ccdomain}) eq 'HASH') {
974: $userchkmsg =
975: &Apache::loncommon::instrule_disallow_msg('username',
1.193 raeburn 976: $domdesc,1).
977: &Apache::loncommon::user_rule_formats($ccdomain,
978: $domdesc,$curr_rules{$ccdomain}{'username'},
979: 'username');
1.196 raeburn 980: }
1.215 raeburn 981: $env{'form.phase'} = '';
1.295.2.18 raeburn 982: &print_username_entry_form($r,$context,$userchkmsg,undef,undef,$crstype);
1.196 raeburn 983: return;
1.215 raeburn 984: }
1.193 raeburn 985: }
1.185 raeburn 986: }
1.187 raeburn 987: } else {
1.188 raeburn 988: $newuser = 0;
1.185 raeburn 989: }
1.160 raeburn 990: if ($response) {
1.215 raeburn 991: $response = '<br />'.$response;
1.160 raeburn 992: }
1.149 raeburn 993:
1.52 matthew 994: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
1.88 raeburn 995: my $dc_setcourse_code = '';
1.119 raeburn 996: my $nondc_setsection_code = '';
1.112 albertel 997: my %loaditem;
1.114 albertel 998:
1.216 raeburn 999: my $groupslist = &Apache::lonuserutils::get_groupslist();
1.88 raeburn 1000:
1.216 raeburn 1001: my $js = &validation_javascript($context,$ccdomain,$pjump_def,
1002: $groupslist,$newuser,$formname,\%loaditem);
1.233 raeburn 1003: my $args = {'add_entries' => \%loaditem};
1004: if ($env{'form.popup'}) {
1005: $args->{'no_nav_bar'} = 1;
1006: }
1.110 albertel 1007: my $start_page =
1.233 raeburn 1008: &Apache::loncommon::start_page('User Management',$js,$args);
1.295.2.18 raeburn 1009: my %breadcrumb_text = &singleuser_breadcrumb($crstype);
1.160 raeburn 1010: &Apache::lonhtmlcommon::add_breadcrumb
1.216 raeburn 1011: ({href=>"javascript:backPage($form)",
1012: text=>$breadcrumb_text{'search'},
1.160 raeburn 1013: faq=>282,bug=>'Instructor Interface',});
1014:
1015: if ($env{'form.phase'} eq 'userpicked') {
1016: &Apache::lonhtmlcommon::add_breadcrumb
1.216 raeburn 1017: ({href=>"javascript:backPage($form,'get_user_info','select')",
1018: text=>$breadcrumb_text{'userpicked'},
1.160 raeburn 1019: faq=>282,bug=>'Instructor Interface',});
1020: }
1021: &Apache::lonhtmlcommon::add_breadcrumb
1.216 raeburn 1022: ({href=>"javascript:backPage($form,'$env{'form.phase'}','modify')",
1023: text=>$breadcrumb_text{'modify'},
1.160 raeburn 1024: faq=>282,bug=>'Instructor Interface',});
1.224 raeburn 1025: my $helpitem = 'Course_Change_Privileges';
1026: if ($env{'form.action'} eq 'singlestudent') {
1027: $helpitem = 'Course_Add_Student';
1028: }
1029: my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('User Management',
1030: $helpitem);
1.3 www 1031:
1.25 matthew 1032: my $forminfo =<<"ENDFORMINFO";
1.216 raeburn 1033: <form action="/adm/createuser" method="post" name="$formname">
1.190 raeburn 1034: <input type="hidden" name="phase" value="update_user_data" />
1.188 raeburn 1035: <input type="hidden" name="ccuname" value="$ccuname" />
1036: <input type="hidden" name="ccdomain" value="$ccdomain" />
1.157 albertel 1037: <input type="hidden" name="pres_value" value="" />
1038: <input type="hidden" name="pres_type" value="" />
1039: <input type="hidden" name="pres_marker" value="" />
1.25 matthew 1040: ENDFORMINFO
1.295.2.26 raeburn 1041: my (%inccourses,$roledom);
1042: if ($context eq 'course') {
1043: $inccourses{$env{'request.course.id'}}=1;
1044: $roledom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1045: } elsif ($context eq 'author') {
1046: $roledom = $env{'request.role.domain'};
1047: } elsif ($context eq 'domain') {
1048: foreach my $key (keys(%env)) {
1049: $roledom = $env{'request.role.domain'};
1050: if ($key=~/^user\.priv\.cm\.\/($roledom)\/($match_username)/) {
1051: $inccourses{$1.'_'.$2}=1;
1052: }
1053: }
1054: } else {
1055: foreach my $key (keys(%env)) {
1056: if ($key=~/^user\.priv\.cm\.\/($match_domain)\/($match_username)/) {
1057: $inccourses{$1.'_'.$2}=1;
1058: }
1.2 www 1059: }
1.24 matthew 1060: }
1.216 raeburn 1061: if ($newuser) {
1.134 raeburn 1062: my $portfolioform;
1.267 raeburn 1063: if ((&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) ||
1064: (&Apache::lonnet::allowed('mut',$env{'request.role.domain'}))) {
1065: # Current user has quota or user tools modification privileges
1.188 raeburn 1066: $portfolioform = '<br />'.&portfolio_quota($ccuname,$ccdomain);
1.134 raeburn 1067: }
1.227 raeburn 1068: &initialize_authen_forms($ccdomain,$formname);
1.188 raeburn 1069: my %lt=&Apache::lonlocal::texthash(
1070: 'cnu' => 'Create New User',
1.213 raeburn 1071: 'ast' => 'as a student',
1.295.2.18 raeburn 1072: 'ame' => 'as a member',
1.188 raeburn 1073: 'ind' => 'in domain',
1074: 'lg' => 'Login Data',
1.190 raeburn 1075: 'hs' => "Home Server",
1.188 raeburn 1076: );
1.185 raeburn 1077: $r->print(<<ENDTITLE);
1.110 albertel 1078: $start_page
1.160 raeburn 1079: $crumbs
1080: $response
1.25 matthew 1081: $forminfo
1.31 matthew 1082: <script type="text/javascript" language="Javascript">
1.295.2.4 raeburn 1083: // <![CDATA[
1.20 harris41 1084: $loginscript
1.295.2.4 raeburn 1085: // ]]>
1.31 matthew 1086: </script>
1.20 harris41 1087: <input type='hidden' name='makeuser' value='1' />
1.216 raeburn 1088: <h2>$lt{'cnu'} "$ccuname" $lt{'ind'} $ccdomain
1.185 raeburn 1089: ENDTITLE
1.213 raeburn 1090: if ($env{'form.action'} eq 'singlestudent') {
1.295.2.18 raeburn 1091: if ($crstype eq 'Community') {
1092: $r->print(' ('.$lt{'ame'}.')');
1093: } else {
1094: $r->print(' ('.$lt{'ast'}.')');
1095: }
1.213 raeburn 1096: }
1097: $r->print('</h2>'."\n".'<div class="LC_left_float">');
1.206 raeburn 1098: my $personal_table =
1.210 raeburn 1099: &personal_data_display($ccuname,$ccdomain,$newuser,$context,
1100: $inst_results{$ccuname.':'.$ccdomain});
1.206 raeburn 1101: $r->print($personal_table);
1.187 raeburn 1102: my ($home_server_pick,$numlib) =
1103: &Apache::loncommon::home_server_form_item($ccdomain,'hserver',
1104: 'default','hide');
1105: if ($numlib > 1) {
1106: $r->print("
1.185 raeburn 1107: <br />
1.187 raeburn 1108: $lt{'hs'}: $home_server_pick
1109: <br />");
1110: } else {
1111: $r->print($home_server_pick);
1112: }
1.295.2.5 raeburn 1113: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.295.2.18 raeburn 1114: $r->print('<br /><h3>'.&mt('User Can Request Creation of Courses/Communities in this Domain?').'</h3>'.
1.295.2.5 raeburn 1115: &Apache::loncommon::start_data_table().
1116: &build_tools_display($ccuname,$ccdomain,
1117: 'requestcourses').
1118: &Apache::loncommon::end_data_table());
1119: }
1.188 raeburn 1120: $r->print('</div>'."\n".'<div class="LC_left_float"><h3>'.
1121: $lt{'lg'}.'</h3>');
1.185 raeburn 1122: my ($fixedauth,$varauth,$authmsg);
1.193 raeburn 1123: if (ref($rulematch{$ccuname.':'.$ccdomain}) eq 'HASH') {
1124: my $matchedrule = $rulematch{$ccuname.':'.$ccdomain}{'username'};
1125: my ($rules,$ruleorder) =
1126: &Apache::lonnet::inst_userrules($ccdomain,'username');
1.185 raeburn 1127: if (ref($rules) eq 'HASH') {
1.193 raeburn 1128: if (ref($rules->{$matchedrule}) eq 'HASH') {
1129: my $authtype = $rules->{$matchedrule}{'authtype'};
1.185 raeburn 1130: if ($authtype !~ /^(krb4|krb5|int|fsys|loc)$/) {
1.190 raeburn 1131: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.275 raeburn 1132: } else {
1.193 raeburn 1133: my $authparm = $rules->{$matchedrule}{'authparm'};
1.273 raeburn 1134: $authmsg = $rules->{$matchedrule}{'authmsg'};
1.185 raeburn 1135: if ($authtype =~ /^krb(4|5)$/) {
1136: my $ver = $1;
1137: if ($authparm ne '') {
1138: $fixedauth = <<"KERB";
1139: <input type="hidden" name="login" value="krb" />
1140: <input type="hidden" name="krbver" value="$ver" />
1141: <input type="hidden" name="krbarg" value="$authparm" />
1142: KERB
1143: }
1144: } else {
1145: $fixedauth =
1146: '<input type="hidden" name="login" value="'.$authtype.'" />'."\n";
1.193 raeburn 1147: if ($rules->{$matchedrule}{'authparmfixed'}) {
1.185 raeburn 1148: $fixedauth .=
1149: '<input type="hidden" name="'.$authtype.'arg" value="'.$authparm.'" />'."\n";
1150: } else {
1.273 raeburn 1151: if ($authtype eq 'int') {
1152: $varauth = '<br />'.
1.295.2.4 raeburn 1153: &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 1154: } elsif ($authtype eq 'loc') {
1155: $varauth = '<br />'.
1156: &mt('[_1] Local Authentication with argument [_2]','','<input type="text" name="'.$authtype.'arg" value="" />')."\n";
1157: } else {
1158: $varauth =
1.185 raeburn 1159: '<input type="text" name="'.$authtype.'arg" value="" />'."\n";
1.273 raeburn 1160: }
1.185 raeburn 1161: }
1162: }
1163: }
1164: } else {
1.190 raeburn 1165: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.185 raeburn 1166: }
1167: }
1168: if ($authmsg) {
1169: $r->print(<<ENDAUTH);
1170: $fixedauth
1171: $authmsg
1172: $varauth
1173: ENDAUTH
1174: }
1175: } else {
1.190 raeburn 1176: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.187 raeburn 1177: }
1.215 raeburn 1178: $r->print($portfolioform);
1179: if ($env{'form.action'} eq 'singlestudent') {
1180: $r->print(&date_sections_select($context,$newuser,$formname,
1181: $permission));
1182: }
1183: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.216 raeburn 1184: } else { # user already exists
1.79 albertel 1185: my %lt=&Apache::lonlocal::texthash(
1.191 raeburn 1186: 'cup' => "Modify existing user: ",
1.213 raeburn 1187: 'ens' => "Enroll one student: ",
1.295.2.18 raeburn 1188: 'enm' => "Enroll one member: ",
1.72 sakharuk 1189: 'id' => "in domain",
1190: );
1.26 matthew 1191: $r->print(<<ENDCHANGEUSER);
1.110 albertel 1192: $start_page
1.160 raeburn 1193: $crumbs
1.25 matthew 1194: $forminfo
1.213 raeburn 1195: <h2>
1.26 matthew 1196: ENDCHANGEUSER
1.213 raeburn 1197: if ($env{'form.action'} eq 'singlestudent') {
1.295.2.18 raeburn 1198: if ($crstype eq 'Community') {
1199: $r->print($lt{'enm'});
1200: } else {
1201: $r->print($lt{'ens'});
1202: }
1.213 raeburn 1203: } else {
1204: $r->print($lt{'cup'});
1205: }
1206: $r->print(' "'.$ccuname.'" '.$lt{'id'}.' "'.$ccdomain.'"</h2>'.
1207: "\n".'<div class="LC_left_float">');
1.206 raeburn 1208: my ($personal_table,$showforceid) =
1.210 raeburn 1209: &personal_data_display($ccuname,$ccdomain,$newuser,$context,
1210: $inst_results{$ccuname.':'.$ccdomain});
1.206 raeburn 1211: $r->print($personal_table);
1212: if ($showforceid) {
1.203 raeburn 1213: $r->print(&Apache::lonuserutils::forceid_change($context));
1.199 raeburn 1214: }
1.275 raeburn 1215: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.295.2.18 raeburn 1216: $r->print('<h3>'.&mt('User Can Request Creation of Courses/Communities in this Domain?').'</h3>'.
1.295.2.4 raeburn 1217: &Apache::loncommon::start_data_table());
1.295.2.3 raeburn 1218: if ($env{'request.role.domain'} eq $ccdomain) {
1219: $r->print(&build_tools_display($ccuname,$ccdomain,'requestcourses'));
1220: } else {
1221: $r->print(&coursereq_externaluser($ccuname,$ccdomain,
1222: $env{'request.role.domain'}));
1223: }
1224: $r->print(&Apache::loncommon::end_data_table());
1.275 raeburn 1225: }
1.199 raeburn 1226: $r->print('</div>');
1.227 raeburn 1227: my $user_auth_text = &user_authentication($ccuname,$ccdomain,$formname);
1.275 raeburn 1228: my ($user_quota_text,$user_tools_text,$user_reqcrs_text);
1.267 raeburn 1229: if ((&Apache::lonnet::allowed('mpq',$ccdomain)) ||
1230: (&Apache::lonnet::allowed('mut',$ccdomain))) {
1.188 raeburn 1231: # Current user has quota modification privileges
1232: $user_quota_text = &portfolio_quota($ccuname,$ccdomain);
1.267 raeburn 1233: }
1234: if (!&Apache::lonnet::allowed('mpq',$ccdomain)) {
1235: if (&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) {
1236: # Get the user's portfolio information
1237: my %portq = &Apache::lonnet::get('environment',['portfolioquota'],
1238: $ccdomain,$ccuname);
1239: my %lt=&Apache::lonlocal::texthash(
1240: 'dska' => "Disk space allocated to user's portfolio files",
1241: 'youd' => "You do not have privileges to modify the portfolio quota for this user.",
1242: 'ichr' => "If a change is required, contact a domain coordinator for the domain",
1243: );
1244: $user_quota_text = <<ENDNOPORTPRIV;
1.188 raeburn 1245: <h3>$lt{'dska'}</h3>
1246: $lt{'youd'} $lt{'ichr'}: $ccdomain
1247: ENDNOPORTPRIV
1.267 raeburn 1248: }
1249: }
1250: if (!&Apache::lonnet::allowed('mut',$ccdomain)) {
1251: if (&Apache::lonnet::allowed('mut',$env{'request.role.domain'})) {
1252: my %lt=&Apache::lonlocal::texthash(
1253: 'utav' => "User Tools Availability",
1.285 weissno 1254: 'yodo' => "You do not have privileges to modify Portfolio, Blog or Personal Information Page settings for this user.",
1.267 raeburn 1255: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
1256: );
1257: $user_tools_text = <<ENDNOTOOLSPRIV;
1258: <h3>$lt{'utav'}</h3>
1259: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1260: ENDNOTOOLSPRIV
1261: }
1.188 raeburn 1262: }
1263: if ($user_auth_text ne '') {
1264: $r->print('<div class="LC_left_float">'.$user_auth_text);
1265: if ($user_quota_text ne '') {
1266: $r->print($user_quota_text);
1267: }
1.267 raeburn 1268: if ($user_tools_text ne '') {
1269: $r->print($user_tools_text);
1270: }
1.213 raeburn 1271: if ($env{'form.action'} eq 'singlestudent') {
1272: $r->print(&date_sections_select($context,$newuser,$formname));
1273: }
1.188 raeburn 1274: } elsif ($user_quota_text ne '') {
1.213 raeburn 1275: $r->print('<div class="LC_left_float">'.$user_quota_text);
1.267 raeburn 1276: if ($user_tools_text ne '') {
1277: $r->print($user_tools_text);
1278: }
1279: if ($env{'form.action'} eq 'singlestudent') {
1280: $r->print(&date_sections_select($context,$newuser,$formname));
1281: }
1282: } elsif ($user_tools_text ne '') {
1283: $r->print('<div class="LC_left_float">'.$user_tools_text);
1.213 raeburn 1284: if ($env{'form.action'} eq 'singlestudent') {
1285: $r->print(&date_sections_select($context,$newuser,$formname));
1286: }
1287: } else {
1288: if ($env{'form.action'} eq 'singlestudent') {
1289: $r->print('<div class="LC_left_float">'.
1290: &date_sections_select($context,$newuser,$formname));
1291: }
1.188 raeburn 1292: }
1.213 raeburn 1293: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.217 raeburn 1294: if ($env{'form.action'} ne 'singlestudent') {
1.295.2.26 raeburn 1295: &display_existing_roles($r,$ccuname,$ccdomain,\%inccourses,$context,
1296: $roledom,$crstype);
1.217 raeburn 1297: }
1.25 matthew 1298: } ## End of new user/old user logic
1.218 raeburn 1299: if ($env{'form.action'} eq 'singlestudent') {
1.295.2.18 raeburn 1300: my $btntxt;
1301: if ($crstype eq 'Community') {
1302: $btntxt = &mt('Enroll Member');
1303: } else {
1304: $btntxt = &mt('Enroll Student');
1305: }
1306: $r->print('<br /><input type="button" value="'.$btntxt.'" onclick="setSections(this.form)" />'."\n");
1.218 raeburn 1307: } else {
1308: $r->print('<h3>'.&mt('Add Roles').'</h3>');
1309: my $addrolesdisplay = 0;
1310: if ($context eq 'domain' || $context eq 'author') {
1311: $addrolesdisplay = &new_coauthor_roles($r,$ccuname,$ccdomain);
1312: }
1313: if ($context eq 'domain') {
1314: my $add_domainroles = &new_domain_roles($r);
1315: if (!$addrolesdisplay) {
1316: $addrolesdisplay = $add_domainroles;
1.2 www 1317: }
1.218 raeburn 1318: $r->print(&course_level_dc($env{'request.role.domain'},'Course'));
1.295.2.4 raeburn 1319: $r->print('<br /><input type="button" value="'.&mt('Save').'" onclick="setCourse()" />'."\n");
1.218 raeburn 1320: } elsif ($context eq 'author') {
1321: if ($addrolesdisplay) {
1.262 schafran 1322: $r->print('<br /><input type="button" value="'.&mt('Save').'"');
1.218 raeburn 1323: if ($newuser) {
1.295.2.4 raeburn 1324: $r->print(' onclick="auth_check()" \>'."\n");
1.218 raeburn 1325: } else {
1.295.2.4 raeburn 1326: $r->print('onclick="this.form.submit()" \>'."\n");
1.218 raeburn 1327: }
1.188 raeburn 1328: } else {
1.218 raeburn 1329: $r->print('<br /><a href="javascript:backPage(document.cu)">'.
1330: &mt('Back to previous page').'</a>');
1.188 raeburn 1331: }
1332: } else {
1.218 raeburn 1333: $r->print(&course_level_table(%inccourses));
1.295.2.4 raeburn 1334: $r->print('<br /><input type="button" value="'.&mt('Save').'" onclick="setSections(this.form)" />'."\n");
1.188 raeburn 1335: }
1.88 raeburn 1336: }
1.188 raeburn 1337: $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','userrole','ccdomain','prevphase','currstate','ccuname','ccdomain']));
1.179 raeburn 1338: $r->print('<input type="hidden" name="currstate" value="" />');
1.160 raeburn 1339: $r->print('<input type="hidden" name="prevphase" value="'.$env{'form.phase'}.'" />');
1.110 albertel 1340: $r->print("</form>".&Apache::loncommon::end_page());
1.218 raeburn 1341: return;
1.2 www 1342: }
1.1 www 1343:
1.213 raeburn 1344: sub singleuser_breadcrumb {
1.295.2.18 raeburn 1345: my ($crstype) = @_;
1.213 raeburn 1346: my %breadcrumb_text;
1347: if ($env{'form.action'} eq 'singlestudent') {
1.295.2.18 raeburn 1348: if ($crstype eq 'Community') {
1349: $breadcrumb_text{'search'} = 'Enroll a member';
1350: } else {
1351: $breadcrumb_text{'search'} = 'Enroll a student';
1352: }
1.213 raeburn 1353: $breadcrumb_text{'userpicked'} = 'Select a user',
1354: $breadcrumb_text{'modify'} = 'Set section/dates',
1355: } else {
1.229 raeburn 1356: $breadcrumb_text{'search'} = 'Create/modify a user';
1.213 raeburn 1357: $breadcrumb_text{'userpicked'} = 'Select a user',
1358: $breadcrumb_text{'modify'} = 'Set user role',
1359: }
1360: return %breadcrumb_text;
1361: }
1362:
1363: sub date_sections_select {
1364: my ($context,$newuser,$formname,$permission) = @_;
1365: my $cid = $env{'request.course.id'};
1366: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity($cid);
1367: my $date_table = '<h3>'.&mt('Starting and Ending Dates').'</h3>'."\n".
1368: &Apache::lonuserutils::date_setting_table(undef,undef,$context,
1369: undef,$formname,$permission);
1370: my $rowtitle = 'Section';
1371: my $secbox = '<h3>'.&mt('Section').'</h3>'."\n".
1372: &Apache::lonuserutils::section_picker($cdom,$cnum,'st',$rowtitle,
1373: $permission);
1374: my $output = $date_table.$secbox;
1375: return $output;
1376: }
1377:
1.216 raeburn 1378: sub validation_javascript {
1379: my ($context,$ccdomain,$pjump_def,$groupslist,$newuser,$formname,
1380: $loaditem) = @_;
1381: my $dc_setcourse_code = '';
1382: my $nondc_setsection_code = '';
1383: if ($context eq 'domain') {
1384: my $dcdom = $env{'request.role.domain'};
1385: $loaditem->{'onload'} = "document.cu.coursedesc.value='';";
1.227 raeburn 1386: $dc_setcourse_code =
1387: &Apache::lonuserutils::dc_setcourse_js('cu','singleuser',$context);
1.216 raeburn 1388: } else {
1.227 raeburn 1389: my $checkauth;
1390: if (($newuser) || (&Apache::lonnet::allowed('mau',$ccdomain))) {
1391: $checkauth = 1;
1392: }
1393: if ($context eq 'course') {
1394: $nondc_setsection_code =
1395: &Apache::lonuserutils::setsections_javascript($formname,$groupslist,
1396: undef,$checkauth);
1397: }
1398: if ($checkauth) {
1399: $nondc_setsection_code .=
1400: &Apache::lonuserutils::verify_authen($formname,$context);
1401: }
1.216 raeburn 1402: }
1403: my $js = &user_modification_js($pjump_def,$dc_setcourse_code,
1404: $nondc_setsection_code,$groupslist);
1405: my ($jsback,$elements) = &crumb_utilities();
1406: $js .= "\n".
1.295.2.4 raeburn 1407: '<script type="text/javascript">'."\n".
1408: '// <![CDATA['."\n".
1409: $jsback."\n".
1410: '// ]]>'."\n".
1411: '</script>'."\n";
1.216 raeburn 1412: return $js;
1413: }
1414:
1.217 raeburn 1415: sub display_existing_roles {
1.295.2.26 raeburn 1416: my ($r,$ccuname,$ccdomain,$inccourses,$context,$roledom,$crstype) = @_;
1417: my $now=time;
1418: my %lt=&Apache::lonlocal::texthash(
1.217 raeburn 1419: 'rer' => "Existing Roles",
1420: 'rev' => "Revoke",
1421: 'del' => "Delete",
1422: 'ren' => "Re-Enable",
1423: 'rol' => "Role",
1424: 'ext' => "Extent",
1425: 'sta' => "Start",
1426: 'end' => "End",
1427: );
1.295.2.26 raeburn 1428: my (%rolesdump,%roletext,%sortrole,%roleclass,%rolepriv);
1429: if ($context eq 'course' || $context eq 'author') {
1430: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
1431: my %roleshash =
1432: &Apache::lonnet::get_my_roles($ccuname,$ccdomain,'userroles',
1433: ['active','previous','future'],\@roles,$roledom,1);
1434: foreach my $key (keys(%roleshash)) {
1435: my ($start,$end) = split(':',$roleshash{$key});
1436: next if ($start eq '-1' || $end eq '-1');
1437: my ($rnum,$rdom,$role,$sec) = split(':',$key);
1438: if ($context eq 'course') {
1439: next unless (($rnum eq $env{'course.'.$env{'request.course.id'}.'.num'})
1440: && ($rdom eq $env{'course.'.$env{'request.course.id'}.'.domain'}));
1441: } elsif ($context eq 'author') {
1442: next unless (($rnum eq $env{'user.name'}) && ($rdom eq $env{'request.role.domain'}));
1443: }
1444: my ($newkey,$newvalue,$newrole);
1445: $newkey = '/'.$rdom.'/'.$rnum;
1446: if ($sec ne '') {
1447: $newkey .= '/'.$sec;
1448: }
1449: $newvalue = $role;
1450: if ($role =~ /^cr/) {
1451: $newrole = 'cr';
1452: } else {
1453: $newrole = $role;
1454: }
1455: $newkey .= '_'.$newrole;
1456: if ($start ne '' && $end ne '') {
1457: $newvalue .= '_'.$end.'_'.$start;
1.295.2.30 raeburn 1458: } elsif ($end ne '') {
1459: $newvalue .= '_'.$end;
1.295.2.26 raeburn 1460: }
1461: $rolesdump{$newkey} = $newvalue;
1462: }
1463: } else {
1464: %rolesdump=&Apache::lonnet::dump('roles',$ccdomain,$ccuname);
1465: }
1466: # Build up table of user roles to allow revocation and re-enabling of roles.
1467: my ($tmp) = keys(%rolesdump);
1468: return if ($tmp =~ /^(con_lost|error)/i);
1469: foreach my $area (sort { my $a1=join('_',(split('_',$a))[1,0]);
1470: my $b1=join('_',(split('_',$b))[1,0]);
1471: return $a1 cmp $b1;
1472: } keys(%rolesdump)) {
1473: next if ($area =~ /^rolesdef/);
1474: my $envkey=$area;
1475: my $role = $rolesdump{$area};
1476: my $thisrole=$area;
1477: $area =~ s/\_\w\w$//;
1478: my ($role_code,$role_end_time,$role_start_time) =
1479: split(/_/,$role);
1.217 raeburn 1480: # Is this a custom role? Get role owner and title.
1.295.2.26 raeburn 1481: my ($croleudom,$croleuname,$croletitle)=
1482: ($role_code=~m{^cr/($match_domain)/($match_username)/(\w+)$});
1483: my $allowed=0;
1484: my $delallowed=0;
1485: my $sortkey=$role_code;
1486: my $class='Unknown';
1487: if ($area =~ m{^/($match_domain)/($match_courseid)} ) {
1488: $class='Course';
1489: my ($coursedom,$coursedir) = ($1,$2);
1.295.2.28 raeburn 1490: my $cid = $1.'_'.$2;
1.295.2.26 raeburn 1491: # $1.'_'.$2 is the course id (eg. 103_12345abcef103l3).
1492: my %coursedata=
1.295.2.28 raeburn 1493: &Apache::lonnet::coursedescription($cid);
1.295.2.26 raeburn 1494: if ($coursedir =~ /^$match_community$/) {
1495: $class='Community';
1496: }
1497: $sortkey.="\0$coursedom";
1498: my $carea;
1499: if (defined($coursedata{'description'})) {
1500: $carea=$coursedata{'description'}.
1501: '<br />'.&mt('Domain').': '.$coursedom.(' 'x8).
1.259 bisitz 1502: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$coursedir,$coursedom);
1.295.2.26 raeburn 1503: $sortkey.="\0".$coursedata{'description'};
1504: } else {
1505: if ($class eq 'Community') {
1506: $carea=&mt('Unavailable community').': '.$area;
1507: $sortkey.="\0".&mt('Unavailable community').': '.$area;
1.217 raeburn 1508: } else {
1509: $carea=&mt('Unavailable course').': '.$area;
1510: $sortkey.="\0".&mt('Unavailable course').': '.$area;
1511: }
1.295.2.26 raeburn 1512: }
1513: $sortkey.="\0$coursedir";
1.295.2.28 raeburn 1514: $inccourses->{$cid}=1;
1515: if ((&Apache::lonnet::allowed('c'.$role_code,$coursedom.'/'.$coursedir)) ||
1.295.2.26 raeburn 1516: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
1517: $allowed=1;
1518: }
1519: unless ($allowed) {
1520: my $isowner = &is_courseowner($cid,$coursedata{'internal.courseowner'});
1521: if ($isowner) {
1522: if (($role_code eq 'co') && ($class eq 'Community')) {
1523: $allowed = 1;
1524: } elsif (($role_code eq 'cc') && ($class eq 'Course')) {
1525: $allowed = 1;
1526: }
1527: }
1528: }
1.295.2.28 raeburn 1529: if ((&Apache::lonnet::allowed('dro',$coursedom)) ||
1.295.2.26 raeburn 1530: (&Apache::lonnet::allowed('dro',$ccdomain))) {
1531: $delallowed=1;
1532: }
1533: # - custom role. Needs more info, too
1534: if ($croletitle) {
1.295.2.28 raeburn 1535: if (&Apache::lonnet::allowed('ccr',$coursedom.'/'.$coursedir)) {
1.295.2.26 raeburn 1536: $allowed=1;
1537: $thisrole.='.'.$role_code;
1538: }
1539: }
1540: if ($area=~m{^/($match_domain)/($match_courseid)/(\w+)}) {
1541: $carea.='<br />Section: '.$3;
1542: $sortkey.="\0$3";
1543: if (!$allowed) {
1544: if ($env{'request.course.sec'} eq $3) {
1545: if (&Apache::lonnet::allowed('c'.$role_code,$1.'/'.$2.'/'.$3)) {
1546: $allowed = 1;
1547: }
1548: }
1549: }
1550: }
1551: $area=$carea;
1552: } else {
1553: $sortkey.="\0".$area;
1554: # Determine if current user is able to revoke privileges
1555: if ($area=~m{^/($match_domain)/}) {
1556: if ((&Apache::lonnet::allowed('c'.$role_code,$1)) ||
1.217 raeburn 1557: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
1558: $allowed=1;
1559: }
1.295.2.26 raeburn 1560: if (((&Apache::lonnet::allowed('dro',$1)) ||
1561: (&Apache::lonnet::allowed('dro',$ccdomain))) &&
1562: ($role_code ne 'dc')) {
1.217 raeburn 1563: $delallowed=1;
1564: }
1565: } else {
1.295.2.26 raeburn 1566: if (&Apache::lonnet::allowed('c'.$role_code,'/')) {
1.217 raeburn 1567: $allowed=1;
1568: }
1569: }
1.295.2.26 raeburn 1570: if ($role_code eq 'ca' || $role_code eq 'au') {
1571: $class='Construction Space';
1572: } elsif ($role_code eq 'su') {
1573: $class='System';
1.217 raeburn 1574: } else {
1.295.2.26 raeburn 1575: $class='Domain';
1.217 raeburn 1576: }
1.295.2.26 raeburn 1577: }
1578: if (($role_code eq 'ca') || ($role_code eq 'aa')) {
1579: $area=~m{/($match_domain)/($match_username)};
1580: if (&Apache::lonuserutils::authorpriv($2,$1)) {
1581: $allowed=1;
1.217 raeburn 1582: } else {
1.295.2.26 raeburn 1583: $allowed=0;
1.217 raeburn 1584: }
1.295.2.26 raeburn 1585: }
1586: my $row = '';
1587: $row.= '<td>';
1588: my $active=1;
1589: $active=0 if (($role_end_time) && ($now>$role_end_time));
1590: if (($active) && ($allowed)) {
1591: $row.= '<input type="checkbox" name="rev:'.$thisrole.'" />';
1592: } else {
1593: if ($active) {
1594: $row.=' ';
1.217 raeburn 1595: } else {
1.295.2.26 raeburn 1596: $row.=&mt('expired or revoked');
1.217 raeburn 1597: }
1.295.2.26 raeburn 1598: }
1599: $row.='</td><td>';
1600: if ($allowed && !$active) {
1601: $row.= '<input type="checkbox" name="ren:'.$thisrole.'" />';
1602: } else {
1603: $row.=' ';
1604: }
1605: $row.='</td><td>';
1606: if ($delallowed) {
1607: $row.= '<input type="checkbox" name="del:'.$thisrole.'" />';
1608: } else {
1609: $row.=' ';
1610: }
1611: my $plaintext='';
1612: if (!$croletitle) {
1613: $plaintext=&Apache::lonnet::plaintext($role_code,$class)
1614: } else {
1615: $plaintext=
1.295.2.35! raeburn 1616: &mt('Customrole [_1][_2]defined by [_3]',
! 1617: '"'.$croletitle.'"',
! 1618: '<br />',
! 1619: $croleuname.':'.$croleudom);
1.295.2.26 raeburn 1620: }
1621: $row.= '</td><td>'.$plaintext.
1622: '</td><td>'.$area.
1623: '</td><td>'.($role_start_time?&Apache::lonlocal::locallocaltime($role_start_time)
1624: : ' ' ).
1625: '</td><td>'.($role_end_time ?&Apache::lonlocal::locallocaltime($role_end_time)
1626: : ' ' )
1627: ."</td>";
1628: $sortrole{$sortkey}=$envkey;
1629: $roletext{$envkey}=$row;
1630: $roleclass{$envkey}=$class;
1631: $rolepriv{$envkey}=$allowed;
1632: } # end of foreach (table building loop)
1.295.2.31 raeburn 1633:
1.295.2.26 raeburn 1634: my $rolesdisplay = 0;
1635: my %output = ();
1636: foreach my $type ('Construction Space','Course','Community','Domain','System','Unknown') {
1637: $output{$type} = '';
1638: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
1639: if ( ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/ ) && ($rolepriv{$sortrole{$which}}) ) {
1640: $output{$type}.=
1641: &Apache::loncommon::start_data_table_row().
1642: $roletext{$sortrole{$which}}.
1643: &Apache::loncommon::end_data_table_row();
1.217 raeburn 1644: }
1.295.2.26 raeburn 1645: }
1646: unless($output{$type} eq '') {
1647: $output{$type} = '<tr class="LC_info_row">'.
1648: "<td align='center' colspan='7'>".&mt($type)."</td></tr>".
1649: $output{$type};
1650: $rolesdisplay = 1;
1651: }
1652: }
1653: if ($rolesdisplay == 1) {
1654: my $contextrole='';
1655: if ($env{'request.course.id'}) {
1656: if (&Apache::loncommon::course_type() eq 'Community') {
1657: $contextrole = &mt('Existing Roles in this Community');
1.290 bisitz 1658: } else {
1.295.2.26 raeburn 1659: $contextrole = &mt('Existing Roles in this Course');
1.290 bisitz 1660: }
1.295.2.26 raeburn 1661: } elsif ($env{'request.role'} =~ /^au\./) {
1.295.2.31 raeburn 1662: $contextrole = &mt('Existing Co-Author Roles in your Construction Space');
1.295.2.26 raeburn 1663: } else {
1.295.2.31 raeburn 1664: $contextrole = &mt('Existing Roles in this Domain');
1.295.2.26 raeburn 1665: }
1666: $r->print('
1.217 raeburn 1667: <h3>'.$lt{'rer'}.'</h3>'.
1.295.2.31 raeburn 1668: '<div>'.$contextrole.'</div>'.
1.217 raeburn 1669: &Apache::loncommon::start_data_table("LC_createuser").
1670: &Apache::loncommon::start_data_table_header_row().
1671: '<th>'.$lt{'rev'}.'</th><th>'.$lt{'ren'}.'</th><th>'.$lt{'del'}.
1672: '</th><th>'.$lt{'rol'}.'</th><th>'.$lt{'ext'}.
1673: '</th><th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
1674: &Apache::loncommon::end_data_table_header_row());
1.295.2.26 raeburn 1675: foreach my $type ('Construction Space','Course','Community','Domain','System','Unknown') {
1676: if ($output{$type}) {
1677: $r->print($output{$type}."\n");
1.217 raeburn 1678: }
1679: }
1.295.2.26 raeburn 1680: $r->print(&Apache::loncommon::end_data_table());
1681: }
1.217 raeburn 1682: return;
1683: }
1684:
1.218 raeburn 1685: sub new_coauthor_roles {
1686: my ($r,$ccuname,$ccdomain) = @_;
1687: my $addrolesdisplay = 0;
1688: #
1689: # Co-Author
1690: #
1691: if (&Apache::lonuserutils::authorpriv($env{'user.name'},
1692: $env{'request.role.domain'}) &&
1693: ($env{'user.name'} ne $ccuname || $env{'user.domain'} ne $ccdomain)) {
1694: # No sense in assigning co-author role to yourself
1695: $addrolesdisplay = 1;
1696: my $cuname=$env{'user.name'};
1697: my $cudom=$env{'request.role.domain'};
1698: my %lt=&Apache::lonlocal::texthash(
1699: 'cs' => "Construction Space",
1700: 'act' => "Activate",
1701: 'rol' => "Role",
1702: 'ext' => "Extent",
1703: 'sta' => "Start",
1704: 'end' => "End",
1705: 'cau' => "Co-Author",
1706: 'caa' => "Assistant Co-Author",
1707: 'ssd' => "Set Start Date",
1708: 'sed' => "Set End Date"
1709: );
1710: $r->print('<h4>'.$lt{'cs'}.'</h4>'."\n".
1711: &Apache::loncommon::start_data_table()."\n".
1712: &Apache::loncommon::start_data_table_header_row()."\n".
1713: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'.
1714: '<th>'.$lt{'ext'}.'</th><th>'.$lt{'sta'}.'</th>'.
1715: '<th>'.$lt{'end'}.'</th>'."\n".
1716: &Apache::loncommon::end_data_table_header_row()."\n".
1717: &Apache::loncommon::start_data_table_row().'
1718: <td>
1.291 bisitz 1719: <input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_ca" />
1.218 raeburn 1720: </td>
1721: <td>'.$lt{'cau'}.'</td>
1722: <td>'.$cudom.'_'.$cuname.'</td>
1723: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_ca" value="" />
1724: <a href=
1725: "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>
1726: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_ca" value="" />
1727: <a href=
1728: "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".
1729: &Apache::loncommon::end_data_table_row()."\n".
1730: &Apache::loncommon::start_data_table_row()."\n".
1.291 bisitz 1731: '<td><input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_aa" /></td>
1.218 raeburn 1732: <td>'.$lt{'caa'}.'</td>
1733: <td>'.$cudom.'_'.$cuname.'</td>
1734: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_aa" value="" />
1735: <a href=
1736: "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>
1737: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_aa" value="" />
1738: <a href=
1739: "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".
1740: &Apache::loncommon::end_data_table_row()."\n".
1741: &Apache::loncommon::end_data_table());
1742: } elsif ($env{'request.role'} =~ /^au\./) {
1743: if (!(&Apache::lonuserutils::authorpriv($env{'user.name'},
1744: $env{'request.role.domain'}))) {
1745: $r->print('<span class="LC_error">'.
1746: &mt('You do not have privileges to assign co-author roles.').
1747: '</span>');
1748: } elsif (($env{'user.name'} eq $ccuname) &&
1749: ($env{'user.domain'} eq $ccdomain)) {
1750: $r->print(&mt('Assigning yourself a co-author or assistant co-author role in your own author area in Construction Space is not permitted'));
1751: }
1752: }
1753: return $addrolesdisplay;;
1754: }
1755:
1756: sub new_domain_roles {
1757: my ($r) = @_;
1758: my $addrolesdisplay = 0;
1759: #
1760: # Domain level
1761: #
1762: my $num_domain_level = 0;
1763: my $domaintext =
1764: '<h4>'.&mt('Domain Level').'</h4>'.
1765: &Apache::loncommon::start_data_table().
1766: &Apache::loncommon::start_data_table_header_row().
1767: '<th>'.&mt('Activate').'</th><th>'.&mt('Role').'</th><th>'.
1768: &mt('Extent').'</th>'.
1769: '<th>'.&mt('Start').'</th><th>'.&mt('End').'</th>'.
1770: &Apache::loncommon::end_data_table_header_row();
1.295.2.13 raeburn 1771: my @allroles = &Apache::lonuserutils::roles_by_context('domain');
1.218 raeburn 1772: foreach my $thisdomain (sort(&Apache::lonnet::all_domains())) {
1.295.2.13 raeburn 1773: foreach my $role (@allroles) {
1774: next if ($role eq 'ad');
1.218 raeburn 1775: if (&Apache::lonnet::allowed('c'.$role,$thisdomain)) {
1776: my $plrole=&Apache::lonnet::plaintext($role);
1777: my %lt=&Apache::lonlocal::texthash(
1778: 'ssd' => "Set Start Date",
1779: 'sed' => "Set End Date"
1780: );
1781: $num_domain_level ++;
1782: $domaintext .=
1783: &Apache::loncommon::start_data_table_row().
1.291 bisitz 1784: '<td><input type="checkbox" name="act_'.$thisdomain.'_'.$role.'" /></td>
1.218 raeburn 1785: <td>'.$plrole.'</td>
1786: <td>'.$thisdomain.'</td>
1787: <td><input type="hidden" name="start_'.$thisdomain.'_'.$role.'" value="" />
1788: <a href=
1789: "javascript:pjump('."'date_start','Start Date $plrole',document.cu.start_$thisdomain\_$role.value,'start_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'ssd'}.'</a></td>
1790: <td><input type="hidden" name="end_'.$thisdomain.'_'.$role.'" value="" />
1791: <a href=
1792: "javascript:pjump('."'date_end','End Date $plrole',document.cu.end_$thisdomain\_$role.value,'end_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'sed'}.'</a></td>'.
1793: &Apache::loncommon::end_data_table_row();
1794: }
1795: }
1796: }
1797: $domaintext.= &Apache::loncommon::end_data_table();
1798: if ($num_domain_level > 0) {
1799: $r->print($domaintext);
1800: $addrolesdisplay = 1;
1801: }
1802: return $addrolesdisplay;
1803: }
1804:
1.188 raeburn 1805: sub user_authentication {
1.227 raeburn 1806: my ($ccuname,$ccdomain,$formname) = @_;
1.188 raeburn 1807: my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
1.227 raeburn 1808: my $outcome;
1.188 raeburn 1809: # Check for a bad authentication type
1810: if ($currentauth !~ /^(krb4|krb5|unix|internal|localauth):/) {
1811: # bad authentication scheme
1812: my %lt=&Apache::lonlocal::texthash(
1813: 'err' => "ERROR",
1814: 'uuas' => "This user has an unrecognized authentication scheme",
1815: 'adcs' => "Please alert a domain coordinator of this situation",
1816: 'sldb' => "Please specify login data below",
1817: 'ld' => "Login Data"
1818: );
1819: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
1.227 raeburn 1820: &initialize_authen_forms($ccdomain,$formname);
1821:
1.190 raeburn 1822: my $choices = &Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc);
1.188 raeburn 1823: $outcome = <<ENDBADAUTH;
1824: <script type="text/javascript" language="Javascript">
1.295.2.4 raeburn 1825: // <![CDATA[
1.188 raeburn 1826: $loginscript
1.295.2.4 raeburn 1827: // ]]>
1.188 raeburn 1828: </script>
1829: <span class="LC_error">$lt{'err'}:
1830: $lt{'uuas'} ($currentauth). $lt{'sldb'}.</span>
1831: <h3>$lt{'ld'}</h3>
1832: $choices
1833: ENDBADAUTH
1834: } else {
1835: # This user is not allowed to modify the user's
1836: # authentication scheme, so just notify them of the problem
1837: $outcome = <<ENDBADAUTH;
1838: <span class="LC_error"> $lt{'err'}:
1839: $lt{'uuas'} ($currentauth). $lt{'adcs'}.
1840: </span>
1841: ENDBADAUTH
1842: }
1843: } else { # Authentication type is valid
1.227 raeburn 1844: &initialize_authen_forms($ccdomain,$formname,$currentauth,'modifyuser');
1.205 raeburn 1845: my ($authformcurrent,$can_modify,@authform_others) =
1.188 raeburn 1846: &modify_login_block($ccdomain,$currentauth);
1847: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
1848: # Current user has login modification privileges
1849: my %lt=&Apache::lonlocal::texthash (
1850: 'ld' => "Login Data",
1851: 'ccld' => "Change Current Login Data",
1852: 'enld' => "Enter New Login Data"
1853: );
1854: $outcome =
1855: '<script type="text/javascript" language="Javascript">'."\n".
1.295.2.4 raeburn 1856: '// <![CDATA['."\n".
1.188 raeburn 1857: $loginscript."\n".
1.295.2.4 raeburn 1858: '// ]]>'."\n".
1.188 raeburn 1859: '</script>'."\n".
1860: '<h3>'.$lt{'ld'}.'</h3>'.
1861: &Apache::loncommon::start_data_table().
1.205 raeburn 1862: &Apache::loncommon::start_data_table_row().
1.188 raeburn 1863: '<td>'.$authformnop;
1864: if ($can_modify) {
1865: $outcome .= '</td>'."\n".
1866: &Apache::loncommon::end_data_table_row().
1867: &Apache::loncommon::start_data_table_row().
1868: '<td>'.$authformcurrent.'</td>'.
1869: &Apache::loncommon::end_data_table_row()."\n";
1870: } else {
1.200 raeburn 1871: $outcome .= ' ('.$authformcurrent.')</td>'.
1872: &Apache::loncommon::end_data_table_row()."\n";
1.188 raeburn 1873: }
1.205 raeburn 1874: foreach my $item (@authform_others) {
1875: $outcome .= &Apache::loncommon::start_data_table_row().
1876: '<td>'.$item.'</td>'.
1877: &Apache::loncommon::end_data_table_row()."\n";
1.188 raeburn 1878: }
1.205 raeburn 1879: $outcome .= &Apache::loncommon::end_data_table();
1.188 raeburn 1880: } else {
1881: if (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
1882: my %lt=&Apache::lonlocal::texthash(
1883: 'ccld' => "Change Current Login Data",
1884: 'yodo' => "You do not have privileges to modify the authentication configuration for this user.",
1885: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
1886: );
1887: $outcome .= <<ENDNOPRIV;
1888: <h3>$lt{'ccld'}</h3>
1889: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1.235 raeburn 1890: <input type="hidden" name="login" value="nochange" />
1.188 raeburn 1891: ENDNOPRIV
1892: }
1893: }
1894: } ## End of "check for bad authentication type" logic
1895: return $outcome;
1896: }
1897:
1.187 raeburn 1898: sub modify_login_block {
1899: my ($dom,$currentauth) = @_;
1900: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
1901: my ($authnum,%can_assign) =
1902: &Apache::loncommon::get_assignable_auth($dom);
1.205 raeburn 1903: my ($authformcurrent,@authform_others,$show_override_msg);
1.187 raeburn 1904: if ($currentauth=~/^krb(4|5):/) {
1905: $authformcurrent=$authformkrb;
1906: if ($can_assign{'int'}) {
1.205 raeburn 1907: push(@authform_others,$authformint);
1.187 raeburn 1908: }
1909: if ($can_assign{'loc'}) {
1.205 raeburn 1910: push(@authform_others,$authformloc);
1.187 raeburn 1911: }
1912: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1913: $show_override_msg = 1;
1914: }
1915: } elsif ($currentauth=~/^internal:/) {
1916: $authformcurrent=$authformint;
1917: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 1918: push(@authform_others,$authformkrb);
1.187 raeburn 1919: }
1920: if ($can_assign{'loc'}) {
1.205 raeburn 1921: push(@authform_others,$authformloc);
1.187 raeburn 1922: }
1923: if ($can_assign{'int'}) {
1924: $show_override_msg = 1;
1925: }
1926: } elsif ($currentauth=~/^unix:/) {
1927: $authformcurrent=$authformfsys;
1928: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 1929: push(@authform_others,$authformkrb);
1.187 raeburn 1930: }
1931: if ($can_assign{'int'}) {
1.205 raeburn 1932: push(@authform_others,$authformint);
1.187 raeburn 1933: }
1934: if ($can_assign{'loc'}) {
1.205 raeburn 1935: push(@authform_others,$authformloc);
1.187 raeburn 1936: }
1937: if ($can_assign{'fsys'}) {
1938: $show_override_msg = 1;
1939: }
1940: } elsif ($currentauth=~/^localauth:/) {
1941: $authformcurrent=$authformloc;
1942: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 1943: push(@authform_others,$authformkrb);
1.187 raeburn 1944: }
1945: if ($can_assign{'int'}) {
1.205 raeburn 1946: push(@authform_others,$authformint);
1.187 raeburn 1947: }
1948: if ($can_assign{'loc'}) {
1949: $show_override_msg = 1;
1950: }
1951: }
1952: if ($show_override_msg) {
1.205 raeburn 1953: $authformcurrent = '<table><tr><td colspan="3">'.$authformcurrent.
1954: '</td></tr>'."\n".
1955: '<tr><td> </td>'.
1956: '<td><b>'.&mt('Currently in use').'</b></td>'.
1957: '<td align="right"><span class="LC_cusr_emph">'.
1.187 raeburn 1958: &mt('will override current values').
1.205 raeburn 1959: '</span></td></tr></table>';
1.187 raeburn 1960: }
1.205 raeburn 1961: return ($authformcurrent,$show_override_msg,@authform_others);
1.187 raeburn 1962: }
1963:
1.188 raeburn 1964: sub personal_data_display {
1.252 raeburn 1965: my ($ccuname,$ccdomain,$newuser,$context,$inst_results,$rolesarray) = @_;
1.286 raeburn 1966: my ($output,$showforceid,%userenv,%canmodify,%canmodify_status);
1.219 raeburn 1967: my @userinfo = ('firstname','middlename','lastname','generation',
1968: 'permanentemail','id');
1.252 raeburn 1969: my $rowcount = 0;
1970: my $editable = 0;
1.286 raeburn 1971: %canmodify_status =
1972: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
1973: ['inststatus'],$rolesarray);
1.253 raeburn 1974: if (!$newuser) {
1.188 raeburn 1975: # Get the users information
1976: %userenv = &Apache::lonnet::get('environment',
1977: ['firstname','middlename','lastname','generation',
1.286 raeburn 1978: 'permanentemail','id','inststatus'],$ccdomain,$ccuname);
1.219 raeburn 1979: %canmodify =
1980: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
1.252 raeburn 1981: \@userinfo,$rolesarray);
1.257 raeburn 1982: } elsif ($context eq 'selfcreate') {
1983: %canmodify = &selfcreate_canmodify($context,$ccdomain,\@userinfo,
1984: $inst_results,$rolesarray);
1.188 raeburn 1985: }
1986: my %lt=&Apache::lonlocal::texthash(
1987: 'pd' => "Personal Data",
1988: 'firstname' => "First Name",
1989: 'middlename' => "Middle Name",
1990: 'lastname' => "Last Name",
1991: 'generation' => "Generation",
1992: 'permanentemail' => "Permanent e-mail address",
1.259 bisitz 1993: 'id' => "Student/Employee ID",
1.286 raeburn 1994: 'lg' => "Login Data",
1995: 'inststatus' => "Affiliation",
1.188 raeburn 1996: );
1997: my %textboxsize = (
1998: firstname => '15',
1999: middlename => '15',
2000: lastname => '15',
2001: generation => '5',
2002: permanentemail => '25',
2003: id => '15',
2004: );
2005: my $genhelp=&Apache::loncommon::help_open_topic('Generation');
2006: $output = '<h3>'.$lt{'pd'}.'</h3>'.
2007: &Apache::lonhtmlcommon::start_pick_box();
2008: foreach my $item (@userinfo) {
2009: my $rowtitle = $lt{$item};
1.252 raeburn 2010: my $hiderow = 0;
1.188 raeburn 2011: if ($item eq 'generation') {
2012: $rowtitle = $genhelp.$rowtitle;
2013: }
1.252 raeburn 2014: my $row = &Apache::lonhtmlcommon::row_title($rowtitle,undef,'LC_oddrow_value')."\n";
1.188 raeburn 2015: if ($newuser) {
1.210 raeburn 2016: if (ref($inst_results) eq 'HASH') {
2017: if ($inst_results->{$item} ne '') {
1.252 raeburn 2018: $row .= '<input type="hidden" name="c'.$item.'" value="'.$inst_results->{$item}.'" />'.$inst_results->{$item};
1.210 raeburn 2019: } else {
1.252 raeburn 2020: if ($context eq 'selfcreate') {
2021: if ($canmodify{$item}) {
2022: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
2023: $editable ++;
2024: } else {
2025: $hiderow = 1;
2026: }
1.253 raeburn 2027: } else {
2028: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1.252 raeburn 2029: }
1.210 raeburn 2030: }
1.188 raeburn 2031: } else {
1.252 raeburn 2032: if ($context eq 'selfcreate') {
1.287 raeburn 2033: if (($item eq 'permanentemail') && ($newuser eq 'email')) {
2034: $row .= $ccuname;
1.252 raeburn 2035: } else {
1.287 raeburn 2036: if ($canmodify{$item}) {
2037: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
2038: $editable ++;
2039: } else {
2040: $hiderow = 1;
2041: }
1.252 raeburn 2042: }
1.253 raeburn 2043: } else {
2044: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1.252 raeburn 2045: }
1.188 raeburn 2046: }
2047: } else {
1.219 raeburn 2048: if ($canmodify{$item}) {
1.252 raeburn 2049: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="'.$userenv{$item}.'" />';
1.188 raeburn 2050: } else {
1.252 raeburn 2051: $row .= $userenv{$item};
1.188 raeburn 2052: }
1.206 raeburn 2053: if ($item eq 'id') {
1.219 raeburn 2054: $showforceid = $canmodify{$item};
2055: }
1.188 raeburn 2056: }
1.252 raeburn 2057: $row .= &Apache::lonhtmlcommon::row_closure(1);
2058: if (!$hiderow) {
2059: $output .= $row;
2060: $rowcount ++;
2061: }
1.188 raeburn 2062: }
1.286 raeburn 2063: if (($canmodify_status{'inststatus'}) || ($context ne 'selfcreate')) {
2064: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($ccdomain);
2065: if (ref($types) eq 'ARRAY') {
2066: if (@{$types} > 0) {
2067: my ($hiderow,$shown);
2068: if ($canmodify_status{'inststatus'}) {
2069: $shown = &pick_inst_statuses($userenv{'inststatus'},$usertypes,$types);
2070: } else {
2071: if ($userenv{'inststatus'} eq '') {
2072: $hiderow = 1;
1.295.2.31 raeburn 2073: } else {
2074: my @showitems;
2075: foreach my $item ( map { &unescape($_); } split(':',$userenv{'inststatus'})) {
2076: if (exists($usertypes->{$item})) {
2077: push(@showitems,$usertypes->{$item});
2078: } else {
2079: push(@showitems,$item);
2080: }
2081: }
2082: if (@showitems) {
2083: $shown = join(', ',@showitems);
2084: } else {
2085: $hiderow = 1;
2086: }
1.286 raeburn 2087: }
2088: }
2089: if (!$hiderow) {
2090: my $row = &Apache::lonhtmlcommon::row_title(&mt('Affliations'),undef,'LC_oddrow_value')."\n".
2091: $shown.&Apache::lonhtmlcommon::row_closure(1);
2092: if ($context eq 'selfcreate') {
2093: $rowcount ++;
2094: }
2095: $output .= $row;
2096: }
2097: }
2098: }
2099: }
1.188 raeburn 2100: $output .= &Apache::lonhtmlcommon::end_pick_box();
1.206 raeburn 2101: if (wantarray) {
1.252 raeburn 2102: if ($context eq 'selfcreate') {
2103: return($output,$rowcount,$editable);
2104: } else {
2105: return ($output,$showforceid);
2106: }
1.206 raeburn 2107: } else {
2108: return $output;
2109: }
1.188 raeburn 2110: }
2111:
1.286 raeburn 2112: sub pick_inst_statuses {
2113: my ($curr,$usertypes,$types) = @_;
2114: my ($output,$rem,@currtypes);
2115: if ($curr ne '') {
2116: @currtypes = map { &unescape($_); } split(/:/,$curr);
2117: }
2118: my $numinrow = 2;
2119: if (ref($types) eq 'ARRAY') {
2120: $output = '<table>';
2121: my $lastcolspan;
2122: for (my $i=0; $i<@{$types}; $i++) {
2123: if (defined($usertypes->{$types->[$i]})) {
2124: my $rem = $i%($numinrow);
2125: if ($rem == 0) {
2126: if ($i<@{$types}-1) {
2127: if ($i > 0) {
2128: $output .= '</tr>';
2129: }
2130: $output .= '<tr>';
2131: }
2132: } elsif ($i==@{$types}-1) {
2133: my $colsleft = $numinrow - $rem;
2134: if ($colsleft > 1) {
2135: $lastcolspan = ' colspan="'.$colsleft.'"';
2136: }
2137: }
2138: my $check = ' ';
2139: if (grep(/^\Q$types->[$i]\E$/,@currtypes)) {
2140: $check = ' checked="checked" ';
2141: }
2142: $output .= '<td class="LC_left_item"'.$lastcolspan.'>'.
2143: '<span class="LC_nobreak"><label>'.
2144: '<input type="checkbox" name="inststatus" '.
2145: 'value="'.$types->[$i].'"'.$check.'/>'.
2146: $usertypes->{$types->[$i]}.'</label></span></td>';
2147: }
2148: }
2149: $output .= '</tr></table>';
2150: }
2151: return $output;
2152: }
2153:
1.257 raeburn 2154: sub selfcreate_canmodify {
2155: my ($context,$dom,$userinfo,$inst_results,$rolesarray) = @_;
2156: if (ref($inst_results) eq 'HASH') {
2157: my @inststatuses = &get_inststatuses($inst_results);
2158: if (@inststatuses == 0) {
2159: @inststatuses = ('default');
2160: }
2161: $rolesarray = \@inststatuses;
2162: }
2163: my %canmodify =
2164: &Apache::lonuserutils::can_modify_userinfo($context,$dom,$userinfo,
2165: $rolesarray);
2166: return %canmodify;
2167: }
2168:
1.252 raeburn 2169: sub get_inststatuses {
2170: my ($insthashref) = @_;
2171: my @inststatuses = ();
2172: if (ref($insthashref) eq 'HASH') {
2173: if (ref($insthashref->{'inststatus'}) eq 'ARRAY') {
2174: @inststatuses = @{$insthashref->{'inststatus'}};
2175: }
2176: }
2177: return @inststatuses;
2178: }
2179:
1.4 www 2180: # ================================================================= Phase Three
1.42 matthew 2181: sub update_user_data {
1.295.2.18 raeburn 2182: my ($r,$context,$crstype) = @_;
1.101 albertel 2183: my $uhome=&Apache::lonnet::homeserver($env{'form.ccuname'},
2184: $env{'form.ccdomain'});
1.27 matthew 2185: # Error messages
1.188 raeburn 2186: my $error = '<span class="LC_error">'.&mt('Error').': ';
1.193 raeburn 2187: my $end = '</span><br /><br />';
2188: my $rtnlink = '<a href="javascript:backPage(document.userupdate,'.
1.188 raeburn 2189: "'$env{'form.prevphase'}','modify')".'" />'.
1.219 raeburn 2190: &mt('Return to previous page').'</a>'.
2191: &Apache::loncommon::end_page();
2192: my $now = time;
1.40 www 2193: my $title;
1.101 albertel 2194: if (exists($env{'form.makeuser'})) {
1.40 www 2195: $title='Set Privileges for New User';
2196: } else {
2197: $title='Modify User Privileges';
2198: }
1.213 raeburn 2199: my $newuser = 0;
1.160 raeburn 2200: my ($jsback,$elements) = &crumb_utilities();
2201: my $jscript = '<script type="text/javascript">'."\n".
1.295.2.4 raeburn 2202: '// <![CDATA['."\n".
2203: $jsback."\n".
2204: '// ]]>'."\n".
2205: '</script>'."\n";
1.295.2.18 raeburn 2206: my %breadcrumb_text = &singleuser_breadcrumb($crstype);
1.233 raeburn 2207: my $args;
2208: if ($env{'form.popup'}) {
2209: $args->{'no_nav_bar'} = 1;
2210: } else {
2211: $args = undef;
2212: }
2213: $r->print(&Apache::loncommon::start_page($title,$jscript,$args));
1.160 raeburn 2214: &Apache::lonhtmlcommon::add_breadcrumb
2215: ({href=>"javascript:backPage(document.userupdate)",
1.213 raeburn 2216: text=>$breadcrumb_text{'search'},
1.160 raeburn 2217: faq=>282,bug=>'Instructor Interface',});
2218: if ($env{'form.prevphase'} eq 'userpicked') {
2219: &Apache::lonhtmlcommon::add_breadcrumb
2220: ({href=>"javascript:backPage(document.userupdate,'get_user_info','select')",
1.213 raeburn 2221: text=>$breadcrumb_text{'userpicked'},
1.160 raeburn 2222: faq=>282,bug=>'Instructor Interface',});
2223: }
2224: &Apache::lonhtmlcommon::add_breadcrumb
2225: ({href=>"javascript:backPage(document.userupdate,'$env{'form.prevphase'}','modify')",
1.219 raeburn 2226: text=>$breadcrumb_text{'modify'},
1.160 raeburn 2227: faq=>282,bug=>'Instructor Interface',},
2228: {href=>"/adm/createuser",
2229: text=>"Result",
2230: faq=>282,bug=>'Instructor Interface',});
1.224 raeburn 2231: my $helpitem = 'Course_Change_Privileges';
2232: if ($env{'form.action'} eq 'singlestudent') {
2233: $helpitem = 'Course_Add_Student';
2234: }
2235: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management',
2236: $helpitem));
1.188 raeburn 2237: $r->print(&update_result_form($uhome));
1.27 matthew 2238: # Check Inputs
1.101 albertel 2239: if (! $env{'form.ccuname'} ) {
1.193 raeburn 2240: $r->print($error.&mt('No login name specified').'.'.$end.$rtnlink);
1.27 matthew 2241: return;
2242: }
1.138 albertel 2243: if ( $env{'form.ccuname'} ne
2244: &LONCAPA::clean_username($env{'form.ccuname'}) ) {
1.281 bisitz 2245: $r->print($error.&mt('Invalid login name.').' '.
2246: &mt('Only letters, numbers, periods, dashes, @, and underscores are valid.').
1.193 raeburn 2247: $end.$rtnlink);
1.27 matthew 2248: return;
2249: }
1.101 albertel 2250: if (! $env{'form.ccdomain'} ) {
1.193 raeburn 2251: $r->print($error.&mt('No domain specified').'.'.$end.$rtnlink);
1.27 matthew 2252: return;
2253: }
1.138 albertel 2254: if ( $env{'form.ccdomain'} ne
2255: &LONCAPA::clean_domain($env{'form.ccdomain'}) ) {
1.281 bisitz 2256: $r->print($error.&mt('Invalid domain name.').' '.
2257: &mt('Only letters, numbers, periods, dashes, and underscores are valid.').
1.193 raeburn 2258: $end.$rtnlink);
1.27 matthew 2259: return;
2260: }
1.219 raeburn 2261: if ($uhome eq 'no_host') {
2262: $newuser = 1;
2263: }
1.101 albertel 2264: if (! exists($env{'form.makeuser'})) {
1.29 matthew 2265: # Modifying an existing user, so check the validity of the name
2266: if ($uhome eq 'no_host') {
1.73 sakharuk 2267: $r->print($error.&mt('Unable to determine home server for ').
1.101 albertel 2268: $env{'form.ccuname'}.&mt(' in domain ').
2269: $env{'form.ccdomain'}.'.');
1.29 matthew 2270: return;
2271: }
2272: }
1.27 matthew 2273: # Determine authentication method and password for the user being modified
2274: my $amode='';
2275: my $genpwd='';
1.101 albertel 2276: if ($env{'form.login'} eq 'krb') {
1.41 albertel 2277: $amode='krb';
1.101 albertel 2278: $amode.=$env{'form.krbver'};
2279: $genpwd=$env{'form.krbarg'};
2280: } elsif ($env{'form.login'} eq 'int') {
1.27 matthew 2281: $amode='internal';
1.101 albertel 2282: $genpwd=$env{'form.intarg'};
2283: } elsif ($env{'form.login'} eq 'fsys') {
1.27 matthew 2284: $amode='unix';
1.101 albertel 2285: $genpwd=$env{'form.fsysarg'};
2286: } elsif ($env{'form.login'} eq 'loc') {
1.27 matthew 2287: $amode='localauth';
1.101 albertel 2288: $genpwd=$env{'form.locarg'};
1.27 matthew 2289: $genpwd=" " if (!$genpwd);
1.101 albertel 2290: } elsif (($env{'form.login'} eq 'nochange') ||
2291: ($env{'form.login'} eq '' )) {
1.34 matthew 2292: # There is no need to tell the user we did not change what they
2293: # did not ask us to change.
1.35 matthew 2294: # If they are creating a new user but have not specified login
2295: # information this will be caught below.
1.30 matthew 2296: } else {
1.193 raeburn 2297: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
1.30 matthew 2298: return;
1.27 matthew 2299: }
1.164 albertel 2300:
1.188 raeburn 2301: $r->print('<h3>'.&mt('User [_1] in domain [_2]',
2302: $env{'form.ccuname'}, $env{'form.ccdomain'}).'</h3>');
1.295.2.35! raeburn 2303: $r->print('<p class="LC_info">'.&mt('Please be patient').'</p>');
1.193 raeburn 2304: my (%alerts,%rulematch,%inst_results,%curr_rules);
1.295.2.31 raeburn 2305: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
1.267 raeburn 2306: my @usertools = ('aboutme','blog','portfolio');
1.295.2.31 raeburn 2307: my @requestcourses = ('official','unofficial','community');
1.286 raeburn 2308: my ($othertitle,$usertypes,$types) =
2309: &Apache::loncommon::sorted_inst_types($env{'form.ccdomain'});
1.295.2.31 raeburn 2310: my %canmodify_status =
2311: &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},
2312: ['inststatus']);
1.101 albertel 2313: if ($env{'form.makeuser'}) {
1.164 albertel 2314: $r->print('<h3>'.&mt('Creating new account.').'</h3>');
1.27 matthew 2315: # Check for the authentication mode and password
2316: if (! $amode || ! $genpwd) {
1.193 raeburn 2317: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
1.27 matthew 2318: return;
1.18 albertel 2319: }
1.29 matthew 2320: # Determine desired host
1.101 albertel 2321: my $desiredhost = $env{'form.hserver'};
1.29 matthew 2322: if (lc($desiredhost) eq 'default') {
2323: $desiredhost = undef;
2324: } else {
1.147 albertel 2325: my %home_servers =
2326: &Apache::lonnet::get_servers($env{'form.ccdomain'},'library');
1.29 matthew 2327: if (! exists($home_servers{$desiredhost})) {
1.193 raeburn 2328: $r->print($error.&mt('Invalid home server specified').$end.$rtnlink);
2329: return;
2330: }
2331: }
2332: # Check ID format
2333: my %checkhash;
2334: my %checks = ('id' => 1);
2335: %{$checkhash{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}}} = (
1.219 raeburn 2336: 'newuser' => $newuser,
1.196 raeburn 2337: 'id' => $env{'form.cid'},
1.193 raeburn 2338: );
1.196 raeburn 2339: if ($env{'form.cid'} ne '') {
2340: &Apache::loncommon::user_rule_check(\%checkhash,\%checks,\%alerts,
2341: \%rulematch,\%inst_results,\%curr_rules);
2342: if (ref($alerts{'id'}) eq 'HASH') {
2343: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
2344: my $domdesc =
2345: &Apache::lonnet::domain($env{'form.ccdomain'},'description');
2346: if ($alerts{'id'}{$env{'form.ccdomain'}}{$env{'form.cid'}}) {
2347: my $userchkmsg;
2348: if (ref($curr_rules{$env{'form.ccdomain'}}) eq 'HASH') {
2349: $userchkmsg =
2350: &Apache::loncommon::instrule_disallow_msg('id',
2351: $domdesc,1).
2352: &Apache::loncommon::user_rule_formats($env{'form.ccdomain'},
2353: $domdesc,$curr_rules{$env{'form.ccdomain'}}{'id'},'id');
2354: }
2355: $r->print($error.&mt('Invalid ID format').$end.
2356: $userchkmsg.$rtnlink);
2357: return;
2358: }
2359: }
1.29 matthew 2360: }
2361: }
1.27 matthew 2362: # Call modifyuser
2363: my $result = &Apache::lonnet::modifyuser
1.193 raeburn 2364: ($env{'form.ccdomain'},$env{'form.ccuname'},$env{'form.cid'},
1.188 raeburn 2365: $amode,$genpwd,$env{'form.cfirstname'},
2366: $env{'form.cmiddlename'},$env{'form.clastname'},
2367: $env{'form.cgeneration'},undef,$desiredhost,
2368: $env{'form.cpermanentemail'});
1.77 www 2369: $r->print(&mt('Generating user').': '.$result);
1.219 raeburn 2370: $uhome = &Apache::lonnet::homeserver($env{'form.ccuname'},
1.101 albertel 2371: $env{'form.ccdomain'});
1.295.2.31 raeburn 2372: my (%changeHash,%newcustom,%changed,%changedinfo);
1.267 raeburn 2373: if ($uhome ne 'no_host') {
1.295.2.31 raeburn 2374: if ($context eq 'domain') {
2375: if ($env{'form.customquota'} == 1) {
2376: if ($env{'form.portfolioquota'} eq '') {
2377: $newcustom{'quota'} = 0;
2378: } else {
2379: $newcustom{'quota'} = $env{'form.portfolioquota'};
2380: $newcustom{'quota'} =~ s/[^\d\.]//g;
2381: }
2382: $changed{'quota'} = "a_admin($newcustom{'quota'},\%changeHash);
1.275 raeburn 2383: }
1.295.2.31 raeburn 2384: foreach my $item (@usertools) {
2385: if ($env{'form.custom'.$item} == 1) {
2386: $newcustom{$item} = $env{'form.tools_'.$item};
2387: $changed{$item} = &tool_admin($item,$newcustom{$item},
2388: \%changeHash,'tools');
1.295.2.7 raeburn 2389: }
2390: }
1.295.2.31 raeburn 2391: foreach my $item (@requestcourses) {
1.295.2.33 raeburn 2392: if ($env{'form.custom'.$item} == 1) {
2393: $newcustom{$item} = $env{'form.crsreq_'.$item};
2394: if ($env{'form.crsreq_'.$item} eq 'autolimit') {
2395: $newcustom{$item} .= '=';
2396: unless ($env{'form.crsreq_'.$item.'_limit'} =~ /\D/) {
2397: $newcustom{$item} .= $env{'form.crsreq_'.$item.'_limit'};
2398: }
1.295.2.31 raeburn 2399: }
1.295.2.33 raeburn 2400: $changed{$item} = &tool_admin($item,$newcustom{$item},
2401: \%changeHash,'requestcourses');
1.295.2.31 raeburn 2402: }
2403: }
1.232 raeburn 2404: }
1.295.2.31 raeburn 2405: if ($canmodify_status{'inststatus'}) {
2406: if (exists($env{'form.inststatus'})) {
2407: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
2408: if (@inststatuses > 0) {
2409: $changeHash{'inststatus'} = join(',',@inststatuses);
2410: $changed{'inststatus'} = $changeHash{'inststatus'};
2411: }
1.286 raeburn 2412: }
2413: }
1.267 raeburn 2414: if (keys(%changed)) {
1.295.2.31 raeburn 2415: foreach my $item (@userinfo) {
2416: $changeHash{$item} = $env{'form.c'.$item};
2417: }
1.267 raeburn 2418: my $chgresult =
2419: &Apache::lonnet::put('environment',\%changeHash,
2420: $env{'form.ccdomain'},$env{'form.ccuname'});
2421: }
1.232 raeburn 2422: }
1.219 raeburn 2423: $r->print('<br />'.&mt('Home server').': '.$uhome.' '.
2424: &Apache::lonnet::hostname($uhome));
1.101 albertel 2425: } elsif (($env{'form.login'} ne 'nochange') &&
2426: ($env{'form.login'} ne '' )) {
1.27 matthew 2427: # Modify user privileges
2428: if (! $amode || ! $genpwd) {
1.193 raeburn 2429: $r->print($error.'Invalid login mode or password'.$end.$rtnlink);
1.27 matthew 2430: return;
1.20 harris41 2431: }
1.27 matthew 2432: # Only allow authentification modification if the person has authority
1.101 albertel 2433: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.20 harris41 2434: $r->print('Modifying authentication: '.
1.31 matthew 2435: &Apache::lonnet::modifyuserauth(
1.101 albertel 2436: $env{'form.ccdomain'},$env{'form.ccuname'},
1.21 harris41 2437: $amode,$genpwd));
1.102 albertel 2438: $r->print('<br />'.&mt('Home server').': '.&Apache::lonnet::homeserver
1.101 albertel 2439: ($env{'form.ccuname'},$env{'form.ccdomain'}));
1.4 www 2440: } else {
1.27 matthew 2441: # Okay, this is a non-fatal error.
1.193 raeburn 2442: $r->print($error.&mt('You do not have the authority to modify this users authentification information').'.'.$end);
1.27 matthew 2443: }
1.28 matthew 2444: }
1.295.2.35! raeburn 2445:
! 2446: $r->rflush(); # Finish display of header before time consuming actions start
! 2447:
1.28 matthew 2448: ##
1.295.2.34 raeburn 2449: my (@userroles,%userupdate,$cnum,$cdom,%namechanged);
1.213 raeburn 2450: if ($context eq 'course') {
2451: ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity();
1.295.2.18 raeburn 2452: $crstype = &Apache::loncommon::course_type($cdom.'_'.$cnum);
1.213 raeburn 2453: }
1.101 albertel 2454: if (! $env{'form.makeuser'} ) {
1.28 matthew 2455: # Check for need to change
2456: my %userenv = &Apache::lonnet::get
1.134 raeburn 2457: ('environment',['firstname','middlename','lastname','generation',
1.267 raeburn 2458: 'id','permanentemail','portfolioquota','inststatus','tools.aboutme',
1.279 raeburn 2459: 'tools.blog','tools.portfolio','requestcourses.official',
1.295.2.3 raeburn 2460: 'requestcourses.unofficial','requestcourses.community',
2461: 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
2462: 'reqcrsotherdom.community'],
1.160 raeburn 2463: $env{'form.ccdomain'},$env{'form.ccuname'});
1.28 matthew 2464: my ($tmp) = keys(%userenv);
2465: if ($tmp =~ /^(con_lost|error)/i) {
2466: %userenv = ();
2467: }
1.206 raeburn 2468: my $no_forceid_alert;
2469: # Check to see if user information can be changed
2470: my %domconfig =
2471: &Apache::lonnet::get_dom('configuration',['usermodification'],
2472: $env{'form.ccdomain'});
1.213 raeburn 2473: my @statuses = ('active','future');
2474: my %roles = &Apache::lonnet::get_my_roles($env{'form.ccuname'},$env{'form.ccdomain'},'userroles',\@statuses,undef,$env{'request.role.domain'});
2475: my ($auname,$audom);
1.220 raeburn 2476: if ($context eq 'author') {
1.206 raeburn 2477: $auname = $env{'user.name'};
2478: $audom = $env{'user.domain'};
2479: }
2480: foreach my $item (keys(%roles)) {
1.220 raeburn 2481: my ($rolenum,$roledom,$role) = split(/:/,$item,-1);
1.206 raeburn 2482: if ($context eq 'course') {
2483: if ($cnum ne '' && $cdom ne '') {
2484: if ($rolenum eq $cnum && $roledom eq $cdom) {
2485: if (!grep(/^\Q$role\E$/,@userroles)) {
2486: push(@userroles,$role);
2487: }
2488: }
2489: }
2490: } elsif ($context eq 'author') {
2491: if ($rolenum eq $auname && $roledom eq $audom) {
2492: if (!grep(/^\Q$role\E$/,@userroles)) {
2493: push(@userroles,$role);
2494: }
2495: }
2496: }
2497: }
1.220 raeburn 2498: if ($env{'form.action'} eq 'singlestudent') {
2499: if (!grep(/^st$/,@userroles)) {
2500: push(@userroles,'st');
2501: }
2502: } else {
2503: # Check for course or co-author roles being activated or re-enabled
2504: if ($context eq 'author' || $context eq 'course') {
2505: foreach my $key (keys(%env)) {
2506: if ($context eq 'author') {
2507: if ($key=~/^form\.act_\Q$audom\E_\Q$auname\E_([^_]+)/) {
2508: if (!grep(/^\Q$1\E$/,@userroles)) {
2509: push(@userroles,$1);
2510: }
2511: } elsif ($key =~/^form\.ren\:\Q$audom\E\/\Q$auname\E_([^_]+)/) {
2512: if (!grep(/^\Q$1\E$/,@userroles)) {
2513: push(@userroles,$1);
2514: }
1.206 raeburn 2515: }
1.220 raeburn 2516: } elsif ($context eq 'course') {
2517: if ($key=~/^form\.act_\Q$cdom\E_\Q$cnum\E_([^_]+)/) {
2518: if (!grep(/^\Q$1\E$/,@userroles)) {
2519: push(@userroles,$1);
2520: }
2521: } elsif ($key =~/^form\.ren\:\Q$cdom\E\/\Q$cnum\E(\/?\w*)_([^_]+)/) {
2522: if (!grep(/^\Q$1\E$/,@userroles)) {
2523: push(@userroles,$1);
2524: }
1.206 raeburn 2525: }
2526: }
2527: }
2528: }
2529: }
2530: #Check to see if we can change personal data for the user
2531: my (@mod_disallowed,@longroles);
2532: foreach my $role (@userroles) {
2533: if ($role eq 'cr') {
2534: push(@longroles,'Custom');
2535: } else {
1.295.2.18 raeburn 2536: push(@longroles,&Apache::lonnet::plaintext($role,$crstype));
1.206 raeburn 2537: }
2538: }
1.219 raeburn 2539: my %canmodify = &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},\@userinfo,\@userroles);
2540: foreach my $item (@userinfo) {
1.28 matthew 2541: # Strip leading and trailing whitespace
1.203 raeburn 2542: $env{'form.c'.$item} =~ s/(\s+$|^\s+)//g;
1.219 raeburn 2543: if (!$canmodify{$item}) {
1.207 raeburn 2544: if (defined($env{'form.c'.$item})) {
2545: if ($env{'form.c'.$item} ne $userenv{$item}) {
2546: push(@mod_disallowed,$item);
2547: }
1.206 raeburn 2548: }
2549: $env{'form.c'.$item} = $userenv{$item};
2550: }
1.28 matthew 2551: }
1.259 bisitz 2552: # Check to see if we can change the Student/Employee ID
1.196 raeburn 2553: my $forceid = $env{'form.forceid'};
2554: my $recurseid = $env{'form.recurseid'};
2555: my (%alerts,%rulematch,%idinst_results,%curr_rules,%got_rules);
1.203 raeburn 2556: my %uidhash = &Apache::lonnet::idrget($env{'form.ccdomain'},
2557: $env{'form.ccuname'});
2558: if (($uidhash{$env{'form.ccuname'}}) &&
2559: ($uidhash{$env{'form.ccuname'}}!~/error\:/) &&
2560: (!$forceid)) {
2561: if ($env{'form.cid'} ne $uidhash{$env{'form.ccuname'}}) {
2562: $env{'form.cid'} = $userenv{'id'};
1.293 bisitz 2563: $no_forceid_alert = &mt('New student/employee ID does not match existing ID for this user.')
1.259 bisitz 2564: .'<br />'
2565: .&mt("Change is not permitted without checking the 'Force ID change' checkbox on the previous page.")
2566: .'<br />'."\n";
1.203 raeburn 2567: }
2568: }
2569: if ($env{'form.cid'} ne $userenv{'id'}) {
1.196 raeburn 2570: my $checkhash;
2571: my $checks = { 'id' => 1 };
2572: $checkhash->{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}} =
2573: { 'newuser' => $newuser,
2574: 'id' => $env{'form.cid'},
2575: };
2576: &Apache::loncommon::user_rule_check($checkhash,$checks,
2577: \%alerts,\%rulematch,\%idinst_results,\%curr_rules,\%got_rules);
2578: if (ref($alerts{'id'}) eq 'HASH') {
2579: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
1.203 raeburn 2580: $env{'form.cid'} = $userenv{'id'};
1.196 raeburn 2581: }
2582: }
2583: }
1.286 raeburn 2584: my ($quotachanged,$oldportfolioquota,$newportfolioquota,$oldinststatus,
1.295.2.31 raeburn 2585: $newinststatus,$oldisdefault,$newisdefault,%oldsettings,
1.295.2.32 raeburn 2586: %oldsettingstext,%newsettings,%newsettingstext,@disporder,
2587: $olddefquota,$oldsettingstatus,$newdefquota,$newsettingstatus);
1.295.2.31 raeburn 2588: @disporder = ('inststatus');
2589: if ($env{'request.role.domain'} eq $env{'form.ccdomain'}) {
2590: push(@disporder,'requestcourses');
2591: } else {
2592: push(@disporder,'reqcrsotherdom');
2593: }
2594: push(@disporder,('quota','tools'));
1.295.2.32 raeburn 2595: $oldinststatus = $userenv{'inststatus'};
2596: ($olddefquota,$oldsettingstatus) =
1.295.2.31 raeburn 2597: &Apache::loncommon::default_quota($env{'form.ccdomain'},$oldinststatus);
1.295.2.32 raeburn 2598: ($newdefquota,$newsettingstatus) = ($olddefquota,$oldsettingstatus);
1.295.2.31 raeburn 2599: my %canshow;
1.220 raeburn 2600: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
1.295.2.31 raeburn 2601: $canshow{'quota'} = 1;
1.220 raeburn 2602: }
1.267 raeburn 2603: if (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
1.295.2.31 raeburn 2604: $canshow{'tools'} = 1;
1.267 raeburn 2605: }
1.275 raeburn 2606: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
1.295.2.31 raeburn 2607: $canshow{'requestcourses'} = 1;
1.295.2.3 raeburn 2608: } elsif (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.295.2.31 raeburn 2609: $canshow{'reqcrsotherdom'} = 1;
1.275 raeburn 2610: }
1.286 raeburn 2611: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.295.2.31 raeburn 2612: $canshow{'inststatus'} = 1;
1.286 raeburn 2613: }
1.267 raeburn 2614: my (%changeHash,%changed);
1.286 raeburn 2615: if ($oldinststatus eq '') {
1.295.2.31 raeburn 2616: $oldsettings{'inststatus'} = $othertitle;
1.286 raeburn 2617: } else {
2618: if (ref($usertypes) eq 'HASH') {
1.295.2.31 raeburn 2619: $oldsettings{'inststatus'} = join(', ',map{ $usertypes->{ &unescape($_) }; } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 2620: } else {
1.295.2.31 raeburn 2621: $oldsettings{'inststatus'} = join(', ',map{ &unescape($_); } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 2622: }
2623: }
2624: $changeHash{'inststatus'} = $userenv{'inststatus'};
1.295.2.31 raeburn 2625: if ($canmodify_status{'inststatus'}) {
2626: $canshow{'inststatus'} = 1;
1.286 raeburn 2627: if (exists($env{'form.inststatus'})) {
2628: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
2629: if (@inststatuses > 0) {
2630: $newinststatus = join(':',map { &escape($_); } @inststatuses);
2631: $changeHash{'inststatus'} = $newinststatus;
2632: if ($newinststatus ne $oldinststatus) {
2633: $changed{'inststatus'} = $newinststatus;
1.295.2.32 raeburn 2634: ($newdefquota,$newsettingstatus) =
2635: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus);
1.286 raeburn 2636: }
2637: if (ref($usertypes) eq 'HASH') {
1.295.2.31 raeburn 2638: $newsettings{'inststatus'} = join(', ',map{ $usertypes->{$_}; } (@inststatuses));
1.286 raeburn 2639: } else {
1.295.2.31 raeburn 2640: $newsettings{'inststatus'} = join(', ',@inststatuses);
1.286 raeburn 2641: }
2642: }
1.295.2.31 raeburn 2643: } else {
2644: $newinststatus = '';
2645: $changeHash{'inststatus'} = $newinststatus;
2646: $newsettings{'inststatus'} = $othertitle;
2647: if ($newinststatus ne $oldinststatus) {
2648: $changed{'inststatus'} = $changeHash{'inststatus'};
1.295.2.32 raeburn 2649: ($newdefquota,$newsettingstatus) =
2650: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus);
1.295.2.31 raeburn 2651: }
1.286 raeburn 2652: }
1.295.2.31 raeburn 2653: } elsif ($context ne 'selfcreate') {
2654: $canshow{'inststatus'} = 1;
2655: $newsettings{'inststatus'} = $oldsettings{'inststatus'};
1.286 raeburn 2656: }
1.204 raeburn 2657: $changeHash{'portfolioquota'} = $userenv{'portfolioquota'};
1.295.2.31 raeburn 2658: if ($context eq 'domain') {
2659: if ($userenv{'portfolioquota'} ne '') {
2660: $oldportfolioquota = $userenv{'portfolioquota'};
2661: if ($env{'form.customquota'} == 1) {
2662: if ($env{'form.portfolioquota'} eq '') {
2663: $newportfolioquota = 0;
2664: } else {
2665: $newportfolioquota = $env{'form.portfolioquota'};
2666: $newportfolioquota =~ s/[^\d\.]//g;
2667: }
2668: if ($newportfolioquota != $oldportfolioquota) {
2669: $changed{'quota'} = "a_admin($newportfolioquota,\%changeHash);
2670: }
1.149 raeburn 2671: } else {
1.295.2.31 raeburn 2672: $changed{'quota'} = "a_admin('',\%changeHash);
1.295.2.32 raeburn 2673: $newportfolioquota = $newdefquota;
1.295.2.31 raeburn 2674: $newisdefault = 1;
1.134 raeburn 2675: }
1.149 raeburn 2676: } else {
1.295.2.31 raeburn 2677: $oldisdefault = 1;
1.295.2.32 raeburn 2678: $oldportfolioquota = $olddefquota;
1.295.2.31 raeburn 2679: if ($env{'form.customquota'} == 1) {
2680: if ($env{'form.portfolioquota'} eq '') {
2681: $newportfolioquota = 0;
2682: } else {
2683: $newportfolioquota = $env{'form.portfolioquota'};
2684: $newportfolioquota =~ s/[^\d\.]//g;
2685: }
2686: $changed{'quota'} = "a_admin($newportfolioquota,\%changeHash);
1.149 raeburn 2687: } else {
1.295.2.32 raeburn 2688: $newportfolioquota = $newdefquota;
1.295.2.31 raeburn 2689: $newisdefault = 1;
1.149 raeburn 2690: }
1.295.2.31 raeburn 2691: }
2692: if ($oldisdefault) {
1.295.2.32 raeburn 2693: $oldsettingstext{'quota'} = &get_defaultquota_text($oldsettingstatus);
1.295.2.31 raeburn 2694: }
2695: if ($newisdefault) {
1.295.2.32 raeburn 2696: $newsettingstext{'quota'} = &get_defaultquota_text($newsettingstatus);
1.295.2.31 raeburn 2697: }
2698: &tool_changes('tools',\@usertools,\%oldsettings,\%oldsettingstext,\%userenv,
2699: \%changeHash,\%changed,\%newsettings,\%newsettingstext);
2700: if ($env{'form.ccdomain'} eq $env{'request.role.domain'}) {
2701: &tool_changes('requestcourses',\@requestcourses,\%oldsettings,\%oldsettingstext,
2702: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 2703: } else {
1.295.2.31 raeburn 2704: &tool_changes('reqcrsotherdom',\@requestcourses,\%oldsettings,\%oldsettingstext,
2705: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
2706: }
2707: }
2708: foreach my $item (@userinfo) {
2709: if ($env{'form.c'.$item} ne $userenv{$item}) {
2710: $namechanged{$item} = 1;
1.149 raeburn 2711: }
2712: }
1.295.2.31 raeburn 2713: $oldsettings{'quota'} = $oldportfolioquota.' Mb';
2714: $newsettings{'quota'} = $newportfolioquota.' Mb';
2715: if ((keys(%namechanged) > 0) || (keys(%changed) > 0)) {
1.267 raeburn 2716: my ($chgresult,$namechgresult);
2717: if (keys(%changed) > 0) {
2718: $chgresult =
1.204 raeburn 2719: &Apache::lonnet::put('environment',\%changeHash,
2720: $env{'form.ccdomain'},$env{'form.ccuname'});
1.267 raeburn 2721: if ($chgresult eq 'ok') {
2722: if (($env{'user.name'} eq $env{'form.ccuname'}) &&
2723: ($env{'user.domain'} eq $env{'form.ccdomain'})) {
1.270 raeburn 2724: my %newenvhash;
2725: foreach my $key (keys(%changed)) {
1.295.2.29 raeburn 2726: if (($key eq 'official') || ($key eq 'unofficial')
2727: || ($key eq 'community')) {
1.279 raeburn 2728: $newenvhash{'environment.requestcourses.'.$key} =
2729: $changeHash{'requestcourses.'.$key};
2730: if ($changeHash{'requestcourses.'.$key} ne '') {
1.295.2.15 raeburn 2731: $newenvhash{'environment.canrequest.'.$key} = 1;
1.279 raeburn 2732: } else {
2733: $newenvhash{'environment.canrequest.'.$key} =
2734: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
2735: $key,'reload','requestcourses');
2736: }
1.275 raeburn 2737: } elsif ($key ne 'quota') {
1.270 raeburn 2738: $newenvhash{'environment.tools.'.$key} =
2739: $changeHash{'tools.'.$key};
1.279 raeburn 2740: if ($changeHash{'tools.'.$key} ne '') {
2741: $newenvhash{'environment.availabletools.'.$key} =
2742: $changeHash{'tools.'.$key};
2743: } else {
2744: $newenvhash{'environment.availabletools.'.$key} =
2745: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'}, $key,'reload','tools');
2746: }
1.270 raeburn 2747: }
2748: }
1.271 raeburn 2749: if (keys(%newenvhash)) {
2750: &Apache::lonnet::appenv(\%newenvhash);
2751: }
1.267 raeburn 2752: }
2753: }
1.204 raeburn 2754: }
1.295.2.31 raeburn 2755: if (keys(%namechanged) > 0) {
2756: foreach my $field (@userinfo) {
2757: $changeHash{$field} = $env{'form.c'.$field};
2758: }
2759: # Make the change
1.204 raeburn 2760: $namechgresult =
2761: &Apache::lonnet::modifyuser($env{'form.ccdomain'},
2762: $env{'form.ccuname'},$changeHash{'id'},undef,undef,
2763: $changeHash{'firstname'},$changeHash{'middlename'},
2764: $changeHash{'lastname'},$changeHash{'generation'},
1.295.2.31 raeburn 2765: $changeHash{'id'},undef,$changeHash{'permanentemail'},undef,\@userinfo);
1.220 raeburn 2766: %userupdate = (
2767: lastname => $env{'form.clastname'},
2768: middlename => $env{'form.cmiddlename'},
2769: firstname => $env{'form.cfirstname'},
2770: generation => $env{'form.cgeneration'},
2771: id => $env{'form.cid'},
2772: );
1.204 raeburn 2773: }
1.295.2.31 raeburn 2774: if (((keys(%namechanged) > 0) && $namechgresult eq 'ok') ||
1.267 raeburn 2775: ((keys(%changed) > 0) && $chgresult eq 'ok')) {
1.28 matthew 2776: # Tell the user we changed the name
1.295.2.31 raeburn 2777: &display_userinfo($r,1,\@disporder,\%canshow,\@requestcourses,
2778: \@usertools,\%userenv,\%changed,\%namechanged,
2779: \%oldsettings, \%oldsettingstext,\%newsettings,
2780: \%newsettingstext);
2781:
1.203 raeburn 2782: if ($env{'form.cid'} ne $userenv{'id'}) {
2783: &Apache::lonnet::idput($env{'form.ccdomain'},
2784: ($env{'form.ccuname'} => $env{'form.cid'}));
2785: if (($recurseid) &&
2786: (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}))) {
2787: my $idresult =
2788: &Apache::lonuserutils::propagate_id_change(
2789: $env{'form.ccuname'},$env{'form.ccdomain'},
2790: \%userupdate);
2791: $r->print('<br />'.$idresult.'<br />');
2792: }
1.196 raeburn 2793: }
1.149 raeburn 2794: if (($env{'form.ccdomain'} eq $env{'user.domain'}) &&
2795: ($env{'form.ccuname'} eq $env{'user.name'})) {
2796: my %newenvhash;
2797: foreach my $key (keys(%changeHash)) {
2798: $newenvhash{'environment.'.$key} = $changeHash{$key};
2799: }
1.238 raeburn 2800: &Apache::lonnet::appenv(\%newenvhash);
1.149 raeburn 2801: }
1.28 matthew 2802: } else { # error occurred
1.188 raeburn 2803: $r->print('<span class="LC_error">'.&mt('Unable to successfully change environment for').' '.
2804: $env{'form.ccuname'}.' '.&mt('in domain').' '.
1.206 raeburn 2805: $env{'form.ccdomain'}.'</span><br />');
1.28 matthew 2806: }
1.295.2.31 raeburn 2807: } else { # End of if ($env ... ) logic
1.275 raeburn 2808: # They did not want to change the users name, quota, tool availability,
2809: # or ability to request creation of courses,
1.267 raeburn 2810: # but we can still tell them what the name and quota and availabilities are
1.295.2.31 raeburn 2811: &display_userinfo($r,undef,\@disporder,\%canshow,\@requestcourses,
2812: \@usertools,\%userenv,\%changed,\%namechanged,\%oldsettings,
2813: \%oldsettingstext,\%newsettings,\%newsettingstext);
1.28 matthew 2814: }
1.206 raeburn 2815: if (@mod_disallowed) {
2816: my ($rolestr,$contextname);
2817: if (@longroles > 0) {
2818: $rolestr = join(', ',@longroles);
2819: } else {
2820: $rolestr = &mt('No roles');
2821: }
2822: if ($context eq 'course') {
2823: $contextname = &mt('course');
2824: } elsif ($context eq 'author') {
2825: $contextname = &mt('co-author');
2826: }
2827: $r->print(&mt('The following fields were not updated: ').'<ul>');
2828: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
2829: foreach my $field (@mod_disallowed) {
2830: $r->print('<li>'.$fieldtitles{$field}.'</li>'."\n");
2831: }
1.207 raeburn 2832: $r->print('</ul>');
2833: if (@mod_disallowed == 1) {
2834: $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));
2835: } else {
2836: $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));
2837: }
1.292 bisitz 2838: my $helplink = 'javascript:helpMenu('."'display'".')';
2839: $r->print('<span class="LC_cusr_emph">'.$rolestr.'</span><br />'
2840: .&mt('Please contact your [_1]helpdesk[_2] for more information.'
2841: ,'<a href="'.$helplink.'">','</a>')
2842: .'<br />');
1.206 raeburn 2843: }
1.259 bisitz 2844: $r->print('<span class="LC_warning">'
2845: .$no_forceid_alert
2846: .&Apache::lonuserutils::print_namespacing_alerts($env{'form.ccdomain'},\%alerts,\%curr_rules)
2847: .'</span>');
1.4 www 2848: }
1.220 raeburn 2849: if ($env{'form.action'} eq 'singlestudent') {
1.295.2.18 raeburn 2850: &enroll_single_student($r,$uhome,$amode,$genpwd,$now,$newuser,$context,$crstype);
2851: $r->print('<p><a href="javascript:backPage(document.userupdate)">');
2852: if ($crstype eq 'Community') {
2853: $r->print(&mt('Enroll Another Member'));
2854: } else {
2855: $r->print(&mt('Enroll Another Student'));
2856: }
2857: $r->print('</a></p>');
1.220 raeburn 2858: } else {
1.239 raeburn 2859: my @rolechanges = &update_roles($r,$context);
1.295.2.31 raeburn 2860: if (keys(%namechanged) > 0) {
1.220 raeburn 2861: if ($context eq 'course') {
2862: if (@userroles > 0) {
1.225 raeburn 2863: if ((@rolechanges == 0) ||
2864: (!(grep(/^st$/,@rolechanges)))) {
2865: if (grep(/^st$/,@userroles)) {
2866: my $classlistupdated =
2867: &Apache::lonuserutils::update_classlist($cdom,
1.220 raeburn 2868: $cnum,$env{'form.ccdomain'},
2869: $env{'form.ccuname'},\%userupdate);
1.225 raeburn 2870: }
1.220 raeburn 2871: }
2872: }
2873: }
2874: }
1.226 raeburn 2875: my $userinfo = &Apache::loncommon::plainname($env{'form.ccuname'},
1.233 raeburn 2876: $env{'form.ccdomain'});
2877: if ($env{'form.popup'}) {
2878: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
2879: } else {
1.246 bisitz 2880: $r->print('<p><a href="javascript:backPage(document.userupdate,'."'$env{'form.prevphase'}','modify'".')">'
2881: .&mt('Modify this user: [_1]','<span class="LC_cusr_emph">'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.' ('.$userinfo.')</span>').'</a>'
2882: .(' 'x5).'<a href="javascript:backPage(document.userupdate)">'
2883: .&mt('Create/Modify Another User').'</a></p>');
1.233 raeburn 2884: }
1.220 raeburn 2885: }
2886: $r->print(&Apache::loncommon::end_page());
2887: }
2888:
1.295.2.31 raeburn 2889: sub display_userinfo {
2890: my ($r,$changed,$order,$canshow,$requestcourses,$usertools,$userenv,
2891: $changedhash,$namechangedhash,$oldsetting,$oldsettingtext,
2892: $newsetting,$newsettingtext) = @_;
2893: return unless (ref($order) eq 'ARRAY' &&
2894: ref($canshow) eq 'HASH' &&
2895: ref($requestcourses) eq 'ARRAY' &&
2896: ref($usertools) eq 'ARRAY' &&
2897: ref($userenv) eq 'HASH' &&
2898: ref($changedhash) eq 'HASH' &&
2899: ref($oldsetting) eq 'HASH' &&
2900: ref($oldsettingtext) eq 'HASH' &&
2901: ref($newsetting) eq 'HASH' &&
2902: ref($newsettingtext) eq 'HASH');
2903: my %lt=&Apache::lonlocal::texthash(
2904: 'ui' => 'User Information (unchanged)',
2905: 'uic' => 'User Information Changed',
2906: 'firstname' => 'First Name',
2907: 'middlename' => 'Middle Name',
2908: 'lastname' => 'Last Name',
2909: 'generation' => 'Generation',
2910: 'id' => 'Student/Employee ID',
2911: 'permanentemail' => 'Permanent e-mail address',
2912: 'quota' => 'Disk space allocated to portfolio files',
2913: 'blog' => 'Blog Availability',
2914: 'aboutme' => 'Personal Information Page Availability',
2915: 'portfolio' => 'Portfolio Availability',
2916: 'official' => 'Can Request Official Courses',
2917: 'unofficial' => 'Can Request Unofficial Courses',
2918: 'community' => 'Can Request Communities',
2919: 'inststatus' => "Affiliation",
2920: 'prvs' => 'Previous Value:',
2921: 'chto' => 'Changed To:'
2922: );
2923: my $title = $lt{'ui'};
2924: if ($changed) {
2925: $title = $lt{'uic'};
2926: }
2927: $r->print('<h4>'.$title.'</h4>'.
2928: &Apache::loncommon::start_data_table().
2929: &Apache::loncommon::start_data_table_header_row());
2930: if ($changed) {
2931: $r->print("<th> </th>\n");
2932: }
2933: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
2934: foreach my $item (@userinfo) {
2935: $r->print("<th>$lt{$item}</th>\n");
2936: }
2937: foreach my $entry (@{$order}) {
2938: if ($canshow->{$entry}) {
2939: if (($entry eq 'requestcourses') || ($entry eq 'reqcrsotherdom')) {
2940: foreach my $item (@{$requestcourses}) {
2941: $r->print("<th>$lt{$item}</th>\n");
2942: }
2943: } elsif ($entry eq 'tools') {
2944: foreach my $item (@{$usertools}) {
2945: $r->print("<th>$lt{$item}</th>\n");
2946: }
2947: } else {
2948: $r->print("<th>$lt{$entry}</th>\n");
2949: }
2950: }
2951: }
2952: $r->print(&Apache::loncommon::end_data_table_header_row().
2953: &Apache::loncommon::start_data_table_row());
2954: if ($changed) {
2955: $r->print('<td><b>'.$lt{'prvs'}.'</b></td>'."\n");
2956: }
2957: foreach my $item (@userinfo) {
2958: $r->print('<td>'.$userenv->{$item}.' </td>'."\n");
2959: }
2960: foreach my $entry (@{$order}) {
2961: if ($canshow->{$entry}) {
2962: if (($entry eq 'requestcourses') || ($entry eq 'reqcrsotherdom')) {
2963: foreach my $item (@{$requestcourses}) {
2964: $r->print("<td>$oldsetting->{$item} $oldsettingtext->{$item}</td>\n");
2965: }
2966: } elsif ($entry eq 'tools') {
2967: foreach my $item (@{$usertools}) {
2968: $r->print("<td>$oldsetting->{$item} $oldsettingtext->{$item}</td>\n");
2969: }
2970: } else {
2971: $r->print("<td>$oldsetting->{$entry} $oldsettingtext->{$entry} </td>\n");
2972: }
2973: }
2974: }
2975: $r->print(&Apache::loncommon::end_data_table_row());
2976: if ($changed) {
2977: $r->print(&Apache::loncommon::start_data_table_row().
2978: '<td><span class="LC_nobreak"><b>'.$lt{'chto'}.'</b></span></td>'."\n");
2979: foreach my $item (@userinfo) {
2980: my $value = $env{'form.c'.$item};
2981: if ($namechangedhash->{$item}) {
2982: $value = '<span class="LC_cusr_emph">'.$value.'</span>';
2983: }
2984: $r->print("<td>$value </td>\n");
2985: }
2986: foreach my $entry (@{$order}) {
2987: if ($canshow->{$entry}) {
2988: if (($entry eq 'requestcourses') || ($entry eq 'reqcrsotherdom')) {
2989: foreach my $item (@{$requestcourses}) {
2990: my $value = $newsetting->{$item}.' '.$newsettingtext->{$item};
2991: if ($changedhash->{$item}) {
2992: $value = '<span class="LC_cusr_emph">'.$value.'</span>';
2993: }
2994: $r->print("<td>$value </td>\n");
2995: }
2996: } elsif ($entry eq 'tools') {
2997: foreach my $item (@{$usertools}) {
2998: my $value = $newsetting->{$item}.' '.$newsettingtext->{$item};
2999: if ($changedhash->{$item}) {
3000: $value = '<span class="LC_cusr_emph">'.$value.'</span>';
3001: }
3002: $r->print("<td>$value </td>\n");
3003: }
3004: } else {
3005: my $value = $newsetting->{$entry}.' '.$newsettingtext->{$entry};
3006: if ($changedhash->{$entry}) {
3007: $value = '<span class="LC_cusr_emph">'.$value.'</span>';
3008: }
3009: $r->print("<td>$value </td>\n");
3010: }
3011: }
3012: }
3013: $r->print(&Apache::loncommon::end_data_table_row());
3014: }
3015: $r->print(&Apache::loncommon::end_data_table().'<br />');
3016: return;
3017: }
3018:
1.275 raeburn 3019: sub tool_changes {
3020: my ($context,$usertools,$oldaccess,$oldaccesstext,$userenv,$changeHash,
3021: $changed,$newaccess,$newaccesstext) = @_;
3022: if (!((ref($usertools) eq 'ARRAY') && (ref($oldaccess) eq 'HASH') &&
3023: (ref($oldaccesstext) eq 'HASH') && (ref($userenv) eq 'HASH') &&
3024: (ref($changeHash) eq 'HASH') && (ref($changed) eq 'HASH') &&
3025: (ref($newaccess) eq 'HASH') && (ref($newaccesstext) eq 'HASH'))) {
3026: return;
3027: }
1.295.2.3 raeburn 3028: if ($context eq 'reqcrsotherdom') {
1.295.2.10 raeburn 3029: my @options = ('approval','validate','autolimit');
1.295.2.3 raeburn 3030: my $optregex = join('|',@options);
3031: my %reqdisplay = &courserequest_display();
3032: my $cdom = $env{'request.role.domain'};
3033: foreach my $tool (@{$usertools}) {
1.295.2.14 raeburn 3034: $oldaccesstext->{$tool} = &mt('No');
3035: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
1.295.2.7 raeburn 3036: $changeHash->{$context.'.'.$tool} = $userenv->{$context.'.'.$tool};
1.295.2.14 raeburn 3037: my $newop;
3038: if ($env{'form.'.$context.'_'.$tool}) {
3039: $newop = $env{'form.'.$context.'_'.$tool};
3040: if ($newop eq 'autolimit') {
3041: my $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
3042: $limit =~ s/\D+//g;
3043: $newop .= '='.$limit;
3044: }
3045: }
1.295.2.3 raeburn 3046: if ($userenv->{$context.'.'.$tool} eq '') {
1.295.2.14 raeburn 3047: if ($newop) {
3048: $changed->{$tool}=&tool_admin($tool,$cdom.':'.$newop,
1.295.2.3 raeburn 3049: $changeHash,$context);
3050: if ($changed->{$tool}) {
1.295.2.14 raeburn 3051: $newaccesstext->{$tool} = &mt('Yes');
1.295.2.3 raeburn 3052: } else {
1.295.2.14 raeburn 3053: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3054: }
1.295.2.3 raeburn 3055: }
3056: } else {
3057: my @curr = split(',',$userenv->{$context.'.'.$tool});
3058: my @new;
3059: my $changedoms;
1.295.2.14 raeburn 3060: foreach my $req (@curr) {
3061: if ($req =~ /^\Q$cdom\E\:($optregex\=?\d*)$/) {
3062: $oldaccesstext->{$tool} = &mt('Yes');
3063: my $oldop = $1;
3064: if ($oldop ne $newop) {
3065: $changedoms = 1;
3066: foreach my $item (@curr) {
3067: my ($reqdom,$option) = split(':',$item);
3068: unless ($reqdom eq $cdom) {
3069: push(@new,$item);
3070: }
1.295.2.3 raeburn 3071: }
1.295.2.14 raeburn 3072: if ($newop) {
3073: push(@new,$cdom.':'.$newop);
3074: }
3075: @new = sort(@new);
1.295.2.3 raeburn 3076: }
1.295.2.14 raeburn 3077: last;
1.295.2.3 raeburn 3078: }
1.295.2.14 raeburn 3079: }
3080: if ((!$changedoms) && ($newop)) {
1.295.2.3 raeburn 3081: $changedoms = 1;
3082: @new = sort(@curr,$cdom.':'.$newop);
3083: }
3084: if ($changedoms) {
3085: my $newdomstr;
3086: if (@new) {
3087: $newdomstr = join(',',@new);
3088: }
3089: $changed->{$tool}=&tool_admin($tool,$newdomstr,$changeHash,
3090: $context);
3091: if ($changed->{$tool}) {
3092: if ($env{'form.'.$context.'_'.$tool}) {
3093: if ($env{'form.'.$context.'_'.$tool} eq 'autolimit') {
1.295.2.14 raeburn 3094: my $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
3095: $limit =~ s/\D+//g;
3096: if ($limit) {
3097: $newaccesstext->{$tool} = &mt('Yes, up to limit of [quant,_1,request] per user.',$limit);
1.295.2.3 raeburn 3098: } else {
1.295.2.14 raeburn 3099: $newaccesstext->{$tool} = &mt('Yes, processed automatically');
1.295.2.3 raeburn 3100: }
3101: } else {
3102: $newaccesstext->{$tool} = $reqdisplay{$env{'form.'.$context.'_'.$tool}};
3103: }
3104: } else {
3105: $newaccesstext->{$tool} = &mt('No');
3106: }
3107: }
3108: }
3109: }
3110: }
3111: return;
3112: }
1.275 raeburn 3113: foreach my $tool (@{$usertools}) {
1.295.2.7 raeburn 3114: my $newval;
3115: if ($context eq 'requestcourses') {
3116: $newval = $env{'form.crsreq_'.$tool};
3117: if ($newval eq 'autolimit') {
3118: $newval .= '='.$env{'form.crsreq_'.$tool.'_limit'};
3119: }
3120: } else {
3121: $newval = $env{'form.'.$context.'_'.$tool};
3122: }
1.275 raeburn 3123: if ($userenv->{$context.'.'.$tool} ne '') {
3124: $oldaccess->{$tool} = &mt('custom');
3125: if ($userenv->{$context.'.'.$tool}) {
3126: $oldaccesstext->{$tool} = &mt("availability set to 'on'");
3127: } else {
3128: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
3129: }
1.279 raeburn 3130: $changeHash->{$context.'.'.$tool} = $userenv->{$context.'.'.$tool};
1.275 raeburn 3131: if ($env{'form.custom'.$tool} == 1) {
1.295.2.7 raeburn 3132: if ($newval ne $userenv->{$context.'.'.$tool}) {
3133: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
3134: $context);
1.275 raeburn 3135: if ($changed->{$tool}) {
3136: $newaccess->{$tool} = &mt('custom');
1.295.2.7 raeburn 3137: if ($newval) {
1.275 raeburn 3138: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3139: } else {
3140: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3141: }
3142: } else {
3143: $newaccess->{$tool} = $oldaccess->{$tool};
3144: if ($userenv->{$context.'.'.$tool}) {
3145: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3146: } else {
3147: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3148: }
3149: }
3150: } else {
3151: $newaccess->{$tool} = $oldaccess->{$tool};
3152: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3153: }
3154: } else {
3155: $changed->{$tool} = &tool_admin($tool,'',$changeHash,$context);
3156: if ($changed->{$tool}) {
3157: $newaccess->{$tool} = &mt('default');
3158: } else {
3159: $newaccess->{$tool} = $oldaccess->{$tool};
3160: if ($userenv->{$context.'.'.$tool}) {
1.295.2.7 raeburn 3161: $newaccesstext->{$tool} = &mt("availability set to 'on'");
1.275 raeburn 3162: } else {
1.295.2.7 raeburn 3163: $newaccesstext->{$tool} = &mt("availability set to 'off'");
1.275 raeburn 3164: }
3165: }
3166: }
3167: } else {
3168: $oldaccess->{$tool} = &mt('default');
3169: if ($env{'form.custom'.$tool} == 1) {
1.295.2.7 raeburn 3170: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
3171: $context);
1.275 raeburn 3172: if ($changed->{$tool}) {
3173: $newaccess->{$tool} = &mt('custom');
1.295.2.7 raeburn 3174: if ($newval) {
1.275 raeburn 3175: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3176: } else {
3177: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3178: }
3179: } else {
3180: $newaccess->{$tool} = $oldaccess->{$tool};
3181: }
3182: } else {
3183: $newaccess->{$tool} = $oldaccess->{$tool};
3184: }
3185: }
3186: }
3187: return;
3188: }
3189:
1.220 raeburn 3190: sub update_roles {
1.239 raeburn 3191: my ($r,$context) = @_;
1.4 www 3192: my $now=time;
1.225 raeburn 3193: my @rolechanges;
1.220 raeburn 3194: my %disallowed;
1.73 sakharuk 3195: $r->print('<h3>'.&mt('Modifying Roles').'</h3>');
1.135 raeburn 3196: foreach my $key (keys (%env)) {
3197: next if (! $env{$key});
1.190 raeburn 3198: next if ($key eq 'form.action');
1.27 matthew 3199: # Revoke roles
1.135 raeburn 3200: if ($key=~/^form\.rev/) {
3201: if ($key=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) {
1.64 www 3202: # Revoke standard role
1.170 albertel 3203: my ($scope,$role) = ($1,$2);
3204: my $result =
3205: &Apache::lonnet::revokerole($env{'form.ccdomain'},
3206: $env{'form.ccuname'},
1.239 raeburn 3207: $scope,$role,'','',$context);
1.170 albertel 3208: $r->print(&mt('Revoking [_1] in [_2]: [_3]',
3209: $role,$scope,'<b>'.$result.'</b>').'<br />');
3210: if ($role eq 'st') {
1.202 raeburn 3211: my $result =
1.198 raeburn 3212: &Apache::lonuserutils::classlist_drop($scope,
3213: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 3214: $now);
1.170 albertel 3215: $r->print($result);
1.53 www 3216: }
1.225 raeburn 3217: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3218: push(@rolechanges,$role);
3219: }
1.196 raeburn 3220: }
1.195 raeburn 3221: if ($key=~m{^form\.rev\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}s) {
1.64 www 3222: # Revoke custom role
1.113 raeburn 3223: $r->print(&mt('Revoking custom role:').
1.139 albertel 3224: ' '.$4.' by '.$3.':'.$2.' in '.$1.': <b>'.
1.101 albertel 3225: &Apache::lonnet::revokecustomrole($env{'form.ccdomain'},
1.239 raeburn 3226: $env{'form.ccuname'},$1,$2,$3,$4,'','',$context).
1.102 albertel 3227: '</b><br />');
1.225 raeburn 3228: if (!grep(/^cr$/,@rolechanges)) {
3229: push(@rolechanges,'cr');
3230: }
1.64 www 3231: }
1.135 raeburn 3232: } elsif ($key=~/^form\.del/) {
3233: if ($key=~/^form\.del\:([^\_]+)\_([^\_\.]+)$/) {
1.116 raeburn 3234: # Delete standard role
1.170 albertel 3235: my ($scope,$role) = ($1,$2);
3236: my $result =
3237: &Apache::lonnet::assignrole($env{'form.ccdomain'},
3238: $env{'form.ccuname'},
1.239 raeburn 3239: $scope,$role,$now,0,1,'',
3240: $context);
1.170 albertel 3241: $r->print(&mt('Deleting [_1] in [_2]: [_3]',$role,$scope,
3242: '<b>'.$result.'</b>').'<br />');
3243: if ($role eq 'st') {
1.202 raeburn 3244: my $result =
1.198 raeburn 3245: &Apache::lonuserutils::classlist_drop($scope,
3246: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 3247: $now);
1.170 albertel 3248: $r->print($result);
1.81 albertel 3249: }
1.225 raeburn 3250: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3251: push(@rolechanges,$role);
3252: }
1.116 raeburn 3253: }
1.139 albertel 3254: if ($key=~m{^form\.del\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 3255: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
3256: # Delete custom role
1.294 bisitz 3257: $r->print(&mt('Deleting custom role [_1] by [_2] in [_3]',
3258: $rolename,$rnam.':'.$rdom,$url).': <b>'.
1.116 raeburn 3259: &Apache::lonnet::assigncustomrole($env{'form.ccdomain'},
3260: $env{'form.ccuname'},$url,$rdom,$rnam,$rolename,$now,
1.240 raeburn 3261: 0,1,$context).'</b><br />');
1.225 raeburn 3262: if (!grep(/^cr$/,@rolechanges)) {
3263: push(@rolechanges,'cr');
3264: }
1.116 raeburn 3265: }
1.135 raeburn 3266: } elsif ($key=~/^form\.ren/) {
1.101 albertel 3267: my $udom = $env{'form.ccdomain'};
3268: my $uname = $env{'form.ccuname'};
1.116 raeburn 3269: # Re-enable standard role
1.135 raeburn 3270: if ($key=~/^form\.ren\:([^\_]+)\_([^\_\.]+)$/) {
1.89 raeburn 3271: my $url = $1;
3272: my $role = $2;
3273: my $logmsg;
3274: my $output;
3275: if ($role eq 'st') {
1.141 albertel 3276: if ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
1.129 albertel 3277: my $result = &Apache::loncommon::commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$1,$2,$3);
1.220 raeburn 3278: if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course') || ($result eq 'refused')) {
1.223 raeburn 3279: if ($result eq 'refused' && $logmsg) {
3280: $output = $logmsg;
3281: } else {
3282: $output = "Error: $result\n";
3283: }
1.89 raeburn 3284: } else {
3285: $output = &mt('Assigning').' '.$role.' in '.$url.
3286: &mt('starting').' '.localtime($now).
3287: ': <br />'.$logmsg.'<br />'.
3288: &mt('Add to classlist').': <b>ok</b><br />';
3289: }
3290: }
3291: } else {
1.101 albertel 3292: my $result=&Apache::lonnet::assignrole($env{'form.ccdomain'},
1.239 raeburn 3293: $env{'form.ccuname'},$url,$role,0,$now,'','',
3294: $context);
1.266 bisitz 3295: $output = &mt('Re-enabling [_1] in [_2]: [_3]',
3296: $role,$url,'<b>'.$result.'</b>').'<br />';
1.27 matthew 3297: }
1.89 raeburn 3298: $r->print($output);
1.225 raeburn 3299: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3300: push(@rolechanges,$role);
3301: }
1.113 raeburn 3302: }
1.116 raeburn 3303: # Re-enable custom role
1.139 albertel 3304: if ($key=~m{^form\.ren\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 3305: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
3306: my $result = &Apache::lonnet::assigncustomrole(
3307: $env{'form.ccdomain'}, $env{'form.ccuname'},
1.240 raeburn 3308: $url,$rdom,$rnam,$rolename,0,$now,undef,$context);
1.294 bisitz 3309: $r->print(&mt('Re-enabling custom role [_1] by [_2] in [_3]: [_4]',
3310: $rolename,$rnam.':'.$rdom,$url,'<b>'.$result.'</b>').'<br />');
1.225 raeburn 3311: if (!grep(/^cr$/,@rolechanges)) {
3312: push(@rolechanges,'cr');
3313: }
1.116 raeburn 3314: }
1.135 raeburn 3315: } elsif ($key=~/^form\.act/) {
1.101 albertel 3316: my $udom = $env{'form.ccdomain'};
3317: my $uname = $env{'form.ccuname'};
1.141 albertel 3318: if ($key=~/^form\.act\_($match_domain)\_($match_courseid)\_cr_cr_($match_domain)_($match_username)_([^\_]+)$/) {
1.65 www 3319: # Activate a custom role
1.83 albertel 3320: my ($one,$two,$three,$four,$five)=($1,$2,$3,$4,$5);
3321: my $url='/'.$one.'/'.$two;
3322: my $full=$one.'_'.$two.'_cr_cr_'.$three.'_'.$four.'_'.$five;
1.65 www 3323:
1.101 albertel 3324: my $start = ( $env{'form.start_'.$full} ?
3325: $env{'form.start_'.$full} :
1.88 raeburn 3326: $now );
1.101 albertel 3327: my $end = ( $env{'form.end_'.$full} ?
3328: $env{'form.end_'.$full} :
1.88 raeburn 3329: 0 );
3330:
3331: # split multiple sections
3332: my %sections = ();
1.101 albertel 3333: my $num_sections = &build_roles($env{'form.sec_'.$full},\%sections,$5);
1.88 raeburn 3334: if ($num_sections == 0) {
1.240 raeburn 3335: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end,$context));
1.88 raeburn 3336: } else {
1.114 albertel 3337: my %curr_groups =
1.117 raeburn 3338: &Apache::longroup::coursegroups($one,$two);
1.113 raeburn 3339: foreach my $sec (sort {$a cmp $b} keys %sections) {
3340: if (($sec eq 'none') || ($sec eq 'all') ||
3341: exists($curr_groups{$sec})) {
3342: $disallowed{$sec} = $url;
3343: next;
3344: }
3345: my $securl = $url.'/'.$sec;
1.240 raeburn 3346: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end,$context));
1.88 raeburn 3347: }
3348: }
1.225 raeburn 3349: if (!grep(/^cr$/,@rolechanges)) {
3350: push(@rolechanges,'cr');
3351: }
1.142 raeburn 3352: } elsif ($key=~/^form\.act\_($match_domain)\_($match_name)\_([^\_]+)$/) {
1.27 matthew 3353: # Activate roles for sections with 3 id numbers
3354: # set start, end times, and the url for the class
1.83 albertel 3355: my ($one,$two,$three)=($1,$2,$3);
1.101 albertel 3356: my $start = ( $env{'form.start_'.$one.'_'.$two.'_'.$three} ?
3357: $env{'form.start_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 3358: $now );
1.101 albertel 3359: my $end = ( $env{'form.end_'.$one.'_'.$two.'_'.$three} ?
3360: $env{'form.end_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 3361: 0 );
1.83 albertel 3362: my $url='/'.$one.'/'.$two;
1.88 raeburn 3363: my $type = 'three';
3364: # split multiple sections
3365: my %sections = ();
1.101 albertel 3366: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections,$three);
1.88 raeburn 3367: if ($num_sections == 0) {
1.240 raeburn 3368: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context));
1.88 raeburn 3369: } else {
1.114 albertel 3370: my %curr_groups =
1.117 raeburn 3371: &Apache::longroup::coursegroups($one,$two);
1.88 raeburn 3372: my $emptysec = 0;
3373: foreach my $sec (sort {$a cmp $b} keys %sections) {
3374: $sec =~ s/\W//g;
1.113 raeburn 3375: if ($sec ne '') {
3376: if (($sec eq 'none') || ($sec eq 'all') ||
3377: exists($curr_groups{$sec})) {
3378: $disallowed{$sec} = $url;
3379: next;
3380: }
1.88 raeburn 3381: my $securl = $url.'/'.$sec;
1.240 raeburn 3382: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec,$context));
1.88 raeburn 3383: } else {
3384: $emptysec = 1;
3385: }
3386: }
3387: if ($emptysec) {
1.240 raeburn 3388: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context));
1.88 raeburn 3389: }
1.225 raeburn 3390: }
3391: if (!grep(/^\Q$three\E$/,@rolechanges)) {
3392: push(@rolechanges,$three);
3393: }
1.135 raeburn 3394: } elsif ($key=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
1.27 matthew 3395: # Activate roles for sections with two id numbers
3396: # set start, end times, and the url for the class
1.101 albertel 3397: my $start = ( $env{'form.start_'.$1.'_'.$2} ?
3398: $env{'form.start_'.$1.'_'.$2} :
1.27 matthew 3399: $now );
1.101 albertel 3400: my $end = ( $env{'form.end_'.$1.'_'.$2} ?
3401: $env{'form.end_'.$1.'_'.$2} :
1.27 matthew 3402: 0 );
1.225 raeburn 3403: my $one = $1;
3404: my $two = $2;
3405: my $url='/'.$one.'/';
1.88 raeburn 3406: # split multiple sections
3407: my %sections = ();
1.225 raeburn 3408: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two},\%sections,$two);
1.88 raeburn 3409: if ($num_sections == 0) {
1.240 raeburn 3410: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 3411: } else {
3412: my $emptysec = 0;
3413: foreach my $sec (sort {$a cmp $b} keys %sections) {
3414: if ($sec ne '') {
3415: my $securl = $url.'/'.$sec;
1.240 raeburn 3416: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$two,$start,$end,$one,undef,$sec,$context));
1.88 raeburn 3417: } else {
3418: $emptysec = 1;
3419: }
3420: }
3421: if ($emptysec) {
1.240 raeburn 3422: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 3423: }
3424: }
1.225 raeburn 3425: if (!grep(/^\Q$two\E$/,@rolechanges)) {
3426: push(@rolechanges,$two);
3427: }
1.64 www 3428: } else {
1.190 raeburn 3429: $r->print('<p><span class="LC_error">'.&mt('ERROR').': '.&mt('Unknown command').' <tt>'.$key.'</tt></span></p><br />');
1.64 www 3430: }
1.113 raeburn 3431: foreach my $key (sort(keys(%disallowed))) {
1.274 bisitz 3432: $r->print('<p class="LC_warning">');
1.113 raeburn 3433: if (($key eq 'none') || ($key eq 'all')) {
1.274 bisitz 3434: $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 3435: } else {
1.274 bisitz 3436: $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 3437: }
1.274 bisitz 3438: $r->print('</p><p>'
3439: .&mt('Please [_1]go back[_2] and choose a different section name.'
3440: ,'<a href="javascript:history.go(-1)'
3441: ,'</a>')
3442: .'</p><br />'
3443: );
1.113 raeburn 3444: }
3445: }
1.101 albertel 3446: } # End of foreach (keys(%env))
1.75 www 3447: # Flush the course logs so reverse user roles immediately updated
3448: &Apache::lonnet::flushcourselogs();
1.225 raeburn 3449: if (@rolechanges == 0) {
1.193 raeburn 3450: $r->print(&mt('No roles to modify'));
3451: }
1.225 raeburn 3452: return @rolechanges;
1.220 raeburn 3453: }
3454:
3455: sub enroll_single_student {
1.295.2.18 raeburn 3456: my ($r,$uhome,$amode,$genpwd,$now,$newuser,$context,$crstype) = @_;
3457: $r->print('<h3>');
3458: if ($crstype eq 'Community') {
3459: $r->print(&mt('Enrolling Member'));
3460: } else {
3461: $r->print(&mt('Enrolling Student'));
3462: }
3463: $r->print('</h3>');
1.220 raeburn 3464:
3465: # Remove non alphanumeric values from section
3466: $env{'form.sections'}=~s/\W//g;
3467:
3468: # Clean out any old student roles the user has in this class.
3469: &Apache::lonuserutils::modifystudent($env{'form.ccdomain'},
3470: $env{'form.ccuname'},$env{'request.course.id'},undef,$uhome);
3471: my ($startdate,$enddate) = &Apache::lonuserutils::get_dates_from_form();
3472: my $enroll_result =
3473: &Apache::lonnet::modify_student_enrollment($env{'form.ccdomain'},
3474: $env{'form.ccuname'},$env{'form.cid'},$env{'form.cfirstname'},
3475: $env{'form.cmiddlename'},$env{'form.clastname'},
3476: $env{'form.generation'},$env{'form.sections'},$enddate,
1.239 raeburn 3477: $startdate,'manual',undef,$env{'request.course.id'},'',$context);
1.220 raeburn 3478: if ($enroll_result =~ /^ok/) {
3479: $r->print(&mt('<b>[_1]</b> enrolled',$env{'form.ccuname'}.':'.$env{'form.ccdomain'}));
3480: if ($env{'form.sections'} ne '') {
3481: $r->print(' '.&mt('in section [_1]',$env{'form.sections'}));
3482: }
3483: my ($showstart,$showend);
3484: if ($startdate <= $now) {
3485: $showstart = &mt('Access starts immediately');
3486: } else {
3487: $showstart = &mt('Access starts: ').&Apache::lonlocal::locallocaltime($startdate);
3488: }
3489: if ($enddate == 0) {
3490: $showend = &mt('ends: no ending date');
3491: } else {
3492: $showend = &mt('ends: ').&Apache::lonlocal::locallocaltime($enddate);
3493: }
3494: $r->print('.<br />'.$showstart.'; '.$showend);
3495: if ($startdate <= $now && !$newuser) {
1.295.2.18 raeburn 3496: $r->print('<p> ');
3497: if ($crstype eq 'Community') {
3498: $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.'));
3499: } else {
3500: $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.'));
3501: }
3502: $r->print('</p>');
1.220 raeburn 3503: }
3504: } else {
3505: $r->print(&mt('unable to enroll').": ".$enroll_result);
3506: }
3507: return;
1.188 raeburn 3508: }
3509:
1.204 raeburn 3510: sub get_defaultquota_text {
3511: my ($settingstatus) = @_;
3512: my $defquotatext;
3513: if ($settingstatus eq '') {
3514: $defquotatext = &mt('(default)');
3515: } else {
3516: my ($usertypes,$order) =
3517: &Apache::lonnet::retrieve_inst_usertypes($env{'form.ccdomain'});
3518: if ($usertypes->{$settingstatus} eq '') {
3519: $defquotatext = &mt('(default)');
3520: } else {
3521: $defquotatext = &mt('(default for [_1])',$usertypes->{$settingstatus});
3522: }
3523: }
3524: return $defquotatext;
3525: }
3526:
1.188 raeburn 3527: sub update_result_form {
3528: my ($uhome) = @_;
3529: my $outcome =
3530: '<form name="userupdate" method="post" />'."\n";
1.160 raeburn 3531: foreach my $item ('srchby','srchin','srchtype','srchterm','srchdomain','ccuname','ccdomain') {
1.188 raeburn 3532: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 3533: }
1.207 raeburn 3534: if ($env{'form.origname'} ne '') {
3535: $outcome .= '<input type="hidden" name="origname" value="'.$env{'form.origname'}.'" />'."\n";
3536: }
1.160 raeburn 3537: foreach my $item ('sortby','seluname','seludom') {
3538: if (exists($env{'form.'.$item})) {
1.188 raeburn 3539: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 3540: }
3541: }
1.188 raeburn 3542: if ($uhome eq 'no_host') {
3543: $outcome .= '<input type="hidden" name="forcenewuser" value="1" />'."\n";
3544: }
3545: $outcome .= '<input type="hidden" name="phase" value="" />'."\n".
3546: '<input type ="hidden" name="currstate" value="" />'."\n".
1.220 raeburn 3547: '<input type ="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
1.188 raeburn 3548: '</form>';
3549: return $outcome;
1.4 www 3550: }
3551:
1.149 raeburn 3552: sub quota_admin {
3553: my ($setquota,$changeHash) = @_;
3554: my $quotachanged;
3555: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
3556: # Current user has quota modification privileges
1.267 raeburn 3557: if (ref($changeHash) eq 'HASH') {
3558: $quotachanged = 1;
3559: $changeHash->{'portfolioquota'} = $setquota;
3560: }
1.149 raeburn 3561: }
3562: return $quotachanged;
3563: }
3564:
1.267 raeburn 3565: sub tool_admin {
1.275 raeburn 3566: my ($tool,$settool,$changeHash,$context) = @_;
3567: my $canchange = 0;
1.279 raeburn 3568: if ($context eq 'requestcourses') {
1.275 raeburn 3569: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
3570: $canchange = 1;
3571: }
1.295.2.3 raeburn 3572: } elsif ($context eq 'reqcrsotherdom') {
3573: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
3574: $canchange = 1;
3575: }
1.275 raeburn 3576: } elsif (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
3577: # Current user has quota modification privileges
3578: $canchange = 1;
3579: }
1.267 raeburn 3580: my $toolchanged;
1.275 raeburn 3581: if ($canchange) {
1.267 raeburn 3582: if (ref($changeHash) eq 'HASH') {
3583: $toolchanged = 1;
1.275 raeburn 3584: $changeHash->{$context.'.'.$tool} = $settool;
1.267 raeburn 3585: }
3586: }
3587: return $toolchanged;
3588: }
3589:
1.88 raeburn 3590: sub build_roles {
1.89 raeburn 3591: my ($sectionstr,$sections,$role) = @_;
1.88 raeburn 3592: my $num_sections = 0;
3593: if ($sectionstr=~ /,/) {
3594: my @secnums = split/,/,$sectionstr;
1.89 raeburn 3595: if ($role eq 'st') {
3596: $secnums[0] =~ s/\W//g;
3597: $$sections{$secnums[0]} = 1;
3598: $num_sections = 1;
3599: } else {
3600: foreach my $sec (@secnums) {
3601: $sec =~ ~s/\W//g;
1.150 banghart 3602: if (!($sec eq "")) {
1.89 raeburn 3603: if (exists($$sections{$sec})) {
3604: $$sections{$sec} ++;
3605: } else {
3606: $$sections{$sec} = 1;
3607: $num_sections ++;
3608: }
1.88 raeburn 3609: }
3610: }
3611: }
3612: } else {
3613: $sectionstr=~s/\W//g;
3614: unless ($sectionstr eq '') {
3615: $$sections{$sectionstr} = 1;
3616: $num_sections ++;
3617: }
3618: }
1.129 albertel 3619:
1.88 raeburn 3620: return $num_sections;
3621: }
3622:
1.58 www 3623: # ========================================================== Custom Role Editor
3624:
3625: sub custom_role_editor {
1.160 raeburn 3626: my ($r) = @_;
1.295.2.24 raeburn 3627: my $action = $env{'form.customroleaction'};
3628: my $rolename;
3629: if ($action eq 'new') {
3630: $rolename=$env{'form.newrolename'};
3631: } else {
3632: $rolename=$env{'form.rolename'};
1.59 www 3633: }
3634:
1.63 www 3635: $rolename=~s/[^A-Za-z0-9]//gs;
1.190 raeburn 3636: if (!$rolename || $env{'form.phase'} eq 'pickrole') {
1.58 www 3637: &print_username_entry_form($r);
3638: return;
3639: }
1.295.2.24 raeburn 3640: my ($crstype,$context);
3641: if ($env{'request.course.id'}) {
3642: $crstype = &Apache::loncommon::course_type();
3643: $context = 'course';
3644: } else {
3645: $context = 'domain';
3646: $crstype = $env{'form.templatecrstype'};
3647: }
1.153 banghart 3648: # ------------------------------------------------------- What can be assigned?
3649: my %full=();
3650: my %courselevel=();
3651: my %courselevelcurrent=();
1.61 www 3652: my $syspriv='';
3653: my $dompriv='';
3654: my $coursepriv='';
1.153 banghart 3655: my $body_top;
1.59 www 3656: my ($rdummy,$roledef)=
3657: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
1.60 www 3658: # ------------------------------------------------------- Does this role exist?
1.153 banghart 3659: $body_top .= '<h2>';
1.59 www 3660: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.153 banghart 3661: $body_top .= &mt('Existing Role').' "';
1.61 www 3662: # ------------------------------------------------- Get current role privileges
3663: ($syspriv,$dompriv,$coursepriv)=split(/\_/,$roledef);
1.295.2.24 raeburn 3664: if ($crstype eq 'Community') {
3665: $syspriv =~ s/bre\&S//;
3666: }
1.59 www 3667: } else {
1.153 banghart 3668: $body_top .= &mt('New Role').' "';
1.59 www 3669: $roledef='';
3670: }
1.153 banghart 3671: $body_top .= $rolename.'"</h2>';
1.135 raeburn 3672: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
3673: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 3674: if (!$restrict) { $restrict='F'; }
1.60 www 3675: $courselevel{$priv}=$restrict;
1.61 www 3676: if ($coursepriv=~/\:$priv/) {
3677: $courselevelcurrent{$priv}=1;
3678: }
1.60 www 3679: $full{$priv}=1;
3680: }
3681: my %domainlevel=();
1.61 www 3682: my %domainlevelcurrent=();
1.135 raeburn 3683: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
3684: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 3685: if (!$restrict) { $restrict='F'; }
1.60 www 3686: $domainlevel{$priv}=$restrict;
1.61 www 3687: if ($dompriv=~/\:$priv/) {
3688: $domainlevelcurrent{$priv}=1;
3689: }
1.60 www 3690: $full{$priv}=1;
3691: }
1.61 www 3692: my %systemlevel=();
3693: my %systemlevelcurrent=();
1.135 raeburn 3694: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
3695: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 3696: if (!$restrict) { $restrict='F'; }
1.61 www 3697: $systemlevel{$priv}=$restrict;
3698: if ($syspriv=~/\:$priv/) {
3699: $systemlevelcurrent{$priv}=1;
3700: }
3701: $full{$priv}=1;
3702: }
1.160 raeburn 3703: my ($jsback,$elements) = &crumb_utilities();
1.154 banghart 3704: my $button_code = "\n";
1.153 banghart 3705: my $head_script = "\n";
1.295.2.4 raeburn 3706: $head_script .= '<script type="text/javascript">'."\n".
3707: '// <![CDATA['."\n";
1.295.2.24 raeburn 3708: my @template_roles = ("in","ta","ep");
3709: if ($context eq 'domain') {
3710: push(@template_roles,"ad");
1.295.2.18 raeburn 3711: }
1.295.2.24 raeburn 3712: push(@template_roles,"st");
1.295.2.18 raeburn 3713: if ($crstype eq 'Community') {
3714: unshift(@template_roles,'co');
3715: } else {
3716: unshift(@template_roles,'cc');
3717: }
1.154 banghart 3718: foreach my $role (@template_roles) {
1.295.2.24 raeburn 3719: $head_script .= &make_script_template($role,$crstype);
1.295.2.18 raeburn 3720: $button_code .= &make_button_code($role,$crstype).' ';
1.154 banghart 3721: }
1.295.2.24 raeburn 3722: my $context_code;
3723: if ($context eq 'domain') {
3724: my $checkedCommunity = '';
3725: my $checkedCourse = ' checked="checked"';
3726: if ($env{'form.templatecrstype'} eq 'Community') {
3727: $checkedCommunity = $checkedCourse;
3728: $checkedCourse = '';
3729: }
3730: $context_code = '<label>'.
3731: '<input type="radio" name="templatecrstype" value="Course"'.$checkedCourse.' onclick="this.form.submit();">'.
3732: &mt('Course').
3733: '</label>'.(' ' x2).
3734: '<label>'.
3735: '<input type="radio" name="templatecrstype" value="Community"'.$checkedCommunity.' onclick="this.form.submit();">'.
3736: &mt('Community').
3737: '</label>'.
3738: '</fieldset>'.
3739: '<input type="hidden" name="customroleaction" value="'.
3740: $action.'" />';
3741: if ($env{'form.customroleaction'} eq 'new') {
3742: $context_code .= '<input type="hidden" name="newrolename" value="'.
3743: $rolename.'" />';
3744: } else {
3745: $context_code .= '<input type="hidden" name="rolename" value="'.
3746: $rolename.'" />';
3747: }
3748: $context_code .= '<input type="hidden" name="action" value="custom" />'.
3749: '<input type="hidden" name="phase" value="selected_custom_edit" />';
3750: }
1.295.2.4 raeburn 3751: $head_script .= "\n".$jsback."\n".
3752: '// ]]>'."\n".
3753: '</script>'."\n";
1.153 banghart 3754: $r->print(&Apache::loncommon::start_page('Custom Role Editor',$head_script));
1.295.2.24 raeburn 3755: &Apache::lonhtmlcommon::add_breadcrumb
1.190 raeburn 3756: ({href=>"javascript:backPage(document.form1,'pickrole','')",
3757: text=>"Pick custom role",
1.160 raeburn 3758: faq=>282,bug=>'Instructor Interface',},
3759: {href=>"javascript:backPage(document.form1,'','')",
3760: text=>"Edit custom role",
3761: faq=>282,bug=>'Instructor Interface',});
1.224 raeburn 3762: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management',
3763: 'Course_Editing_Custom_Roles'));
1.160 raeburn 3764:
1.153 banghart 3765: $r->print($body_top);
1.73 sakharuk 3766: my %lt=&Apache::lonlocal::texthash(
3767: 'prv' => "Privilege",
1.131 raeburn 3768: 'crl' => "Course Level",
1.73 sakharuk 3769: 'dml' => "Domain Level",
1.150 banghart 3770: 'ssl' => "System Level");
1.264 bisitz 3771:
1.295.2.24 raeburn 3772: $r->print('<div class="LC_left_float">'
1.264 bisitz 3773: .'<form action=""><fieldset>'
3774: .'<legend>'.&mt('Select a Template').'</legend>'
3775: .$button_code
1.295.2.24 raeburn 3776: .'</fieldset></form></div>');
3777: if ($context_code) {
3778: $r->print('<div class="LC_left_float">'
3779: .'<form action="/adm/createuser" method="post"><fieldset>'
3780: .'<legend>'.&mt('Context').'</legend>'
3781: .$context_code
3782: .'</form>'
3783: .'</div>'
3784: );
3785: }
3786: $r->print('<br clear="all" />');
1.264 bisitz 3787:
1.61 www 3788: $r->print(<<ENDCCF);
1.160 raeburn 3789: <form name="form1" method="post">
1.61 www 3790: <input type="hidden" name="phase" value="set_custom_roles" />
3791: <input type="hidden" name="rolename" value="$rolename" />
3792: ENDCCF
1.135 raeburn 3793: $r->print(&Apache::loncommon::start_data_table().
3794: &Apache::loncommon::start_data_table_header_row().
3795: '<th>'.$lt{'prv'}.'</th><th>'.$lt{'crl'}.'</th><th>'.$lt{'dml'}.
3796: '</th><th>'.$lt{'ssl'}.'</th>'.
3797: &Apache::loncommon::end_data_table_header_row());
1.295.2.31 raeburn 3798: foreach my $priv (sort(keys(%full))) {
1.295.2.18 raeburn 3799: my $privtext = &Apache::lonnet::plaintext($priv,$crstype);
1.135 raeburn 3800: $r->print(&Apache::loncommon::start_data_table_row().
3801: '<td>'.$privtext.'</td><td>'.
1.288 bisitz 3802: ($courselevel{$priv}?'<input type="checkbox" name="'.$priv.'_c"'.
3803: ($courselevelcurrent{$priv}?' checked="checked"':'').' />':' ').
1.61 www 3804: '</td><td>'.
1.288 bisitz 3805: ($domainlevel{$priv}?'<input type="checkbox" name="'.$priv.'_d"'.
3806: ($domainlevelcurrent{$priv}?' checked="checked"':'').' />':' ').
1.295.2.24 raeburn 3807: '</td><td>');
3808: if ($priv eq 'bre' && $crstype eq 'Community') {
3809: $r->print(' ');
3810: } else {
3811: $r->print($systemlevel{$priv}?'<input type="checkbox" name="'.$priv.'_s"'.
3812: ($systemlevelcurrent{$priv}?' checked="checked"':'').' />':' ');
3813: }
3814: $r->print('</td>'.
3815: &Apache::loncommon::end_data_table_row());
1.60 www 3816: }
1.135 raeburn 3817: $r->print(&Apache::loncommon::end_data_table().
1.190 raeburn 3818: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
1.160 raeburn 3819: '<input type="hidden" name="startrolename" value="'.$env{'form.rolename'}.
1.179 raeburn 3820: '" />'."\n".'<input type="hidden" name="currstate" value="" />'."\n".
1.160 raeburn 3821: '<input type="reset" value="'.&mt("Reset").'" />'."\n".
1.282 schafran 3822: '<input type="submit" value="'.&mt('Save').'" /></form>'.
1.110 albertel 3823: &Apache::loncommon::end_page());
1.61 www 3824: }
1.153 banghart 3825: # --------------------------------------------------------
3826: sub make_script_template {
1.295.2.24 raeburn 3827: my ($role,$crstype) = @_;
1.153 banghart 3828: my %full_c=();
3829: my %full_d=();
3830: my %full_s=();
3831: my $return_script;
3832: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
3833: my ($priv,$restrict)=split(/\&/,$item);
3834: $full_c{$priv}=1;
3835: }
3836: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
3837: my ($priv,$restrict)=split(/\&/,$item);
3838: $full_d{$priv}=1;
3839: }
1.154 banghart 3840: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
1.295.2.24 raeburn 3841: next if (($crstype eq 'Community') && ($item eq 'bre&S'));
1.153 banghart 3842: my ($priv,$restrict)=split(/\&/,$item);
3843: $full_s{$priv}=1;
3844: }
3845: $return_script .= 'function set_'.$role.'() {'."\n";
3846: my @temp = split(/:/,$Apache::lonnet::pr{$role.':c'});
3847: my %role_c;
1.155 banghart 3848: foreach my $priv (@temp) {
1.153 banghart 3849: my ($priv_item, $dummy) = split(/\&/,$priv);
3850: $role_c{$priv_item} = 1;
3851: }
1.269 raeburn 3852: my %role_d;
3853: @temp = split(/:/,$Apache::lonnet::pr{$role.':d'});
3854: foreach my $priv(@temp) {
3855: my ($priv_item, $dummy) = split(/\&/,$priv);
3856: $role_d{$priv_item} = 1;
3857: }
3858: my %role_s;
3859: @temp = split(/:/,$Apache::lonnet::pr{$role.':s'});
3860: foreach my $priv(@temp) {
3861: my ($priv_item, $dummy) = split(/\&/,$priv);
3862: $role_s{$priv_item} = 1;
3863: }
1.153 banghart 3864: foreach my $priv_item (keys(%full_c)) {
3865: my ($priv, $dummy) = split(/\&/,$priv_item);
1.269 raeburn 3866: if ((exists($role_c{$priv})) || (exists($role_d{$priv})) ||
3867: (exists($role_s{$priv}))) {
1.153 banghart 3868: $return_script .= "document.form1.$priv"."_c.checked = true;\n";
3869: } else {
3870: $return_script .= "document.form1.$priv"."_c.checked = false;\n";
3871: }
3872: }
1.154 banghart 3873: foreach my $priv_item (keys(%full_d)) {
3874: my ($priv, $dummy) = split(/\&/,$priv_item);
1.269 raeburn 3875: if ((exists($role_d{$priv})) || (exists($role_s{$priv}))) {
1.154 banghart 3876: $return_script .= "document.form1.$priv"."_d.checked = true;\n";
3877: } else {
3878: $return_script .= "document.form1.$priv"."_d.checked = false;\n";
3879: }
3880: }
3881: foreach my $priv_item (keys(%full_s)) {
1.153 banghart 3882: my ($priv, $dummy) = split(/\&/,$priv_item);
1.154 banghart 3883: if (exists($role_s{$priv})) {
3884: $return_script .= "document.form1.$priv"."_s.checked = true;\n";
3885: } else {
3886: $return_script .= "document.form1.$priv"."_s.checked = false;\n";
3887: }
1.153 banghart 3888: }
3889: $return_script .= '}'."\n";
1.154 banghart 3890: return ($return_script);
3891: }
3892: # ----------------------------------------------------------
3893: sub make_button_code {
1.295.2.18 raeburn 3894: my ($role,$crstype) = @_;
3895: my $label = &Apache::lonnet::plaintext($role,$crstype);
1.295.2.4 raeburn 3896: my $button_code = '<input type="button" onclick="set_'.$role.'()" value="'.$label.'" />';
1.154 banghart 3897: return ($button_code);
1.153 banghart 3898: }
1.61 www 3899: # ---------------------------------------------------------- Call to definerole
3900: sub set_custom_role {
1.240 raeburn 3901: my ($r,$context) = @_;
1.101 albertel 3902: my $rolename=$env{'form.rolename'};
1.63 www 3903: $rolename=~s/[^A-Za-z0-9]//gs;
1.150 banghart 3904: if (!$rolename) {
1.190 raeburn 3905: &custom_role_editor($r);
1.61 www 3906: return;
3907: }
1.160 raeburn 3908: my ($jsback,$elements) = &crumb_utilities();
1.295.2.4 raeburn 3909: my $jscript = '<script type="text/javascript">'.
3910: '// <![CDATA['."\n".
3911: $jsback."\n".
3912: '// ]]>'."\n".
3913: '</script>';
1.160 raeburn 3914:
3915: $r->print(&Apache::loncommon::start_page('Save Custom Role'),$jscript);
3916: &Apache::lonhtmlcommon::add_breadcrumb
1.190 raeburn 3917: ({href=>"javascript:backPage(document.customresult,'pickrole','')",
3918: text=>"Pick custom role",
1.160 raeburn 3919: faq=>282,bug=>'Instructor Interface',},
3920: {href=>"javascript:backPage(document.customresult,'selected_custom_edit','')",
3921: text=>"Edit custom role",
3922: faq=>282,bug=>'Instructor Interface',},
3923: {href=>"javascript:backPage(document.customresult,'set_custom_roles','')",
3924: text=>"Result",
3925: faq=>282,bug=>'Instructor Interface',});
1.224 raeburn 3926: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management',
3927: 'Course_Editing_Custom_Roles'));
1.160 raeburn 3928:
1.61 www 3929: my ($rdummy,$roledef)=
1.110 albertel 3930: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
3931:
1.61 www 3932: # ------------------------------------------------------- Does this role exist?
1.188 raeburn 3933: $r->print('<h3>');
1.61 www 3934: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.73 sakharuk 3935: $r->print(&mt('Existing Role').' "');
1.61 www 3936: } else {
1.73 sakharuk 3937: $r->print(&mt('New Role').' "');
1.61 www 3938: $roledef='';
3939: }
1.188 raeburn 3940: $r->print($rolename.'"</h3>');
1.61 www 3941: # ------------------------------------------------------- What can be assigned?
3942: my $sysrole='';
3943: my $domrole='';
3944: my $courole='';
3945:
1.135 raeburn 3946: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
3947: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 3948: if (!$restrict) { $restrict=''; }
3949: if ($env{'form.'.$priv.'_c'}) {
1.135 raeburn 3950: $courole.=':'.$item;
1.61 www 3951: }
3952: }
3953:
1.135 raeburn 3954: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
3955: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 3956: if (!$restrict) { $restrict=''; }
3957: if ($env{'form.'.$priv.'_d'}) {
1.135 raeburn 3958: $domrole.=':'.$item;
1.61 www 3959: }
3960: }
3961:
1.135 raeburn 3962: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
3963: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 3964: if (!$restrict) { $restrict=''; }
3965: if ($env{'form.'.$priv.'_s'}) {
1.135 raeburn 3966: $sysrole.=':'.$item;
1.61 www 3967: }
3968: }
1.63 www 3969: $r->print('<br />Defining Role: '.
1.61 www 3970: &Apache::lonnet::definerole($rolename,$sysrole,$domrole,$courole));
1.101 albertel 3971: if ($env{'request.course.id'}) {
3972: my $url='/'.$env{'request.course.id'};
1.63 www 3973: $url=~s/\_/\//g;
1.73 sakharuk 3974: $r->print('<br />'.&mt('Assigning Role to Self').': '.
1.101 albertel 3975: &Apache::lonnet::assigncustomrole($env{'user.domain'},
3976: $env{'user.name'},
1.63 www 3977: $url,
1.101 albertel 3978: $env{'user.domain'},
3979: $env{'user.name'},
1.240 raeburn 3980: $rolename,undef,undef,undef,$context));
1.63 www 3981: }
1.190 raeburn 3982: $r->print('<p><a href="javascript:backPage(document.customresult,'."'pickrole'".')">'.&mt('Create or edit another custom role').'</a></p><form name="customresult" method="post">');
1.160 raeburn 3983: $r->print(&Apache::lonhtmlcommon::echo_form_input([]).'</form>');
1.110 albertel 3984: $r->print(&Apache::loncommon::end_page());
1.58 www 3985: }
3986:
1.2 www 3987: # ================================================================ Main Handler
3988: sub handler {
3989: my $r = shift;
3990: if ($r->header_only) {
1.68 www 3991: &Apache::loncommon::content_type($r,'text/html');
1.2 www 3992: $r->send_http_header;
3993: return OK;
3994: }
1.295.2.18 raeburn 3995: my ($context,$crstype);
1.190 raeburn 3996: if ($env{'request.course.id'}) {
3997: $context = 'course';
1.295.2.18 raeburn 3998: $crstype = &Apache::loncommon::course_type();
1.190 raeburn 3999: } elsif ($env{'request.role'} =~ /^au\./) {
1.206 raeburn 4000: $context = 'author';
1.190 raeburn 4001: } else {
4002: $context = 'domain';
4003: }
4004: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.233 raeburn 4005: ['action','state','callingform','roletype','showrole','bulkaction','popup','phase',
4006: 'username','domain','srchterm','srchdomain','srchin','srchby','srchtype']);
1.190 raeburn 4007: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.202 raeburn 4008: if ($env{'form.action'} ne 'dateselect') {
4009: &Apache::lonhtmlcommon::add_breadcrumb
4010: ({href=>"/adm/createuser",
1.289 droeschl 4011: text=>"User Management",
4012: 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'});
1.202 raeburn 4013: }
1.289 droeschl 4014: #SD Following files not added to help, because the corresponding .tex-files seem to
4015: #be missing: Course_Approve_Selfenroll,Course_User_Logs,
1.209 raeburn 4016: my ($permission,$allowed) =
1.295.2.18 raeburn 4017: &Apache::lonuserutils::get_permission($context,$crstype);
1.190 raeburn 4018: if (!$allowed) {
4019: $env{'user.error.msg'}=
4020: "/adm/createuser:cst:0:0:Cannot create/modify user data ".
4021: "or view user status.";
4022: return HTTP_NOT_ACCEPTABLE;
4023: }
4024:
4025: &Apache::loncommon::content_type($r,'text/html');
4026: $r->send_http_header;
4027:
4028: # Main switch on form.action and form.state, as appropriate
4029: if (! exists($env{'form.action'})) {
4030: $r->print(&header());
4031: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management'));
1.295.2.18 raeburn 4032: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 4033: $r->print(&Apache::loncommon::end_page());
4034: } elsif ($env{'form.action'} eq 'upload' && $permission->{'cusr'}) {
4035: $r->print(&header());
4036: &Apache::lonhtmlcommon::add_breadcrumb
4037: ({href=>'/adm/createuser?action=upload&state=',
4038: text=>"Upload Users List"});
4039: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Upload Users List',
1.224 raeburn 4040: 'Course_Create_Class_List'));
1.190 raeburn 4041: $r->print('<form name="studentform" method="post" '.
4042: 'enctype="multipart/form-data" '.
4043: ' action="/adm/createuser">'."\n");
4044: if (! exists($env{'form.state'})) {
4045: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4046: } elsif ($env{'form.state'} eq 'got_file') {
1.221 raeburn 4047: &Apache::lonuserutils::print_upload_manager_form($r,$context,
1.295.2.18 raeburn 4048: $permission,$crstype);
1.190 raeburn 4049: } elsif ($env{'form.state'} eq 'enrolling') {
4050: if ($env{'form.datatoken'}) {
1.221 raeburn 4051: &Apache::lonuserutils::upfile_drop_add($r,$context,$permission);
1.190 raeburn 4052: }
4053: } else {
4054: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4055: }
4056: $r->print('</form>'.&Apache::loncommon::end_page());
1.213 raeburn 4057: } elsif ((($env{'form.action'} eq 'singleuser') || ($env{'form.action'}
4058: eq 'singlestudent')) && ($permission->{'cusr'})) {
1.190 raeburn 4059: my $phase = $env{'form.phase'};
4060: my @search = ('srchterm','srchby','srchin','srchtype','srchdomain');
1.192 albertel 4061: &Apache::loncreateuser::restore_prev_selections();
4062: my $srch;
4063: foreach my $item (@search) {
4064: $srch->{$item} = $env{'form.'.$item};
4065: }
1.207 raeburn 4066: if (($phase eq 'get_user_info') || ($phase eq 'userpicked') ||
4067: ($phase eq 'createnewuser')) {
4068: if ($env{'form.phase'} eq 'createnewuser') {
4069: my $response;
4070: if ($env{'form.srchterm'} !~ /^$match_username$/) {
4071: my $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
1.221 raeburn 4072: $env{'form.phase'} = '';
1.295.2.18 raeburn 4073: &print_username_entry_form($r,$context,$response,$srch,undef,$crstype);
1.207 raeburn 4074: } else {
4075: my $ccuname =&LONCAPA::clean_username($srch->{'srchterm'});
4076: my $ccdomain=&LONCAPA::clean_domain($srch->{'srchdomain'});
4077: &print_user_modification_page($r,$ccuname,$ccdomain,
1.221 raeburn 4078: $srch,$response,$context,
1.295.2.18 raeburn 4079: $permission,$crstype);
1.207 raeburn 4080: }
4081: } elsif ($env{'form.phase'} eq 'get_user_info') {
1.190 raeburn 4082: my ($currstate,$response,$forcenewuser,$results) =
1.221 raeburn 4083: &user_search_result($context,$srch);
1.190 raeburn 4084: if ($env{'form.currstate'} eq 'modify') {
4085: $currstate = $env{'form.currstate'};
4086: }
4087: if ($currstate eq 'select') {
4088: &print_user_selection_page($r,$response,$srch,$results,
1.295.2.18 raeburn 4089: \@search,$context,undef,$crstype);
1.190 raeburn 4090: } elsif ($currstate eq 'modify') {
4091: my ($ccuname,$ccdomain);
4092: if (($srch->{'srchby'} eq 'uname') &&
4093: ($srch->{'srchtype'} eq 'exact')) {
4094: $ccuname = $srch->{'srchterm'};
4095: $ccdomain= $srch->{'srchdomain'};
4096: } else {
4097: my @matchedunames = keys(%{$results});
4098: ($ccuname,$ccdomain) = split(/:/,$matchedunames[0]);
4099: }
4100: $ccuname =&LONCAPA::clean_username($ccuname);
4101: $ccdomain=&LONCAPA::clean_domain($ccdomain);
4102: if ($env{'form.forcenewuser'}) {
4103: $response = '';
4104: }
4105: &print_user_modification_page($r,$ccuname,$ccdomain,
1.221 raeburn 4106: $srch,$response,$context,
1.295.2.18 raeburn 4107: $permission,$crstype);
1.190 raeburn 4108: } elsif ($currstate eq 'query') {
4109: &print_user_query_page($r,'createuser');
4110: } else {
1.229 raeburn 4111: $env{'form.phase'} = '';
1.207 raeburn 4112: &print_username_entry_form($r,$context,$response,$srch,
1.295.2.18 raeburn 4113: $forcenewuser,$crstype);
1.190 raeburn 4114: }
4115: } elsif ($env{'form.phase'} eq 'userpicked') {
4116: my $ccuname = &LONCAPA::clean_username($env{'form.seluname'});
4117: my $ccdomain = &LONCAPA::clean_domain($env{'form.seludom'});
1.196 raeburn 4118: &print_user_modification_page($r,$ccuname,$ccdomain,$srch,'',
1.295.2.18 raeburn 4119: $context,$permission,$crstype);
1.190 raeburn 4120: }
4121: } elsif ($env{'form.phase'} eq 'update_user_data') {
1.295.2.18 raeburn 4122: &update_user_data($r,$context,$crstype);
1.190 raeburn 4123: } else {
1.295.2.18 raeburn 4124: &print_username_entry_form($r,$context,undef,$srch,undef,$crstype);
1.190 raeburn 4125: }
4126: } elsif ($env{'form.action'} eq 'custom' && $permission->{'custom'}) {
4127: if ($env{'form.phase'} eq 'set_custom_roles') {
1.240 raeburn 4128: &set_custom_role($r,$context);
1.190 raeburn 4129: } else {
4130: &custom_role_editor($r);
4131: }
1.207 raeburn 4132: } elsif (($env{'form.action'} eq 'listusers') &&
4133: ($permission->{'view'} || $permission->{'cusr'})) {
1.202 raeburn 4134: if ($env{'form.phase'} eq 'bulkchange') {
4135: &Apache::lonhtmlcommon::add_breadcrumb
1.221 raeburn 4136: ({href=>'/adm/createuser?action=listusers',
4137: text=>"List Users"},
4138: {href=>"/adm/createuser",
4139: text=>"Result"});
1.202 raeburn 4140: my $setting = $env{'form.roletype'};
4141: my $choice = $env{'form.bulkaction'};
4142: $r->print(&header());
1.221 raeburn 4143: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Update Users",
1.224 raeburn 4144: 'Course_View_Class_List'));
1.202 raeburn 4145: if ($permission->{'cusr'}) {
1.295.2.31 raeburn 4146: &Apache::lonuserutils::update_user_list($r,$context,$setting,$choice,$crstype);
1.221 raeburn 4147: $r->print(&Apache::loncommon::end_page());
4148: } else {
4149: $r->print(&mt('You are not authorized to make bulk changes to user roles'));
1.223 raeburn 4150: $r->print('<p><a href="/adm/createuser?action=listusers">'.&mt('Display User Lists').'</a>');
1.221 raeburn 4151: $r->print(&Apache::loncommon::end_page());
1.202 raeburn 4152: }
4153: } else {
4154: &Apache::lonhtmlcommon::add_breadcrumb
4155: ({href=>'/adm/createuser?action=listusers',
4156: text=>"List Users"});
4157: my ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles);
4158: my $formname = 'studentform';
1.295.2.21 raeburn 4159: if (($context eq 'domain') && (($env{'form.roletype'} eq 'course') ||
4160: ($env{'form.roletype'} eq 'community'))) {
4161: if ($env{'form.roletype'} eq 'course') {
4162: ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles) =
4163: &Apache::lonuserutils::courses_selector($env{'request.role.domain'},
4164: $formname);
4165: } elsif ($env{'form.roletype'} eq 'community') {
4166: $cb_jscript =
4167: &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
4168: my %elements = (
4169: coursepick => 'radio',
4170: coursetotal => 'text',
4171: courselist => 'text',
4172: );
4173: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements);
4174: }
1.202 raeburn 4175: $jscript .= &verify_user_display();
4176: my $js = &add_script($jscript).$cb_jscript;
4177: my $loadcode =
4178: &Apache::lonuserutils::course_selector_loadcode($formname);
4179: if ($loadcode ne '') {
4180: $r->print(&header($js,{'onload' => $loadcode,}));
4181: } else {
4182: $r->print(&header($js));
4183: }
1.191 raeburn 4184: } else {
1.202 raeburn 4185: $r->print(&header(&add_script(&verify_user_display())));
1.191 raeburn 4186: }
1.202 raeburn 4187: $r->print(&Apache::lonhtmlcommon::breadcrumbs("List Users",
1.224 raeburn 4188: 'Course_View_Class_List'));
1.202 raeburn 4189: &Apache::lonuserutils::print_userlist($r,undef,$permission,$context,
4190: $formname,$totcodes,$codetitles,$idlist,$idlist_titles);
4191: $r->print(&Apache::loncommon::end_page());
1.191 raeburn 4192: }
1.213 raeburn 4193: } elsif ($env{'form.action'} eq 'drop' && $permission->{'cusr'}) {
4194: $r->print(&header());
1.295.2.18 raeburn 4195: my $brtext;
4196: if ($crstype eq 'Community') {
4197: $brtext = 'Drop Members';
4198: } else {
4199: $brtext = 'Drop Students';
4200: }
1.213 raeburn 4201: &Apache::lonhtmlcommon::add_breadcrumb
4202: ({href=>'/adm/createuser?action=drop',
1.295.2.19 raeburn 4203: text=>$brtext});
1.213 raeburn 4204: if (!exists($env{'form.state'})) {
1.295.2.31 raeburn 4205: $r->print(&Apache::lonhtmlcommon::breadcrumbs($brtext,
1.213 raeburn 4206: 'Course_Drop_Student'));
4207:
1.295.2.18 raeburn 4208: &Apache::lonuserutils::print_drop_menu($r,$context,$permission,$crstype);
1.213 raeburn 4209: } elsif ($env{'form.state'} eq 'done') {
4210: &Apache::lonhtmlcommon::add_breadcrumb
4211: ({href=>'/adm/createuser?action=drop',
4212: text=>"Result"});
1.295.2.18 raeburn 4213: $r->print(&Apache::lonhtmlcommon::breadcrumbs($brtext,
1.213 raeburn 4214: 'Course_Drop_Student'));
4215: &Apache::lonuserutils::update_user_list($r,$context,undef,
4216: $env{'form.action'});
4217: }
4218: $r->print(&Apache::loncommon::end_page());
1.202 raeburn 4219: } elsif ($env{'form.action'} eq 'dateselect') {
4220: if ($permission->{'cusr'}) {
4221: $r->print(&header(undef,undef,{'no_nav_bar' => 1}).
1.221 raeburn 4222: &Apache::lonuserutils::date_section_selector($context,
1.295.2.18 raeburn 4223: $permission,$crstype).
1.202 raeburn 4224: &Apache::loncommon::end_page());
4225: } else {
4226: $r->print(&header().
4227: '<span class="LC_error">'.&mt('You do not have permission to modify dates or sections for users').'</span>'.
4228: &Apache::loncommon::end_page());
4229: }
1.237 raeburn 4230: } elsif ($env{'form.action'} eq 'selfenroll') {
4231: $r->print(&header());
4232: &Apache::lonhtmlcommon::add_breadcrumb
4233: ({href=>'/adm/createuser?action=selfenroll',
4234: text=>"Configure Self-enrollment"});
4235: if (!exists($env{'form.state'})) {
4236: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Configure Self-enrollment',
4237: 'Course_Self_Enrollment'));
1.241 raeburn 4238: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
1.237 raeburn 4239: &print_selfenroll_menu($r,$context,$permission);
4240: } elsif ($env{'form.state'} eq 'done') {
4241: &Apache::lonhtmlcommon::add_breadcrumb
4242: ({href=>'/adm/createuser?action=selfenroll',
4243: text=>"Result"});
4244: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Self-enrollment result',
4245: 'Course_Self_Enrollment'));
1.241 raeburn 4246: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
4247: &update_selfenroll_config($r,$context,$permission);
1.237 raeburn 4248: }
4249: $r->print(&Apache::loncommon::end_page());
1.277 raeburn 4250: } elsif ($env{'form.action'} eq 'selfenrollqueue') {
4251: $r->print(&header());
4252: &Apache::lonhtmlcommon::add_breadcrumb
4253: ({href=>'/adm/createuser?action=selfenrollqueue',
4254: text=>"Enrollment requests"});
4255: my $cid = $env{'request.course.id'};
4256: my $cdom = $env{'course.'.$cid.'.domain'};
4257: my $cnum = $env{'course.'.$cid.'.num'};
1.295.2.7 raeburn 4258: my $coursedesc = $env{'course.'.$cid.'.description'};
1.277 raeburn 4259: if (!exists($env{'form.state'})) {
4260: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Enrollment requests',
4261: 'Course_SelfEnrollment_Approval'));
4262: $r->print('<h3>'.&mt('Pending enrollment requests').'</h3>'."\n");
1.295.2.7 raeburn 4263: $r->print(&Apache::loncoursequeueadmin::display_queued_requests($context,
4264: $cdom,$cnum));
4265:
1.277 raeburn 4266: } elsif ($env{'form.state'} eq 'done') {
4267: &Apache::lonhtmlcommon::add_breadcrumb
4268: ({href=>'/adm/createuser?action=selfenrollqueue',
4269: text=>"Result"});
4270: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Enrollment result',
4271: 'Course_Self_Enrollment'));
4272: $r->print('<h3>'.&mt('Enrollment request processing').'</h3>'."\n");
1.295.2.7 raeburn 4273: $r->print(&Apache::loncoursequeueadmin::update_request_queue($context,
4274: $cdom,$cnum,$coursedesc));
1.277 raeburn 4275: }
4276: $r->print(&Apache::loncommon::end_page());
1.239 raeburn 4277: } elsif ($env{'form.action'} eq 'changelogs') {
4278: $r->print(&header());
4279: &Apache::lonhtmlcommon::add_breadcrumb
4280: ({href=>'/adm/createuser?action=changelogs',
4281: text=>"User Management Logs"});
4282: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Changes',
4283: 'Course_User_Logs'));
4284: &print_userchangelogs_display($r,$context,$permission);
4285: $r->print(&Apache::loncommon::end_page());
1.190 raeburn 4286: } else {
4287: $r->print(&header());
1.202 raeburn 4288: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management'));
1.295.2.18 raeburn 4289: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 4290: $r->print(&Apache::loncommon::end_page());
4291: }
4292: return OK;
4293: }
4294:
4295: sub header {
1.202 raeburn 4296: my ($jscript,$loaditems,$args) = @_;
1.190 raeburn 4297: my $start_page;
4298: if (ref($loaditems) eq 'HASH') {
1.202 raeburn 4299: $start_page=&Apache::loncommon::start_page('User Management',$jscript,{'add_entries' => $loaditems});
1.190 raeburn 4300: } else {
1.202 raeburn 4301: $start_page=&Apache::loncommon::start_page('User Management',$jscript,$args);
1.190 raeburn 4302: }
4303: return $start_page;
4304: }
1.2 www 4305:
1.191 raeburn 4306: sub add_script {
4307: my ($js) = @_;
1.295.2.4 raeburn 4308: return '<script type="text/javascript">'."\n".
4309: '// <![CDATA['."\n".
4310: "\n".$js."\n".
1.295.2.8 raeburn 4311: '// ]]>'."\n".
1.295.2.4 raeburn 4312: '</script>'."\n";
1.191 raeburn 4313: }
4314:
1.202 raeburn 4315: sub verify_user_display {
4316: my $output = <<"END";
4317:
4318: function display_update() {
4319: document.studentform.action.value = 'listusers';
4320: document.studentform.phase.value = 'display';
4321: document.studentform.submit();
4322: }
4323:
4324: END
4325: return $output;
4326:
4327: }
4328:
1.190 raeburn 4329: ###############################################################
4330: ###############################################################
4331: # Menu Phase One
4332: sub print_main_menu {
1.295.2.18 raeburn 4333: my ($permission,$context,$crstype) = @_;
4334: my $linkcontext = $context;
4335: my $stuterm = lc(&Apache::lonnet::plaintext('st',$crstype));
4336: if (($context eq 'course') && ($crstype eq 'Community')) {
4337: $linkcontext = lc($crstype);
4338: $stuterm = 'Members';
4339: }
4340:
1.208 raeburn 4341: my %links = (
4342: domain => {
4343: upload => 'Upload a File of Users',
1.295.2.31 raeburn 4344: singleuser => 'Add/Modify a User',
4345: listusers => 'Manage Users',
1.208 raeburn 4346: },
4347: author => {
4348: upload => 'Upload a File of Co-authors',
1.295.2.31 raeburn 4349: singleuser => 'Add/Modify a Co-author',
4350: listusers => 'Manage Co-authors',
1.208 raeburn 4351: },
4352: course => {
1.295.2.1 raeburn 4353: upload => 'Upload a File of Course Users',
1.295.2.31 raeburn 4354: singleuser => 'Add/Modify a Course User',
1.295.2.1 raeburn 4355: listusers => 'Display Class Lists and Manage Multiple Users',
1.208 raeburn 4356: },
1.295.2.18 raeburn 4357: community => {
4358: upload => 'Upload a File of Community Users',
4359: singleuser => 'Add/Modify a Community User',
4360: listusers => 'Manage Community Users',
4361: },
1.295.2.1 raeburn 4362: );
4363: my @menu =
4364: (
4365: { text => $links{$context}{'upload'},
4366: help => 'Course_Create_Class_List',
4367: action => 'upload',
4368: permission => $permission->{'cusr'},
4369: },
4370: { text => $links{$context}{'singleuser'},
4371: help => 'Course_Change_Privileges',
4372: action => 'singleuser',
4373: permission => $permission->{'cusr'},
4374: },
4375: { text => $links{$context}{'listusers'},
4376: help => 'Course_View_Class_List',
4377: action => 'listusers',
4378: permission => ($permission->{'view'} || $permission->{'cusr'}),
4379: },
4380: );
4381: if ($context eq 'domain' || $context eq 'course') {
4382: my $customlink = { text => 'Edit Custom Roles',
4383: help => 'Course_Editing_Custom_Roles',
4384: action => 'custom',
4385: permission => $permission->{'custom'},
4386: };
4387: push(@menu,$customlink);
4388: }
4389: if ($context eq 'course') {
4390: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity();
4391: my @courselinks =
4392: (
4393: { text => 'Enroll a Single Student',
4394: help => 'Course_Add_Student',
4395: action => 'singlestudent',
4396: permission => $permission->{'cusr'},
4397: },
4398: { text => 'Drop Students',
4399: help => 'Course_Drop_Student',
4400: action => 'drop',
4401: permission => $permission->{'cusr'},
4402: });
4403: if (!exists($permission->{'cusr_section'})) {
1.295.2.20 raeburn 4404: if ($crstype ne 'Community') {
4405: push(@courselinks,
4406: { text => 'Automated Enrollment Manager',
4407: help => 'Course_Automated_Enrollment',
4408: permission => (&Apache::lonnet::auto_run($cnum,$cdom)
4409: && $permission->{'cusr'}),
4410: url => '/adm/populate',
4411: });
4412: }
4413: push(@courselinks,
4414: { text => 'Configure User Self-enrollment',
4415: help => 'Course_Self_Enrollment',
4416: action => 'selfenroll',
4417: permission => $permission->{'cusr'},
4418: });
1.295.2.1 raeburn 4419: }
1.295.2.2 raeburn 4420: if ($env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'}) {
4421: push(@courselinks,
4422: { text => 'Enrollment Requests',
4423: help => 'Course_Approve_Selfenroll',
4424: action => 'selfenrollqueue',
4425: permission => $permission->{'cusr'},
4426: });
4427: }
1.295.2.1 raeburn 4428: push(@courselinks,
4429: { text => 'Manage Course Groups',
4430: help => 'Course_Manage_Group',
4431: permission => $permission->{'grp_manage'},
4432: url => '/adm/coursegroups?refpage=cusr',
4433: },
4434: { text => 'View Change Logs',
4435: help => 'Course_User_Logs',
4436: action => 'changelogs',
4437: permission => $permission->{'cusr'},
4438: },);
1.250 raeburn 4439: # { text => 'View Log-in History',
4440: # help => 'Course_User_Logins',
4441: # action => 'logins',
4442: # permission => $permission->{'cusr'},
4443: # });
1.295.2.1 raeburn 4444: push(@menu,@courselinks);
4445: }
4446: my $menu_html = '';
4447: foreach my $menu_item (@menu) {
4448: next if (! $menu_item->{'permission'});
4449: $menu_html.='<p>';
4450: if (exists($menu_item->{'help'})) {
4451: $menu_html.=
4452: &Apache::loncommon::help_open_topic($menu_item->{'help'});
4453: }
4454: $menu_html.='<font size="+1">';
4455: if (exists($menu_item->{'url'})) {
4456: $menu_html.=qq{<a href="$menu_item->{'url'}">};
4457: } else {
4458: $menu_html.=
4459: qq{<a href="/adm/createuser?action=$menu_item->{'action'}">}; }
4460: $menu_html.= &mt($menu_item->{'text'}).'</a></font>';
4461: $menu_html.='</p>';
4462: }
4463: return $menu_html;
1.190 raeburn 4464: }
4465:
1.189 albertel 4466: sub restore_prev_selections {
4467: my %saveable_parameters = ('srchby' => 'scalar',
4468: 'srchin' => 'scalar',
4469: 'srchtype' => 'scalar',
4470: );
4471: &Apache::loncommon::store_settings('user','user_picker',
4472: \%saveable_parameters);
4473: &Apache::loncommon::restore_settings('user','user_picker',
4474: \%saveable_parameters);
4475: }
4476:
1.237 raeburn 4477: sub print_selfenroll_menu {
4478: my ($r,$context,$permission) = @_;
1.295.2.22 raeburn 4479: my $crstype = &Apache::loncommon::course_type();
1.237 raeburn 4480: my $formname = 'enrollstudent';
4481: my $nolink = 1;
4482: my ($row,$lt) = &get_selfenroll_titles();
4483: my $groupslist = &Apache::lonuserutils::get_groupslist();
4484: my $setsec_js =
4485: &Apache::lonuserutils::setsections_javascript($formname,$groupslist);
1.249 raeburn 4486: my %alerts = &Apache::lonlocal::texthash(
4487: acto => 'Activation of self-enrollment was selected for the following domain(s)',
4488: butn => 'but no user types have been checked.',
4489: wilf => "Please uncheck 'activate' or check at least one type.",
4490: );
4491: my $selfenroll_js = <<"ENDSCRIPT";
4492: function update_types(caller,num) {
4493: var delidx = getIndexByName('selfenroll_delete');
4494: var actidx = getIndexByName('selfenroll_activate');
4495: if (caller == 'selfenroll_all') {
4496: var selall;
4497: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
4498: if (document.$formname.selfenroll_all[i].checked) {
4499: selall = document.$formname.selfenroll_all[i].value;
4500: }
4501: }
4502: if (selall == 1) {
4503: if (delidx != -1) {
4504: if (document.$formname.selfenroll_delete.length) {
4505: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
4506: document.$formname.selfenroll_delete[j].checked = true;
4507: }
4508: } else {
4509: document.$formname.elements[delidx].checked = true;
4510: }
4511: }
4512: if (actidx != -1) {
4513: if (document.$formname.selfenroll_activate.length) {
4514: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
4515: document.$formname.selfenroll_activate[j].checked = false;
4516: }
4517: } else {
4518: document.$formname.elements[actidx].checked = false;
4519: }
4520: }
4521: document.$formname.selfenroll_newdom.selectedIndex = 0;
4522: }
4523: }
4524: if (caller == 'selfenroll_activate') {
4525: if (document.$formname.selfenroll_activate.length) {
4526: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
4527: if (document.$formname.selfenroll_activate[j].value == num) {
4528: if (document.$formname.selfenroll_activate[j].checked) {
4529: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
4530: if (document.$formname.selfenroll_all[i].value == '1') {
4531: document.$formname.selfenroll_all[i].checked = false;
4532: }
4533: if (document.$formname.selfenroll_all[i].value == '0') {
4534: document.$formname.selfenroll_all[i].checked = true;
4535: }
4536: }
4537: }
4538: }
4539: }
4540: } else {
4541: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
4542: if (document.$formname.selfenroll_all[i].value == '1') {
4543: document.$formname.selfenroll_all[i].checked = false;
4544: }
4545: if (document.$formname.selfenroll_all[i].value == '0') {
4546: document.$formname.selfenroll_all[i].checked = true;
4547: }
4548: }
4549: }
4550: }
4551: if (caller == 'selfenroll_delete') {
4552: if (document.$formname.selfenroll_delete.length) {
4553: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
4554: if (document.$formname.selfenroll_delete[j].value == num) {
4555: if (document.$formname.selfenroll_delete[j].checked) {
4556: var delindex = getIndexByName('selfenroll_types_'+num);
4557: if (delindex != -1) {
4558: if (document.$formname.elements[delindex].length) {
4559: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
4560: document.$formname.elements[delindex][k].checked = false;
4561: }
4562: } else {
4563: document.$formname.elements[delindex].checked = false;
4564: }
4565: }
4566: }
4567: }
4568: }
4569: } else {
4570: if (document.$formname.selfenroll_delete.checked) {
4571: var delindex = getIndexByName('selfenroll_types_'+num);
4572: if (delindex != -1) {
4573: if (document.$formname.elements[delindex].length) {
4574: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
4575: document.$formname.elements[delindex][k].checked = false;
4576: }
4577: } else {
4578: document.$formname.elements[delindex].checked = false;
4579: }
4580: }
4581: }
4582: }
4583: }
4584: return;
4585: }
4586:
4587: function validate_types(form) {
4588: var needaction = new Array();
4589: var countfail = 0;
4590: var actidx = getIndexByName('selfenroll_activate');
4591: if (actidx != -1) {
4592: if (document.$formname.selfenroll_activate.length) {
4593: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
4594: var num = document.$formname.selfenroll_activate[j].value;
4595: if (document.$formname.selfenroll_activate[j].checked) {
4596: countfail = check_types(num,countfail,needaction)
4597: }
4598: }
4599: } else {
4600: if (document.$formname.selfenroll_activate.checked) {
4601: var num = document.enrollstudent.selfenroll_activate.value;
4602: countfail = check_types(num,countfail,needaction)
4603: }
4604: }
4605: }
4606: if (countfail > 0) {
4607: var msg = "$alerts{'acto'}\\n";
4608: var loopend = needaction.length -1;
4609: if (loopend > 0) {
4610: for (var m=0; m<loopend; m++) {
4611: msg += needaction[m]+", ";
4612: }
4613: }
4614: msg += needaction[loopend]+"\\n$alerts{'butn'}\\n$alerts{'wilf'}";
4615: alert(msg);
4616: return;
4617: }
4618: setSections(form);
4619: }
4620:
4621: function check_types(num,countfail,needaction) {
4622: var typeidx = getIndexByName('selfenroll_types_'+num);
4623: var count = 0;
4624: if (typeidx != -1) {
4625: if (document.$formname.elements[typeidx].length) {
4626: for (var k=0; k<document.$formname.elements[typeidx].length; k++) {
4627: if (document.$formname.elements[typeidx][k].checked) {
4628: count ++;
4629: }
4630: }
4631: } else {
4632: if (document.$formname.elements[typeidx].checked) {
4633: count ++;
4634: }
4635: }
4636: if (count == 0) {
4637: var domidx = getIndexByName('selfenroll_dom_'+num);
4638: if (domidx != -1) {
4639: var domname = document.$formname.elements[domidx].value;
4640: needaction[countfail] = domname;
4641: countfail ++;
4642: }
4643: }
4644: }
4645: return countfail;
4646: }
4647:
4648: function getIndexByName(item) {
4649: for (var i=0;i<document.$formname.elements.length;i++) {
4650: if (document.$formname.elements[i].name == item) {
4651: return i;
4652: }
4653: }
4654: return -1;
4655: }
4656: ENDSCRIPT
1.256 raeburn 4657: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4658: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
4659:
1.237 raeburn 4660: my $output = '<script type="text/javascript">'."\n".
1.295.2.4 raeburn 4661: '// <![CDATA['."\n".
1.249 raeburn 4662: $setsec_js."\n".$selfenroll_js."\n".
1.295.2.4 raeburn 4663: '// ]]>'."\n".
1.237 raeburn 4664: '</script>'."\n".
1.256 raeburn 4665: '<h3>'.$lt->{'selfenroll'}.'</h3>'."\n";
4666: my ($visible,$cansetvis,$vismsgs,$visactions) = &visible_in_cat($cdom,$cnum);
4667: if (ref($visactions) eq 'HASH') {
4668: if ($visible) {
1.283 bisitz 4669: $output .= '<p class="LC_info">'.$visactions->{'vis'}.'</p>';
1.256 raeburn 4670: } else {
1.283 bisitz 4671: $output .= '<p class="LC_warning">'.$visactions->{'miss'}.'</p>'
4672: .$visactions->{'yous'}.
1.256 raeburn 4673: '<p>'.$visactions->{'gen'}.'<br />'.$visactions->{'coca'};
4674: if (ref($vismsgs) eq 'ARRAY') {
4675: $output .= '<br />'.$visactions->{'make'}.'<ul>';
4676: foreach my $item (@{$vismsgs}) {
4677: $output .= '<li>'.$visactions->{$item}.'</li>';
4678: }
4679: $output .= '</ul>';
4680: }
4681: $output .= '</p>';
4682: }
4683: }
4684: $output .= '<form name="'.$formname.'" method="post" action="/adm/createuser">'."\n".
4685: &Apache::lonhtmlcommon::start_pick_box();
1.237 raeburn 4686: if (ref($row) eq 'ARRAY') {
4687: foreach my $item (@{$row}) {
4688: my $title = $item;
4689: if (ref($lt) eq 'HASH') {
4690: $title = $lt->{$item};
4691: }
4692: $output .=
4693: &Apache::lonhtmlcommon::row_title($title,
4694: 'LC_selfenroll_pick_box_title','LC_oddrow_value')."\n";
4695: if ($item eq 'types') {
4696: my $curr_types = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_types'};
1.241 raeburn 4697: my $showdomdesc = 1;
4698: my $includeempty = 1;
4699: my $num = 0;
4700: $output .= &Apache::loncommon::start_data_table().
4701: &Apache::loncommon::start_data_table_row()
4702: .'<td colspan="2"><span class="LC_nobreak"><label>'
4703: .&mt('Any user in any domain:')
4704: .' <input type="radio" name="selfenroll_all" value="1" ';
4705: if ($curr_types eq '*') {
4706: $output .= ' checked="checked" ';
4707: }
1.249 raeburn 4708: $output .= 'onchange="javascript:update_types('.
4709: "'selfenroll_all'".');" />'.&mt('Yes').'</label>'.
4710: ' <input type="radio" name="selfenroll_all" value="0" ';
1.241 raeburn 4711: if ($curr_types ne '*') {
4712: $output .= ' checked="checked" ';
4713: }
1.249 raeburn 4714: $output .= ' onchange="javascript:update_types('.
4715: "'selfenroll_all'".');"/>'.&mt('No').'</label></td>'.
4716: &Apache::loncommon::end_data_table_row().
4717: &Apache::loncommon::end_data_table().
4718: &mt('Or').'<br />'.
4719: &Apache::loncommon::start_data_table();
1.241 raeburn 4720: my %currdoms;
1.249 raeburn 4721: if ($curr_types eq '') {
1.241 raeburn 4722: $output .= &new_selfenroll_dom_row($cdom,'0');
4723: } elsif ($curr_types ne '*') {
4724: my @entries = split(/;/,$curr_types);
4725: if (@entries > 0) {
4726: foreach my $entry (@entries) {
4727: my ($currdom,$typestr) = split(/:/,$entry);
4728: $currdoms{$currdom} = 1;
4729: my $domdesc = &Apache::lonnet::domain($currdom);
1.249 raeburn 4730: my @currinsttypes = split(',',$typestr);
1.241 raeburn 4731: $output .= &Apache::loncommon::start_data_table_row()
4732: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').'<b>'
4733: .' '.$domdesc.' ('.$currdom.')'
4734: .'</b><input type="hidden" name="selfenroll_dom_'.$num
4735: .'" value="'.$currdom.'" /></span><br />'
4736: .'<span class="LC_nobreak"><label><input type="checkbox" '
1.249 raeburn 4737: .'name="selfenroll_delete" value="'.$num.'" onchange="javascript:update_types('."'selfenroll_delete','$num'".');" />'
1.241 raeburn 4738: .&mt('Delete').'</label></span></td>';
1.249 raeburn 4739: $output .= '<td valign="top"> '.&mt('User types:').'<br />'
1.241 raeburn 4740: .&selfenroll_inst_types($num,$currdom,\@currinsttypes).'</td>'
4741: .&Apache::loncommon::end_data_table_row();
4742: $num ++;
4743: }
4744: }
4745: }
1.249 raeburn 4746: my $add_domtitle = &mt('Users in additional domain:');
1.241 raeburn 4747: if ($curr_types eq '*') {
1.249 raeburn 4748: $add_domtitle = &mt('Users in specific domain:');
1.241 raeburn 4749: } elsif ($curr_types eq '') {
1.249 raeburn 4750: $add_domtitle = &mt('Users in other domain:');
1.241 raeburn 4751: }
4752: $output .= &Apache::loncommon::start_data_table_row()
4753: .'<td colspan="2"><span class="LC_nobreak">'.$add_domtitle.'</span><br />'
4754: .&Apache::loncommon::select_dom_form('','selfenroll_newdom',
4755: $includeempty,$showdomdesc)
4756: .'<input type="hidden" name="selfenroll_types_total" value="'.$num.'" />'
4757: .'</td>'.&Apache::loncommon::end_data_table_row()
4758: .&Apache::loncommon::end_data_table();
1.237 raeburn 4759: } elsif ($item eq 'registered') {
4760: my ($regon,$regoff);
4761: if ($env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_registered'}) {
4762: $regon = ' checked="checked" ';
4763: $regoff = ' ';
4764: } else {
4765: $regon = ' ';
4766: $regoff = ' checked="checked" ';
4767: }
4768: $output .= '<label>'.
1.245 raeburn 4769: '<input type="radio" name="selfenroll_registered" value="1"'.$regon.'/>'.
1.244 bisitz 4770: &mt('Yes').'</label> <label>'.
1.245 raeburn 4771: '<input type="radio" name="selfenroll_registered" value="0"'.$regoff.'/>'.
1.244 bisitz 4772: &mt('No').'</label>';
1.237 raeburn 4773: } elsif ($item eq 'enroll_dates') {
4774: my $starttime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_start_date'};
4775: my $endtime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_end_date'};
4776: if ($starttime eq '') {
4777: $starttime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_start_date'};
4778: }
4779: if ($endtime eq '') {
4780: $endtime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_end_date'};
4781: }
4782: my $startform =
4783: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_date',$starttime,
4784: undef,undef,undef,undef,undef,undef,undef,$nolink);
4785: my $endform =
4786: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_date',$endtime,
4787: undef,undef,undef,undef,undef,undef,undef,$nolink);
4788: $output .= &selfenroll_date_forms($startform,$endform);
4789: } elsif ($item eq 'access_dates') {
4790: my $starttime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_start_access'};
4791: my $endtime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_end_access'};
4792: if ($starttime eq '') {
4793: $starttime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_start_date'};
4794: }
4795: if ($endtime eq '') {
4796: $endtime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_end_date'};
4797: }
4798: my $startform =
4799: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_access',$starttime,
4800: undef,undef,undef,undef,undef,undef,undef,$nolink);
4801: my $endform =
4802: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_access',$endtime,
4803: undef,undef,undef,undef,undef,undef,undef,$nolink);
4804: $output .= &selfenroll_date_forms($startform,$endform);
4805: } elsif ($item eq 'section') {
4806: my $currsec = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_section'};
4807: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
4808: my $newsecval;
4809: if ($currsec ne 'none' && $currsec ne '') {
4810: if (!defined($sections_count{$currsec})) {
4811: $newsecval = $currsec;
4812: }
4813: }
4814: my $sections_select =
4815: &Apache::lonuserutils::course_sections(\%sections_count,'st',$currsec);
4816: $output .= '<table class="LC_createuser">'."\n".
4817: '<tr class="LC_section_row">'."\n".
4818: '<td align="center">'.&mt('Existing sections')."\n".
4819: '<br />'.$sections_select.'</td><td align="center">'.
4820: &mt('New section').'<br />'."\n".
4821: '<input type="text" name="newsec" size="15" value="'.$newsecval.'" />'."\n".
4822: '<input type="hidden" name="sections" value="" />'."\n".
4823: '<input type="hidden" name="state" value="done" />'."\n".
4824: '</td></tr></table>'."\n";
1.276 raeburn 4825: } elsif ($item eq 'approval') {
4826: my ($appon,$appoff);
4827: my $cid = $env{'request.course.id'};
4828: my $currnotified = $env{'course.'.$cid.'.internal.selfenroll_notifylist'};
4829: if ($env{'course.'.$cid.'.internal.selfenroll_approval'}) {
4830: $appon = ' checked="checked" ';
4831: $appoff = ' ';
4832: } else {
4833: $appon = ' ';
4834: $appoff = ' checked="checked" ';
4835: }
4836: $output .= '<label>'.
4837: '<input type="radio" name="selfenroll_approval" value="1"'.$appon.'/>'.
4838: &mt('Yes').'</label> <label>'.
4839: '<input type="radio" name="selfenroll_approval" value="0"'.$appoff.'/>'.
4840: &mt('No').'</label>';
4841: my %advhash = &Apache::lonnet::get_course_adv_roles($cid,1);
4842: my (@ccs,%notified);
1.295.2.22 raeburn 4843: my $ccrole = 'cc';
4844: if ($crstype eq 'Community') {
4845: $ccrole = 'co';
4846: }
4847: if ($advhash{$ccrole}) {
4848: @ccs = split(/,/,$advhash{$ccrole});
1.276 raeburn 4849: }
4850: if ($currnotified) {
4851: foreach my $current (split(/,/,$currnotified)) {
4852: $notified{$current} = 1;
4853: if (!grep(/^\Q$current\E$/,@ccs)) {
4854: push(@ccs,$current);
4855: }
4856: }
4857: }
4858: if (@ccs) {
1.277 raeburn 4859: $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 4860: &Apache::loncommon::start_data_table_row();
4861: my $count = 0;
4862: my $numcols = 4;
4863: foreach my $cc (sort(@ccs)) {
4864: my $notifyon;
4865: my ($ccuname,$ccudom) = split(/:/,$cc);
4866: if ($notified{$cc}) {
4867: $notifyon = ' checked="checked" ';
4868: }
4869: if ($count && !$count%$numcols) {
4870: $output .= &Apache::loncommon::end_data_table_row().
4871: &Apache::loncommon::start_data_table_row()
4872: }
4873: $output .= '<td><span class="LC_nobreak"><label>'.
4874: '<input type="checkbox" name="selfenroll_notify"'.$notifyon.' value="'.$cc.'" />'.
4875: &Apache::loncommon::plainname($ccuname,$ccudom).
4876: '</label></span></td>';
1.295.2.34 raeburn 4877: $count ++;
1.276 raeburn 4878: }
4879: my $rem = $count%$numcols;
4880: if ($rem) {
4881: my $emptycols = $numcols - $rem;
4882: for (my $i=0; $i<$emptycols; $i++) {
4883: $output .= '<td> </td>';
4884: }
4885: }
4886: $output .= &Apache::loncommon::end_data_table_row().
4887: &Apache::loncommon::end_data_table();
4888: }
4889: } elsif ($item eq 'limit') {
4890: my ($crslimit,$selflimit,$nolimit);
4891: my $cid = $env{'request.course.id'};
4892: my $currlim = $env{'course.'.$cid.'.internal.selfenroll_limit'};
4893: my $currcap = $env{'course.'.$cid.'.internal.selfenroll_cap'};
1.295.2.34 raeburn 4894: $nolimit = ' checked="checked" ';
1.276 raeburn 4895: if ($currlim eq 'allstudents') {
4896: $crslimit = ' checked="checked" ';
4897: $selflimit = ' ';
4898: $nolimit = ' ';
4899: } elsif ($currlim eq 'selfenrolled') {
4900: $crslimit = ' ';
4901: $selflimit = ' checked="checked" ';
4902: $nolimit = ' ';
4903: } else {
4904: $crslimit = ' ';
4905: $selflimit = ' ';
4906: }
4907: $output .= '<table><tr><td><label>'.
1.278 raeburn 4908: '<input type="radio" name="selfenroll_limit" value="none"'.$nolimit.'/>'.
1.276 raeburn 4909: &mt('No limit').'</label></td><td><label>'.
4910: '<input type="radio" name="selfenroll_limit" value="allstudents"'.$crslimit.'/>'.
4911: &mt('Limit by total students').'</label></td><td><label>'.
4912: '<input type="radio" name="selfenroll_limit" value="selfenrolled"'.$selflimit.'/>'.
4913: &mt('Limit by total self-enrolled students').
4914: '</td></tr><tr>'.
4915: '<td> </td><td colspan="2"><span class="LC_nobreak">'.
4916: (' 'x3).&mt('Maximum number allowed: ').
4917: '<input type="text" name="selfenroll_cap" size = "5" value="'.$currcap.'" /></td></tr></table>';
1.237 raeburn 4918: }
4919: $output .= &Apache::lonhtmlcommon::row_closure(1);
4920: }
4921: }
4922: $output .= &Apache::lonhtmlcommon::end_pick_box().
1.241 raeburn 4923: '<br /><input type="button" name="selfenrollconf" value="'
1.282 schafran 4924: .&mt('Save').'" onclick="validate_types(this.form);" />'
1.241 raeburn 4925: .'<input type="hidden" name="action" value="selfenroll" /></form>';
1.237 raeburn 4926: $r->print($output);
4927: return;
4928: }
4929:
1.256 raeburn 4930: sub visible_in_cat {
4931: my ($cdom,$cnum) = @_;
4932: my %domconf = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
4933: my ($cathash,%settable,@vismsgs,$cansetvis);
4934: my %visactions = &Apache::lonlocal::texthash(
1.295.2.17 raeburn 4935: vis => 'Your course/community currently appears in the Course/Community Catalog for this domain.',
1.256 raeburn 4936: 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.295.2.17 raeburn 4937: miss => 'Your course/community does not currently appear in the Course/Community Catalog for this domain.',
1.256 raeburn 4938: yous => 'You should remedy this if you plan to allow self-enrollment, otherwise students will have difficulty finding your course.',
4939: 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 4940: make => 'Make any changes to self-enrollment settings below, click "Save", then take action to include the course in the Catalog:',
1.256 raeburn 4941: take => 'Take the following action to ensure the course appears in the Catalog:',
4942: dc_unhide => 'Ask a domain coordinator to change the "Exclude from course catalog" setting.',
4943: dc_addinst => 'Ask a domain coordinator to enable display the catalog of "Official courses (with institutional codes)".',
4944: dc_instcode => 'Ask a domain coordinator to assign an institutional code (if this is an official course).',
4945: dc_catalog => 'Ask a domain coordinator to enable or create at least one course category in the domain.',
4946: dc_categories => 'Ask a domain coordinator to create a hierarchy of categories and sub categories for courses in the domain.',
4947: 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',
4948: dc_addcat => 'Ask a domain coordinator to assign a category to the course.',
4949: );
1.261 raeburn 4950: $visactions{'unhide'} = &mt('Use [_1]Set course environment[_2] to change the "Exclude from course catalog" setting.','"<a href="/adm/parmset?action=crsenv">','</a>"');
4951: $visactions{'chgcat'} = &mt('Use [_1]Set course environment[_2] to change the category assigned to the course, as the one currently assigned is no longer used in the domain.','"<a href="/adm/parmset?action=crsenv">','</a>"');
4952: $visactions{'addcat'} = &mt('Use [_1]Set course environment[_2] to assign a category to the course.','"<a href="/adm/parmset?action=crsenv">','</a>"');
1.256 raeburn 4953: if (ref($domconf{'coursecategories'}) eq 'HASH') {
4954: if ($domconf{'coursecategories'}{'togglecats'} eq 'crs') {
4955: $settable{'togglecats'} = 1;
4956: }
4957: if ($domconf{'coursecategories'}{'categorize'} eq 'crs') {
4958: $settable{'categorize'} = 1;
4959: }
4960: $cathash = $domconf{'coursecategories'}{'cats'};
4961: }
1.260 raeburn 4962: if ($settable{'togglecats'} && $settable{'categorize'}) {
1.256 raeburn 4963: $cansetvis = &mt('You are able to both assign a course category and choose to exclude this course from the catalog.');
4964: } elsif ($settable{'togglecats'}) {
4965: $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 4966: } elsif ($settable{'categorize'}) {
1.256 raeburn 4967: $cansetvis = &mt('You may assign a course category, but only a Domain Coordinator may choose to exclude this course from the catalog.');
4968: } else {
4969: $cansetvis = &mt('Only a Domain Coordinator may assign a course category or choose to exclude this course from the catalog.');
4970: }
4971:
4972: my %currsettings =
4973: &Apache::lonnet::get('environment',['hidefromcat','categories','internal.coursecode'],
4974: $cdom,$cnum);
4975: my $visible = 0;
4976: if ($currsettings{'internal.coursecode'} ne '') {
4977: if (ref($domconf{'coursecategories'}) eq 'HASH') {
4978: $cathash = $domconf{'coursecategories'}{'cats'};
4979: if (ref($cathash) eq 'HASH') {
4980: if ($cathash->{'instcode::0'} eq '') {
4981: push(@vismsgs,'dc_addinst');
4982: } else {
4983: $visible = 1;
4984: }
4985: } else {
4986: $visible = 1;
4987: }
4988: } else {
4989: $visible = 1;
4990: }
4991: } else {
4992: if (ref($cathash) eq 'HASH') {
4993: if ($cathash->{'instcode::0'} ne '') {
4994: push(@vismsgs,'dc_instcode');
4995: }
4996: } else {
4997: push(@vismsgs,'dc_instcode');
4998: }
4999: }
5000: if ($currsettings{'categories'} ne '') {
5001: my $cathash;
5002: if (ref($domconf{'coursecategories'}) eq 'HASH') {
5003: $cathash = $domconf{'coursecategories'}{'cats'};
5004: if (ref($cathash) eq 'HASH') {
5005: if (keys(%{$cathash}) == 0) {
5006: push(@vismsgs,'dc_catalog');
5007: } elsif ((keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} ne '')) {
5008: push(@vismsgs,'dc_categories');
5009: } else {
5010: my @currcategories = split('&',$currsettings{'categories'});
5011: my $matched = 0;
5012: foreach my $cat (@currcategories) {
5013: if ($cathash->{$cat} ne '') {
5014: $visible = 1;
5015: $matched = 1;
5016: last;
5017: }
5018: }
5019: if (!$matched) {
1.260 raeburn 5020: if ($settable{'categorize'}) {
1.256 raeburn 5021: push(@vismsgs,'chgcat');
5022: } else {
5023: push(@vismsgs,'dc_chgcat');
5024: }
5025: }
5026: }
5027: }
5028: }
5029: } else {
5030: if (ref($cathash) eq 'HASH') {
5031: if ((keys(%{$cathash}) > 1) ||
5032: (keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} eq '')) {
1.260 raeburn 5033: if ($settable{'categorize'}) {
1.256 raeburn 5034: push(@vismsgs,'addcat');
5035: } else {
5036: push(@vismsgs,'dc_addcat');
5037: }
5038: }
5039: }
5040: }
5041: if ($currsettings{'hidefromcat'} eq 'yes') {
5042: $visible = 0;
5043: if ($settable{'togglecats'}) {
5044: unshift(@vismsgs,'unhide');
5045: } else {
5046: unshift(@vismsgs,'dc_unhide')
5047: }
5048: }
5049: return ($visible,$cansetvis,\@vismsgs,\%visactions);
5050: }
5051:
1.241 raeburn 5052: sub new_selfenroll_dom_row {
5053: my ($newdom,$num) = @_;
5054: my $domdesc = &Apache::lonnet::domain($newdom);
5055: my $output;
5056: if ($domdesc ne '') {
5057: $output .= &Apache::loncommon::start_data_table_row()
5058: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').' <b>'.$domdesc
5059: .' ('.$newdom.')</b><input type="hidden" name="selfenroll_dom_'.$num
1.249 raeburn 5060: .'" value="'.$newdom.'" /></span><br />'
5061: .'<span class="LC_nobreak"><label><input type="checkbox" '
5062: .'name="selfenroll_activate" value="'.$num.'" '
5063: .'onchange="javascript:update_types('
5064: ."'selfenroll_activate','$num'".');" />'
5065: .&mt('Activate').'</label></span></td>';
1.241 raeburn 5066: my @currinsttypes;
5067: $output .= '<td>'.&mt('User types:').'<br />'
5068: .&selfenroll_inst_types($num,$newdom,\@currinsttypes).'</td>'
5069: .&Apache::loncommon::end_data_table_row();
5070: }
5071: return $output;
5072: }
5073:
5074: sub selfenroll_inst_types {
5075: my ($num,$currdom,$currinsttypes) = @_;
5076: my $output;
5077: my $numinrow = 4;
5078: my $count = 0;
5079: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($currdom);
1.247 raeburn 5080: my $othervalue = 'any';
1.241 raeburn 5081: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
1.251 raeburn 5082: if (keys(%{$usertypes}) > 0) {
1.247 raeburn 5083: $othervalue = 'other';
5084: }
1.241 raeburn 5085: $output .= '<table><tr>';
5086: foreach my $type (@{$types}) {
5087: if (($count > 0) && ($count%$numinrow == 0)) {
5088: $output .= '</tr><tr>';
5089: }
5090: if (defined($usertypes->{$type})) {
1.257 raeburn 5091: my $esc_type = &escape($type);
1.241 raeburn 5092: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.
1.257 raeburn 5093: $esc_type.'" ';
1.241 raeburn 5094: if (ref($currinsttypes) eq 'ARRAY') {
5095: if (@{$currinsttypes} > 0) {
1.249 raeburn 5096: if (grep(/^any$/,@{$currinsttypes})) {
5097: $output .= 'checked="checked"';
1.257 raeburn 5098: } elsif (grep(/^\Q$esc_type\E$/,@{$currinsttypes})) {
1.241 raeburn 5099: $output .= 'checked="checked"';
5100: }
1.249 raeburn 5101: } else {
5102: $output .= 'checked="checked"';
1.241 raeburn 5103: }
5104: }
5105: $output .= ' name="selfenroll_types_'.$num.'" />'.$usertypes->{$type}.'</label></span></td>';
5106: }
5107: $count ++;
5108: }
5109: if (($count > 0) && ($count%$numinrow == 0)) {
5110: $output .= '</tr><tr>';
5111: }
1.249 raeburn 5112: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.$othervalue.'"';
1.241 raeburn 5113: if (ref($currinsttypes) eq 'ARRAY') {
5114: if (@{$currinsttypes} > 0) {
1.249 raeburn 5115: if (grep(/^any$/,@{$currinsttypes})) {
5116: $output .= ' checked="checked"';
5117: } elsif ($othervalue eq 'other') {
5118: if (grep(/^\Q$othervalue\E$/,@{$currinsttypes})) {
5119: $output .= ' checked="checked"';
5120: }
1.241 raeburn 5121: }
1.249 raeburn 5122: } else {
5123: $output .= ' checked="checked"';
1.241 raeburn 5124: }
1.249 raeburn 5125: } else {
5126: $output .= ' checked="checked"';
1.241 raeburn 5127: }
5128: $output .= ' name="selfenroll_types_'.$num.'" />'.$othertitle.'</label></span></td></tr></table>';
5129: }
5130: return $output;
5131: }
5132:
1.237 raeburn 5133: sub selfenroll_date_forms {
5134: my ($startform,$endform) = @_;
5135: my $output .= &Apache::lonhtmlcommon::start_pick_box()."\n".
1.244 bisitz 5136: &Apache::lonhtmlcommon::row_title(&mt('Start date'),
1.237 raeburn 5137: 'LC_oddrow_value')."\n".
5138: $startform."\n".
5139: &Apache::lonhtmlcommon::row_closure(1).
1.244 bisitz 5140: &Apache::lonhtmlcommon::row_title(&mt('End date'),
1.237 raeburn 5141: 'LC_oddrow_value')."\n".
5142: $endform."\n".
5143: &Apache::lonhtmlcommon::row_closure(1).
5144: &Apache::lonhtmlcommon::end_pick_box();
5145: return $output;
5146: }
5147:
1.239 raeburn 5148: sub print_userchangelogs_display {
5149: my ($r,$context,$permission) = @_;
5150: my $formname = 'roleslog';
5151: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
5152: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.295.2.18 raeburn 5153: my $crstype = &Apache::loncommon::course_type();
1.239 raeburn 5154: my %roleslog=&Apache::lonnet::dump('nohist_rolelog',$cdom,$cnum);
5155: if ((keys(%roleslog))[0]=~/^error\:/) { undef(%roleslog); }
5156:
5157: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">');
5158: my %saveable_parameters = ('show' => 'scalar',);
5159: &Apache::loncommon::store_course_settings('roles_log',
5160: \%saveable_parameters);
5161: &Apache::loncommon::restore_course_settings('roles_log',
5162: \%saveable_parameters);
5163: # set defaults
5164: my $now = time();
5165: my $defstart = $now - (7*24*3600); #7 days ago
5166: my %defaults = (
5167: page => '1',
5168: show => '10',
5169: role => 'any',
5170: chgcontext => 'any',
5171: rolelog_start_date => $defstart,
5172: rolelog_end_date => $now,
5173: );
5174: my $more_records = 0;
5175:
5176: # set current
5177: my %curr;
5178: foreach my $item ('show','page','role','chgcontext') {
5179: $curr{$item} = $env{'form.'.$item};
5180: }
5181: my ($startdate,$enddate) =
5182: &Apache::lonuserutils::get_dates_from_form('rolelog_start_date','rolelog_end_date');
5183: $curr{'rolelog_start_date'} = $startdate;
5184: $curr{'rolelog_end_date'} = $enddate;
5185: foreach my $key (keys(%defaults)) {
5186: if ($curr{$key} eq '') {
5187: $curr{$key} = $defaults{$key};
5188: }
5189: }
1.248 raeburn 5190: my (%whodunit,%changed,$version);
5191: ($version) = ($r->dir_config('lonVersion') =~ /^([\d\.]+)\-/);
1.295.2.18 raeburn 5192: $r->print(&role_display_filter($formname,$cdom,$cnum,\%curr,$version,$crstype));
1.239 raeburn 5193: my $showntablehdr = 0;
5194: my $tablehdr = &Apache::loncommon::start_data_table().
5195: &Apache::loncommon::start_data_table_header_row().
5196: '<th> </th><th>'.&mt('When').'</th><th>'.&mt('Who made the change').
5197: '</th><th>'.&mt('Changed User').'</th><th>'.&mt('Role').'</th><th>'.&mt('Section').'</th><th>'.
5198: &mt('Context').'</th><th>'.&mt('Start').'</th><th>'.&mt('End').'</th>'.
5199: &Apache::loncommon::end_data_table_header_row();
5200: my ($minshown,$maxshown);
1.255 raeburn 5201: $minshown = 1;
1.239 raeburn 5202: my $count = 0;
5203: if ($curr{'show'} ne &mt('all')) {
5204: $maxshown = $curr{'page'} * $curr{'show'};
5205: if ($curr{'page'} > 1) {
5206: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
5207: }
5208: }
5209: foreach my $id (sort { $roleslog{$b}{'exe_time'}<=>$roleslog{$a}{'exe_time'} } (keys(%roleslog))) {
5210: next if (($roleslog{$id}{'exe_time'} < $curr{'rolelog_start_date'}) ||
5211: ($roleslog{$id}{'exe_time'} > $curr{'rolelog_end_date'}));
5212: if ($curr{'show'} ne &mt('all')) {
5213: if ($count >= $curr{'page'} * $curr{'show'}) {
5214: $more_records = 1;
5215: last;
5216: }
5217: }
5218: if ($curr{'role'} ne 'any') {
5219: next if ($roleslog{$id}{'logentry'}{'role'} ne $curr{'role'});
5220: }
5221: if ($curr{'chgcontext'} ne 'any') {
5222: if ($curr{'chgcontext'} eq 'selfenroll') {
5223: next if (!$roleslog{$id}{'logentry'}{'selfenroll'});
5224: } else {
5225: next if ($roleslog{$id}{'logentry'}{'context'} ne $curr{'chgcontext'});
5226: }
5227: }
5228: $count ++;
5229: next if ($count < $minshown);
5230: if (!$showntablehdr) {
5231: $r->print($tablehdr);
5232: $showntablehdr = 1;
5233: }
5234: if ($whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} eq '') {
5235: $whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} =
5236: &Apache::loncommon::plainname($roleslog{$id}{'exe_uname'},$roleslog{$id}{'exe_udom'});
5237: }
5238: if ($changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} eq '') {
5239: $changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} =
5240: &Apache::loncommon::plainname($roleslog{$id}{'uname'},$roleslog{$id}{'udom'});
5241: }
5242: my $sec = $roleslog{$id}{'logentry'}{'section'};
5243: if ($sec eq '') {
5244: $sec = &mt('None');
5245: }
5246: my ($rolestart,$roleend);
5247: if ($roleslog{$id}{'delflag'}) {
5248: $rolestart = &mt('deleted');
5249: $roleend = &mt('deleted');
5250: } else {
5251: $rolestart = $roleslog{$id}{'logentry'}{'start'};
5252: $roleend = $roleslog{$id}{'logentry'}{'end'};
5253: if ($rolestart eq '' || $rolestart == 0) {
5254: $rolestart = &mt('No start date');
5255: } else {
5256: $rolestart = &Apache::lonlocal::locallocaltime($rolestart);
5257: }
5258: if ($roleend eq '' || $roleend == 0) {
5259: $roleend = &mt('No end date');
5260: } else {
5261: $roleend = &Apache::lonlocal::locallocaltime($roleend);
5262: }
5263: }
5264: my $chgcontext = $roleslog{$id}{'logentry'}{'context'};
5265: if ($roleslog{$id}{'logentry'}{'selfenroll'}) {
5266: $chgcontext = 'selfenroll';
5267: }
1.295.2.18 raeburn 5268: my %lt = &rolechg_contexts($crstype);
1.239 raeburn 5269: if ($chgcontext ne '' && $lt{$chgcontext} ne '') {
5270: $chgcontext = $lt{$chgcontext};
5271: }
1.295.2.18 raeburn 5272: $r->print(&Apache::loncommon::start_data_table_row().'<td>'.$count.'</td><td>'.&Apache::lonlocal::locallocaltime($roleslog{$id}{'exe_time'}).'</td><td>'.$whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}}.'</td><td>'.$changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}}.'</td><td>'.&Apache::lonnet::plaintext($roleslog{$id}{'logentry'}{'role'},$crstype).'</td><td>'.$sec.'</td><td>'.$chgcontext.'</td><td>'.$rolestart.'</td><td>'.$roleend.'</td>'.&Apache::loncommon::end_data_table_row()."\n");
1.239 raeburn 5273: }
5274: if ($showntablehdr) {
5275: $r->print(&Apache::loncommon::end_data_table().'<br />');
5276: if (($curr{'page'} > 1) || ($more_records)) {
5277: $r->print('<table><tr>');
5278: if ($curr{'page'} > 1) {
5279: $r->print('<td><a href="javascript:chgPage('."'previous'".');">'.&mt('Previous [_1] changes',$curr{'show'}).'</a></td>');
5280: }
5281: if ($more_records) {
5282: $r->print('<td><a href="javascript:chgPage('."'next'".');">'.&mt('Next [_1] changes',$curr{'show'}).'</a></td>');
5283: }
5284: $r->print('</tr></table>');
5285: $r->print(<<"ENDSCRIPT");
5286: <script type="text/javascript">
1.295.2.4 raeburn 5287: // <![CDATA[
1.239 raeburn 5288: function chgPage(caller) {
5289: if (caller == 'previous') {
5290: document.$formname.page.value --;
5291: }
5292: if (caller == 'next') {
5293: document.$formname.page.value ++;
5294: }
5295: document.$formname.submit();
5296: return;
5297: }
1.295.2.4 raeburn 5298: // ]]>
1.239 raeburn 5299: </script>
5300: ENDSCRIPT
5301: }
5302: } else {
1.295.2.4 raeburn 5303: $r->print('<p class="LC_info">'.
5304: &mt('There are no records to display').
5305: '</p>');
1.239 raeburn 5306: }
5307: $r->print('<input type="hidden" name="page" value="'.$curr{'page'}.'" />'.
5308: '<input type="hidden" name="action" value="changelogs" /></form>');
5309: return;
5310: }
5311:
5312: sub role_display_filter {
1.295.2.18 raeburn 5313: my ($formname,$cdom,$cnum,$curr,$version,$crstype) = @_;
1.239 raeburn 5314: my $context = 'course';
1.295.2.18 raeburn 5315: my $lctype = lc($crstype);
1.239 raeburn 5316: my $nolink = 1;
5317: my $output = '<table><tr><td valign="top">'.
1.295.2.4 raeburn 5318: '<span class="LC_nobreak"><b>'.&mt('Changes/page:').'</b></span><br />'.
1.239 raeburn 5319: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
5320: (&mt('all'),5,10,20,50,100,1000,10000)).
5321: '</td><td> </td>';
5322: my $startform =
5323: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_start_date',
5324: $curr->{'rolelog_start_date'},undef,
5325: undef,undef,undef,undef,undef,undef,$nolink);
5326: my $endform =
5327: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_end_date',
5328: $curr->{'rolelog_end_date'},undef,
5329: undef,undef,undef,undef,undef,undef,$nolink);
1.295.2.18 raeburn 5330: my %lt = &rolechg_contexts($crstype);
1.239 raeburn 5331: $output .= '<td valign="top"><b>'.&mt('Window during which changes occurred:').'</b><br /><table><tr><td>'.&mt('After:').
5332: '</td><td>'.$startform.'</td></tr><tr><td>'.&mt('Before:').'</td><td>'.
5333: $endform.'</td></tr></table></td><td> </td>'.
5334: '<td valign="top"><b>'.&mt('Role:').'</b><br />'.
5335: '<select name="role"><option value="any"';
5336: if ($curr->{'role'} eq 'any') {
5337: $output .= ' selected="selected"';
5338: }
5339: $output .= '>'.&mt('Any').'</option>'."\n";
1.295.2.18 raeburn 5340: my @roles = &Apache::lonuserutils::course_roles($context,undef,1,$lctype);
1.239 raeburn 5341: foreach my $role (@roles) {
5342: my $plrole;
5343: if ($role eq 'cr') {
5344: $plrole = &mt('Custom Role');
5345: } else {
1.295.2.18 raeburn 5346: $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.239 raeburn 5347: }
5348: my $selstr = '';
5349: if ($role eq $curr->{'role'}) {
5350: $selstr = ' selected="selected"';
5351: }
5352: $output .= ' <option value="'.$role.'"'.$selstr.'>'.$plrole.'</option>';
5353: }
5354: $output .= '</select></td><td> </td><td valign="top"><b>'.
5355: &mt('Context:').'</b><br /><select name="chgcontext">';
1.295.2.18 raeburn 5356: foreach my $chgtype ('any','auto','updatenow','createcourse','course','domain','selfenroll','requestcourses') {
1.239 raeburn 5357: my $selstr = '';
5358: if ($curr->{'chgcontext'} eq $chgtype) {
1.295.2.4 raeburn 5359: $selstr = ' selected="selected"';
1.239 raeburn 5360: }
5361: if (($chgtype eq 'auto') || ($chgtype eq 'updatenow')) {
5362: next if (!&Apache::lonnet::auto_run($cnum,$cdom));
5363: }
5364: $output .= '<option value="'.$chgtype.'"'.$selstr.'>'.$lt{$chgtype}.'</option>'."\n";
1.248 raeburn 5365: }
1.295.2.7 raeburn 5366: $output .= '</select></td>'
5367: .'</tr></table>';
5368:
5369: # Update Display button
5370: $output .= '<p>'
5371: .'<input type="submit" value="'.&mt('Update Display').'" />'
5372: .'</p>';
5373:
5374: # Server version info
5375: $output .= '<p style="font-size: smaller;" class="LC_info">'
5376: .&mt('Only changes made from servers running LON-CAPA [_1] or later are displayed.'
5377: ,'2.6.99.0');
1.248 raeburn 5378: if ($version) {
1.295.2.7 raeburn 5379: $output .= ' '.&mt('This LON-CAPA server is version [_1]',$version);
5380: }
5381: $output .= '</p><hr /><br />';
1.239 raeburn 5382: return $output;
5383: }
5384:
5385: sub rolechg_contexts {
1.295.2.18 raeburn 5386: my ($crstype) = @_;
1.239 raeburn 5387: my %lt = &Apache::lonlocal::texthash (
5388: any => 'Any',
5389: auto => 'Automated enrollment',
5390: updatenow => 'Roster Update',
5391: createcourse => 'Course Creation',
5392: course => 'User Management in course',
5393: domain => 'User Management in domain',
1.295.2.13 raeburn 5394: selfenroll => 'Self-enrolled',
5395: requestcourses => 'Course Request',
1.239 raeburn 5396: );
1.295.2.18 raeburn 5397: if ($crstype eq 'Community') {
5398: $lt{'createcourse'} = &mt('Community Creation');
5399: $lt{'course'} = &mt('User Management in community');
5400: $lt{'requestcourses'} = &mt('Community Request');
5401: }
1.239 raeburn 5402: return %lt;
5403: }
5404:
1.27 matthew 5405: #-------------------------------------------------- functions for &phase_two
1.160 raeburn 5406: sub user_search_result {
1.221 raeburn 5407: my ($context,$srch) = @_;
1.160 raeburn 5408: my %allhomes;
5409: my %inst_matches;
5410: my %srch_results;
1.181 raeburn 5411: my ($response,$currstate,$forcenewuser,$dirsrchres);
1.183 raeburn 5412: $srch->{'srchterm'} =~ s/\s+/ /g;
1.176 raeburn 5413: if ($srch->{'srchby'} !~ /^(uname|lastname|lastfirst)$/) {
1.160 raeburn 5414: $response = &mt('Invalid search.');
5415: }
5416: if ($srch->{'srchin'} !~ /^(crs|dom|alc|instd)$/) {
5417: $response = &mt('Invalid search.');
5418: }
1.177 raeburn 5419: if ($srch->{'srchtype'} !~ /^(exact|contains|begins)$/) {
1.160 raeburn 5420: $response = &mt('Invalid search.');
5421: }
5422: if ($srch->{'srchterm'} eq '') {
5423: $response = &mt('You must enter a search term.');
5424: }
1.183 raeburn 5425: if ($srch->{'srchterm'} =~ /^\s+$/) {
5426: $response = &mt('Your search term must contain more than just spaces.');
5427: }
1.160 raeburn 5428: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'instd')) {
5429: if (($srch->{'srchdomain'} eq '') ||
1.163 albertel 5430: ! (&Apache::lonnet::domain($srch->{'srchdomain'}))) {
1.160 raeburn 5431: $response = &mt('You must specify a valid domain when searching in a domain or institutional directory.')
5432: }
5433: }
5434: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs') ||
5435: ($srch->{'srchin'} eq 'alc')) {
1.176 raeburn 5436: if ($srch->{'srchby'} eq 'uname') {
1.243 raeburn 5437: my $unamecheck = $srch->{'srchterm'};
5438: if ($srch->{'srchtype'} eq 'contains') {
5439: if ($unamecheck !~ /^\w/) {
5440: $unamecheck = 'a'.$unamecheck;
5441: }
5442: }
5443: if ($unamecheck !~ /^$match_username$/) {
1.176 raeburn 5444: $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
5445: }
1.160 raeburn 5446: }
5447: }
1.180 raeburn 5448: if ($response ne '') {
5449: $response = '<span class="LC_warning">'.$response.'</span>';
5450: }
1.160 raeburn 5451: if ($srch->{'srchin'} eq 'instd') {
5452: my $instd_chk = &directorysrch_check($srch);
5453: if ($instd_chk ne 'ok') {
1.180 raeburn 5454: $response = '<span class="LC_warning">'.$instd_chk.'</span>'.
5455: '<br />'.&mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').'<br /><br />';
1.160 raeburn 5456: }
5457: }
5458: if ($response ne '') {
1.180 raeburn 5459: return ($currstate,$response);
1.160 raeburn 5460: }
5461: if ($srch->{'srchby'} eq 'uname') {
5462: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs')) {
5463: if ($env{'form.forcenew'}) {
5464: if ($srch->{'srchdomain'} ne $env{'request.role.domain'}) {
5465: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
5466: if ($uhome eq 'no_host') {
5467: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
1.180 raeburn 5468: my $showdom = &display_domain_info($env{'request.role.domain'});
5469: $response = &mt('New users can only be created in the domain to which your current role belongs - [_1].',$showdom);
1.160 raeburn 5470: } else {
1.179 raeburn 5471: $currstate = 'modify';
1.160 raeburn 5472: }
5473: } else {
1.179 raeburn 5474: $currstate = 'modify';
1.160 raeburn 5475: }
5476: } else {
5477: if ($srch->{'srchin'} eq 'dom') {
1.162 raeburn 5478: if ($srch->{'srchtype'} eq 'exact') {
5479: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
5480: if ($uhome eq 'no_host') {
1.179 raeburn 5481: ($currstate,$response,$forcenewuser) =
1.221 raeburn 5482: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 5483: } else {
1.179 raeburn 5484: $currstate = 'modify';
1.295.2.11 raeburn 5485: my $uname = $srch->{'srchterm'};
5486: my $udom = $srch->{'srchdomain'};
5487: $srch_results{$uname.':'.$udom} =
5488: { &Apache::lonnet::get('environment',
5489: ['firstname',
5490: 'lastname',
5491: 'permanentemail'],
5492: $udom,$uname)
5493: };
1.162 raeburn 5494: }
5495: } else {
5496: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 5497: ($currstate,$response,$forcenewuser) =
1.221 raeburn 5498: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 5499: }
5500: } else {
1.167 albertel 5501: my $courseusers = &get_courseusers();
1.162 raeburn 5502: if ($srch->{'srchtype'} eq 'exact') {
1.167 albertel 5503: if (exists($courseusers->{$srch->{'srchterm'}.':'.$srch->{'srchdomain'}})) {
1.179 raeburn 5504: $currstate = 'modify';
1.162 raeburn 5505: } else {
1.179 raeburn 5506: ($currstate,$response,$forcenewuser) =
1.221 raeburn 5507: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 5508: }
1.160 raeburn 5509: } else {
1.167 albertel 5510: foreach my $user (keys(%$courseusers)) {
1.162 raeburn 5511: my ($cuname,$cudomain) = split(/:/,$user);
5512: if ($cudomain eq $srch->{'srchdomain'}) {
1.177 raeburn 5513: my $matched = 0;
5514: if ($srch->{'srchtype'} eq 'begins') {
5515: if ($cuname =~ /^\Q$srch->{'srchterm'}\E/i) {
5516: $matched = 1;
5517: }
5518: } else {
5519: if ($cuname =~ /\Q$srch->{'srchterm'}\E/i) {
5520: $matched = 1;
5521: }
5522: }
5523: if ($matched) {
1.167 albertel 5524: $srch_results{$user} =
5525: {&Apache::lonnet::get('environment',
5526: ['firstname',
5527: 'lastname',
1.194 albertel 5528: 'permanentemail'],
5529: $cudomain,$cuname)};
1.162 raeburn 5530: }
5531: }
5532: }
1.179 raeburn 5533: ($currstate,$response,$forcenewuser) =
1.221 raeburn 5534: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 5535: }
5536: }
5537: }
5538: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 5539: $currstate = 'query';
1.160 raeburn 5540: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 5541: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
5542: if ($dirsrchres eq 'ok') {
5543: ($currstate,$response,$forcenewuser) =
1.221 raeburn 5544: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 5545: } else {
5546: my $showdom = &display_domain_info($srch->{'srchdomain'});
5547: $response = '<span class="LC_warning">'.
5548: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
5549: '</span><br />'.
5550: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
5551: '<br /><br />';
5552: }
1.160 raeburn 5553: }
5554: } else {
5555: if ($srch->{'srchin'} eq 'dom') {
5556: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 5557: ($currstate,$response,$forcenewuser) =
1.221 raeburn 5558: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 5559: } elsif ($srch->{'srchin'} eq 'crs') {
1.167 albertel 5560: my $courseusers = &get_courseusers();
5561: foreach my $user (keys(%$courseusers)) {
1.160 raeburn 5562: my ($uname,$udom) = split(/:/,$user);
5563: my %names = &Apache::loncommon::getnames($uname,$udom);
5564: my %emails = &Apache::loncommon::getemails($uname,$udom);
5565: if ($srch->{'srchby'} eq 'lastname') {
5566: if ((($srch->{'srchtype'} eq 'exact') &&
5567: ($names{'lastname'} eq $srch->{'srchterm'})) ||
1.177 raeburn 5568: (($srch->{'srchtype'} eq 'begins') &&
5569: ($names{'lastname'} =~ /^\Q$srch->{'srchterm'}\E/i)) ||
1.160 raeburn 5570: (($srch->{'srchtype'} eq 'contains') &&
5571: ($names{'lastname'} =~ /\Q$srch->{'srchterm'}\E/i))) {
5572: $srch_results{$user} = {firstname => $names{'firstname'},
5573: lastname => $names{'lastname'},
5574: permanentemail => $emails{'permanentemail'},
5575: };
5576: }
5577: } elsif ($srch->{'srchby'} eq 'lastfirst') {
5578: my ($srchlast,$srchfirst) = split(/,/,$srch->{'srchterm'});
1.177 raeburn 5579: $srchlast =~ s/\s+$//;
5580: $srchfirst =~ s/^\s+//;
1.160 raeburn 5581: if ($srch->{'srchtype'} eq 'exact') {
5582: if (($names{'lastname'} eq $srchlast) &&
5583: ($names{'firstname'} eq $srchfirst)) {
5584: $srch_results{$user} = {firstname => $names{'firstname'},
5585: lastname => $names{'lastname'},
5586: permanentemail => $emails{'permanentemail'},
5587:
5588: };
5589: }
1.177 raeburn 5590: } elsif ($srch->{'srchtype'} eq 'begins') {
5591: if (($names{'lastname'} =~ /^\Q$srchlast\E/i) &&
5592: ($names{'firstname'} =~ /^\Q$srchfirst\E/i)) {
5593: $srch_results{$user} = {firstname => $names{'firstname'},
5594: lastname => $names{'lastname'},
5595: permanentemail => $emails{'permanentemail'},
5596: };
5597: }
5598: } else {
1.160 raeburn 5599: if (($names{'lastname'} =~ /\Q$srchlast\E/i) &&
5600: ($names{'firstname'} =~ /\Q$srchfirst\E/i)) {
5601: $srch_results{$user} = {firstname => $names{'firstname'},
5602: lastname => $names{'lastname'},
5603: permanentemail => $emails{'permanentemail'},
5604: };
5605: }
5606: }
5607: }
5608: }
1.179 raeburn 5609: ($currstate,$response,$forcenewuser) =
1.221 raeburn 5610: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 5611: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 5612: $currstate = 'query';
1.160 raeburn 5613: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 5614: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
5615: if ($dirsrchres eq 'ok') {
5616: ($currstate,$response,$forcenewuser) =
1.221 raeburn 5617: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 5618: } else {
5619: my $showdom = &display_domain_info($srch->{'srchdomain'}); $response = '<span class="LC_warning">'.
5620: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
5621: '</span><br />'.
5622: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
5623: '<br /><br />';
5624: }
1.160 raeburn 5625: }
5626: }
1.179 raeburn 5627: return ($currstate,$response,$forcenewuser,\%srch_results);
1.160 raeburn 5628: }
5629:
5630: sub directorysrch_check {
5631: my ($srch) = @_;
5632: my $can_search = 0;
5633: my $response;
5634: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
5635: ['directorysrch'],$srch->{'srchdomain'});
1.180 raeburn 5636: my $showdom = &display_domain_info($srch->{'srchdomain'});
1.160 raeburn 5637: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
5638: if (!$dom_inst_srch{'directorysrch'}{'available'}) {
1.180 raeburn 5639: return &mt('Institutional directory search is not available in domain: [_1]',$showdom);
1.160 raeburn 5640: }
5641: if ($dom_inst_srch{'directorysrch'}{'localonly'}) {
5642: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
1.180 raeburn 5643: return &mt('Institutional directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
1.160 raeburn 5644: }
5645: my @usertypes = split(/:/,$env{'environment.inststatus'});
5646: if (!@usertypes) {
5647: push(@usertypes,'default');
5648: }
5649: if (ref($dom_inst_srch{'directorysrch'}{'cansearch'}) eq 'ARRAY') {
5650: foreach my $type (@usertypes) {
5651: if (grep(/^\Q$type\E$/,@{$dom_inst_srch{'directorysrch'}{'cansearch'}})) {
5652: $can_search = 1;
5653: last;
5654: }
5655: }
5656: }
5657: if (!$can_search) {
5658: my ($insttypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($srch->{'srchdomain'});
5659: my @longtypes;
5660: foreach my $item (@usertypes) {
1.229 raeburn 5661: if (defined($insttypes->{$item})) {
5662: push (@longtypes,$insttypes->{$item});
5663: } elsif ($item eq 'default') {
5664: push (@longtypes,&mt('other'));
5665: }
1.160 raeburn 5666: }
5667: my $insttype_str = join(', ',@longtypes);
1.180 raeburn 5668: return &mt('Institutional directory search in domain: [_1] is not available to your user type: ',$showdom).$insttype_str;
1.229 raeburn 5669: }
1.160 raeburn 5670: } else {
5671: $can_search = 1;
5672: }
5673: } else {
1.180 raeburn 5674: return &mt('Institutional directory search has not been configured for domain: [_1]',$showdom);
1.160 raeburn 5675: }
5676: my %longtext = &Apache::lonlocal::texthash (
1.167 albertel 5677: uname => 'username',
1.160 raeburn 5678: lastfirst => 'last name, first name',
1.167 albertel 5679: lastname => 'last name',
1.172 raeburn 5680: contains => 'contains',
1.178 raeburn 5681: exact => 'as exact match to',
5682: begins => 'begins with',
1.160 raeburn 5683: );
5684: if ($can_search) {
5685: if (ref($dom_inst_srch{'directorysrch'}{'searchby'}) eq 'ARRAY') {
5686: if (!grep(/^\Q$srch->{'srchby'}\E$/,@{$dom_inst_srch{'directorysrch'}{'searchby'}})) {
1.180 raeburn 5687: return &mt('Institutional directory search in domain: [_1] is not available for searching by "[_2]"',$showdom,$longtext{$srch->{'srchby'}});
1.160 raeburn 5688: }
5689: } else {
1.180 raeburn 5690: return &mt('Institutional directory search in domain: [_1] is not available.', $showdom);
1.160 raeburn 5691: }
5692: }
5693: if ($can_search) {
1.178 raeburn 5694: if (ref($dom_inst_srch{'directorysrch'}{'searchtypes'}) eq 'ARRAY') {
5695: if (grep(/^\Q$srch->{'srchtype'}\E/,@{$dom_inst_srch{'directorysrch'}{'searchtypes'}})) {
5696: return 'ok';
5697: } else {
1.180 raeburn 5698: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 5699: }
5700: } else {
5701: if ((($dom_inst_srch{'directorysrch'}{'searchtypes'} eq 'specify') &&
5702: ($srch->{'srchtype'} eq 'exact' || $srch->{'srchtype'} eq 'contains')) ||
5703: ($dom_inst_srch{'directorysrch'}{'searchtypes'} eq $srch->{'srchtype'})) {
5704: return 'ok';
5705: } else {
1.180 raeburn 5706: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 5707: }
1.160 raeburn 5708: }
5709: }
5710: }
5711:
5712: sub get_courseusers {
5713: my %advhash;
1.167 albertel 5714: my $classlist = &Apache::loncoursedata::get_classlist();
1.160 raeburn 5715: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles();
5716: foreach my $role (sort(keys(%coursepersonnel))) {
5717: foreach my $user (split(/\,/,$coursepersonnel{$role})) {
1.167 albertel 5718: if (!exists($classlist->{$user})) {
5719: $classlist->{$user} = [];
5720: }
1.160 raeburn 5721: }
5722: }
1.167 albertel 5723: return $classlist;
1.160 raeburn 5724: }
5725:
5726: sub build_search_response {
1.221 raeburn 5727: my ($context,$srch,%srch_results) = @_;
1.179 raeburn 5728: my ($currstate,$response,$forcenewuser);
1.160 raeburn 5729: my %names = (
5730: 'uname' => 'username',
5731: 'lastname' => 'last name',
5732: 'lastfirst' => 'last name, first name',
5733: 'crs' => 'this course',
1.180 raeburn 5734: 'dom' => 'LON-CAPA domain: ',
5735: 'instd' => 'the institutional directory for domain: ',
1.160 raeburn 5736: );
5737:
5738: my %single = (
1.180 raeburn 5739: begins => 'A match',
1.160 raeburn 5740: contains => 'A match',
1.180 raeburn 5741: exact => 'An exact match',
1.160 raeburn 5742: );
5743: my %nomatch = (
1.180 raeburn 5744: begins => 'No match',
1.160 raeburn 5745: contains => 'No match',
1.180 raeburn 5746: exact => 'No exact match',
1.160 raeburn 5747: );
5748: if (keys(%srch_results) > 1) {
1.179 raeburn 5749: $currstate = 'select';
1.160 raeburn 5750: } else {
5751: if (keys(%srch_results) == 1) {
1.179 raeburn 5752: $currstate = 'modify';
1.180 raeburn 5753: $response = &mt("$single{$srch->{'srchtype'}} was found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}.",$srch->{'srchterm'});
5754: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
5755: $response .= &display_domain_info($srch->{'srchdomain'});
5756: }
1.160 raeburn 5757: } else {
1.180 raeburn 5758: $response = '<span class="LC_warning">'.&mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}",$srch->{'srchterm'});
5759: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
5760: $response .= &display_domain_info($srch->{'srchdomain'});
5761: }
5762: $response .= '</span>';
1.160 raeburn 5763: if ($srch->{'srchin'} ne 'alc') {
5764: $forcenewuser = 1;
5765: my $cansrchinst = 0;
5766: if ($srch->{'srchdomain'}) {
5767: my %domconfig = &Apache::lonnet::get_dom('configuration',['directorysrch'],$srch->{'srchdomain'});
5768: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
5769: if ($domconfig{'directorysrch'}{'available'}) {
5770: $cansrchinst = 1;
5771: }
5772: }
5773: }
1.180 raeburn 5774: if ((($srch->{'srchby'} eq 'lastfirst') ||
5775: ($srch->{'srchby'} eq 'lastname')) &&
5776: ($srch->{'srchin'} eq 'dom')) {
5777: if ($cansrchinst) {
5778: $response .= '<br />'.&mt('You may want to broaden your search to a search of the institutional directory for the domain.');
1.160 raeburn 5779: }
5780: }
1.180 raeburn 5781: if ($srch->{'srchin'} eq 'crs') {
5782: $response .= '<br />'.&mt('You may want to broaden your search to the selected LON-CAPA domain.');
5783: }
5784: }
1.295.2.6 raeburn 5785: my $createdom = $env{'request.role.domain'};
5786: if ($context eq 'requestcrs') {
5787: if ($env{'form.coursedom'} ne '') {
5788: $createdom = $env{'form.coursedom'};
5789: }
5790: }
5791: if (!($srch->{'srchby'} eq 'uname' && $srch->{'srchin'} eq 'dom' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchdomain'} eq $createdom)) {
1.221 raeburn 5792: my $cancreate =
1.295.2.7 raeburn 5793: &Apache::lonuserutils::can_create_user($createdom,$context);
5794: my $targetdom = '<span class="LC_cusr_emph">'.$createdom.'</span>';
1.221 raeburn 5795: if ($cancreate) {
1.295.2.6 raeburn 5796: my $showdom = &display_domain_info($createdom);
1.266 bisitz 5797: $response .= '<br /><br />'
5798: .'<b>'.&mt('To add a new user:').'</b>'
1.295.2.6 raeburn 5799: .'<br />';
5800: if ($context eq 'requestcrs') {
1.295.2.7 raeburn 5801: $response .= &mt("(You can only define new users in the new course's domain - [_1])",$targetdom);
1.295.2.6 raeburn 5802: } else {
1.295.2.7 raeburn 5803: $response .= &mt("(You can only create new users in your current role's domain - [_1])",$targetdom);
5804: }
1.295.2.6 raeburn 5805: $response .= '<ul><li>'
1.266 bisitz 5806: .&mt("Set 'Domain/institution to search' to: [_1]",'<span class="LC_cusr_emph">'.$showdom.'</span>')
5807: .'</li><li>'
5808: .&mt("Set 'Search criteria' to: [_1]username is ..... in selected LON-CAPA domain[_2]",'<span class="LC_cusr_emph">','</span>')
5809: .'</li><li>'
5810: .&mt('Provide the proposed username')
5811: .'</li><li>'
5812: .&mt("Click 'Search'")
5813: .'</li></ul><br />';
1.221 raeburn 5814: } else {
5815: my $helplink = ' href="javascript:helpMenu('."'display'".')"';
1.295.2.6 raeburn 5816: $response .= '<br /><br />';
5817: if ($context eq 'requestcrs') {
1.295.2.7 raeburn 5818: $response .= &mt("You are not authorized to define new users in the new course's domain - [_1].",$targetdom);
1.295.2.6 raeburn 5819: } else {
5820: $response .= &mt("You are not authorized to create new users in your current role's domain - [_1].",$targetdom);
5821: }
5822: $response .= '<br />'
1.292 bisitz 5823: .&mt('Please contact the [_1]helpdesk[_2] if you need to create a new user.'
1.266 bisitz 5824: ,' <a'.$helplink.'>'
5825: ,'</a>')
5826: .'<br /><br />';
1.221 raeburn 5827: }
1.160 raeburn 5828: }
5829: }
5830: }
1.179 raeburn 5831: return ($currstate,$response,$forcenewuser);
1.160 raeburn 5832: }
5833:
1.180 raeburn 5834: sub display_domain_info {
5835: my ($dom) = @_;
5836: my $output = $dom;
5837: if ($dom ne '') {
5838: my $domdesc = &Apache::lonnet::domain($dom,'description');
5839: if ($domdesc ne '') {
5840: $output .= ' <span class="LC_cusr_emph">('.$domdesc.')</span>';
5841: }
5842: }
5843: return $output;
5844: }
5845:
1.160 raeburn 5846: sub crumb_utilities {
5847: my %elements = (
5848: crtuser => {
5849: srchterm => 'text',
1.172 raeburn 5850: srchin => 'selectbox',
1.160 raeburn 5851: srchby => 'selectbox',
5852: srchtype => 'selectbox',
5853: srchdomain => 'selectbox',
5854: },
1.207 raeburn 5855: crtusername => {
5856: srchterm => 'text',
5857: srchdomain => 'selectbox',
5858: },
1.160 raeburn 5859: docustom => {
5860: rolename => 'selectbox',
5861: newrolename => 'textbox',
5862: },
1.179 raeburn 5863: studentform => {
5864: srchterm => 'text',
5865: srchin => 'selectbox',
5866: srchby => 'selectbox',
5867: srchtype => 'selectbox',
5868: srchdomain => 'selectbox',
5869: },
1.160 raeburn 5870: );
5871:
5872: my $jsback .= qq|
5873: function backPage(formname,prevphase,prevstate) {
1.211 raeburn 5874: if (typeof prevphase == 'undefined') {
5875: formname.phase.value = '';
5876: }
5877: else {
5878: formname.phase.value = prevphase;
5879: }
5880: if (typeof prevstate == 'undefined') {
5881: formname.currstate.value = '';
5882: }
5883: else {
5884: formname.currstate.value = prevstate;
5885: }
1.160 raeburn 5886: formname.submit();
5887: }
5888: |;
5889: return ($jsback,\%elements);
5890: }
5891:
1.26 matthew 5892: sub course_level_table {
1.89 raeburn 5893: my (%inccourses) = @_;
1.26 matthew 5894: my $table = '';
1.62 www 5895: # Custom Roles?
5896:
1.190 raeburn 5897: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.89 raeburn 5898: my %lt=&Apache::lonlocal::texthash(
5899: 'exs' => "Existing sections",
5900: 'new' => "Define new section",
5901: 'ssd' => "Set Start Date",
5902: 'sed' => "Set End Date",
1.131 raeburn 5903: 'crl' => "Course Level",
1.89 raeburn 5904: 'act' => "Activate",
5905: 'rol' => "Role",
5906: 'ext' => "Extent",
1.113 raeburn 5907: 'grs' => "Section",
1.89 raeburn 5908: 'sta' => "Start",
5909: 'end' => "End"
5910: );
1.62 www 5911:
1.295.2.26 raeburn 5912: foreach my $protectedcourse (sort(keys(%inccourses))) {
1.135 raeburn 5913: my $thiscourse=$protectedcourse;
1.26 matthew 5914: $thiscourse=~s:_:/:g;
5915: my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
1.295.2.26 raeburn 5916: my $isowner = &is_courseowner($protectedcourse,$coursedata{'internal.courseowner'});
1.26 matthew 5917: my $area=$coursedata{'description'};
1.295.2.19 raeburn 5918: my $crstype=$coursedata{'type'};
1.135 raeburn 5919: if (!defined($area)) { $area=&mt('Unavailable course').': '.$protectedcourse; }
1.89 raeburn 5920: my ($domain,$cnum)=split(/\//,$thiscourse);
1.115 albertel 5921: my %sections_count;
1.101 albertel 5922: if (defined($env{'request.course.id'})) {
5923: if ($env{'request.course.id'} eq $domain.'_'.$cnum) {
1.115 albertel 5924: %sections_count =
5925: &Apache::loncommon::get_sections($domain,$cnum);
1.92 raeburn 5926: }
5927: }
1.295.2.21 raeburn 5928: my @roles = &Apache::lonuserutils::roles_by_context('course','',$crstype);
1.213 raeburn 5929: foreach my $role (@roles) {
1.295.2.18 raeburn 5930: my $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.295.2.26 raeburn 5931: if ((&Apache::lonnet::allowed('c'.$role,$thiscourse)) ||
5932: ((($role eq 'cc') || ($role eq 'co')) && ($isowner))) {
1.221 raeburn 5933: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.295.2.26 raeburn 5934: $plrole,\%sections_count,\%lt);
1.221 raeburn 5935: } elsif ($env{'request.course.sec'} ne '') {
5936: if (&Apache::lonnet::allowed('c'.$role,$thiscourse.'/'.
5937: $env{'request.course.sec'})) {
5938: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
5939: $plrole,\%sections_count,\%lt);
1.26 matthew 5940: }
5941: }
5942: }
1.221 raeburn 5943: if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
1.295.2.24 raeburn 5944: foreach my $cust (sort(keys(%customroles))) {
5945: next if ($crstype eq 'Community' && $customroles{$cust} =~ /bre\&S/);
1.221 raeburn 5946: my $role = 'cr_cr_'.$env{'user.domain'}.'_'.$env{'user.name'}.'_'.$cust;
5947: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
5948: $cust,\%sections_count,\%lt);
5949: }
1.62 www 5950: }
1.26 matthew 5951: }
5952: return '' if ($table eq ''); # return nothing if there is nothing
5953: # in the table
1.188 raeburn 5954: my $result;
5955: if (!$env{'request.course.id'}) {
5956: $result = '<h4>'.$lt{'crl'}.'</h4>'."\n";
5957: }
5958: $result .=
1.136 raeburn 5959: &Apache::loncommon::start_data_table().
5960: &Apache::loncommon::start_data_table_header_row().
5961: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th><th>'.$lt{'ext'}.'</th>
5962: <th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
5963: &Apache::loncommon::end_data_table_header_row().
5964: $table.
5965: &Apache::loncommon::end_data_table();
1.26 matthew 5966: return $result;
5967: }
1.88 raeburn 5968:
1.221 raeburn 5969: sub course_level_row {
5970: my ($protectedcourse,$role,$area,$domain,$plrole,$sections_count,$lt) = @_;
1.222 raeburn 5971: my $row = &Apache::loncommon::start_data_table_row().
5972: ' <td><input type="checkbox" name="act_'.
5973: $protectedcourse.'_'.$role.'" /></td>'."\n".
5974: ' <td>'.$plrole.'</td>'."\n".
5975: ' <td>'.$area.'<br />Domain: '.$domain.'</td>'."\n";
1.295.2.22 raeburn 5976: if (($role eq 'cc') || ($role eq 'co')) {
1.222 raeburn 5977: $row .= '<td> </td>';
1.221 raeburn 5978: } elsif ($env{'request.course.sec'} ne '') {
1.222 raeburn 5979: $row .= ' <td><input type="hidden" value="'.
5980: $env{'request.course.sec'}.'" '.
5981: 'name="sec_'.$protectedcourse.'_'.$role.'" />'.
5982: $env{'request.course.sec'}.'</td>';
1.221 raeburn 5983: } else {
5984: if (ref($sections_count) eq 'HASH') {
5985: my $currsec =
5986: &Apache::lonuserutils::course_sections($sections_count,
5987: $protectedcourse.'_'.$role);
1.222 raeburn 5988: $row .= '<td><table class="LC_createuser">'."\n".
5989: '<tr class="LC_section_row">'."\n".
5990: ' <td valign="top">'.$lt->{'exs'}.'<br />'.
5991: $currsec.'</td>'."\n".
5992: ' <td> </td>'."\n".
5993: ' <td valign="top"> '.$lt->{'new'}.'<br />'.
1.221 raeburn 5994: '<input type="text" name="newsec_'.$protectedcourse.'_'.$role.
5995: '" value="" />'.
5996: '<input type="hidden" '.
5997: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n".
1.222 raeburn 5998: '</tr></table></td>'."\n";
1.221 raeburn 5999: } else {
1.222 raeburn 6000: $row .= '<td><input type="text" size="10" '.
6001: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n";
1.221 raeburn 6002: }
6003: }
1.222 raeburn 6004: $row .= <<ENDTIMEENTRY;
6005: <td><input type="hidden" name="start_$protectedcourse\_$role" value="" />
1.221 raeburn 6006: <a href=
6007: "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 6008: <td><input type="hidden" name="end_$protectedcourse\_$role" value="" />
1.221 raeburn 6009: <a href=
6010: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$role.value,'end_$protectedcourse\_$role','cu.pres','dateset')">$lt->{'sed'}</a></td>
6011: ENDTIMEENTRY
1.222 raeburn 6012: $row .= &Apache::loncommon::end_data_table_row();
6013: return $row;
1.221 raeburn 6014: }
6015:
1.88 raeburn 6016: sub course_level_dc {
6017: my ($dcdom) = @_;
1.190 raeburn 6018: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.213 raeburn 6019: my @roles = &Apache::lonuserutils::roles_by_context('course');
1.88 raeburn 6020: my $hiddenitems = '<input type="hidden" name="dcdomain" value="'.$dcdom.'" />'.
6021: '<input type="hidden" name="origdom" value="'.$dcdom.'" />'.
1.133 raeburn 6022: '<input type="hidden" name="dccourse" value="" />';
1.88 raeburn 6023: my $courseform='<b>'.&Apache::loncommon::selectcourse_link
1.295.2.31 raeburn 6024: ('cu','dccourse','dcdomain','coursedesc',undef,undef,'Course/Community','crstype').'</b>';
1.295.2.19 raeburn 6025: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,'currsec','cu','role','Course/Community Browser');
1.88 raeburn 6026: my %lt=&Apache::lonlocal::texthash(
6027: 'rol' => "Role",
1.113 raeburn 6028: 'grs' => "Section",
1.88 raeburn 6029: 'exs' => "Existing sections",
6030: 'new' => "Define new section",
6031: 'sta' => "Start",
6032: 'end' => "End",
6033: 'ssd' => "Set Start Date",
6034: 'sed' => "Set End Date"
6035: );
1.295.2.23 raeburn 6036: my $header = '<h4>'.&mt('Course/Community Level').'</h4>'.
1.136 raeburn 6037: &Apache::loncommon::start_data_table().
6038: &Apache::loncommon::start_data_table_header_row().
1.143 raeburn 6039: '<th>'.$courseform.'</th><th>'.$lt{'rol'}.'</th><th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
1.136 raeburn 6040: &Apache::loncommon::end_data_table_header_row();
1.143 raeburn 6041: my $otheritems = &Apache::loncommon::start_data_table_row()."\n".
1.295.2.23 raeburn 6042: '<td><br /><input type="text" name="coursedesc" value="" onfocus="this.blur();opencrsbrowser('."'cu','dccourse','dcdomain','coursedesc','','','','crstype'".')" /></td>'."\n".
6043: '<td valign><br /><select name="role">'."\n";
1.213 raeburn 6044: foreach my $role (@roles) {
1.135 raeburn 6045: my $plrole=&Apache::lonnet::plaintext($role);
6046: $otheritems .= ' <option value="'.$role.'">'.$plrole;
1.88 raeburn 6047: }
6048: if ( keys %customroles > 0) {
1.135 raeburn 6049: foreach my $cust (sort keys %customroles) {
1.101 albertel 6050: my $custrole='cr_cr_'.$env{'user.domain'}.
1.135 raeburn 6051: '_'.$env{'user.name'}.'_'.$cust;
6052: $otheritems .= ' <option value="'.$custrole.'">'.$cust;
1.88 raeburn 6053: }
6054: }
6055: $otheritems .= '</select></td><td>'.
6056: '<table border="0" cellspacing="0" cellpadding="0">'.
6057: '<tr><td valign="top"><b>'.$lt{'exs'}.'</b><br /><select name="currsec">'.
6058: ' <option value=""><--'.&mt('Pick course first').'</select></td>'.
6059: '<td> </td>'.
6060: '<td valign="top"> <b>'.$lt{'new'}.'</b><br />'.
1.113 raeburn 6061: '<input type="text" name="newsec" value="" />'.
1.237 raeburn 6062: '<input type="hidden" name="section" value="" />'.
1.295.2.23 raeburn 6063: '<input type="hidden" name="groups" value="" />'.
6064: '<input type="hidden" name="crstype" value="" /></td>'.
1.88 raeburn 6065: '</tr></table></td>';
6066: $otheritems .= <<ENDTIMEENTRY;
1.295.2.23 raeburn 6067: <td><br /><input type="hidden" name="start" value='' />
1.88 raeburn 6068: <a href=
6069: "javascript:pjump('date_start','Start Date',document.cu.start.value,'start','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.295.2.23 raeburn 6070: <td><br /><input type="hidden" name="end" value='' />
1.88 raeburn 6071: <a href=
6072: "javascript:pjump('date_end','End Date',document.cu.end.value,'end','cu.pres','dateset')">$lt{'sed'}</a></td>
6073: ENDTIMEENTRY
1.136 raeburn 6074: $otheritems .= &Apache::loncommon::end_data_table_row().
6075: &Apache::loncommon::end_data_table()."\n";
1.88 raeburn 6076: return $cb_jscript.$header.$hiddenitems.$otheritems;
6077: }
6078:
1.237 raeburn 6079: sub update_selfenroll_config {
1.241 raeburn 6080: my ($r,$context,$permission) = @_;
1.237 raeburn 6081: my ($row,$lt) = &get_selfenroll_titles();
1.241 raeburn 6082: my %curr_groups = &Apache::longroup::coursegroups();
1.237 raeburn 6083: my (%changes,%warning);
6084: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
6085: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.241 raeburn 6086: my $curr_types;
1.237 raeburn 6087: if (ref($row) eq 'ARRAY') {
6088: foreach my $item (@{$row}) {
6089: if ($item eq 'enroll_dates') {
6090: my (%currenrolldate,%newenrolldate);
6091: foreach my $type ('start','end') {
6092: $currenrolldate{$type} = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$type.'_date'};
6093: $newenrolldate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_date');
6094: if ($newenrolldate{$type} ne $currenrolldate{$type}) {
6095: $changes{'internal.selfenroll_'.$type.'_date'} = $newenrolldate{$type};
6096: }
6097: }
6098: } elsif ($item eq 'access_dates') {
6099: my (%currdate,%newdate);
6100: foreach my $type ('start','end') {
6101: $currdate{$type} = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$type.'_access'};
6102: $newdate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_access');
6103: if ($newdate{$type} ne $currdate{$type}) {
6104: $changes{'internal.selfenroll_'.$type.'_access'} = $newdate{$type};
6105: }
6106: }
1.241 raeburn 6107: } elsif ($item eq 'types') {
6108: $curr_types =
6109: $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$item};
6110: if ($env{'form.selfenroll_all'}) {
6111: if ($curr_types ne '*') {
6112: $changes{'internal.selfenroll_types'} = '*';
6113: } else {
6114: next;
6115: }
6116: } else {
1.249 raeburn 6117: my %currdoms;
1.241 raeburn 6118: my @entries = split(/;/,$curr_types);
6119: my @deletedoms = &Apache::loncommon::get_env_multiple('form.selfenroll_delete');
1.249 raeburn 6120: my @activations = &Apache::loncommon::get_env_multiple('form.selfenroll_activate');
1.241 raeburn 6121: my $newnum = 0;
1.249 raeburn 6122: my @latesttypes;
6123: foreach my $num (@activations) {
6124: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$num);
6125: if (@types > 0) {
1.241 raeburn 6126: @types = sort(@types);
6127: my $typestr = join(',',@types);
1.249 raeburn 6128: my $typedom = $env{'form.selfenroll_dom_'.$num};
6129: $latesttypes[$newnum] = $typedom.':'.$typestr;
6130: $currdoms{$typedom} = 1;
1.241 raeburn 6131: $newnum ++;
6132: }
6133: }
1.295.2.23 raeburn 6134: for (my $j=0; $j<$env{'form.selfenroll_types_total'}; $j++) {
6135: if ((!grep(/^$j$/,@deletedoms)) && (!grep(/^$j$/,@activations))) {
1.249 raeburn 6136: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$j);
6137: if (@types > 0) {
6138: @types = sort(@types);
6139: my $typestr = join(',',@types);
6140: my $typedom = $env{'form.selfenroll_dom_'.$j};
6141: $latesttypes[$newnum] = $typedom.':'.$typestr;
6142: $currdoms{$typedom} = 1;
6143: $newnum ++;
6144: }
6145: }
6146: }
6147: if ($env{'form.selfenroll_newdom'} ne '') {
6148: my $typedom = $env{'form.selfenroll_newdom'};
6149: if ((!defined($currdoms{$typedom})) &&
6150: (&Apache::lonnet::domain($typedom) ne '')) {
6151: my $typestr;
6152: my ($othertitle,$usertypes,$types) =
6153: &Apache::loncommon::sorted_inst_types($typedom);
6154: my $othervalue = 'any';
6155: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
6156: if (@{$types} > 0) {
1.257 raeburn 6157: my @esc_types = map { &escape($_); } @{$types};
1.249 raeburn 6158: $othervalue = 'other';
1.258 raeburn 6159: $typestr = join(',',(@esc_types,$othervalue));
1.249 raeburn 6160: }
6161: $typestr = $othervalue;
6162: } else {
6163: $typestr = $othervalue;
6164: }
6165: $latesttypes[$newnum] = $typedom.':'.$typestr;
6166: $newnum ++ ;
6167: }
6168: }
1.241 raeburn 6169: my $selfenroll_types = join(';',@latesttypes);
6170: if ($selfenroll_types ne $curr_types) {
6171: $changes{'internal.selfenroll_types'} = $selfenroll_types;
6172: }
6173: }
1.276 raeburn 6174: } elsif ($item eq 'limit') {
6175: my $newlimit = $env{'form.selfenroll_limit'};
6176: my $newcap = $env{'form.selfenroll_cap'};
6177: $newcap =~s/\s+//g;
6178: my $currlimit = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_limit'};
6179: $currlimit = 'none' if ($currlimit eq '');
6180: my $currcap = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_cap'};
6181: if ($newlimit ne $currlimit) {
6182: if ($newlimit ne 'none') {
6183: if ($newcap =~ /^\d+$/) {
6184: if ($newcap ne $currcap) {
6185: $changes{'internal.selfenroll_cap'} = $newcap;
6186: }
6187: $changes{'internal.selfenroll_limit'} = $newlimit;
6188: } else {
6189: $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.');
6190: }
6191: } elsif ($currcap ne '') {
6192: $changes{'internal.selfenroll_cap'} = '';
6193: $changes{'internal.selfenroll_limit'} = $newlimit;
6194: }
6195: } elsif ($currlimit ne 'none') {
6196: if ($newcap =~ /^\d+$/) {
6197: if ($newcap ne $currcap) {
6198: $changes{'internal.selfenroll_cap'} = $newcap;
6199: }
6200: } else {
6201: $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.');
6202: }
6203: }
6204: } elsif ($item eq 'approval') {
6205: my (@currnotified,@newnotified);
6206: my $currapproval = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'};
6207: my $currnotifylist = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_notifylist'};
6208: if ($currnotifylist ne '') {
6209: @currnotified = split(/,/,$currnotifylist);
6210: @currnotified = sort(@currnotified);
6211: }
6212: my $newapproval = $env{'form.selfenroll_approval'};
6213: @newnotified = &Apache::loncommon::get_env_multiple('form.selfenroll_notify');
6214: @newnotified = sort(@newnotified);
6215: if ($newapproval ne $currapproval) {
6216: $changes{'internal.selfenroll_approval'} = $newapproval;
6217: if (!$newapproval) {
6218: if ($currnotifylist ne '') {
6219: $changes{'internal.selfenroll_notifylist'} = '';
6220: }
6221: } else {
6222: my @differences =
1.295 raeburn 6223: &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 6224: if (@differences > 0) {
6225: if (@newnotified > 0) {
6226: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
6227: } else {
6228: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
6229: }
6230: }
6231: }
6232: } else {
1.295 raeburn 6233: my @differences = &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 6234: if (@differences > 0) {
6235: if (@newnotified > 0) {
6236: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
6237: } else {
6238: $changes{'internal.selfenroll_notifylist'} = '';
6239: }
6240: }
6241: }
1.237 raeburn 6242: } else {
6243: my $curr_val =
6244: $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$item};
6245: my $newval = $env{'form.selfenroll_'.$item};
6246: if ($item eq 'section') {
6247: $newval = $env{'form.sections'};
1.241 raeburn 6248: if (defined($curr_groups{$newval})) {
1.237 raeburn 6249: $newval = $curr_val;
6250: $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');
6251: } elsif ($newval eq 'all') {
6252: $newval = $curr_val;
1.274 bisitz 6253: $warning{$item} = &mt('Section for self-enrolled users unchanged, as "all" is a reserved section name.');
1.237 raeburn 6254: }
6255: if ($newval eq '') {
6256: $newval = 'none';
6257: }
6258: }
6259: if ($newval ne $curr_val) {
6260: $changes{'internal.selfenroll_'.$item} = $newval;
6261: }
1.241 raeburn 6262: }
1.237 raeburn 6263: }
6264: if (keys(%warning) > 0) {
6265: foreach my $item (@{$row}) {
6266: if (exists($warning{$item})) {
6267: $r->print($warning{$item}.'<br />');
6268: }
6269: }
6270: }
6271: if (keys(%changes) > 0) {
6272: my $putresult = &Apache::lonnet::put('environment',\%changes,$cdom,$cnum);
6273: if ($putresult eq 'ok') {
6274: if ((exists($changes{'internal.selfenroll_types'})) ||
6275: (exists($changes{'internal.selfenroll_start_date'})) ||
6276: (exists($changes{'internal.selfenroll_end_date'}))) {
6277: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',
6278: $cnum,undef,undef,'Course');
6279: my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
6280: if (ref($crsinfo{$env{'request.course.id'}}) eq 'HASH') {
6281: foreach my $item ('selfenroll_types','selfenroll_start_date','selfenroll_end_date') {
6282: if (exists($changes{'internal.'.$item})) {
6283: $crsinfo{$env{'request.course.id'}}{$item} =
6284: $changes{'internal.'.$item};
6285: }
6286: }
6287: my $crsputresult =
6288: &Apache::lonnet::courseidput($cdom,\%crsinfo,
6289: $chome,'notime');
6290: }
6291: }
6292: $r->print(&mt('The following changes were made to self-enrollment settings:').'<ul>');
6293: foreach my $item (@{$row}) {
6294: my $title = $item;
6295: if (ref($lt) eq 'HASH') {
6296: $title = $lt->{$item};
6297: }
6298: if ($item eq 'enroll_dates') {
6299: foreach my $type ('start','end') {
6300: if (exists($changes{'internal.selfenroll_'.$type.'_date'})) {
6301: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_date'});
1.244 bisitz 6302: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 6303: $title,$type,$newdate).'</li>');
6304: }
6305: }
6306: } elsif ($item eq 'access_dates') {
6307: foreach my $type ('start','end') {
6308: if (exists($changes{'internal.selfenroll_'.$type.'_access'})) {
6309: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_access'});
1.244 bisitz 6310: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 6311: $title,$type,$newdate).'</li>');
6312: }
6313: }
1.276 raeburn 6314: } elsif ($item eq 'limit') {
6315: if ((exists($changes{'internal.selfenroll_limit'})) ||
6316: (exists($changes{'internal.selfenroll_cap'}))) {
6317: my ($newval,$newcap);
6318: if ($changes{'internal.selfenroll_cap'} ne '') {
6319: $newcap = $changes{'internal.selfenroll_cap'}
6320: } else {
6321: $newcap = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_cap'};
6322: }
6323: if ($changes{'internal.selfenroll_limit'} eq 'none') {
6324: $newval = &mt('No limit');
6325: } elsif ($changes{'internal.selfenroll_limit'} eq
6326: 'allstudents') {
6327: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
6328: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
6329: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
6330: } else {
6331: my $currlimit = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_limit'};
6332: if ($currlimit eq 'allstudents') {
6333: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
6334: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
1.295.2.9 raeburn 6335: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
1.276 raeburn 6336: }
6337: }
6338: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
6339: }
6340: } elsif ($item eq 'approval') {
6341: if ((exists($changes{'internal.selfenroll_approval'})) ||
6342: (exists($changes{'internal.selfenroll_notifylist'}))) {
6343: my ($newval,$newnotify);
6344: if (exists($changes{'internal.selfenroll_notifylist'})) {
6345: $newnotify = $changes{'internal.selfenroll_notifylist'};
6346: } else {
6347: $newnotify = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_notifylist'};
6348: }
6349: if ($changes{'internal.selfenroll_approval'}) {
6350: $newval = &mt('Yes');
6351: } elsif ($changes{'internal.selfenroll_approval'} eq '0') {
6352: $newval = &mt('No');
6353: } else {
6354: my $currapproval =
6355: $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'};
6356: if ($currapproval) {
6357: $newval = &mt('Yes');
6358: } else {
6359: $newval = &mt('No');
6360: }
6361: }
6362: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval));
6363: if ($newnotify) {
1.277 raeburn 6364: $r->print('<br />'.&mt('The following will be notified when an enrollment request needs approval, or has been approved: [_1].',$newnotify));
1.276 raeburn 6365: } else {
1.277 raeburn 6366: $r->print('<br />'.&mt('No notifications sent when an enrollment request needs approval, or has been approved.'));
1.276 raeburn 6367: }
6368: $r->print('</li>'."\n");
6369: }
1.237 raeburn 6370: } else {
6371: if (exists($changes{'internal.selfenroll_'.$item})) {
1.241 raeburn 6372: my $newval = $changes{'internal.selfenroll_'.$item};
6373: if ($item eq 'types') {
6374: if ($newval eq '') {
6375: $newval = &mt('None');
6376: } elsif ($newval eq '*') {
6377: $newval = &mt('Any user in any domain');
6378: }
1.245 raeburn 6379: } elsif ($item eq 'registered') {
6380: if ($newval eq '1') {
6381: $newval = &mt('Yes');
6382: } elsif ($newval eq '0') {
6383: $newval = &mt('No');
6384: }
1.241 raeburn 6385: }
1.244 bisitz 6386: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
1.237 raeburn 6387: }
6388: }
6389: }
6390: $r->print('</ul>');
6391: my %newenvhash;
6392: foreach my $key (keys(%changes)) {
6393: $newenvhash{'course.'.$env{'request.course.id'}.'.'.$key} = $changes{$key};
6394: }
1.238 raeburn 6395: &Apache::lonnet::appenv(\%newenvhash);
1.237 raeburn 6396: } else {
6397: $r->print(&mt('An error occurred when saving changes to self-enrollment settings in this course.').'<br />'.&mt('The error was: [_1].',$putresult));
6398: }
6399: } else {
1.249 raeburn 6400: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.237 raeburn 6401: }
6402: } else {
1.249 raeburn 6403: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.241 raeburn 6404: }
1.256 raeburn 6405: my ($visible,$cansetvis,$vismsgs,$visactions) = &visible_in_cat($cdom,$cnum);
6406: if (ref($visactions) eq 'HASH') {
6407: if (!$visible) {
6408: $r->print('<br />'.$visactions->{'miss'}.'<br />'.$visactions->{'yous'}.
6409: '<br />');
6410: if (ref($vismsgs) eq 'ARRAY') {
6411: $r->print('<br />'.$visactions->{'take'}.'<ul>');
6412: foreach my $item (@{$vismsgs}) {
6413: $r->print('<li>'.$visactions->{$item}.'</li>');
6414: }
6415: $r->print('</ul>');
6416: }
6417: $r->print($cansetvis);
6418: }
6419: }
1.237 raeburn 6420: return;
6421: }
6422:
6423: sub get_selfenroll_titles {
1.276 raeburn 6424: my @row = ('types','registered','enroll_dates','access_dates','section',
6425: 'approval','limit');
1.237 raeburn 6426: my %lt = &Apache::lonlocal::texthash (
6427: types => 'Users allowed to self-enroll in this course',
1.245 raeburn 6428: registered => 'Restrict self-enrollment to students officially registered for the course',
1.237 raeburn 6429: enroll_dates => 'Dates self-enrollment available',
1.256 raeburn 6430: access_dates => 'Course access dates assigned to self-enrolling users',
6431: section => 'Section assigned to self-enrolling users',
1.276 raeburn 6432: approval => 'Self-enrollment requests need approval?',
6433: limit => 'Enrollment limit',
1.237 raeburn 6434: );
6435: return (\@row,\%lt);
6436: }
6437:
1.295.2.26 raeburn 6438: sub is_courseowner {
6439: my ($thiscourse,$courseowner) = @_;
6440: if ($courseowner eq '') {
6441: if ($env{'request.course.id'} eq $thiscourse) {
6442: $courseowner = $env{'course.'.$env{'request.course.id'}.'.internal.courseowner'};
6443: }
6444: }
6445: if ($courseowner ne '') {
6446: if ($courseowner eq $env{'user.name'}.':'.$env{'user.domain'}) {
6447: return 1;
6448: }
6449: }
6450: return;
6451: }
6452:
1.27 matthew 6453: #---------------------------------------------- end functions for &phase_two
1.29 matthew 6454:
6455: #--------------------------------- functions for &phase_two and &phase_three
6456:
6457: #--------------------------end of functions for &phase_two and &phase_three
1.1 www 6458:
6459: 1;
6460: __END__
1.2 www 6461:
6462:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>