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