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