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