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