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