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