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